urlmon: Improved MapUrlToZone{Ex2} and GetSecurityId support.
[wine] / dlls / urlmon / tests / sec_mgr.c
1 /*
2  * Copyright 2005-2006 Jacek Caban for CodeWeavers
3  * Copyright 2009-2011 Detlef Riekenberg
4  * Copyright 2011 Thomas Mullaly for CodeWeavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #define COBJMACROS
22 #define CONST_VTABLE
23 #define NONAMELESSUNION
24
25 /* needed for IInternetZoneManagerEx2 */
26 #define _WIN32_IE 0x0700
27
28 #include <wine/test.h>
29 #include <stdarg.h>
30 #include <stddef.h>
31 #include <stdio.h>
32
33 #include "windef.h"
34 #include "winbase.h"
35 #include "ole2.h"
36 #include "urlmon.h"
37
38 #include "initguid.h"
39
40 #define URLZONE_CUSTOM  URLZONE_USER_MIN+1
41 #define URLZONE_CUSTOM2 URLZONE_CUSTOM+1
42
43 #define DEFINE_EXPECT(func) \
44     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
45
46 #define SET_EXPECT(func) \
47     expect_ ## func = TRUE
48
49 #define CHECK_EXPECT(func) \
50     do { \
51         ok(expect_ ##func, "unexpected call " #func "\n"); \
52         expect_ ## func = FALSE; \
53         called_ ## func = TRUE; \
54     }while(0)
55
56 #define CHECK_EXPECT2(func) \
57     do { \
58         ok(expect_ ##func, "unexpected call " #func "\n"); \
59         called_ ## func = TRUE; \
60     }while(0)
61
62 #define CHECK_CALLED(func) \
63     do { \
64         ok(called_ ## func, "expected " #func "\n"); \
65         expect_ ## func = called_ ## func = FALSE; \
66     }while(0)
67
68 DEFINE_EXPECT(ParseUrl_SECURITY_URL_input);
69 DEFINE_EXPECT(ParseUrl_SECURITY_URL_input2);
70 DEFINE_EXPECT(ParseUrl_SECURITY_URL_expected);
71 DEFINE_EXPECT(ParseUrl_SECURITY_URL_http);
72 DEFINE_EXPECT(ParseUrl_SECURITY_DOMAIN_expected);
73 DEFINE_EXPECT(ProcessUrlAction);
74
75 static HRESULT (WINAPI *pCoInternetCreateSecurityManager)(IServiceProvider *, IInternetSecurityManager**, DWORD);
76 static HRESULT (WINAPI *pCoInternetCreateZoneManager)(IServiceProvider *, IInternetZoneManager**, DWORD);
77 static HRESULT (WINAPI *pCoInternetGetSecurityUrl)(LPCWSTR, LPWSTR*, PSUACTION, DWORD);
78 static HRESULT (WINAPI *pCoInternetGetSecurityUrlEx)(IUri*, IUri**, PSUACTION, DWORD_PTR);
79 static HRESULT (WINAPI *pCreateUri)(LPCWSTR, DWORD, DWORD_PTR, IUri**);
80 static HRESULT (WINAPI *pCoInternetGetSession)(DWORD, IInternetSession**, DWORD);
81 static HRESULT (WINAPI *pCoInternetIsFeatureEnabled)(INTERNETFEATURELIST, DWORD);
82 static HRESULT (WINAPI *pCoInternetIsFeatureEnabledForUrl)(INTERNETFEATURELIST, DWORD, LPCWSTR, IInternetSecurityManager*);
83 static HRESULT (WINAPI *pCoInternetIsFeatureZoneElevationEnabled)(LPCWSTR, LPCWSTR, IInternetSecurityManager*, DWORD);
84
85 static const WCHAR url1[] = {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',
86         '/','b','l','a','n','k','.','h','t','m',0};
87 static const WCHAR url2[] = {'i','n','d','e','x','.','h','t','m',0};
88 static const WCHAR url3[] = {'f','i','l','e',':','/','/','c',':','\\','I','n','d','e','x','.','h','t','m',0};
89 static const WCHAR url4[] = {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e',
90         '%','2','e','j','p','g',0};
91 static const WCHAR url5[] = {'h','t','t','p',':','/','/','w','w','w','.','z','o','n','e','3',
92         '.','w','i','n','e','t','e','s','t',0};
93 static const WCHAR url6[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
94 static const WCHAR url7[] = {'f','t','p',':','/','/','z','o','n','e','3',
95         '.','w','i','n','e','t','e','s','t','/','f','i','l','e','.','t','e','s','t',0};
96 static const WCHAR url8[] = {'t','e','s','t',':','1','2','3','a','b','c',0};
97 static const WCHAR url9[] = {'h','t','t','p',':','/','/','w','w','w','.','z','o','n','e','3',
98         '.','w','i','n','e','t','e','s','t', '/','s','i','t','e','/','a','b','o','u','t',0};
99 static const WCHAR url10[] = {'f','i','l','e',':','/','/','s','o','m','e','%','2','0','f','i','l','e',
100         '.','j','p','g',0};
101 static const WCHAR url11[] = {'f','i','l','e',':','/','/','c',':','/','I','n','d','e','x','.','h','t','m',0};
102 static const WCHAR url12[] = {'f','i','l','e',':','/','/','/','c',':','/','I','n','d','e','x','.','h','t','m',0};
103 static const WCHAR url13[] = {'h','t','t','p',':','g','o','o','g','l','e','.','c','o','m',0};
104 static const WCHAR url14[] = {'z','i','p',':','t','e','s','t','i','n','g','.','c','o','m','/','t','e','s','t','i','n','g',0};
105
106 static const WCHAR url4e[] = {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e',
107         '.','j','p','g',0};
108
109 static const WCHAR winetestW[] = {'w','i','n','e','t','e','s','t',0};
110 static const WCHAR security_urlW[] = {'w','i','n','e','t','e','s','t',':','t','e','s','t','i','n','g',0};
111 static const WCHAR security_url2W[] = {'w','i','n','e','t','e','s','t',':','t','e','s','t','i','n','g','2',0};
112 static const WCHAR security_expectedW[] = {'w','i','n','e','t','e','s','t',':','z','i','p',0};
113 static const WCHAR winetest_to_httpW[] = {'w','i','n','e','t','e','s','t',':','h',0};
114
115 static const char *szZoneMapDomainsKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains";
116 static const char *szInternetSettingsKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
117
118 static const BYTE secid1[] = {'f','i','l','e',':',0,0,0,0};
119 static const BYTE secid5[] = {'h','t','t','p',':','w','w','w','.','z','o','n','e','3',
120         '.','w','i','n','e','t','e','s','t',3,0,0,0};
121 static const BYTE secid6[] = {'a','b','o','u','t',':','b','l','a','n','k',3,0,0,0};
122 static const BYTE secid7[] = {'f','t','p',':','z','o','n','e','3',
123         '.','w','i','n','e','t','e','s','t',3,0,0,0};
124 static const BYTE secid10[] =
125     {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e','.','j','p','g',3,0,0,0};
126 static const BYTE secid14[] =
127     {'z','i','p',':','t','e','s','t','i','n','g','.','c','o','m','/','t','e','s','t','i','n','g',3,0,0,0};
128 static const BYTE secid10_2[] =
129     {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e','.','j','p','g',3,0,0,0};
130
131 static const GUID CLSID_TestActiveX =
132     {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
133
134 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
135 const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
136     {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
137
138 static int called_securl_http;
139 static DWORD ProcessUrlAction_policy;
140
141 static struct secmgr_test {
142     LPCWSTR url;
143     DWORD zone;
144     HRESULT zone_hres;
145     DWORD secid_size;
146     const BYTE *secid;
147     HRESULT secid_hres;
148 } secmgr_tests[] = {
149     {url1, 0,   S_OK, sizeof(secid1), secid1, S_OK},
150     {url2, 100, 0x80041001, 0, NULL, E_INVALIDARG},
151     {url3, 0,   S_OK, sizeof(secid1), secid1, S_OK},
152     {url5, 3,   S_OK, sizeof(secid5), secid5, S_OK},
153     {url6, 3,   S_OK, sizeof(secid6), secid6, S_OK},
154     {url7, 3,   S_OK, sizeof(secid7), secid7, S_OK},
155     {url11,0,   S_OK, sizeof(secid1), secid1, S_OK},
156     {url12,0,   S_OK, sizeof(secid1), secid1, S_OK}
157 };
158
159 static int strcmp_w(const WCHAR *str1, const WCHAR *str2)
160 {
161     DWORD len1 = lstrlenW(str1);
162     DWORD len2 = lstrlenW(str2);
163
164     if(len1!=len2) return 1;
165     return memcmp(str1, str2, len1*sizeof(WCHAR));
166 }
167
168 static inline void heap_free(void *mem)
169 {
170     HeapFree(GetProcessHeap(), 0, mem);
171 }
172
173 static inline LPWSTR a2w(LPCSTR str)
174 {
175     LPWSTR ret = NULL;
176
177     if(str) {
178         DWORD len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
179         ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
180         MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
181     }
182
183     return ret;
184 }
185
186 static inline DWORD strcmp_aw(LPCSTR strA, LPCWSTR strB) {
187     LPWSTR strAW = a2w(strA);
188     DWORD ret = lstrcmpW(strAW, strB);
189     heap_free(strAW);
190     return ret;
191 }
192
193
194 /* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
195 static LONG myRegDeleteTreeA(HKEY hKey, LPCSTR lpszSubKey)
196 {
197     LONG ret;
198     DWORD dwMaxSubkeyLen, dwMaxValueLen;
199     DWORD dwMaxLen, dwSize;
200     CHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
201     HKEY hSubKey = hKey;
202
203     if(lpszSubKey)
204     {
205         ret = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
206         if (ret) return ret;
207     }
208
209     /* Get highest length for keys, values */
210     ret = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, NULL,
211             &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
212     if (ret) goto cleanup;
213
214     dwMaxSubkeyLen++;
215     dwMaxValueLen++;
216     dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
217     if (dwMaxLen > sizeof(szNameBuf)/sizeof(CHAR))
218     {
219         /* Name too big: alloc a buffer for it */
220         if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(CHAR))))
221         {
222             ret = ERROR_NOT_ENOUGH_MEMORY;
223             goto cleanup;
224         }
225     }
226
227     /* Recursively delete all the subkeys */
228     while (TRUE)
229     {
230         dwSize = dwMaxLen;
231         if (RegEnumKeyExA(hSubKey, 0, lpszName, &dwSize, NULL,
232                           NULL, NULL, NULL)) break;
233
234         ret = myRegDeleteTreeA(hSubKey, lpszName);
235         if (ret) goto cleanup;
236     }
237
238     if (lpszSubKey)
239         ret = RegDeleteKeyA(hKey, lpszSubKey);
240     else
241         while (TRUE)
242         {
243             dwSize = dwMaxLen;
244             if (RegEnumValueA(hKey, 0, lpszName, &dwSize,
245                   NULL, NULL, NULL, NULL)) break;
246
247             ret = RegDeleteValueA(hKey, lpszName);
248             if (ret) goto cleanup;
249         }
250
251 cleanup:
252     /* Free buffer if allocated */
253     if (lpszName != szNameBuf)
254         heap_free(lpszName);
255     if(lpszSubKey)
256         RegCloseKey(hSubKey);
257     return ret;
258 }
259
260 static HRESULT WINAPI SecurityManager_QueryInterface(IInternetSecurityManager* This,
261         REFIID riid, void **ppvObject)
262 {
263     ok(0, "unexpected call\n");
264     return E_NOTIMPL;
265 }
266
267 static ULONG WINAPI SecurityManager_AddRef(IInternetSecurityManager* This)
268 {
269     return 2;
270 }
271
272 static ULONG WINAPI SecurityManager_Release(IInternetSecurityManager* This)
273 {
274     return 1;
275 }
276
277 static HRESULT WINAPI SecurityManager_SetSecuritySite(IInternetSecurityManager* This,
278         IInternetSecurityMgrSite *pSite)
279 {
280     ok(0, "unexpected call\n");
281     return E_NOTIMPL;
282 }
283
284 static HRESULT WINAPI SecurityManager_GetSecuritySite(IInternetSecurityManager* This,
285         IInternetSecurityMgrSite **ppSite)
286 {
287     ok(0, "unexpected call\n");
288     return E_NOTIMPL;
289 }
290
291 static HRESULT WINAPI SecurityManager_MapUrlToZone(IInternetSecurityManager* This,
292         LPCWSTR pwszUrl, DWORD *pdwZone, DWORD dwFlags)
293 {
294     ok(0, "unexpected call\n");
295     return E_NOTIMPL;
296 }
297
298 static HRESULT WINAPI SecurityManager_GetSecurityId(IInternetSecurityManager* This,
299         LPCWSTR pwszUrl, BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
300 {
301     ok(0, "unexpected call\n");
302     return E_NOTIMPL;
303 }
304
305 static HRESULT WINAPI SecurityManager_ProcessUrlAction(IInternetSecurityManager* This,
306         LPCWSTR pwszUrl, DWORD dwAction, BYTE *pPolicy, DWORD cbPolicy,
307         BYTE *pContext, DWORD cbContext, DWORD dwFlags, DWORD dwReserved)
308 {
309     CHECK_EXPECT(ProcessUrlAction);
310     ok(dwAction == URLACTION_FEATURE_ZONE_ELEVATION, "dwAction = %x\n", dwAction);
311     ok(cbPolicy == sizeof(DWORD), "cbPolicy = %d\n", cbPolicy);
312     ok(!pContext, "pContext != NULL\n");
313     ok(dwFlags == PUAF_NOUI, "dwFlags = %x\n", dwFlags);
314     ok(dwReserved == 0, "dwReserved = %x\n", dwReserved);
315
316     *pPolicy = ProcessUrlAction_policy;
317     return ProcessUrlAction_policy==URLPOLICY_ALLOW ? S_OK : S_FALSE;
318 }
319
320 static HRESULT WINAPI SecurityManager_QueryCustomPolicy(IInternetSecurityManager* This,
321         LPCWSTR pwszUrl, REFGUID guidKey, BYTE **ppPolicy, DWORD *pcbPolicy,
322         BYTE *pContext, DWORD cbContext, DWORD dwReserved)
323 {
324     ok(0, "unexpected call\n");
325     return E_NOTIMPL;
326 }
327
328 static HRESULT WINAPI SecurityManager_SetZoneMapping(IInternetSecurityManager* This,
329         DWORD dwZone, LPCWSTR lpszPattern, DWORD dwFlags)
330 {
331     ok(0, "unexpected call\n");
332     return E_NOTIMPL;
333 }
334
335 static HRESULT WINAPI SecurityManager_GetZoneMappings(IInternetSecurityManager* This,
336         DWORD dwZone, IEnumString **ppenumString, DWORD dwFlags)
337 {
338     ok(0, "unexpected call\n");
339     return E_NOTIMPL;
340 }
341
342 static const IInternetSecurityManagerVtbl SecurityManagerVtbl = {
343     SecurityManager_QueryInterface,
344     SecurityManager_AddRef,
345     SecurityManager_Release,
346     SecurityManager_SetSecuritySite,
347     SecurityManager_GetSecuritySite,
348     SecurityManager_MapUrlToZone,
349     SecurityManager_GetSecurityId,
350     SecurityManager_ProcessUrlAction,
351     SecurityManager_QueryCustomPolicy,
352     SecurityManager_SetZoneMapping,
353     SecurityManager_GetZoneMappings
354 };
355
356 static IInternetSecurityManager security_manager = { &SecurityManagerVtbl };
357
358 static void test_SecurityManager(void)
359 {
360     int i;
361     IInternetSecurityManager *secmgr = NULL;
362     BYTE buf[512];
363     DWORD zone, size, policy;
364     HRESULT hres;
365
366     if(!pCoInternetCreateSecurityManager) {
367         return;
368     }
369
370     trace("Testing security manager...\n");
371
372     hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
373     ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
374     if(FAILED(hres))
375         return;
376
377     for(i=0; i < sizeof(secmgr_tests)/sizeof(secmgr_tests[0]); i++) {
378         zone = 100;
379         hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url,
380                                                      &zone, 0);
381         ok(hres == secmgr_tests[i].zone_hres /* IE <=6 */
382            || (FAILED(secmgr_tests[i].zone_hres) && hres == E_INVALIDARG), /* IE7 */
383            "[%d] MapUrlToZone failed: %08x, expected %08x\n",
384                 i, hres, secmgr_tests[i].zone_hres);
385         if(SUCCEEDED(hres))
386             ok(zone == secmgr_tests[i].zone, "[%d] zone=%d, expected %d\n", i, zone,
387                secmgr_tests[i].zone);
388         else
389             ok(zone == secmgr_tests[i].zone || zone == -1, "[%d] zone=%d\n", i, zone);
390
391         size = sizeof(buf);
392         memset(buf, 0xf0, sizeof(buf));
393         hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[i].url,
394                 buf, &size, 0);
395         ok(hres == secmgr_tests[i].secid_hres,
396            "[%d] GetSecurityId failed: %08x, expected %08x\n",
397            i, hres, secmgr_tests[i].secid_hres);
398         if(secmgr_tests[i].secid) {
399             ok(size == secmgr_tests[i].secid_size, "[%d] size=%d, expected %d\n",
400                     i, size, secmgr_tests[i].secid_size);
401             ok(!memcmp(buf, secmgr_tests[i].secid, size), "[%d] wrong secid\n", i);
402         }
403     }
404
405     zone = 100;
406     hres = IInternetSecurityManager_MapUrlToZone(secmgr, url10, &zone, 0);
407     ok(hres == S_OK, "MapUrlToZone failed: %08x, expected S_OK\n", hres);
408     ok(zone == 3, "zone=%d, expected 3\n", zone);
409
410     /* win2k3 translates %20 into a space */
411     size = sizeof(buf);
412     memset(buf, 0xf0, sizeof(buf));
413     hres = IInternetSecurityManager_GetSecurityId(secmgr, url10, buf, &size, 0);
414     ok(hres == S_OK, "GetSecurityId failed: %08x, expected S_OK\n", hres);
415     ok(size == sizeof(secid10) ||
416        size == sizeof(secid10_2), /* win2k3 */
417        "size=%d\n", size);
418     ok(!memcmp(buf, secid10, size) ||
419        !memcmp(buf, secid10_2, size), /* win2k3 */
420        "wrong secid\n");
421
422     zone = 100;
423     hres = IInternetSecurityManager_MapUrlToZone(secmgr, url13, &zone, 0);
424     ok(hres == S_OK, "MapUrlToZone failed: %08x\n", hres);
425     ok(zone == URLZONE_INVALID || broken(zone == URLZONE_INTERNET), "zone=%d\n", zone);
426
427     size = sizeof(buf);
428     memset(buf, 0xf0, sizeof(buf));
429     hres = IInternetSecurityManager_GetSecurityId(secmgr, url13, buf, &size, 0);
430     ok(hres == E_INVALIDARG || broken(hres == S_OK), "GetSecurityId failed: %08x\n", hres);
431
432     zone = 100;
433     hres = IInternetSecurityManager_MapUrlToZone(secmgr, url14, &zone, 0);
434     ok(hres == S_OK, "MapUrlToZone failed: %08x, expected S_OK\n", hres);
435     ok(zone == URLZONE_INTERNET, "zone=%d\n", zone);
436
437     size = sizeof(buf);
438     memset(buf, 0xf0, sizeof(buf));
439     hres = IInternetSecurityManager_GetSecurityId(secmgr, url14, buf, &size, 0);
440     ok(hres == S_OK, "GetSecurityId failed: %08x, expected S_OK\n", hres);
441     todo_wine ok(size == sizeof(secid14), "size=%d\n", size);
442     todo_wine ok(!memcmp(buf, secid14, size), "wrong secid\n");
443
444     zone = 100;
445     hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
446     ok(hres == E_INVALIDARG, "MapUrlToZone failed: %08x, expected E_INVALIDARG\n", hres);
447     ok(zone == 100 || zone == -1, "zone=%d\n", zone);
448
449     size = sizeof(buf);
450     hres = IInternetSecurityManager_GetSecurityId(secmgr, NULL, buf, &size, 0);
451     ok(hres == E_INVALIDARG,
452        "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
453     hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
454                                                   NULL, &size, 0);
455     ok(hres == E_INVALIDARG,
456        "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
457     hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
458                                                   buf, NULL, 0);
459     ok(hres == E_INVALIDARG,
460        "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
461
462     hres = IInternetSecurityManager_ProcessUrlAction(secmgr, NULL, URLACTION_SCRIPT_RUN, (BYTE*)&policy,
463             sizeof(WCHAR), NULL, 0, 0, 0);
464     ok(hres == E_INVALIDARG, "ProcessUrlAction failed: %08x, expected E_INVALIDARG\n", hres);
465
466     IInternetSecurityManager_Release(secmgr);
467 }
468
469 /* Check if Internet Explorer is configured to run in "Enhanced Security Configuration" (aka hardened mode) */
470 /* Note: this code is duplicated in dlls/mshtml/tests/mshtml_test.h and dlls/urlmon/tests/sec_mgr.c */
471 static BOOL is_ie_hardened(void)
472 {
473     HKEY zone_map;
474     DWORD ie_harden, type, size;
475
476     ie_harden = 0;
477     if(RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap",
478                     0, KEY_QUERY_VALUE, &zone_map) == ERROR_SUCCESS) {
479         size = sizeof(DWORD);
480         if (RegQueryValueExA(zone_map, "IEHarden", NULL, &type, (LPBYTE) &ie_harden, &size) != ERROR_SUCCESS ||
481             type != REG_DWORD) {
482             ie_harden = 0;
483         }
484         RegCloseKey(zone_map);
485     }
486
487     return ie_harden != 0;
488 }
489
490 static void test_url_action(IInternetSecurityManager *secmgr, IInternetZoneManager *zonemgr, DWORD action)
491 {
492     DWORD res, size, policy, reg_policy;
493     char buf[10];
494     HKEY hkey;
495     HRESULT hres;
496
497     /* FIXME: HKEY_CURRENT_USER is most of the time the default but this can be changed on a system.
498      * The test should be changed to cope with that, if need be.
499      */
500     res = RegOpenKeyA(HKEY_CURRENT_USER,
501             "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3", &hkey);
502     if(res != ERROR_SUCCESS) {
503         ok(0, "Could not open zone key\n");
504         return;
505     }
506
507     wsprintf(buf, "%X", action);
508     size = sizeof(DWORD);
509     res = RegQueryValueExA(hkey, buf, NULL, NULL, (BYTE*)&reg_policy, &size);
510     RegCloseKey(hkey);
511     if(res != ERROR_SUCCESS || size != sizeof(DWORD)) {
512         policy = 0xdeadbeef;
513         hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
514                 sizeof(WCHAR), NULL, 0, 0, 0);
515         ok(hres == E_FAIL || broken(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)),
516             "(0x%x) got 0x%x (expected E_FAIL)\n", action, hres);
517         ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
518
519         policy = 0xdeadbeef;
520         hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, (BYTE*)&policy,
521                 sizeof(DWORD), URLZONEREG_DEFAULT);
522         ok(hres == E_FAIL || broken(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)),
523             "(0x%x) got 0x%x (expected E_FAIL)\n", action, hres);
524         ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
525         return;
526     }
527
528     policy = 0xdeadbeef;
529     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, (BYTE*)&policy,
530             sizeof(DWORD), URLZONEREG_DEFAULT);
531     ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
532     ok(policy == reg_policy, "(%x) policy=%x, expected %x\n", action, policy, reg_policy);
533
534     if(policy != URLPOLICY_QUERY) {
535         if(winetest_interactive || ! is_ie_hardened()) {
536             BOOL expect_parse_call = !called_securl_http;
537
538             policy = 0xdeadbeef;
539             hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
540                     sizeof(WCHAR), NULL, 0, 0, 0);
541             if(reg_policy == URLPOLICY_DISALLOW)
542                 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
543             else
544                 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
545             ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
546
547             policy = 0xdeadbeef;
548             hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
549                     2, NULL, 0, 0, 0);
550             if(reg_policy == URLPOLICY_DISALLOW)
551                 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
552             else
553                 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
554             ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
555
556             policy = 0xdeadbeef;
557             hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
558                     sizeof(DWORD), NULL, 0, 0, 0);
559             if(reg_policy == URLPOLICY_DISALLOW)
560                 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
561             else
562                 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
563             ok(policy == reg_policy, "(%x) policy=%x\n", action, policy);
564
565             policy = 0xdeadbeef;
566             hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
567                     sizeof(WCHAR), (BYTE*)0xdeadbeef, 16, 0, 0);
568             if(reg_policy == URLPOLICY_DISALLOW)
569                 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
570             else
571                 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
572             ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
573
574             policy = 0xdeadbeef;
575             if(expect_parse_call)
576                 SET_EXPECT(ParseUrl_SECURITY_URL_http);
577             hres = IInternetSecurityManager_ProcessUrlAction(secmgr, winetest_to_httpW, action, (BYTE*)&policy,
578                     sizeof(DWORD), NULL, 0, 0, 0);
579             if(expect_parse_call)
580                 CHECK_CALLED(ParseUrl_SECURITY_URL_http);
581             if(reg_policy == URLPOLICY_DISALLOW)
582                 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
583             else
584                 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
585             ok(policy == reg_policy, "(%x) policy=%x\n", action, policy);
586         }else {
587             skip("IE running in Enhanced Security Configuration\n");
588         }
589     }
590 }
591
592 static void test_special_url_action(IInternetSecurityManager *secmgr, IInternetZoneManager *zonemgr, DWORD action)
593 {
594     DWORD policy;
595     HRESULT hres;
596
597     policy = 0xdeadbeef;
598     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, (BYTE*)&policy,
599             sizeof(DWORD), URLZONEREG_DEFAULT);
600     ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
601     ok(policy == URLPOLICY_DISALLOW, "(%x) policy=%x, expected URLPOLICY_DISALLOW\n", action, policy);
602
603     policy = 0xdeadbeef;
604     hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url1, action, (BYTE*)&policy,
605             sizeof(WCHAR), NULL, 0, 0, 0);
606     ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
607
608     policy = 0xdeadbeef;
609     hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url1, action, (BYTE*)&policy,
610             sizeof(DWORD), NULL, 0, 0, 0);
611     ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
612     ok(policy == URLPOLICY_DISALLOW, "policy = %x\n", policy);
613 }
614
615 static void test_activex(IInternetSecurityManager *secmgr)
616 {
617     DWORD policy, policy_size;
618     struct CONFIRMSAFETY cs;
619     BYTE *ppolicy;
620     HRESULT hres;
621
622     policy = 0xdeadbeef;
623     hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url1, URLACTION_ACTIVEX_RUN, (BYTE*)&policy,
624             sizeof(DWORD), (BYTE*)&CLSID_TestActiveX, sizeof(CLSID), 0, 0);
625     ok(hres == S_OK, "ProcessUrlAction(URLACTION_ACTIVEX_RUN) failed: %08x\n", hres);
626     ok(policy == URLPOLICY_ALLOW || policy == URLPOLICY_DISALLOW, "policy = %x\n", policy);
627
628     cs.clsid = CLSID_TestActiveX;
629     cs.pUnk = (IUnknown*)0xdeadbeef;
630     cs.dwFlags = 0;
631     hres = IInternetSecurityManager_QueryCustomPolicy(secmgr, url1, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
632             &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
633     ok(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND), "QueryCusromPolicy failed: %08x\n", hres);
634 }
635
636 static void test_polices(void)
637 {
638     IInternetZoneManager *zonemgr = NULL;
639     IInternetSecurityManager *secmgr = NULL;
640     HRESULT hres;
641
642     trace("testing polices...\n");
643
644     hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
645     ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
646     hres = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
647     ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08x\n", hres);
648
649     test_url_action(secmgr, zonemgr, URLACTION_SCRIPT_RUN);
650     test_url_action(secmgr, zonemgr, URLACTION_ACTIVEX_RUN);
651     test_url_action(secmgr, zonemgr, URLACTION_ACTIVEX_OVERRIDE_OBJECT_SAFETY);
652     test_url_action(secmgr, zonemgr, URLACTION_CHANNEL_SOFTDIST_PERMISSIONS);
653     test_url_action(secmgr, zonemgr, 0xdeadbeef);
654
655     test_special_url_action(secmgr, zonemgr, URLACTION_SCRIPT_OVERRIDE_SAFETY);
656     test_special_url_action(secmgr, zonemgr, URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY);
657
658     test_activex(secmgr);
659
660     IInternetSecurityManager_Release(secmgr);
661     IInternetZoneManager_Release(zonemgr);
662 }
663
664 /* IE (or at least newer versions of it) seem to cache the keys in ZoneMap
665  * when urlmon.dll is loaded and it doesn't seem to update its cache, unless
666  * SetZoneMapping is used.
667  */
668 static void test_zone_domain_cache(void)
669 {
670     HRESULT hres;
671     DWORD res, zone;
672     IInternetSecurityManager *secmgr = NULL;
673     HKEY domains, domain;
674
675     static const WCHAR testing_domain_urlW[] = {'h','t','t','p',':','/','/','t','e','s','t','i','n','g','.',
676             'd','o','m','a','i','n','/',0};
677
678     res = RegOpenKeyA(HKEY_CURRENT_USER, szZoneMapDomainsKey, &domains);
679     ok(res == ERROR_SUCCESS, "RegOpenKey failed: %d\n", res);
680     if(res != ERROR_SUCCESS)
681         return;
682
683     res = RegCreateKeyA(domains, "testing.domain", &domain);
684     ok(res == ERROR_SUCCESS, "RegCreateKey failed: %d\n", res);
685     if(res != ERROR_SUCCESS) {
686         RegCloseKey(domains);
687         return;
688     }
689
690     zone = URLZONE_CUSTOM;
691     res = RegSetValueExA(domain, "http", 0, REG_DWORD, (BYTE*)&zone, sizeof(DWORD));
692     ok(res == ERROR_SUCCESS, "RegSetValueEx failed: %d\n", res);
693
694     RegCloseKey(domain);
695
696     hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
697     ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
698
699     zone = URLZONE_INVALID;
700     hres = IInternetSecurityManager_MapUrlToZone(secmgr, testing_domain_urlW, &zone, 0);
701     ok(hres == S_OK, "MapUrlToZone failed: %08x\n", hres);
702     todo_wine ok(zone == URLZONE_INTERNET, "Got %d, expected URLZONE_INTERNET\n", zone);
703
704     /* FIXME: Play nice with ZoneMaps that existed before the test is run. */
705     res = RegDeleteKeyA(domains, "testing.domain");
706     ok(res == ERROR_SUCCESS, "RegDeleteKey failed: %d\n", res);
707
708     RegCloseKey(domains);
709     IInternetSecurityManager_Release(secmgr);
710 }
711
712 typedef struct {
713     const char  *domain;
714     const char  *subdomain;
715     const char  *scheme;
716     DWORD       zone;
717 } zone_domain_mapping;
718
719 /* FIXME: Move these into SetZoneMapping tests when the day comes... */
720 static const zone_domain_mapping zone_domain_mappings[] = {
721     /* Implicitly means "*.yabadaba.do". */
722     {"yabadaba.do",NULL,"http",URLZONE_CUSTOM},
723     /* The '*' doesn't count as a wildcard, since its not the first component of the subdomain. */
724     {"super.cool","testing.*","ftp",URLZONE_CUSTOM2},
725     /* The '*' counts since it's the first component of the subdomain. */
726     {"super.cool","*.testing","ftp",URLZONE_CUSTOM2},
727     /* All known scheme types apply to wildcard schemes. */
728     {"tests.test",NULL,"*",URLZONE_CUSTOM},
729     /* Due to a defect with how windows checks the mappings, unknown scheme types
730      * never seem to get mapped properly. */
731     {"tests.test",NULL,"zip",URLZONE_CUSTOM},
732     {"www.testing.com",NULL,"http",URLZONE_CUSTOM},
733     {"www.testing.com","testing","http",URLZONE_CUSTOM2},
734     {"org",NULL,"http",URLZONE_CUSTOM},
735     {"org","testing","http",URLZONE_CUSTOM2},
736     {"wine.testing",NULL,"*",URLZONE_CUSTOM2}
737 };
738
739 static void register_zone_domains(void)
740 {
741     HKEY domains;
742     DWORD res, i;
743
744     /* Some Windows versions don't seem to have a "Domains" key in their HKLM. */
745     res = RegOpenKeyA(HKEY_LOCAL_MACHINE, szZoneMapDomainsKey, &domains);
746     ok(res == ERROR_SUCCESS || broken(res == ERROR_FILE_NOT_FOUND), "RegOpenKey failed: %d\n", res);
747     if(res == ERROR_SUCCESS) {
748         HKEY domain;
749         DWORD zone = URLZONE_CUSTOM;
750
751         res = RegCreateKeyA(domains, "local.machine", &domain);
752         ok(res == ERROR_SUCCESS, "RegCreateKey failed: %d\n", res);
753
754         res = RegSetValueExA(domain, "http", 0, REG_DWORD, (BYTE*)&zone, sizeof(DWORD));
755         ok(res == ERROR_SUCCESS, "RegSetValueEx failed: %d\n", res);
756
757         RegCloseKey(domain);
758         RegCloseKey(domains);
759     }
760
761     res = RegOpenKeyA(HKEY_CURRENT_USER, szZoneMapDomainsKey, &domains);
762     ok(res == ERROR_SUCCESS, "RegOpenKey failed: %d\n", res);
763
764     for(i = 0; i < sizeof(zone_domain_mappings)/sizeof(zone_domain_mappings[0]); ++i) {
765         const zone_domain_mapping *test = zone_domain_mappings+i;
766         HKEY domain;
767
768         res = RegCreateKeyA(domains, test->domain, &domain);
769         ok(res == ERROR_SUCCESS, "RegCreateKey failed with %d on test %d\n", res, i);
770
771         /* Only set the value if there's no subdomain. */
772         if(!test->subdomain) {
773             res = RegSetValueExA(domain, test->scheme, 0, REG_DWORD, (BYTE*)&test->zone, sizeof(DWORD));
774             ok(res == ERROR_SUCCESS, "RegSetValueEx failed with %d on test %d\n", res, i);
775         } else {
776             HKEY subdomain;
777
778             res = RegCreateKeyA(domain, test->subdomain, &subdomain);
779             ok(res == ERROR_SUCCESS, "RegCreateKey failed with %d on test %d\n", res, i);
780
781             res = RegSetValueExA(subdomain, test->scheme, 0, REG_DWORD, (BYTE*)&test->zone, sizeof(DWORD));
782             ok(res == ERROR_SUCCESS, "RegSetValueEx failed with %d on test %d\n", res, i);
783
784             RegCloseKey(subdomain);
785         }
786
787         RegCloseKey(domain);
788     }
789
790     RegCloseKey(domains);
791 }
792
793 static void unregister_zone_domains(void)
794 {
795     HKEY domains;
796     DWORD res, i;
797
798     res = RegOpenKeyA(HKEY_LOCAL_MACHINE, szZoneMapDomainsKey, &domains);
799     ok(res == ERROR_SUCCESS || broken(res == ERROR_FILE_NOT_FOUND), "RegOpenKey failed: %d\n", res);
800     if(res == ERROR_SUCCESS) {
801         RegDeleteKeyA(domains, "local.machine");
802         RegCloseKey(domains);
803     }
804
805     res = RegOpenKeyA(HKEY_CURRENT_USER, szZoneMapDomainsKey, &domains);
806     ok(res == ERROR_SUCCESS, "RegOpenKey failed: %d\n", res);
807
808     for(i = 0; i < sizeof(zone_domain_mappings)/sizeof(zone_domain_mappings[0]); ++i) {
809         const zone_domain_mapping *test = zone_domain_mappings+i;
810
811         /* FIXME: Uses the "cludge" approach to remove the test data from the registry!
812          *        Although, if domain names are... unique, this shouldn't cause any harm
813          *        to keys (if any) that existed before the tests.
814          */
815         if(test->subdomain) {
816             HKEY domain;
817
818             res = RegOpenKeyA(domains, test->domain, &domain);
819             if(res == ERROR_SUCCESS) {
820                 RegDeleteKeyA(domain, test->subdomain);
821                 RegCloseKey(domain);
822             }
823         }
824         RegDeleteKeyA(domains, test->domain);
825     }
826
827     RegCloseKey(domains);
828 }
829
830 static void run_child_process(void)
831 {
832     char cmdline[MAX_PATH];
833     char path[MAX_PATH];
834     char **argv;
835     PROCESS_INFORMATION pi;
836     STARTUPINFO si = { 0 };
837     BOOL ret;
838
839     GetModuleFileNameA(NULL, path, MAX_PATH);
840
841     si.cb = sizeof(si);
842     winetest_get_mainargs(&argv);
843     sprintf(cmdline, "\"%s\" %s domain_tests", argv[0], argv[1]);
844     ret = CreateProcess(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
845     ok(ret, "Failed to spawn child process: %u\n", GetLastError());
846     winetest_wait_child_process(pi.hProcess);
847     CloseHandle(pi.hThread);
848     CloseHandle(pi.hProcess);
849 }
850
851 typedef struct {
852     const char  *url;
853     DWORD       zone;
854     BOOL        todo;
855     DWORD       broken_zone;
856 } zone_mapping_test;
857
858 static const zone_mapping_test zone_mapping_tests[] = {
859     /* Tests for "yabadaba.do" zone mappings. */
860     {"http://yabadaba.do/",URLZONE_CUSTOM},
861     {"http://google.yabadaba.do/",URLZONE_CUSTOM},
862     {"zip://yabadaba.do/",URLZONE_INTERNET},
863     /* Tests for "super.cool" zone mappings. */
864     {"ftp://testing.google.super.cool/",URLZONE_INTERNET},
865     {"ftp://testing.*.super.cool/",URLZONE_CUSTOM2},
866     {"ftp://google.testing.super.cool/",URLZONE_CUSTOM2},
867     /* Tests for "tests.test" zone mappings. */
868     {"http://tests.test/",URLZONE_CUSTOM},
869     {"http://www.tests.test/",URLZONE_CUSTOM},
870     {"ftp://tests.test/",URLZONE_CUSTOM},
871     {"ftp://www.tests.test/",URLZONE_CUSTOM},
872     {"test://www.tests.test/",URLZONE_INTERNET},
873     {"test://tests.test/",URLZONE_INTERNET},
874     {"zip://www.tests.test/",URLZONE_INTERNET},
875     {"zip://tests.test/",URLZONE_INTERNET},
876     /* Tests for "www.testing.com" zone mappings. */
877     {"http://google.www.testing.com/",URLZONE_INTERNET},
878     {"http://www.testing.com/",URLZONE_CUSTOM,FALSE,URLZONE_INTERNET},
879     {"http://testing.www.testing.com/",URLZONE_CUSTOM2,FALSE,URLZONE_INTERNET},
880     /* Tests for "org" zone mappings. */
881     {"http://google.org/",URLZONE_INTERNET,FALSE,URLZONE_CUSTOM},
882     {"http://org/",URLZONE_CUSTOM},
883     {"http://testing.org/",URLZONE_CUSTOM2},
884     /* Tests for "wine.testing" mapping */
885     {"*:wine.testing/test",URLZONE_CUSTOM2},
886     {"http://wine.testing/testing",URLZONE_CUSTOM2}
887 };
888
889 static void test_zone_domain_mappings(void)
890 {
891     HRESULT hres;
892     DWORD i, res;
893     IInternetSecurityManager *secmgr = NULL;
894     HKEY domains;
895     DWORD zone = URLZONE_INVALID;
896
897     trace("testing zone domain mappings...\n");
898
899     hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
900     ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
901
902     res = RegOpenKeyA(HKEY_LOCAL_MACHINE, szZoneMapDomainsKey, &domains);
903     if(res == ERROR_SUCCESS) {
904         static const WCHAR local_machineW[] = {'h','t','t','p',':','/','/','t','e','s','t','.','l','o','c','a','l',
905                 '.','m','a','c','h','i','n','e','/',0};
906
907         hres = IInternetSecurityManager_MapUrlToZone(secmgr, local_machineW, &zone, 0);
908         ok(hres == S_OK, "MapUrlToZone failed: %08x\n", hres);
909         ok(zone == URLZONE_CUSTOM, "Expected URLZONE_CUSTOM, but got %d\n", zone);
910
911         RegCloseKey(domains);
912     }
913
914     for(i = 0; i < sizeof(zone_mapping_tests)/sizeof(zone_mapping_tests[0]); ++i) {
915         const zone_mapping_test *test = zone_mapping_tests+i;
916         LPWSTR urlW = a2w(test->url);
917         zone = URLZONE_INVALID;
918
919         hres = IInternetSecurityManager_MapUrlToZone(secmgr, urlW, &zone, 0);
920         ok(hres == S_OK, "MapUrlToZone failed: %08x\n", hres);
921         if(test->todo)
922             todo_wine
923                 ok(zone == test->zone || broken(test->broken_zone == zone),
924                     "Expected %d, but got %d on test %d\n", test->zone, zone, i);
925         else
926             ok(zone == test->zone || broken(test->broken_zone == zone),
927                 "Expected %d, but got %d on test %d\n", test->zone, zone, i);
928
929         heap_free(urlW);
930     }
931
932     IInternetSecurityManager_Release(secmgr);
933 }
934
935 static void test_zone_domains(void)
936 {
937     if(is_ie_hardened()) {
938         skip("IE running in Enhanced Security Configuration\n");
939         return;
940     } else if(!pCreateUri) {
941         win_skip("Skipping zone domain tests, IE too old\n");
942         return;
943     }
944
945     trace("testing zone domains...\n");
946
947     test_zone_domain_cache();
948
949     register_zone_domains();
950     run_child_process();
951     unregister_zone_domains();
952 }
953
954 static void test_CoInternetCreateZoneManager(void)
955 {
956     IInternetZoneManager *zonemgr = NULL;
957     IUnknown *punk = NULL;
958     HRESULT hr;
959
960     trace("simple zone manager tests...\n");
961
962     hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
963     ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
964     if (FAILED(hr))
965         return;
966
967     hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IUnknown, (void **) &punk);
968     ok(SUCCEEDED(hr), "got 0x%x with %p (expected Success)\n", hr, punk);
969     if (punk)
970         IUnknown_Release(punk);
971
972     hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IInternetZoneManager, (void **) &punk);
973     ok(SUCCEEDED(hr), "got 0x%x with %p (expected Success)\n", hr, punk);
974     if (punk)
975         IUnknown_Release(punk);
976
977
978     hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IInternetZoneManagerEx, (void **) &punk);
979     if (SUCCEEDED(hr)) {
980         IUnknown_Release(punk);
981
982         hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IInternetZoneManagerEx2, (void **) &punk);
983         ok(hr == S_OK || broken(hr == E_NOINTERFACE /* some W2K3 */),
984            "got 0x%x (expected S_OK)\n", hr);
985         if (punk)
986             IUnknown_Release(punk);
987         else
988             win_skip("InternetZoneManagerEx2 not supported\n");
989
990     }
991     else
992         win_skip("InternetZoneManagerEx not supported\n");
993
994     hr = IInternetZoneManager_Release(zonemgr);
995     ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
996
997 }
998
999 static void test_CreateZoneEnumerator(void)
1000 {
1001     IInternetZoneManager *zonemgr = NULL;
1002     HRESULT hr;
1003     DWORD dwEnum;
1004     DWORD dwEnum2;
1005     DWORD dwCount;
1006     DWORD dwCount2;
1007
1008     trace("testing zone enumerator...\n");
1009
1010     hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
1011     ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
1012     if (FAILED(hr))
1013         return;
1014
1015     dwEnum=0xdeadbeef;
1016     hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, NULL, 0);
1017     ok((hr == E_INVALIDARG) && (dwEnum == 0xdeadbeef),
1018         "got 0x%x with 0x%x (expected E_INVALIDARG with 0xdeadbeef)\n", hr, dwEnum);
1019
1020     dwCount=0xdeadbeef;
1021     hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, NULL, &dwCount, 0);
1022     ok((hr == E_INVALIDARG) && (dwCount == 0xdeadbeef),
1023         "got 0x%x and 0x%x (expected E_INVALIDARG and 0xdeadbeef)\n", hr, dwCount);
1024
1025     dwEnum=0xdeadbeef;
1026     dwCount=0xdeadbeef;
1027     hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 0xffffffff);
1028     ok((hr == E_INVALIDARG) && (dwEnum == 0xdeadbeef) && (dwCount == 0xdeadbeef),
1029         "got 0x%x with 0x%x and 0x%x (expected E_INVALIDARG with 0xdeadbeef and 0xdeadbeef)\n",
1030         hr, dwEnum, dwCount);
1031
1032     dwEnum=0xdeadbeef;
1033     dwCount=0xdeadbeef;
1034     hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 1);
1035     ok((hr == E_INVALIDARG) && (dwEnum == 0xdeadbeef) && (dwCount == 0xdeadbeef),
1036         "got 0x%x with 0x%x and 0x%x (expected E_INVALIDARG with 0xdeadbeef and 0xdeadbeef)\n",
1037         hr, dwEnum, dwCount);
1038
1039     dwEnum=0xdeadbeef;
1040     dwCount=0xdeadbeef;
1041     /* Normal use */
1042     hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 0);
1043     ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1044
1045     if (SUCCEEDED(hr)) {
1046         dwEnum2=0xdeadbeef;
1047         dwCount2=0xdeadbeef;
1048         hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum2, &dwCount2, 0);
1049         ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1050         if (SUCCEEDED(hr)) {
1051             /* native urlmon has an incrementing counter for dwEnum */
1052             hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum2);
1053             ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1054         }
1055
1056         hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum);
1057         ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1058
1059         /* Destroy the Enumerator twice is detected and handled in native urlmon */
1060         hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum);
1061         ok((hr == E_INVALIDARG), "got 0x%x (expected E_INVALIDARG)\n", hr);
1062     }
1063
1064     /* ::Release succeed also, when a ::DestroyZoneEnumerator is missing */
1065     hr = IInternetZoneManager_Release(zonemgr);
1066     ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1067 }
1068
1069 static void test_GetZoneActionPolicy(void)
1070 {
1071     IInternetZoneManager *zonemgr = NULL;
1072     BYTE buf[32];
1073     HRESULT hres;
1074     DWORD action = URLACTION_CREDENTIALS_USE; /* Implemented on all IE versions */
1075
1076     trace("testing GetZoneActionPolixy...\n");
1077
1078     hres = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
1079     ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08x\n", hres);
1080     if(FAILED(hres))
1081         return;
1082
1083     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, buf,
1084             sizeof(DWORD), URLZONEREG_DEFAULT);
1085     ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
1086     ok(*(DWORD*)buf == URLPOLICY_CREDENTIALS_SILENT_LOGON_OK ||
1087             *(DWORD*)buf == URLPOLICY_CREDENTIALS_MUST_PROMPT_USER ||
1088             *(DWORD*)buf == URLPOLICY_CREDENTIALS_CONDITIONAL_PROMPT ||
1089             *(DWORD*)buf == URLPOLICY_CREDENTIALS_ANONYMOUS_ONLY,
1090             "unexpected policy=%d\n", *(DWORD*)buf);
1091
1092     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, NULL,
1093             sizeof(DWORD), URLZONEREG_DEFAULT);
1094     ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
1095
1096     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, buf,
1097             2, URLZONEREG_DEFAULT);
1098     ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
1099
1100     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1fff, buf,
1101             sizeof(DWORD), URLZONEREG_DEFAULT);
1102     ok(hres == E_FAIL || broken(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)),
1103             "(0x%x) got 0x%x (expected E_FAIL)\n", action, hres);
1104
1105     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 13, action, buf,
1106             sizeof(DWORD), URLZONEREG_DEFAULT);
1107     ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
1108
1109     IInternetZoneManager_Release(zonemgr);
1110 }
1111
1112 static void test_GetZoneAt(void)
1113 {
1114     IInternetZoneManager *zonemgr = NULL;
1115     HRESULT hr;
1116     DWORD dwEnum;
1117     DWORD dwCount;
1118     DWORD dwZone;
1119     DWORD i;
1120
1121     trace("testing GetZoneAt...\n");
1122
1123     hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
1124     ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
1125     if (FAILED(hr))
1126         return;
1127
1128     hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 0);
1129     if (FAILED(hr))
1130         goto cleanup;
1131
1132     if (0) {
1133         /* this crashes with native urlmon */
1134         IInternetZoneManager_GetZoneAt(zonemgr, dwEnum, 0, NULL);
1135     }
1136
1137     dwZone = 0xdeadbeef;
1138     hr = IInternetZoneManager_GetZoneAt(zonemgr, 0xdeadbeef, 0, &dwZone);
1139     ok(hr == E_INVALIDARG,
1140         "got 0x%x with 0x%x (expected E_INVALIDARG)\n", hr, dwZone);
1141
1142     for (i = 0; i < dwCount; i++)
1143     {
1144         dwZone = 0xdeadbeef;
1145         hr = IInternetZoneManager_GetZoneAt(zonemgr, dwEnum, i, &dwZone);
1146         ok(hr == S_OK, "#%d: got x%x with %d (expected S_OK)\n", i, hr, dwZone);
1147     }
1148
1149     dwZone = 0xdeadbeef;
1150     /* MSDN (index .. must be .. less than or equal to) is wrong */
1151     hr = IInternetZoneManager_GetZoneAt(zonemgr, dwEnum, dwCount, &dwZone);
1152     ok(hr == E_INVALIDARG,
1153         "got 0x%x with 0x%x (expected E_INVALIDARG)\n", hr, dwZone);
1154
1155     hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum);
1156     ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1157
1158 cleanup:
1159     hr = IInternetZoneManager_Release(zonemgr);
1160     ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1161 }
1162
1163 static void test_GetZoneAttributes(void)
1164 {
1165     IInternetZoneManager *zonemgr = NULL;
1166     CHAR buffer [sizeof(ZONEATTRIBUTES) + 32];
1167     ZONEATTRIBUTES* pZA = (ZONEATTRIBUTES*) buffer;
1168     HRESULT hr;
1169     DWORD i;
1170
1171     trace("testing GetZoneAttributes...\n");
1172
1173     hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
1174     ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
1175     if (FAILED(hr))
1176         return;
1177
1178     /* native urlmon has Zone "0" up to Zone "4" since IE4 */
1179     for (i = 0; i < 5; i++) {
1180         memset(buffer, -1, sizeof(buffer));
1181         hr = IInternetZoneManager_GetZoneAttributes(zonemgr, i, pZA);
1182         ok(hr == S_OK, "#%d: got 0x%x (expected S_OK)\n", i, hr);
1183     }
1184
1185     /* IE8 no longer set cbSize */
1186     memset(buffer, -1, sizeof(buffer));
1187     pZA->cbSize = 0;
1188     hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, pZA);
1189     ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1190     ok((pZA->cbSize == 0) || (pZA->cbSize == sizeof(ZONEATTRIBUTES)),
1191         "got cbSize = %d (expected 0)\n", pZA->cbSize);
1192
1193     memset(buffer, -1, sizeof(buffer));
1194     pZA->cbSize = 64;
1195     hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, pZA);
1196     ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1197     ok((pZA->cbSize == 64) || (pZA->cbSize == sizeof(ZONEATTRIBUTES)),
1198         "got cbSize = %d (expected 64)\n", pZA->cbSize);
1199
1200     memset(buffer, -1, sizeof(buffer));
1201     hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, pZA);
1202     ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1203     ok((pZA->cbSize == 0xffffffff) || (pZA->cbSize == sizeof(ZONEATTRIBUTES)),
1204         "got cbSize = 0x%x (expected 0xffffffff)\n", pZA->cbSize);
1205
1206     /* IE8 no longer fail on invalid zones */
1207     memset(buffer, -1, sizeof(buffer));
1208     hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0xdeadbeef, pZA);
1209     ok(hr == S_OK || (hr == E_FAIL),
1210         "got 0x%x (expected S_OK or E_FAIL)\n", hr);
1211
1212     hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, NULL);
1213     ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
1214
1215     hr = IInternetZoneManager_Release(zonemgr);
1216     ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1217 }
1218
1219 static void test_SetZoneAttributes(void)
1220 {
1221     IInternetZoneManager *zonemgr = NULL;
1222     CHAR buffer [sizeof(ZONEATTRIBUTES) + 16];
1223     ZONEATTRIBUTES* pZA = (ZONEATTRIBUTES*) buffer;
1224     CHAR regpath[MAX_PATH];
1225     HKEY hkey;
1226     HRESULT hr;
1227     DWORD res;
1228
1229     trace("testing SetZoneAttributes...\n");
1230     hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
1231     ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
1232     if (FAILED(hr))
1233         return;
1234
1235     memset(buffer, -1, sizeof(buffer));
1236     hr = IInternetZoneManager_GetZoneAttributes(zonemgr, URLZONE_LOCAL_MACHINE, pZA);
1237     ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1238
1239     sprintf(regpath, "%s\\Zones\\%d", szInternetSettingsKey, URLZONE_CUSTOM);
1240     res = RegCreateKeyA(HKEY_CURRENT_USER, regpath, &hkey);
1241     RegCloseKey(hkey);
1242
1243     ok(res == ERROR_SUCCESS, "got %d (expected ERROR_SUCCESS)\n", res);
1244     if (res != ERROR_SUCCESS)
1245         goto cleanup;
1246
1247     pZA->cbSize = sizeof(ZONEATTRIBUTES);
1248     hr = IInternetZoneManager_SetZoneAttributes(zonemgr, URLZONE_CUSTOM, NULL);
1249     ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
1250
1251     /* normal use */
1252     hr = IInternetZoneManager_SetZoneAttributes(zonemgr, URLZONE_CUSTOM, pZA);
1253     if (hr == E_FAIL) {
1254         win_skip("SetZoneAttributes not supported: IE too old\n");
1255         goto cleanup;
1256     }
1257     ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1258
1259     /* native urlmon ignores cbSize */
1260     pZA->cbSize = sizeof(ZONEATTRIBUTES) + sizeof(DWORD);
1261     hr = IInternetZoneManager_SetZoneAttributes(zonemgr, URLZONE_CUSTOM, pZA);
1262     ok(hr == S_OK, "got 0x%x for sizeof(ZONEATTRIBUTES) + sizeof(DWORD) (expected S_OK)\n", hr);
1263
1264     pZA->cbSize = sizeof(ZONEATTRIBUTES) - sizeof(DWORD);
1265     hr = IInternetZoneManager_SetZoneAttributes(zonemgr, URLZONE_CUSTOM, pZA);
1266     ok(hr == S_OK, "got 0x%x for sizeof(ZONEATTRIBUTES) - sizeof(DWORD) (expected S_OK)\n", hr);
1267
1268     pZA->cbSize = 0;
1269     hr = IInternetZoneManager_SetZoneAttributes(zonemgr, URLZONE_CUSTOM, pZA);
1270     ok(hr == S_OK, "got 0x%x for size 0 (expected S_OK)\n", hr);
1271
1272     /* The key for the zone must be present, when calling SetZoneAttributes */
1273     myRegDeleteTreeA(HKEY_CURRENT_USER, regpath);
1274     /* E_FAIL is returned from IE6 here, which is reasonable.
1275        All newer IE return S_OK without saving the zone attributes to the registry.
1276        This is a Windows bug, but we have to accept that as standard */
1277     hr = IInternetZoneManager_SetZoneAttributes(zonemgr, URLZONE_CUSTOM, pZA);
1278     ok((hr == S_OK) || broken(hr == E_FAIL), "got 0x%x (expected S_OK)\n", hr);
1279
1280     /* SetZoneAttributes did not create the directory */
1281     res = RegOpenKeyA(HKEY_CURRENT_USER, regpath, &hkey);
1282     ok((res == ERROR_FILE_NOT_FOUND) && (hkey == NULL),
1283         "got %u with %p (expected ERROR_FILE_NOT_FOUND with NULL)\n", res, hkey);
1284
1285     if (hkey) RegCloseKey(hkey);
1286
1287 cleanup:
1288     /* delete zone settings in the registry */
1289     myRegDeleteTreeA(HKEY_CURRENT_USER, regpath);
1290
1291     hr = IInternetZoneManager_Release(zonemgr);
1292     ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1293 }
1294
1295
1296 static void test_InternetSecurityMarshalling(void)
1297 {
1298     IInternetSecurityManager *secmgr = NULL;
1299     IUnknown *unk;
1300     IStream *stream;
1301     HRESULT hres;
1302
1303     trace("testing marshalling...\n");
1304
1305     hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
1306     ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
1307     if(FAILED(hres))
1308         return;
1309
1310     hres = IInternetSecurityManager_QueryInterface(secmgr, &IID_IUnknown, (void**)&unk);
1311     ok(hres == S_OK, "QueryInterface returned: %08x\n", hres);
1312
1313     hres = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1314     ok(hres == S_OK, "CreateStreamOnHGlobal returned: %08x\n", hres);
1315
1316     hres = CoMarshalInterface(stream, &IID_IInternetSecurityManager, unk, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
1317     /* Not supported in W98 */
1318     ok(hres == S_OK || broken(hres == REGDB_E_IIDNOTREG),
1319         "CoMarshalInterface returned: %08x\n", hres);
1320
1321     IStream_Release(stream);
1322     IUnknown_Release(unk);
1323     IInternetSecurityManager_Release(secmgr);
1324 }
1325
1326 static void test_InternetGetSecurityUrl(void)
1327 {
1328     const WCHAR url5_out[] = {'h','t','t','p',':','w','w','w','.','z','o','n','e','3',
1329                               '.','w','i','n','e','t','e','s','t',0};
1330     const WCHAR url7_out[] = {'f','t','p',':','z','o','n','e','3','.','w','i','n','e','t','e','s','t',0};
1331
1332     const WCHAR *in[] = {url2, url3, url4, url5, url7, url8, url9, url10};
1333     const WCHAR *out_default[] = {url2, url3, url4, url5_out, url7_out, url8, url5_out, url10};
1334     const WCHAR *out_securl[] = {url2, url3, url4, url5, url7, url8, url9, url10};
1335
1336     WCHAR *sec;
1337     DWORD i;
1338     HRESULT hres;
1339
1340     trace("testing CoInternetGetSecurityUrl...\n");
1341
1342     for(i=0; i<sizeof(in)/sizeof(WCHAR*); i++) {
1343         hres = pCoInternetGetSecurityUrl(in[i], &sec, PSU_DEFAULT, 0);
1344         ok(hres == S_OK, "(%d) CoInternetGetSecurityUrl returned: %08x\n", i, hres);
1345         if(hres == S_OK) {
1346             ok(!strcmp_w(sec, out_default[i]), "(%d) Got %s, expected %s\n",
1347                     i, wine_dbgstr_w(sec), wine_dbgstr_w(out_default[i]));
1348             CoTaskMemFree(sec);
1349         }
1350
1351         hres = pCoInternetGetSecurityUrl(in[i], &sec, PSU_SECURITY_URL_ONLY, 0);
1352         ok(hres == S_OK, "(%d) CoInternetGetSecurityUrl returned: %08x\n", i, hres);
1353         if(hres == S_OK) {
1354             ok(!strcmp_w(sec, out_securl[i]), "(%d) Got %s, expected %s\n",
1355                     i, wine_dbgstr_w(sec), wine_dbgstr_w(out_securl[i]));
1356             CoTaskMemFree(sec);
1357         }
1358     }
1359
1360     SET_EXPECT(ParseUrl_SECURITY_URL_input2);
1361     SET_EXPECT(ParseUrl_SECURITY_URL_expected);
1362     SET_EXPECT(ParseUrl_SECURITY_DOMAIN_expected);
1363
1364     hres = pCoInternetGetSecurityUrl(security_url2W, &sec, PSU_DEFAULT, 0);
1365     ok(hres == S_OK, "CoInternetGetSecurityUrl returned 0x%08x, expected S_OK\n", hres);
1366
1367     CHECK_CALLED(ParseUrl_SECURITY_URL_input2);
1368     CHECK_CALLED(ParseUrl_SECURITY_URL_expected);
1369     CHECK_CALLED(ParseUrl_SECURITY_DOMAIN_expected);
1370
1371     ok(!lstrcmpW(security_expectedW, sec), "Expected %s but got %s\n",
1372        wine_dbgstr_w(security_expectedW), wine_dbgstr_w(sec));
1373     CoTaskMemFree(sec);
1374 }
1375
1376 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
1377                                                           REFIID riid, void **ppv)
1378 {
1379     ok(0, "unexpected call\n");
1380     return E_NOINTERFACE;
1381 }
1382
1383 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
1384 {
1385     return 2;
1386 }
1387
1388 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
1389 {
1390     return 1;
1391 }
1392
1393 static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
1394         PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
1395         DWORD *pcchResult, DWORD dwReserved)
1396 {
1397     const WCHAR *ret = NULL;
1398
1399     ok(pwzResult != NULL, "pwzResult == NULL\n");
1400     ok(pcchResult != NULL, "pcchResult == NULL\n");
1401     ok(!dwParseFlags, "Expected 0, but got 0x%08x\n", dwParseFlags);
1402
1403     switch(ParseAction) {
1404     case PARSE_SECURITY_URL:
1405         if(!strcmp_w(pwzUrl, security_urlW)) {
1406             CHECK_EXPECT(ParseUrl_SECURITY_URL_input);
1407             ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1408             ret = security_expectedW;
1409         } else if(!strcmp_w(pwzUrl, security_url2W)) {
1410             CHECK_EXPECT(ParseUrl_SECURITY_URL_input2);
1411             ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1412             ret = security_expectedW;
1413         } else if(!strcmp_w(pwzUrl, security_expectedW)) {
1414             CHECK_EXPECT(ParseUrl_SECURITY_URL_expected);
1415             ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1416             ret = security_expectedW;
1417         } else if(!strcmp_w(pwzUrl, winetest_to_httpW)) {
1418             switch(++called_securl_http) {
1419             case 1:
1420                 ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1421                 break;
1422             case 2:
1423                 CHECK_EXPECT(ParseUrl_SECURITY_URL_http);
1424                 ok(cchResult == lstrlenW(url9)+1, "Got %d\n", cchResult);
1425                 break;
1426             default:
1427                 todo_wine CHECK_EXPECT(ParseUrl_SECURITY_URL_http);
1428             }
1429             ret = url9;
1430         } else
1431             ok(0, "Unexpected call, pwzUrl=%s\n", wine_dbgstr_w(pwzUrl));
1432
1433         break;
1434     case PARSE_SECURITY_DOMAIN:
1435
1436         CHECK_EXPECT(ParseUrl_SECURITY_DOMAIN_expected);
1437
1438         ok(!strcmp_w(pwzUrl, security_expectedW), "Expected %s but got %s\n",
1439             wine_dbgstr_w(security_expectedW), wine_dbgstr_w(pwzUrl));
1440         ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1441         ret = security_expectedW;
1442         break;
1443     default:
1444         ok(0, "Unexpected call, ParseAction=%d pwzUrl=%s\n", ParseAction,
1445             wine_dbgstr_w(pwzUrl));
1446     }
1447
1448     if(!ret)
1449         return E_FAIL;
1450
1451     *pcchResult = lstrlenW(ret)+1;
1452     if(*pcchResult > cchResult)
1453         return S_FALSE;
1454     memcpy(pwzResult, ret, (*pcchResult)*sizeof(WCHAR));
1455     return S_OK;
1456 }
1457
1458 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
1459         LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
1460         LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
1461 {
1462     ok(0, "unexpected call\n");
1463     return E_NOTIMPL;
1464 }
1465
1466 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
1467         LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
1468 {
1469     ok(0, "unexpected call\n");
1470     return E_NOTIMPL;
1471 }
1472
1473 static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
1474         LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
1475         DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
1476 {
1477     ok(0, "unexpected call\n");
1478     return E_NOTIMPL;
1479 }
1480
1481 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
1482     InternetProtocolInfo_QueryInterface,
1483     InternetProtocolInfo_AddRef,
1484     InternetProtocolInfo_Release,
1485     InternetProtocolInfo_ParseUrl,
1486     InternetProtocolInfo_CombineUrl,
1487     InternetProtocolInfo_CompareUrl,
1488     InternetProtocolInfo_QueryInfo
1489 };
1490
1491 static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };
1492
1493 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1494 {
1495     if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
1496         *ppv = &protocol_info;
1497         return S_OK;
1498     }
1499
1500     ok(0, "unexpected call\n");
1501     return E_NOINTERFACE;
1502 }
1503
1504 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1505 {
1506     return 2;
1507 }
1508
1509 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1510 {
1511     return 1;
1512 }
1513
1514 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
1515                                         REFIID riid, void **ppv)
1516 {
1517     ok(0, "unexpected call\n");
1518     return E_NOTIMPL;
1519 }
1520
1521 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1522 {
1523     ok(0, "unexpected call\n");
1524     return S_OK;
1525 }
1526
1527 static const IClassFactoryVtbl ClassFactoryVtbl = {
1528     ClassFactory_QueryInterface,
1529     ClassFactory_AddRef,
1530     ClassFactory_Release,
1531     ClassFactory_CreateInstance,
1532     ClassFactory_LockServer
1533 };
1534
1535 static IClassFactory protocol_cf = { &ClassFactoryVtbl };
1536
1537 static void register_protocols(void)
1538 {
1539     IInternetSession *session;
1540     HRESULT hres;
1541
1542     hres = pCoInternetGetSession(0, &session, 0);
1543     ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
1544     if(FAILED(hres))
1545         return;
1546
1547     hres = IInternetSession_RegisterNameSpace(session, &protocol_cf, &IID_NULL,
1548             winetestW, 0, NULL, 0);
1549     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1550
1551     IInternetSession_Release(session);
1552 }
1553
1554 static void unregister_protocols(void) {
1555     IInternetSession *session;
1556     HRESULT hr;
1557
1558     hr = pCoInternetGetSession(0, &session, 0);
1559     ok(hr == S_OK, "CoInternetGetSession failed: 0x%08x\n", hr);
1560     if(FAILED(hr))
1561         return;
1562
1563     hr = IInternetSession_UnregisterNameSpace(session, &protocol_cf, winetestW);
1564     ok(hr == S_OK, "UnregisterNameSpace failed: 0x%08x\n", hr);
1565
1566     IInternetSession_Release(session);
1567 }
1568
1569 static const struct {
1570     const char  *uri;
1571     DWORD       create_flags;
1572     const char  *security_uri;
1573     HRESULT     security_hres;
1574     const char  *default_uri;
1575     HRESULT     default_hres;
1576     BOOL        todo;
1577 } sec_url_ex_tests[] = {
1578     {"index.htm",Uri_CREATE_ALLOW_RELATIVE,"*:index.html",S_OK,"*:index.htm",S_OK},
1579     {"file://c:\\Index.htm",Uri_CREATE_FILE_USE_DOS_PATH,"file:///c:/Index.htm",S_OK,"file:///c:/Index.htm",S_OK},
1580     {"file:some%20file%2ejpg",0,NULL,E_INVALIDARG,NULL,E_INVALIDARG},
1581     {"file:some file.jpg",0,NULL,E_INVALIDARG,NULL,E_INVALIDARG},
1582     {"http://www.zone3.winetest/",0,"http://www.zone3.winetest/",S_OK,"http://www.zone3.winetest/",S_OK},
1583     {"about:blank",0,"about:blank",S_OK,"about:blank",S_OK},
1584     {"ftp://zone3.winetest/file.test",0,"ftp://zone3.winetest/file.test",S_OK,"ftp://zone3.winetest/file.test",S_OK},
1585     {"test:123abc",0,"test:123abc",S_OK,"test:123abc",S_OK},
1586     {"http:google.com/test.file",0,"http:google.com/test.file",S_OK,"http:google.com/test.file",S_OK},
1587     {"ftp://test@ftp.winehq.org/",0,"ftp://ftp.winehq.org/",S_OK,"ftp://ftp.winehq.org/",S_OK},
1588     {"test://google@ftp.winehq.org/",0,"test://google@ftp.winehq.org/",S_OK,"test://google@ftp.winehq.org/",S_OK}
1589 };
1590
1591 static void test_InternetGetSecurityUrlEx(void)
1592 {
1593     HRESULT hr;
1594     DWORD i;
1595     IUri *uri = NULL, *result = NULL;
1596
1597     trace("testing CoInternetGetSecurityUrlEx...\n");
1598
1599     hr = pCoInternetGetSecurityUrlEx(NULL, NULL, PSU_DEFAULT, 0);
1600     ok(hr == E_INVALIDARG, "CoInternetGetSecurityUrlEx returned 0x%08x, expected E_INVALIDARG\n", hr);
1601
1602     result = (void*) 0xdeadbeef;
1603     hr = pCoInternetGetSecurityUrlEx(NULL, &result, PSU_DEFAULT, 0);
1604     ok(hr == E_INVALIDARG, "CoInternetGetSecurityUrlEx returned 0x%08x, expected E_INVALIDARG\n", hr);
1605     ok(result == (void*) 0xdeadbeef, "'result' was %p\n", result);
1606
1607     for(i = 0; i < sizeof(sec_url_ex_tests)/sizeof(sec_url_ex_tests[0]); ++i) {
1608         LPWSTR uriW = a2w(sec_url_ex_tests[i].uri);
1609         uri = NULL;
1610
1611         hr = pCreateUri(uriW, sec_url_ex_tests[i].create_flags, 0, &uri);
1612         ok(hr == S_OK, "CreateUri returned 0x%08x on test %d\n", hr, i);
1613         if(hr == S_OK) {
1614             result = NULL;
1615
1616             hr = pCoInternetGetSecurityUrlEx(uri, &result, PSU_DEFAULT, 0);
1617             if(sec_url_ex_tests[i].todo) {
1618                 todo_wine
1619                     ok(hr == sec_url_ex_tests[i].default_hres,
1620                         "CoInternetGetSecurityUrlEx returned 0x%08x, expected 0x%08x on test %d\n",
1621                         hr, sec_url_ex_tests[i].default_hres, i);
1622             } else {
1623                 ok(hr == sec_url_ex_tests[i].default_hres,
1624                     "CoInternetGetSecurityUrlEx returned 0x%08x, expected 0x%08x on test %d\n",
1625                     hr, sec_url_ex_tests[i].default_hres, i);
1626             }
1627             if(SUCCEEDED(hr)) {
1628                 BSTR received;
1629
1630                 hr = IUri_GetDisplayUri(result, &received);
1631                 ok(hr == S_OK, "GetDisplayUri returned 0x%08x on test %d\n", hr, i);
1632                 if(hr == S_OK) {
1633                     if(sec_url_ex_tests[i].todo) {
1634                         todo_wine
1635                             ok(!strcmp_aw(sec_url_ex_tests[i].default_uri, received),
1636                                 "Expected %s but got %s on test %d\n", sec_url_ex_tests[i].default_uri,
1637                                 wine_dbgstr_w(received), i);
1638                     } else {
1639                         ok(!strcmp_aw(sec_url_ex_tests[i].default_uri, received),
1640                             "Expected %s but got %s on test %d\n", sec_url_ex_tests[i].default_uri,
1641                             wine_dbgstr_w(received), i);
1642                     }
1643                 }
1644                 SysFreeString(received);
1645             }
1646             if(result) IUri_Release(result);
1647
1648             result = NULL;
1649             hr = pCoInternetGetSecurityUrlEx(uri, &result, PSU_SECURITY_URL_ONLY, 0);
1650             if(sec_url_ex_tests[i].todo) {
1651                 todo_wine
1652                     ok(hr == sec_url_ex_tests[i].default_hres,
1653                         "CoInternetGetSecurityUrlEx returned 0x%08x, expected 0x%08x on test %d\n",
1654                         hr, sec_url_ex_tests[i].default_hres, i);
1655             } else {
1656                 ok(hr == sec_url_ex_tests[i].default_hres,
1657                     "CoInternetGetSecurityUrlEx returned 0x%08x, expected 0x%08x on test %d\n",
1658                     hr, sec_url_ex_tests[i].default_hres, i);
1659             }
1660             if(SUCCEEDED(hr)) {
1661                 BSTR received;
1662
1663                 hr = IUri_GetDisplayUri(result, &received);
1664                 ok(hr == S_OK, "GetDisplayUri returned 0x%08x on test %d\n", hr, i);
1665                 if(hr == S_OK) {
1666                     if(sec_url_ex_tests[i].todo) {
1667                         todo_wine
1668                             ok(!strcmp_aw(sec_url_ex_tests[i].default_uri, received),
1669                                 "Expected %s but got %s on test %d\n", sec_url_ex_tests[i].default_uri,
1670                                 wine_dbgstr_w(received), i);
1671                     } else {
1672                         ok(!strcmp_aw(sec_url_ex_tests[i].default_uri, received),
1673                             "Expected %s but got %s on test %d\n", sec_url_ex_tests[i].default_uri,
1674                             wine_dbgstr_w(received), i);
1675                     }
1676                 }
1677                 SysFreeString(received);
1678             }
1679             if(result) IUri_Release(result);
1680         }
1681
1682         if(uri) IUri_Release(uri);
1683         heap_free(uriW);
1684     }
1685 }
1686
1687 static void test_InternetGetSecurityUrlEx_Pluggable(void)
1688 {
1689     HRESULT hr;
1690     IUri *uri = NULL, *result;
1691
1692     trace("testing CoInternetGetSecurityUrlEx for pluggable protocols...\n");
1693
1694     hr = pCreateUri(security_urlW, 0, 0, &uri);
1695     ok(hr == S_OK, "CreateUri returned 0x%08x\n", hr);
1696     if(hr == S_OK) {
1697         SET_EXPECT(ParseUrl_SECURITY_URL_input);
1698         SET_EXPECT(ParseUrl_SECURITY_URL_expected);
1699         SET_EXPECT(ParseUrl_SECURITY_DOMAIN_expected);
1700
1701         hr = pCoInternetGetSecurityUrlEx(uri, &result, PSU_DEFAULT, 0);
1702         ok(hr == S_OK, "CoInternetGetSecurityUrlEx returned 0x%08x, expected S_OK\n", hr);
1703
1704         CHECK_CALLED(ParseUrl_SECURITY_URL_input);
1705         CHECK_CALLED(ParseUrl_SECURITY_URL_expected);
1706         CHECK_CALLED(ParseUrl_SECURITY_DOMAIN_expected);
1707
1708         if(hr == S_OK) {
1709             BSTR received = NULL;
1710
1711             hr = IUri_GetAbsoluteUri(result, &received);
1712             ok(hr == S_OK, "GetAbsoluteUri returned 0x%08x\n", hr);
1713             if(hr == S_OK) {
1714                 ok(!strcmp_w(security_expectedW, received), "Expected %s but got %s\n",
1715                     wine_dbgstr_w(security_expectedW), wine_dbgstr_w(received));
1716             }
1717             SysFreeString(received);
1718         }
1719         if(result) IUri_Release(result);
1720
1721         result = NULL;
1722
1723         SET_EXPECT(ParseUrl_SECURITY_URL_input);
1724         SET_EXPECT(ParseUrl_SECURITY_URL_expected);
1725
1726         hr = pCoInternetGetSecurityUrlEx(uri, &result, PSU_SECURITY_URL_ONLY, 0);
1727         ok(hr == S_OK, "CoInternetGetSecurityUrlEx returned 0x%08x, expected S_OK\n", hr);
1728
1729         CHECK_CALLED(ParseUrl_SECURITY_URL_input);
1730         CHECK_CALLED(ParseUrl_SECURITY_URL_expected);
1731
1732         if(hr == S_OK) {
1733             BSTR received = NULL;
1734
1735             hr = IUri_GetAbsoluteUri(result, &received);
1736             ok(hr == S_OK, "GetAbsoluteUri returned 0x%08x\n", hr);
1737             if(hr == S_OK) {
1738                 ok(!strcmp_w(security_expectedW, received), "Expected %s but got %s\n",
1739                     wine_dbgstr_w(security_expectedW), wine_dbgstr_w(received));
1740             }
1741             SysFreeString(received);
1742         }
1743         if(result) IUri_Release(result);
1744     }
1745     if(uri) IUri_Release(uri);
1746 }
1747
1748 static const struct {
1749     const char  *uri;
1750     DWORD       create_flags;
1751     HRESULT     map_hres;
1752     DWORD       zone;
1753     BOOL        map_todo;
1754 } sec_mgr_ex2_tests[] = {
1755     {"res://mshtml.dll/blank.htm",0,S_OK,URLZONE_LOCAL_MACHINE},
1756     {"index.htm",Uri_CREATE_ALLOW_RELATIVE,0,URLZONE_INTERNET},
1757     {"file://c:\\Index.html",0,0,URLZONE_LOCAL_MACHINE},
1758     {"http://www.zone3.winetest/",0,0,URLZONE_INTERNET},
1759     {"about:blank",0,0,URLZONE_INTERNET},
1760     {"ftp://zone3.winetest/file.test",0,0,URLZONE_INTERNET},
1761     {"/file/testing/test.test",Uri_CREATE_ALLOW_RELATIVE,0,URLZONE_INTERNET},
1762     {"zip://testing.com/",0,0,URLZONE_INTERNET},
1763     {"zip:testing.com",0,0,URLZONE_INTERNET},
1764     {"http:google.com",0,S_OK,URLZONE_INVALID},
1765     {"http:/google.com",0,S_OK,URLZONE_INVALID}
1766 };
1767
1768 static void test_SecurityManagerEx2(void)
1769 {
1770     HRESULT hres;
1771     DWORD i, zone;
1772     IInternetSecurityManager *sec_mgr;
1773     IInternetSecurityManagerEx2 *sec_mgr2;
1774     IUri *uri = NULL;
1775
1776     if(!pCreateUri) {
1777         win_skip("Skipping SecurityManagerEx2, IE is too old\n");
1778         return;
1779     }
1780
1781     trace("Testing SecurityManagerEx2...\n");
1782
1783     hres = pCoInternetCreateSecurityManager(NULL, &sec_mgr, 0);
1784     ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
1785
1786     hres = IInternetSecurityManager_QueryInterface(sec_mgr, &IID_IInternetSecurityManagerEx2, (void**)&sec_mgr2);
1787     ok(hres == S_OK, "QueryInterface(IID_IInternetSecurityManagerEx2) failed: %08x\n", hres);
1788
1789     zone = 0xdeadbeef;
1790
1791     hres = IInternetSecurityManagerEx2_MapUrlToZoneEx2(sec_mgr2, NULL, &zone, 0, NULL, NULL);
1792     ok(hres == E_INVALIDARG, "MapUrlToZoneEx2 returned %08x, expected E_INVALIDARG\n", hres);
1793     ok(zone == URLZONE_INVALID, "zone was %d\n", zone);
1794
1795     hres = pCreateUri(url5, 0, 0, &uri);
1796     ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
1797
1798     hres = IInternetSecurityManagerEx2_MapUrlToZoneEx2(sec_mgr2, uri, NULL, 0, NULL, NULL);
1799     ok(hres == E_INVALIDARG, "MapToUrlZoneEx2 returned %08x, expected E_INVALIDARG\n", hres);
1800
1801     IUri_Release(uri);
1802
1803     for(i = 0; i < sizeof(sec_mgr_ex2_tests)/sizeof(sec_mgr_ex2_tests[0]); ++i) {
1804         LPWSTR uriW = a2w(sec_mgr_ex2_tests[i].uri);
1805
1806         uri = NULL;
1807         zone = URLZONE_INVALID;
1808
1809         hres = pCreateUri(uriW, sec_mgr_ex2_tests[i].create_flags, 0, &uri);
1810         ok(hres == S_OK, "CreateUri returned %08x for '%s'\n", hres, sec_mgr_ex2_tests[i].uri);
1811
1812         hres = IInternetSecurityManagerEx2_MapUrlToZoneEx2(sec_mgr2, uri, &zone, 0, NULL, NULL);
1813         if(sec_mgr_ex2_tests[i].map_todo) {
1814             todo_wine
1815                 ok(hres == sec_mgr_ex2_tests[i].map_hres, "MapUrlZoneToEx2 returned %08x, expected %08x for '%s'\n",
1816                     hres, sec_mgr_ex2_tests[i].map_hres, sec_mgr_ex2_tests[i].uri);
1817             todo_wine
1818                 ok(zone == sec_mgr_ex2_tests[i].zone, "Expected zone %d, but got %d for '%s'\n", sec_mgr_ex2_tests[i].zone,
1819                     zone, sec_mgr_ex2_tests[i].uri);
1820         } else {
1821             ok(hres == sec_mgr_ex2_tests[i].map_hres, "MapUrlToZoneEx2 returned %08x, expected %08x for '%s'\n",
1822                 hres, sec_mgr_ex2_tests[i].map_hres, sec_mgr_ex2_tests[i].uri);
1823             ok(zone == sec_mgr_ex2_tests[i].zone, "Expected zone %d, but got %d for '%s'\n", sec_mgr_ex2_tests[i].zone,
1824                 zone, sec_mgr_ex2_tests[i].uri);
1825         }
1826
1827         heap_free(uriW);
1828         IUri_Release(uri);
1829     }
1830
1831     IInternetSecurityManagerEx2_Release(sec_mgr2);
1832     IInternetSecurityManager_Release(sec_mgr);
1833 }
1834
1835 static void test_CoInternetIsFeatureZoneElevationEnabled(void)
1836 {
1837     struct {
1838         const char *url_from;
1839         const char *url_to;
1840         DWORD flags;
1841         HRESULT hres;
1842         DWORD policy_flags;
1843     } testcases[] = {
1844         /*  0 */ { "http://www.winehq.org", "http://www.winehq.org", 0, S_FALSE, URLPOLICY_ALLOW },
1845         /*  1 */ { "http://www.winehq.org", "http://www.winehq.org", 0, S_OK, URLPOLICY_DISALLOW },
1846         /*  2 */ { "http://www.winehq.org", "http://www.codeweavers.com", 0, S_FALSE, URLPOLICY_ALLOW },
1847         /*  3 */ { "http://www.winehq.org", "http://www.codeweavers.com", 0, S_OK, URLPOLICY_DISALLOW },
1848         /*  4 */ { "http://www.winehq.org", "http://www.winehq.org", GET_FEATURE_FROM_PROCESS, S_FALSE, -1 },
1849         /*  5 */ { "http://www.winehq.org", "http://www.winehq.org/dir", GET_FEATURE_FROM_PROCESS, S_FALSE, -1 },
1850         /*  6 */ { "http://www.winehq.org", "http://www.codeweavers.com", GET_FEATURE_FROM_PROCESS, S_FALSE, -1 },
1851         /*  7 */ { "http://www.winehq.org", "ftp://winehq.org", GET_FEATURE_FROM_PROCESS, S_FALSE, -1 },
1852         /*  8 */ { "http://www.winehq.org", "ftp://winehq.org", GET_FEATURE_FROM_PROCESS|0x100, S_FALSE, URLPOLICY_ALLOW },
1853         /*  9 */ { "http://www.winehq.org", "ftp://winehq.org", GET_FEATURE_FROM_REGISTRY, S_FALSE, URLPOLICY_ALLOW },
1854     };
1855
1856     WCHAR *url_from, *url_to;
1857     int i;
1858     HRESULT hres;
1859
1860     if(!pCoInternetIsFeatureZoneElevationEnabled || !pCoInternetIsFeatureEnabled
1861             || !pCoInternetIsFeatureEnabledForUrl) {
1862         win_skip("Skipping CoInternetIsFeatureZoneElevationEnabled tests\n");
1863         return;
1864     }
1865
1866
1867     hres = pCoInternetIsFeatureEnabled(FEATURE_ZONE_ELEVATION, GET_FEATURE_FROM_PROCESS);
1868     ok(SUCCEEDED(hres), "CoInternetIsFeatureEnabled returned %x\n", hres);
1869
1870     trace("Testing CoInternetIsFeatureZoneElevationEnabled... (%x)\n", hres);
1871
1872     for(i=0; i<sizeof(testcases)/sizeof(testcases[0]); i++) {
1873         if(hres==S_OK && testcases[i].flags == GET_FEATURE_FROM_PROCESS)
1874             testcases[i].policy_flags = URLPOLICY_ALLOW;
1875     }
1876
1877     for(i=0; i<sizeof(testcases)/sizeof(testcases[0]); i++) {
1878         url_from = a2w(testcases[i].url_from);
1879         url_to = a2w(testcases[i].url_to);
1880
1881         if(testcases[i].policy_flags != -1) {
1882             ProcessUrlAction_policy = testcases[i].policy_flags;
1883             SET_EXPECT(ProcessUrlAction);
1884         }
1885         hres = pCoInternetIsFeatureZoneElevationEnabled(url_from, url_to,
1886                 &security_manager, testcases[i].flags);
1887         ok(hres == testcases[i].hres, "%d) CoInternetIsFeatureZoneElevationEnabled returned %x\n", i, hres);
1888         if(testcases[i].policy_flags != -1)
1889             CHECK_CALLED(ProcessUrlAction);
1890
1891         if(testcases[i].policy_flags != -1)
1892             SET_EXPECT(ProcessUrlAction);
1893         hres = pCoInternetIsFeatureEnabledForUrl(FEATURE_ZONE_ELEVATION,
1894                 testcases[i].flags, url_to, &security_manager);
1895         ok(hres == testcases[i].hres, "%d) CoInternetIsFeatureEnabledForUrl returned %x\n", i, hres);
1896         if(testcases[i].policy_flags != -1)
1897             CHECK_CALLED(ProcessUrlAction);
1898
1899         heap_free(url_from);
1900         heap_free(url_to);
1901     }
1902 }
1903
1904 START_TEST(sec_mgr)
1905 {
1906     HMODULE hurlmon;
1907     int argc;
1908     char **argv;
1909
1910     hurlmon = GetModuleHandle("urlmon.dll");
1911     pCoInternetCreateSecurityManager = (void*) GetProcAddress(hurlmon, "CoInternetCreateSecurityManager");
1912     pCoInternetCreateZoneManager = (void*) GetProcAddress(hurlmon, "CoInternetCreateZoneManager");
1913     pCoInternetGetSecurityUrl = (void*) GetProcAddress(hurlmon, "CoInternetGetSecurityUrl");
1914     pCoInternetGetSecurityUrlEx = (void*) GetProcAddress(hurlmon, "CoInternetGetSecurityUrlEx");
1915     pCreateUri = (void*) GetProcAddress(hurlmon, "CreateUri");
1916     pCoInternetGetSession = (void*) GetProcAddress(hurlmon, "CoInternetGetSession");
1917     pCoInternetIsFeatureEnabled = (void*) GetProcAddress(hurlmon, "CoInternetIsFeatureEnabled");
1918     pCoInternetIsFeatureEnabledForUrl = (void*) GetProcAddress(hurlmon, "CoInternetIsFeatureEnabledForUrl");
1919     pCoInternetIsFeatureZoneElevationEnabled = (void*) GetProcAddress(hurlmon, "CoInternetIsFeatureZoneElevationEnabled");
1920
1921     if (!pCoInternetCreateSecurityManager || !pCoInternetCreateZoneManager ||
1922         !pCoInternetGetSecurityUrl) {
1923         win_skip("Various CoInternet* functions not present in IE 4.0\n");
1924         return;
1925     }
1926
1927     argc = winetest_get_mainargs(&argv);
1928     if(argc > 2 && !strcmp(argv[2], "domain_tests")) {
1929         test_zone_domain_mappings();
1930         return;
1931     }
1932
1933     OleInitialize(NULL);
1934     register_protocols();
1935
1936     test_InternetGetSecurityUrl();
1937
1938     if(!pCoInternetGetSecurityUrlEx || !pCreateUri)
1939         win_skip("Skipping CoInternetGetSecurityUrlEx tests, IE too old\n");
1940     else {
1941         test_InternetGetSecurityUrlEx();
1942         test_InternetGetSecurityUrlEx_Pluggable();
1943     }
1944
1945     test_SecurityManager();
1946     test_SecurityManagerEx2();
1947     test_polices();
1948     test_zone_domains();
1949     test_CoInternetCreateZoneManager();
1950     test_CreateZoneEnumerator();
1951     test_GetZoneActionPolicy();
1952     test_GetZoneAt();
1953     test_GetZoneAttributes();
1954     test_SetZoneAttributes();
1955     test_InternetSecurityMarshalling();
1956     test_CoInternetIsFeatureZoneElevationEnabled();
1957
1958     unregister_protocols();
1959     OleUninitialize();
1960 }