[PATCH 1/3] urlmon: Add basic implementation of MapBrowserEmulationModeToUserAgent.
Jacek Caban
jacek at codeweavers.com
Mon Apr 11 06:00:35 CDT 2022
Hi Gabriel,
On 4/8/22 16:35, Gabriel Ivăncescu wrote:
> @@ -748,6 +750,44 @@ HRESULT WINAPI ObtainUserAgentString(DWORD option, char *ret, DWORD *ret_size)
> return hres;
> }
>
> +/***********************************************************************
> + * MapBrowserEmulationModeToUserAgent (URLMON.445)
> + * Undocumented, added in IE8
> + */
> +HRESULT WINAPI MapBrowserEmulationModeToUserAgent(const void *arg, WCHAR **ret)
> +{
> + DWORD size, version;
> + const WCHAR *ua;
> + WCHAR buf[1024];
> +
> + FIXME("%p %p\n", arg, ret);
I think that TRACE() would be fine here with your implementation. If
you'd like to point out that it's not complete, you may add something
like "semi-stub" in the message itself.
> +static void test_MapBrowserEmulationModeToUserAgent(BOOL custom_ua)
> +{
> + /* Undocumented structure of unknown size, crashes if it's too small (with random values from stack) */
> + struct
> + {
> + DWORD version;
> + char unknown[252];
> + } arg;
> + static char test_str[] = "test";
> + const char *custom_ua_msg = "";
> + HRESULT hres;
> + unsigned i;
> + WCHAR *ua;
> +
> + if(!pMapBrowserEmulationModeToUserAgent) {
> + win_skip("MapBrowserEmulationModeToUserAgent not available\n");
> + return;
> + }
> + memset(&arg, 0, sizeof(arg));
> +
> + if(custom_ua) {
> + hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, test_str, sizeof(test_str), 0);
> + ok(hres == S_OK, "UrlMkSetSessionOption failed: %08lx\n", hres);
> + custom_ua_msg = " (with custom ua)";
> + }
> +
> + for(i = 0; i < 12; i++) {
> + arg.version = i;
> + ua = (WCHAR*)0xdeadbeef;
> + hres = pMapBrowserEmulationModeToUserAgent(&arg, &ua);
> + ok(hres == (i == 5 || i >= 7 || custom_ua ? S_OK : E_FAIL),
> + "[%d] MapBrowserEmulationModeToUserAgent%s returned %08lx\n", i, custom_ua_msg, hres);
> + if(hres != S_OK)
> + ok(ua == NULL, "[%d] ua%s = %p\n", i, custom_ua_msg, ua);
> + else {
> + char buf[1024];
> + DWORD size = sizeof(buf);
> + WCHAR *ua2;
> +
> + hres = pObtainUserAgentString(custom_ua ? 0 : i, buf, &size);
> + ok(hres == S_OK, "[%d] ObtainUserAgentString%s failed: %08lx\n", i, custom_ua_msg, hres);
> + ua2 = a2co(buf);
> + ok(!lstrcmpW(ua, ua2), "[%d] ua%s = %s, expected %s\n", i, custom_ua_msg, wine_dbgstr_w(ua), wine_dbgstr_w(ua2));
> + CoTaskMemFree(ua2);
> + CoTaskMemFree(ua);
> + }
In custom_ua case, you could just compare the result of
MapBrowserEmulationModeToUserAgent directly to custom_ua_msg. I think it
would make it easier to see what you're testing.
Thanks,
Jacek
More information about the wine-devel
mailing list