2 * Copyright 2016 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
27 static BOOL old_jsproxy
;
29 static BOOL (WINAPI
*pInternetInitializeAutoProxyDll
)
30 (DWORD
, LPSTR
, LPSTR
, AutoProxyHelperFunctions
*, AUTO_PROXY_SCRIPT_BUFFER
*);
31 static BOOL (WINAPI
*pInternetDeInitializeAutoProxyDll
)(LPSTR
, DWORD
);
32 static BOOL (WINAPI
*pInternetGetProxyInfo
)(LPCSTR
, DWORD
, LPSTR
, DWORD
, LPSTR
*, LPDWORD
);
34 static void test_InternetInitializeAutoProxyDll(void)
36 const char url
[] = "http://localhost";
37 char script
[] = "function FindProxyForURL(url, host) {return \"DIRECT\";}\0test";
38 char script2
[] = "function FindProxyForURL(url, host) {return \"PROXY 10.0.0.1:8080\";}\0test";
39 char script3
[] = "function FindProxyForURL(url, host) {return \"DIRECT\";}";
40 char *proxy
, host
[] = "localhost";
41 AUTO_PROXY_SCRIPT_BUFFER buf
;
45 buf
.dwStructSize
= sizeof(buf
);
46 buf
.lpszScriptBuffer
= script
;
47 buf
.dwScriptBufferSize
= 0;
48 SetLastError( 0xdeadbeef );
49 ret
= pInternetInitializeAutoProxyDll( 0, NULL
, NULL
, NULL
, &buf
);
51 ok( !ret
, "unexpected success\n" );
52 if (!ret
&& err
== 0xdeadbeef)
54 win_skip("InternetInitializeAutoProxyDll() is not supported on Windows 11\n");
57 ok( err
== ERROR_INVALID_PARAMETER
, "got %lu\n", err
);
59 buf
.dwScriptBufferSize
= strlen(script
) + 1;
60 ret
= pInternetInitializeAutoProxyDll( 0, NULL
, NULL
, NULL
, &buf
);
61 ok( ret
, "got %lu\n", GetLastError() );
63 ret
= pInternetGetProxyInfo( url
, strlen(url
), host
, strlen(host
), &proxy
, &len
);
64 ok( ret
, "got %lu\n", GetLastError() );
65 ok( !strcmp( proxy
, "DIRECT" ), "got \"%s\"\n", proxy
);
66 ok( len
== strlen(proxy
) + 1, "got len=%ld for \"%s\"\n", len
, proxy
);
69 buf
.dwScriptBufferSize
= strlen(script2
) + 1;
70 buf
.lpszScriptBuffer
= script2
;
71 ret
= pInternetInitializeAutoProxyDll( 0, NULL
, NULL
, NULL
, &buf
);
72 ok( ret
, "got %lu\n", GetLastError() );
74 ret
= pInternetGetProxyInfo( url
, strlen(url
), host
, strlen(host
), &proxy
, &len
);
75 ok( ret
, "got %lu\n", GetLastError() );
76 ok( !strcmp( proxy
, "PROXY 10.0.0.1:8080" ), "got \"%s\"\n", proxy
);
77 ok( len
== strlen(proxy
) + 1, "got len=%ld for \"%s\"\n", len
, proxy
);
80 buf
.dwScriptBufferSize
= strlen(script2
) + 2;
81 ret
= pInternetInitializeAutoProxyDll( 0, NULL
, NULL
, NULL
, &buf
);
82 ok( ret
, "got %lu\n", GetLastError() );
84 ret
= pInternetGetProxyInfo( url
, strlen(url
), host
, strlen(host
), &proxy
, &len
);
85 ok( ret
, "got %lu\n", GetLastError() );
86 ok( !strcmp( proxy
, "PROXY 10.0.0.1:8080" ), "got \"%s\"\n", proxy
);
87 ok( len
== strlen(proxy
) + 1, "got len=%ld for \"%s\"\n", len
, proxy
);
90 buf
.lpszScriptBuffer
= script3
;
91 buf
.dwScriptBufferSize
= strlen(script3
);
92 ret
= pInternetInitializeAutoProxyDll( 0, NULL
, NULL
, NULL
, &buf
);
93 ok( ret
|| broken(old_jsproxy
&& !ret
), "got %lu\n", GetLastError() );
95 buf
.dwScriptBufferSize
= 1;
97 ret
= pInternetInitializeAutoProxyDll( 0, NULL
, NULL
, NULL
, &buf
);
98 ok( ret
, "got %lu\n", GetLastError() );
100 ret
= pInternetDeInitializeAutoProxyDll( NULL
, 0 );
101 ok( ret
, "got %lu\n", GetLastError() );
104 static void test_InternetGetProxyInfo(void)
106 const char url
[] = "http://localhost";
107 char script
[] = "function FindProxyForURL(url, host) { "
108 "if (url.substring(0, 4) === 'test') return url + ' ' + host; "
109 "return \"DIRECT\"; }";
110 char *proxy
, host
[] = "localhost";
111 AUTO_PROXY_SCRIPT_BUFFER buf
;
115 SetLastError( 0xdeadbeef );
116 ret
= pInternetGetProxyInfo( url
, strlen(url
), host
, strlen(host
), &proxy
, &len
);
117 err
= GetLastError();
118 if (!ret
&& err
== 0xdeadbeef)
120 win_skip("InternetGetProxyInfo() is not supported on Windows 11\n");
123 ok( !ret
, "unexpected success\n" );
124 ok( err
== ERROR_CAN_NOT_COMPLETE
, "got %lu\n", err
);
126 buf
.dwStructSize
= sizeof(buf
);
127 buf
.lpszScriptBuffer
= script
;
128 buf
.dwScriptBufferSize
= strlen(script
) + 1;
129 ret
= pInternetInitializeAutoProxyDll( 0, NULL
, NULL
, NULL
, &buf
);
130 ok( ret
, "got %lu\n", GetLastError() );
134 ret
= pInternetGetProxyInfo( url
, strlen(url
), host
, strlen(host
), &proxy
, &len
);
135 ok( ret
, "got %lu\n", GetLastError() );
136 ok( !strcmp( proxy
, "DIRECT" ), "got \"%s\"\n", proxy
);
137 ok( len
== strlen("DIRECT") + 1, "got %lu\n", len
);
142 ret
= pInternetGetProxyInfo( url
, strlen(url
) + 1, host
, strlen(host
), &proxy
, &len
);
143 ok( ret
, "got %lu\n", GetLastError() );
144 ok( !strcmp( proxy
, "DIRECT" ), "got \"%s\"\n", proxy
);
145 ok( len
== strlen("DIRECT") + 1, "got %lu\n", len
);
150 ret
= pInternetGetProxyInfo( url
, strlen(url
) - 1, host
, strlen(host
), &proxy
, &len
);
151 ok( ret
, "got %lu\n", GetLastError() );
152 ok( !strcmp( proxy
, "DIRECT" ), "got \"%s\"\n", proxy
);
153 ok( len
== strlen("DIRECT") + 1, "got %lu\n", len
);
158 ret
= pInternetGetProxyInfo( url
, strlen(url
), host
, strlen(host
) + 1, &proxy
, &len
);
159 ok( ret
, "got %lu\n", GetLastError() );
160 ok( !strcmp( proxy
, "DIRECT" ), "got \"%s\"\n", proxy
);
161 ok( len
== strlen("DIRECT") + 1, "got %lu\n", len
);
166 ret
= pInternetGetProxyInfo( "testa", 4, host
, 4, &proxy
, &len
);
167 ok( ret
, "got %lu\n", GetLastError() );
168 ok( !strcmp( proxy
, "test loca" ), "got \"%s\"\n", proxy
);
169 ok( len
== 10, "got %lu\n", len
);
172 ret
= pInternetDeInitializeAutoProxyDll( NULL
, 0 );
173 ok( ret
, "got %lu\n", GetLastError() );
178 HMODULE module
= LoadLibraryA( "jsproxy.dll" );
179 pInternetInitializeAutoProxyDll
= (void *)GetProcAddress( module
, "InternetInitializeAutoProxyDll" );
180 pInternetDeInitializeAutoProxyDll
= (void *)GetProcAddress( module
, "InternetDeInitializeAutoProxyDll" );
181 pInternetGetProxyInfo
= (void *)GetProcAddress( module
, "InternetGetProxyInfo" );
183 if (!pInternetInitializeAutoProxyDll
)
185 win_skip( "InternetInitializeAutoProxyDll not available\n" );
189 old_jsproxy
= !GetProcAddress( module
, "InternetGetProxyInfoEx" );
191 trace( "InternetGetProxyInfoEx not available\n" );
193 test_InternetInitializeAutoProxyDll();
194 test_InternetGetProxyInfo();