From: Gabriel Ivăncescu gabrielopcode@gmail.com
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/mshtml/tests/script.c | 478 ++++++++++++++++++++++++++++++++++++- 1 file changed, 471 insertions(+), 7 deletions(-)
diff --git a/dlls/mshtml/tests/script.c b/dlls/mshtml/tests/script.c index 14e3a148239..80f34a6606e 100644 --- a/dlls/mshtml/tests/script.c +++ b/dlls/mshtml/tests/script.c @@ -62,7 +62,7 @@ const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY = #endif
#define DEFINE_EXPECT(func) \ - static BOOL expect_ ## func = FALSE, called_ ## func = FALSE + static BOOL expect_ ## func, called_ ## func
#define SET_EXPECT(func) \ do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0) @@ -137,6 +137,9 @@ DEFINE_EXPECT(QS_IActiveScriptSite); DEFINE_EXPECT(QS_GetCaller); DEFINE_EXPECT(ChangeType); DEFINE_EXPECT(GetTypeInfo); +DEFINE_EXPECT(doc_onstorage[2]); +DEFINE_EXPECT(doc_onstoragecommit[2]); +DEFINE_EXPECT(window_onstorage[2]);
#define TESTSCRIPT_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80746}" #define TESTACTIVEX_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80646}" @@ -3737,7 +3740,7 @@ static void test_simple_script(void) CHECK_CALLED(Close); }
-static void run_from_moniker(IMoniker *mon) +static void run_from_moniker(IMoniker *mon, IHTMLDocument2 **ret_doc) { IPersistMoniker *persist; IHTMLDocument2 *doc; @@ -3768,6 +3771,11 @@ static void run_from_moniker(IMoniker *mon)
CHECK_CALLED(external_success);
+ if(ret_doc) { + *ret_doc = doc; + return; + } + free_registered_streams(); set_client_site(doc, FALSE); IHTMLDocument2_Release(doc); @@ -3788,12 +3796,12 @@ static void run_js_script(const char *test_name)
hres = CreateURLMoniker(NULL, url, &mon); ok(hres == S_OK, "CreateURLMoniker failed: %08lx\n", hres); - run_from_moniker(mon); + run_from_moniker(mon, NULL);
IMoniker_Release(mon); }
-static void run_from_path(const WCHAR *path, const char *opt) +static void run_from_path(const WCHAR *path, const char *opt, IHTMLDocument2 **doc) { WCHAR buf[255] = L"http://winetest.example.org"; IMoniker *mon; @@ -3808,11 +3816,462 @@ static void run_from_path(const WCHAR *path, const char *opt) SysFreeString(url); ok(hres == S_OK, "CreateUrlMoniker failed: %08lx\n", hres);
- run_from_moniker(mon); + run_from_moniker(mon, doc);
IMoniker_Release(mon); }
+static unsigned onstorage_expect_line, onstorage_expect_document_mode; +static const WCHAR *onstorage_expect_key, *onstorage_expect_old_value, *onstorage_expect_new_value; + +#define check_local_onstorage(a,b,c,d) _check_onstorage(a,b,c,d,TRUE,document_mode,__LINE__) +#define check_session_onstorage(a,b,c,d) _check_onstorage(a,b,c,d,FALSE,document_mode,__LINE__) +static void _check_onstorage(unsigned idx, const WCHAR *key, const WCHAR *old_value, + const WCHAR *new_value, BOOL local, unsigned document_mode, unsigned line) +{ + BOOL *const *expect, *const *called; + MSG msg; + + onstorage_expect_line = line; + onstorage_expect_document_mode = document_mode; + onstorage_expect_key = key; + onstorage_expect_old_value = old_value; + onstorage_expect_new_value = new_value; + + if(local) { + static BOOL *const _expect[] = { expect_doc_onstoragecommit, NULL }; + static BOOL *const _called[] = { called_doc_onstoragecommit, NULL }; + expect = _expect, called = _called; + }else { + if(document_mode < 9) { + static BOOL *const _expect[] = { expect_doc_onstorage, NULL }; + static BOOL *const _called[] = { called_doc_onstorage, NULL }; + expect = _expect, called = _called; + }else { + static BOOL *const _expect[] = { expect_window_onstorage, expect_doc_onstorage, NULL }; + static BOOL *const _called[] = { called_window_onstorage, called_doc_onstorage, NULL }; + expect = _expect, called = _called; + } + } + + (*expect)[idx] = TRUE, (*called)[idx] = FALSE; + do { + while(!(*called)[idx] && GetMessageW(&msg, NULL, 0, 0)) { + TranslateMessage(&msg); + DispatchMessageW(&msg); + } + } while(*++expect && *++called); + CLEAR_CALLED(doc_onstorage[0]); + CLEAR_CALLED(doc_onstoragecommit[0]); + CLEAR_CALLED(window_onstorage[0]); + CLEAR_CALLED(doc_onstorage[1]); + CLEAR_CALLED(doc_onstoragecommit[1]); + CLEAR_CALLED(window_onstorage[1]); +} + +static void test_storage_event(DISPPARAMS *params, BOOL commit) +{ + const WCHAR *expect_key = onstorage_expect_key, *expect_old_value = onstorage_expect_old_value, *expect_new_value = onstorage_expect_new_value; + unsigned line = onstorage_expect_line; + BOOL doc_onstorage = TRUE; + IHTMLEventObj *event_obj; + IDOMStorageEvent *event; + IHTMLWindow2 *window; + IDispatchEx *dispex; + HRESULT hres; + unsigned i; + DISPID id; + BSTR bstr; + + if(onstorage_expect_document_mode < 9) { + ok_(__FILE__,line)(params->cArgs == 1, "cArgs = %u\n", params->cArgs); + ok_(__FILE__,line)(V_VT(¶ms->rgvarg[0]) == VT_DISPATCH, "V_VT(this) = %d\n", V_VT(¶ms->rgvarg[0])); + return; + } + + if(commit) { + expect_key = NULL; + expect_old_value = NULL; + expect_new_value = NULL; + doc_onstorage = FALSE; + } + + ok_(__FILE__,line)(params->cArgs == 2, "cArgs = %u\n", params->cArgs); + ok_(__FILE__,line)(V_VT(¶ms->rgvarg[1]) == VT_DISPATCH, "V_VT(event) = %d\n", V_VT(¶ms->rgvarg[1])); + hres = IDispatch_QueryInterface(V_DISPATCH(¶ms->rgvarg[1]), &IID_IDispatchEx, (void**)&dispex); + ok_(__FILE__,line)(hres == S_OK, "Could not get IDispatchEx: %08lx\n", hres); + + hres = IDispatch_QueryInterface(V_DISPATCH(¶ms->rgvarg[0]), &IID_IHTMLWindow2, (void**)&window); + if(hres == S_OK) { + doc_onstorage = FALSE; + IHTMLWindow2_Release(window); + } + + hres = IDispatchEx_QueryInterface(dispex, &IID_IDOMStorageEvent, (void**)&event); + if(doc_onstorage) { + static const WCHAR *props[] = { L"key", L"oldValue", L"newValue", L"storageArea" }; + ok_(__FILE__,line)(hres != S_OK, "Got IDOMStorageEvent in document.onstorage handler\n"); + + hres = IDispatchEx_QueryInterface(dispex, &IID_IHTMLEventObj, (void**)&event_obj); + ok_(__FILE__,line)(hres == S_OK, "Could not get IHTMLEventObj: %08lx\n", hres); + IHTMLEventObj_Release(event_obj); + + for(i = 0; i < ARRAY_SIZE(props); i++) { + bstr = SysAllocString(props[i]); + hres = IDispatchEx_GetDispID(dispex, bstr, 0, &id); + ok_(__FILE__,line)(hres == DISP_E_UNKNOWNNAME, "GetDispID(%s) failed: %08lx\n", wine_dbgstr_w(bstr), hres); + SysFreeString(bstr); + } + + IDispatchEx_Release(dispex); + return; + } + + ok_(__FILE__,line)(hres == S_OK, "Could not get IDOMStorageEvent: %08lx\n", hres); + IDispatchEx_Release(dispex); + + hres = IDOMStorageEvent_get_key(event, &bstr); + ok_(__FILE__,line)(hres == S_OK, "get_key failed: %08lx\n", hres); + ok_(__FILE__,line)((!bstr || !expect_key) ? (bstr == expect_key) : !wcscmp(bstr, expect_key), + "key = %s\n", wine_dbgstr_w(bstr)); + SysFreeString(bstr); + + hres = IDOMStorageEvent_get_oldValue(event, &bstr); + ok_(__FILE__,line)(hres == S_OK, "get_oldValue failed: %08lx\n", hres); + ok_(__FILE__,line)((!bstr || !expect_old_value) ? (bstr == expect_old_value) : !wcscmp(bstr, expect_old_value), + "oldValue = %s\n", wine_dbgstr_w(bstr)); + SysFreeString(bstr); + + hres = IDOMStorageEvent_get_newValue(event, &bstr); + ok_(__FILE__,line)(hres == S_OK, "get_newValue failed: %08lx\n", hres); + ok_(__FILE__,line)((!bstr || !expect_new_value) ? (bstr == expect_new_value) : !wcscmp(bstr, expect_new_value), + "newValue = %s\n", wine_dbgstr_w(bstr)); + SysFreeString(bstr); + + IDOMStorageEvent_Release(event); +} + +static HRESULT WINAPI doc1_onstorage_func(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp, + VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller) +{ + test_storage_event(pdp, FALSE); + CHECK_EXPECT(doc_onstorage[0]); + return S_OK; +} + +static const IDispatchExVtbl doc1_onstorage_vtbl = { + DispatchEx_QueryInterface, + DispatchEx_AddRef, + DispatchEx_Release, + DispatchEx_GetTypeInfoCount, + DispatchEx_GetTypeInfo, + DispatchEx_GetIDsOfNames, + DispatchEx_Invoke, + DispatchEx_GetDispID, + doc1_onstorage_func, + DispatchEx_DeleteMemberByName, + DispatchEx_DeleteMemberByDispID, + DispatchEx_GetMemberProperties, + DispatchEx_GetMemberName, + DispatchEx_GetNextDispID, + DispatchEx_GetNameSpaceParent +}; + +static HRESULT WINAPI doc1_onstoragecommit_func(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp, + VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller) +{ + test_storage_event(pdp, TRUE); + CHECK_EXPECT(doc_onstoragecommit[0]); + return S_OK; +} + +static const IDispatchExVtbl doc1_onstoragecommit_vtbl = { + DispatchEx_QueryInterface, + DispatchEx_AddRef, + DispatchEx_Release, + DispatchEx_GetTypeInfoCount, + DispatchEx_GetTypeInfo, + DispatchEx_GetIDsOfNames, + DispatchEx_Invoke, + DispatchEx_GetDispID, + doc1_onstoragecommit_func, + DispatchEx_DeleteMemberByName, + DispatchEx_DeleteMemberByDispID, + DispatchEx_GetMemberProperties, + DispatchEx_GetMemberName, + DispatchEx_GetNextDispID, + DispatchEx_GetNameSpaceParent +}; + +static HRESULT WINAPI window1_onstorage_func(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp, + VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller) +{ + test_storage_event(pdp, FALSE); + CHECK_EXPECT(window_onstorage[0]); + SET_EXPECT(doc_onstorage[0]); + return S_OK; +} + +static const IDispatchExVtbl window1_onstorage_vtbl = { + DispatchEx_QueryInterface, + DispatchEx_AddRef, + DispatchEx_Release, + DispatchEx_GetTypeInfoCount, + DispatchEx_GetTypeInfo, + DispatchEx_GetIDsOfNames, + DispatchEx_Invoke, + DispatchEx_GetDispID, + window1_onstorage_func, + DispatchEx_DeleteMemberByName, + DispatchEx_DeleteMemberByDispID, + DispatchEx_GetMemberProperties, + DispatchEx_GetMemberName, + DispatchEx_GetNextDispID, + DispatchEx_GetNameSpaceParent +}; + +static HRESULT WINAPI doc2_onstorage_func(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp, + VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller) +{ + test_storage_event(pdp, FALSE); + CHECK_EXPECT(doc_onstorage[1]); + return S_OK; +} + +static const IDispatchExVtbl doc2_onstorage_vtbl = { + DispatchEx_QueryInterface, + DispatchEx_AddRef, + DispatchEx_Release, + DispatchEx_GetTypeInfoCount, + DispatchEx_GetTypeInfo, + DispatchEx_GetIDsOfNames, + DispatchEx_Invoke, + DispatchEx_GetDispID, + doc2_onstorage_func, + DispatchEx_DeleteMemberByName, + DispatchEx_DeleteMemberByDispID, + DispatchEx_GetMemberProperties, + DispatchEx_GetMemberName, + DispatchEx_GetNextDispID, + DispatchEx_GetNameSpaceParent +}; + +static HRESULT WINAPI doc2_onstoragecommit_func(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp, + VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller) +{ + test_storage_event(pdp, TRUE); + CHECK_EXPECT(doc_onstoragecommit[1]); + return S_OK; +} + +static const IDispatchExVtbl doc2_onstoragecommit_vtbl = { + DispatchEx_QueryInterface, + DispatchEx_AddRef, + DispatchEx_Release, + DispatchEx_GetTypeInfoCount, + DispatchEx_GetTypeInfo, + DispatchEx_GetIDsOfNames, + DispatchEx_Invoke, + DispatchEx_GetDispID, + doc2_onstoragecommit_func, + DispatchEx_DeleteMemberByName, + DispatchEx_DeleteMemberByDispID, + DispatchEx_GetMemberProperties, + DispatchEx_GetMemberName, + DispatchEx_GetNextDispID, + DispatchEx_GetNameSpaceParent +}; + +static HRESULT WINAPI window2_onstorage_func(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp, + VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller) +{ + test_storage_event(pdp, FALSE); + CHECK_EXPECT(window_onstorage[1]); + SET_EXPECT(doc_onstorage[1]); + return S_OK; +} + +static const IDispatchExVtbl window2_onstorage_vtbl = { + DispatchEx_QueryInterface, + DispatchEx_AddRef, + DispatchEx_Release, + DispatchEx_GetTypeInfoCount, + DispatchEx_GetTypeInfo, + DispatchEx_GetIDsOfNames, + DispatchEx_Invoke, + DispatchEx_GetDispID, + window2_onstorage_func, + DispatchEx_DeleteMemberByName, + DispatchEx_DeleteMemberByDispID, + DispatchEx_GetMemberProperties, + DispatchEx_GetMemberName, + DispatchEx_GetNextDispID, + DispatchEx_GetNameSpaceParent +}; + +static void test_storage_events(unsigned document_mode) +{ + static struct { + IDispatchEx onstorage; + IDispatchEx onstoragecommit; + IDispatchEx window_onstorage; + } doc_onstorage_handlers[] = { + { { &doc1_onstorage_vtbl }, { &doc1_onstoragecommit_vtbl }, { &window1_onstorage_vtbl } }, + { { &doc2_onstorage_vtbl }, { &doc2_onstoragecommit_vtbl }, { &window2_onstorage_vtbl } }, + }; + IHTMLStorage *session_storage[2], *local_storage[2]; + IHTMLDocument2 *doc[2]; + BSTR key, value; + HRESULT hres; + VARIANT var; + unsigned i; + + trace("Running test_storage_events in %u mode...\n", document_mode); + + for(i = 0; i < ARRAY_SIZE(doc); i++) { + sprintf(index_html_data, + "<!DOCTYPE html>\n" + "<html>\n" + " <head>\n" + " <meta http-equiv="x-ua-compatible" content="Ie=%u">\n" + " <script src="winetest.js" type="text/javascript"></script>\n" + " <script type="text/javascript">var tests = [ function() { next_test() } ];</script>\n" + " </head>\n" + " <body onload="run_tests();">\n" + " </body>\n" + "</html>\n", document_mode); + + run_from_path(L"/index.html", "test_storage_events", &doc[i]); + } + + for(i = 0; i < ARRAY_SIZE(doc); i++) { + IHTMLWindow6 *window6; + IHTMLWindow7 *window7; + IHTMLWindow2 *window; + IHTMLDocument6 *doc6; + + hres = IHTMLDocument2_get_parentWindow(doc[i], &window); + ok(hres == S_OK, "get_parentWindow[%u] failed: %08lx\n", i, hres); + ok(window != NULL, "window[%u] == NULL\n", i); + + hres = IHTMLWindow2_QueryInterface(window, &IID_IHTMLWindow6, (void**)&window6); + ok(hres == S_OK, "Could not get IHTMLWindow6: %08lx\n", hres); + IHTMLWindow2_Release(window); + + hres = IHTMLWindow6_get_sessionStorage(window6, &session_storage[i]); + ok(hres == S_OK, "get_sessionStorage[%u] failed: %08lx\n", i, hres); + ok(session_storage[i] != NULL, "session_storage[%u] == NULL\n", i); + hres = IHTMLWindow6_get_localStorage(window6, &local_storage[i]); + ok(hres == S_OK, "get_localStorage[%u] failed: %08lx\n", i, hres); + ok(local_storage[i] != NULL, "local_storage[%u] == NULL\n", i); + if(i == 0) { + MSG msg; + IHTMLStorage_clear(local_storage[0]); + while(PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) { + TranslateMessage(&msg); + DispatchMessageW(&msg); + } + } + + hres = IHTMLDocument2_QueryInterface(doc[i], &IID_IHTMLDocument6, (void**)&doc6); + if(SUCCEEDED(hres)) { + V_VT(&var) = VT_DISPATCH; + V_DISPATCH(&var) = (IDispatch*)&doc_onstorage_handlers[i].onstorage; + hres = IHTMLDocument6_put_onstorage(doc6, var); + ok(hres == S_OK, "put_onstorage[%u] failed: %08lx\n", i, hres); + + V_DISPATCH(&var) = (IDispatch*)&doc_onstorage_handlers[i].onstoragecommit; + hres = IHTMLDocument6_put_onstoragecommit(doc6, var); + ok(hres == S_OK, "put_onstoragecommit[%u] failed: %08lx\n", i, hres); + IHTMLDocument6_Release(doc6); + } + + hres = IHTMLWindow6_QueryInterface(window6, &IID_IHTMLWindow7, (void**)&window7); + IHTMLWindow6_Release(window6); + if(SUCCEEDED(hres)) { + V_VT(&var) = VT_DISPATCH; + V_DISPATCH(&var) = (IDispatch*)&doc_onstorage_handlers[i].window_onstorage; + hres = IHTMLWindow7_put_onstorage(window7, var); + ok(hres == S_OK, "put_onstorage[%u] failed: %08lx\n", i, hres); + IHTMLWindow7_Release(window7); + } + } + + /* local storage */ + key = SysAllocString(L"test"); + hres = IHTMLStorage_removeItem(local_storage[0], key); + ok(hres == S_OK, "removeItem failed: %08lx\n", hres); + + value = SysAllocString(L"WINE"); + hres = IHTMLStorage_setItem(local_storage[0], key, value); + ok(hres == S_OK, "setItem failed: %08lx\n", hres); + SysFreeString(value); + check_local_onstorage(0, L"test", NULL, L"WINE"); + + value = SysAllocString(L"wine"); + hres = IHTMLStorage_setItem(local_storage[1], key, value); + ok(hres == S_OK, "setItem failed: %08lx\n", hres); + SysFreeString(value); + check_local_onstorage(1, L"test", L"WINE", L"wine"); + + hres = IHTMLStorage_removeItem(local_storage[0], key); + ok(hres == S_OK, "removeItem failed: %08lx\n", hres); + SysFreeString(key); + check_local_onstorage(0, L"test", L"wine", NULL); + + key = SysAllocString(L"winetest"); + value = SysAllocString(L"WineTest"); + hres = IHTMLStorage_setItem(local_storage[1], key, value); + ok(hres == S_OK, "setItem failed: %08lx\n", hres); + SysFreeString(value); + SysFreeString(key); + check_local_onstorage(1, L"winetest", NULL, L"WineTest"); + + hres = IHTMLStorage_clear(local_storage[0]); + ok(hres == S_OK, "clear failed: %08lx\n", hres); + check_local_onstorage(0, NULL, NULL, NULL); + + /* session storage */ + key = SysAllocString(L"foobar"); + hres = IHTMLStorage_removeItem(session_storage[0], key); + ok(hres == S_OK, "removeItem failed: %08lx\n", hres); + + value = SysAllocString(L"BarFoo"); + hres = IHTMLStorage_setItem(session_storage[0], key, value); + ok(hres == S_OK, "setItem failed: %08lx\n", hres); + SysFreeString(value); + check_session_onstorage(0, L"foobar", NULL, L"BarFoo"); + + value = SysAllocString(L"barfoo"); + hres = IHTMLStorage_setItem(session_storage[1], key, value); + ok(hres == S_OK, "setItem failed: %08lx\n", hres); + SysFreeString(value); + check_session_onstorage(1, L"foobar", L"BarFoo", L"barfoo"); + + hres = IHTMLStorage_removeItem(session_storage[0], key); + ok(hres == S_OK, "removeItem failed: %08lx\n", hres); + SysFreeString(key); + check_session_onstorage(0, L"foobar", L"barfoo", NULL); + + key = SysAllocString(L"winetest"); + value = SysAllocString(L"WineTest"); + hres = IHTMLStorage_setItem(session_storage[1], key, value); + ok(hres == S_OK, "setItem failed: %08lx\n", hres); + SysFreeString(value); + SysFreeString(key); + check_session_onstorage(1, L"winetest", NULL, L"WineTest"); + + hres = IHTMLStorage_clear(session_storage[0]); + ok(hres == S_OK, "clear failed: %08lx\n", hres); + check_session_onstorage(0, NULL, NULL, NULL); + + free_registered_streams(); + set_client_site(doc[0], FALSE); + set_client_site(doc[1], FALSE); + IHTMLDocument2_Release(doc[0]); + IHTMLDocument2_Release(doc[1]); +} + static void run_script_as_http_with_mode(const char *script, const char *opt, const char *document_mode) { trace("Running %s script in %s mode...\n", script, document_mode ? document_mode : "quirks"); @@ -3834,7 +4293,7 @@ static void run_script_as_http_with_mode(const char *script, const char *opt, co document_mode ? "">" : "", script);
- run_from_path(L"/index.html", opt ? opt : script); + run_from_path(L"/index.html", opt ? opt : script, NULL); }
static void test_strict_mode(void) @@ -3856,7 +4315,7 @@ static void test_strict_mode(void) " </body>\n" "</html>\n");
- run_from_path(L"/index.html", "test_strict_mode"); + run_from_path(L"/index.html", "test_strict_mode", NULL); }
static void init_protocol_handler(void) @@ -3893,6 +4352,11 @@ static void run_js_tests(void) init_protocol_handler();
test_strict_mode(); + test_storage_events(0); + test_storage_events(7); + test_storage_events(8); + test_storage_events(9); + test_storage_events(11); run_script_as_http_with_mode("xhr.js", NULL, "9"); run_script_as_http_with_mode("xhr.js", NULL, "10"); run_script_as_http_with_mode("xhr.js", NULL, "11");