On Mon Jun 2 15:13:05 2025 +0000, Jacek Caban wrote:
It aborts early for some reason, and I can't figure out why. I'm not
sure if it's worth considering it's just tests? Maybe you have an idea? Did you try using `file:` protocol for the main HTML document too (instead of `IPersistStreamInit`)?
Sadly it doesn't seem to work either. Here's a diff using it:
```diff diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index b1625b6..663da23 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -12037,6 +12037,144 @@ static void test_quirks_mode(void) } }
+static void test_default_content_charset(void) +{ + static const char *charsets[] = { "utf8", "utf16", "utf8_bom", "utf16_bom" }; + static const char css_utf8[] = "\xef\xbb\xbf""body {background-color: #deadb8;}"; + static const WCHAR css_utf16[] = L"\xfeff""body {background-color: #deadb8;}"; + enum { utf8, utf16, utf8_bom, utf16_bom } doc_charset, css_charset; + WCHAR doc_stringW[128 + MAX_PATH], css_path[MAX_PATH], doc_path[MAX_PATH], docW_path[MAX_PATH]; + IHTMLCSSStyleDeclaration *style; + IHTMLPrivateWindow *priv_window; + HANDLE file, docfile, docWfile; + IHTMLWindow7 *window7; + IHTMLWindow2 *window; + IHTMLDocument2 *doc; + IHTMLElement *body; + IHTMLDOMNode *node; + char *doc_string; + BSTR bstr, bstr2; + DWORD written; + HRESULT hres; + VARIANT var; + VARIANT v; + UINT ret; + MSG msg; + + ret = GetTempPathW(MAX_PATH, doc_stringW); + ok(ret != 0, "GetTempPath failed, error %ld\n", GetLastError()); + ret = GetTempFileNameW(doc_stringW, L"doc", 0, docW_path); + ok(ret != 0, "GetTempFileName failed, error %ld\n", GetLastError()); + wcscpy(docW_path + wcslen(docW_path) - 4, L".htm"); + docWfile = CreateFileW(docW_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, 0); + ok(docWfile != INVALID_HANDLE_VALUE, "CreateFile failed, error %ld\n", GetLastError()); + + ret = GetTempFileNameW(doc_stringW, L"htm", 0, doc_path); + ok(ret != 0, "GetTempFileName failed, error %ld\n", GetLastError()); + wcscpy(doc_path + wcslen(doc_path) - 4, L".htm"); + docfile = CreateFileW(doc_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, 0); + ok(docfile != INVALID_HANDLE_VALUE, "CreateFile failed, error %ld\n", GetLastError()); + + ret = GetTempFileNameW(doc_stringW, L"css", 0, css_path); + ok(ret != 0, "GetTempFileName failed, error %ld\n", GetLastError()); + file = CreateFileW(css_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, 0); + ok(file != INVALID_HANDLE_VALUE, "CreateFile failed, error %ld\n", GetLastError()); + + ret = wsprintfW(doc_stringW, L"<!DOCTYPE html>\n<html><head><link href="file://%s" rel="stylesheet"></head><body></body></html>", css_path); + ret = WriteFile(docWfile, doc_stringW, ret * sizeof(WCHAR), &written, NULL); + ok(ret, "WriteFile failed, error %ld\n", GetLastError()); + + ret = WideCharToMultiByte(CP_UTF8, 0, doc_stringW, -1, NULL, 0, NULL, NULL); + doc_string = malloc(ret); + ret = WideCharToMultiByte(CP_UTF8, 0, doc_stringW, -1, doc_string, ret, NULL, NULL); + ret = WriteFile(docfile, doc_string, ret - 1, &written, NULL); + ok(ret, "WriteFile failed, error %ld\n", GetLastError()); + free(doc_string); + + for(doc_charset = utf8; doc_charset <= utf16; doc_charset++) { + for(css_charset = utf8; css_charset <= utf16_bom; css_charset++) { + notif_doc = doc = create_document(); + if(!doc) + return; + doc_complete = FALSE; + + switch(css_charset) { + case utf8: ret = WriteFile(file, css_utf8 + 3, sizeof(css_utf8) - sizeof(char) - 3, &written, NULL); break; + case utf8_bom: ret = WriteFile(file, css_utf8, sizeof(css_utf8) - sizeof(char), &written, NULL); break; + case utf16: ret = WriteFile(file, css_utf16 + 1, sizeof(css_utf16) - sizeof(WCHAR) - 2, &written, NULL); break; + case utf16_bom: ret = WriteFile(file, css_utf16, sizeof(css_utf16) - sizeof(WCHAR), &written, NULL); break; + } + ok(ret, "WriteFile failed, error %ld\n", GetLastError()); + + set_client_site(doc, TRUE); + do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink); + + hres = IHTMLDocument2_get_parentWindow(doc, &window); + ok(hres == S_OK, "get_parentWindow failed: %08lx\n", hres); + + wsprintfW(doc_stringW, L"file://%s", doc_charset == utf8 ? doc_path : docW_path); + + V_VT(&v) = VT_EMPTY; + bstr = SysAllocString(doc_stringW); + bstr2 = SysAllocString(L""); + hres = IHTMLWindow2_QueryInterface(window, &IID_IHTMLPrivateWindow, (void**)&priv_window); + ok(hres == S_OK, "Could not get IHTMLPrivateWindow) interface: %08lx\n", hres); + hres = IHTMLPrivateWindow_SuperNavigate(priv_window, bstr, bstr2, NULL, NULL, &v, &v, 0); + ok(hres == S_OK, "SuperNavigate failed: %08lx\n", hres); + IHTMLPrivateWindow_Release(priv_window); + IHTMLWindow2_Release(window); + SysFreeString(bstr2); + SysFreeString(bstr); + + while(!doc_complete && GetMessageW(&msg, NULL, 0, 0)) { + TranslateMessage(&msg); + DispatchMessageW(&msg); + } + + hres = IHTMLDocument2_get_parentWindow(doc, &window); + ok(hres == S_OK, "get_parentWindow failed: %08lx\n", hres); + + hres = IHTMLWindow2_QueryInterface(window, &IID_IHTMLWindow7, (void**)&window7); + ok(hres == S_OK, "Could not get IHTMLWindow7: %08lx\n", hres); + IHTMLWindow2_Release(window); + + hres = IHTMLDocument2_get_body(doc, &body); + ok(hres == S_OK, "Could not get body: %08lx\n", hres); + + hres = IHTMLElement_QueryInterface(body, &IID_IHTMLDOMNode, (void**)&node); + ok(hres == S_OK, "Could not get IHTMLDOMNode: %08lx\n", hres); + IHTMLElement_Release(body); + + hres = IHTMLWindow7_getComputedStyle(window7, node, NULL, &style); + ok(hres == S_OK, "getComputedStyle failed: %08lx\n", hres); + IHTMLWindow7_Release(window7); + IHTMLDOMNode_Release(node); + + hres = IHTMLCSSStyleDeclaration_get_backgroundColor(style, &var); + ok(hres == S_OK, "get_backgroundColor failed: %08lx\n", hres); + ok(V_VT(&var) == VT_BSTR, "backgroundColor VT = %d\n", V_VT(&var)); + ok(!wcscmp(V_BSTR(&var), L"rgb(222, 173, 184)"), "[%s:%s] backgroundColor = %s\n", charsets[doc_charset], charsets[css_charset], wine_dbgstr_w(V_BSTR(&var))); + IHTMLCSSStyleDeclaration_Release(style); + VariantClear(&var); + + set_client_site(doc, FALSE); + IHTMLDocument2_Release(doc); + + ret = SetFilePointer(file, 0, NULL, FILE_BEGIN); + ok(ret == 0, "wrong file offset %u\n", ret); + ret = SetEndOfFile(file); + ok(ret, "SetEndOfFile failed, error %ld\n", GetLastError()); + } + } + + CloseHandle(docWfile); + CloseHandle(docfile); + CloseHandle(file); + DeleteFileW(docW_path); + DeleteFileW(doc_path); + DeleteFileW(css_path); +} + static void test_document_mode_lock(void) { IHTMLOptionElementFactory *option, *option2; @@ -12414,6 +12552,7 @@ START_TEST(dom) }
test_quirks_mode(); + test_default_content_charset(); test_document_mode_lock(); test_document_mode_after_initnew(); test_threads(); ``` This code is pretty crude, I had to use actual htm extension so I didn't bother cleaning up the originals (.tmp) but it's enough to test it. Maybe you can try something else from it and see if it works?