ReactOS 0.4.17-dev-934-g091855f
jsproxy.c
Go to the documentation of this file.
1/*
2 * Copyright 2016 Hans Leidekker for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19#include <stdarg.h>
20#include <stdlib.h>
21#include <windef.h>
22#include <winbase.h>
23#include <wininet.h>
24
25#include "wine/test.h"
26
28
29static BOOL (WINAPI *pInternetInitializeAutoProxyDll)
31static BOOL (WINAPI *pInternetDeInitializeAutoProxyDll)(LPSTR, DWORD);
32static BOOL (WINAPI *pInternetGetProxyInfo)(LPCSTR, DWORD, LPSTR, DWORD, LPSTR *, LPDWORD);
33
35{
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";
42 DWORD err, len;
43 BOOL ret;
44
45 buf.dwStructSize = sizeof(buf);
46 buf.lpszScriptBuffer = script;
47 buf.dwScriptBufferSize = 0;
48 SetLastError( 0xdeadbeef );
49 ret = pInternetInitializeAutoProxyDll( 0, NULL, NULL, NULL, &buf );
50 err = GetLastError();
51 ok( !ret, "unexpected success\n" );
52 if (!ret && err == 0xdeadbeef)
53 {
54 win_skip("InternetInitializeAutoProxyDll() is not supported on Windows 11\n");
55 return;
56 }
57 ok( err == ERROR_INVALID_PARAMETER, "got %lu\n", err );
58
59 buf.dwScriptBufferSize = strlen(script) + 1;
60 ret = pInternetInitializeAutoProxyDll( 0, NULL, NULL, NULL, &buf );
61 ok( ret, "got %lu\n", GetLastError() );
62
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 );
68
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() );
73
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 );
79
80 buf.dwScriptBufferSize = strlen(script2) + 2;
81 ret = pInternetInitializeAutoProxyDll( 0, NULL, NULL, NULL, &buf );
82 ok( ret, "got %lu\n", GetLastError() );
83
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 );
89
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() );
94
95 buf.dwScriptBufferSize = 1;
96 script3[0] = 0;
97 ret = pInternetInitializeAutoProxyDll( 0, NULL, NULL, NULL, &buf );
98 ok( ret, "got %lu\n", GetLastError() );
99
100 ret = pInternetDeInitializeAutoProxyDll( NULL, 0 );
101 ok( ret, "got %lu\n", GetLastError() );
102}
103
105{
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";
112 DWORD len, err;
113 BOOL ret;
114
115 SetLastError( 0xdeadbeef );
116 ret = pInternetGetProxyInfo( url, strlen(url), host, strlen(host), &proxy, &len );
117 err = GetLastError();
118 if (!ret && err == 0xdeadbeef)
119 {
120 win_skip("InternetGetProxyInfo() is not supported on Windows 11\n");
121 return;
122 }
123 ok( !ret, "unexpected success\n" );
124 ok( err == ERROR_CAN_NOT_COMPLETE, "got %lu\n", err );
125
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() );
131
132 len = 0;
133 proxy = NULL;
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 );
138 GlobalFree( proxy );
139
140 len = 0;
141 proxy = NULL;
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 );
146 GlobalFree( proxy );
147
148 len = 0;
149 proxy = NULL;
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 );
154 GlobalFree( proxy );
155
156 len = 0;
157 proxy = NULL;
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 );
162 GlobalFree( proxy );
163
164 len = 0;
165 proxy = NULL;
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 );
170 GlobalFree( proxy );
171
172 ret = pInternetDeInitializeAutoProxyDll( NULL, 0 );
173 ok( ret, "got %lu\n", GetLastError() );
174}
175
177{
178 HMODULE module = LoadLibraryA( "jsproxy.dll" );
179 pInternetInitializeAutoProxyDll = (void *)GetProcAddress( module, "InternetInitializeAutoProxyDll" );
180 pInternetDeInitializeAutoProxyDll = (void *)GetProcAddress( module, "InternetDeInitializeAutoProxyDll" );
181 pInternetGetProxyInfo = (void *)GetProcAddress( module, "InternetGetProxyInfo" );
182
183 if (!pInternetInitializeAutoProxyDll)
184 {
185 win_skip( "InternetInitializeAutoProxyDll not available\n" );
186 return;
187 }
188
189 old_jsproxy = !GetProcAddress( module, "InternetGetProxyInfoEx" );
190 if (old_jsproxy)
191 trace( "InternetGetProxyInfoEx not available\n" );
192
195}
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define broken(x)
Definition: atltest.h:178
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define GetProcAddress(x, y)
Definition: compat.h:753
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
return ret
Definition: mutex.c:147
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
int proxy
Definition: main.c:67
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
static void test_InternetGetProxyInfo(void)
Definition: jsproxy.c:104
static LPSTR
Definition: jsproxy.c:30
static LPSTR LPDWORD
Definition: jsproxy.c:32
static BOOL old_jsproxy
Definition: jsproxy.c:27
static AutoProxyHelperFunctions AUTO_PROXY_SCRIPT_BUFFER *static DWORD
Definition: jsproxy.c:31
static void test_InternetInitializeAutoProxyDll(void)
Definition: jsproxy.c:34
#define win_skip
Definition: minitest.h:67
static const WCHAR url[]
Definition: encode.c:1384
script
Definition: msipriv.h:396
#define BOOL
Definition: nt_native.h:43
#define err(...)
Definition: txthost.c:37
const char * LPCSTR
Definition: typedefs.h:52
char * LPSTR
Definition: typedefs.h:51
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WINAPI
Definition: msvc.h:6
#define ERROR_CAN_NOT_COMPLETE
Definition: winerror.h:906