[PATCH 1/4] shdocvw: Implement DocHostUIHandler::TranslateAccelerator.

Jacek Caban jacek at codeweavers.com
Fri Nov 12 06:35:03 CST 2010


Hi David,

On 11/12/10 8:49 AM, David Hedberg wrote:
> ---
>   dlls/shdocvw/dochost.c          |    9 +-
>   dlls/shdocvw/tests/webbrowser.c |  251 ++++++++++++++++++++++++++++++++++++++-
>   2 files changed, 253 insertions(+), 7 deletions(-)
>
> diff --git a/dlls/shdocvw/tests/webbrowser.c b/dlls/shdocvw/tests/webbrowser.c
> index babfe11..fd1c7f8 100644
> --- a/dlls/shdocvw/tests/webbrowser.c
> +++ b/dlls/shdocvw/tests/webbrowser.c
> @@ -122,8 +122,12 @@ DEFINE_EXPECT(QueryStatus_SETPROGRESSTEXT);
>   DEFINE_EXPECT(QueryStatus_STOP);
>   DEFINE_EXPECT(DocHost_EnableModeless_TRUE);
>   DEFINE_EXPECT(DocHost_EnableModeless_FALSE);
> +DEFINE_EXPECT(DocHost_TranslateAccelerator);
>   DEFINE_EXPECT(GetDropTarget);
>   DEFINE_EXPECT(TranslateUrl);
> +DEFINE_EXPECT(ShowUI);
> +DEFINE_EXPECT(HideUI);
> +DEFINE_EXPECT(RequestUIActivate);
>
>   static const WCHAR wszItem[] = {'i','t','e','m',0};
>   static const WCHAR emptyW[] = {0};
> @@ -133,6 +137,7 @@ static IWebBrowser2 *wb;
>
>   static HWND container_hwnd, shell_embedding_hwnd;
>   static BOOL is_downloading, is_first_load;
> +static HRESULT hr_dochost_TranslateAccelerator = E_NOTIMPL;
>   static const char *current_url;
>
>   #define DWL_EXPECT_BEFORE_NAVIGATE  0x01
> @@ -249,6 +254,10 @@ static HRESULT WINAPI OleCommandTarget_Exec(IOleCommandTarget *iface, const GUID
>   {
>       if(!pguidCmdGroup) {
>           switch(nCmdID) {
> +        case OLECMDID_UPDATECOMMANDS:
> +            ok(nCmdexecopt == 2, "nCmdexecopts=%08x\n", nCmdexecopt);
> +            ok(pvaIn == NULL, "Got non-null pvaIn\n");
> +            break;

This should also use CHECK_EXPECT()

>           case OLECMDID_SETPROGRESSMAX:
>               CHECK_EXPECT2(Exec_SETPROGRESSMAX);
>               ok(nCmdexecopt == OLECMDEXECOPT_DONTPROMPTUSER, "nCmdexecopts=%08x\n", nCmdexecopt);
> @@ -1128,7 +1137,7 @@ static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivateEx(IOleInPlaceSiteEx *iface
>
>   static HRESULT WINAPI InPlaceSite_RequestUIActivate(IOleInPlaceSiteEx *iface)
>   {
> -    ok(0, "unexpected call\n");
> +    CHECK_EXPECT2(RequestUIActivate);
>       return S_OK;
>   }
>
> @@ -1195,13 +1204,13 @@ static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD d
>           IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
>           IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
>   {
> -    ok(0, "unexpected call\n");
> +    CHECK_EXPECT(ShowUI);
>       return E_NOTIMPL;
>   }
>
>   static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
>   {
> -    ok(0, "unexpected call\n");
> +    CHECK_EXPECT(HideUI);
>       return E_NOTIMPL;
>   }
>
> @@ -1243,8 +1252,12 @@ static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface, L
>   static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface, LPMSG lpMsg,
>           const GUID *pguidCmdGroup, DWORD nCmdID)
>   {
> -    ok(0, "unexpected call\n");
> -    return E_NOTIMPL;
> +    CHECK_EXPECT(DocHost_TranslateAccelerator);
> +    ok(pguidCmdGroup != NULL, "Got NULL pguidCmdGroup.\n");
> +    if(pguidCmdGroup)
> +        ok(IsEqualGUID(pguidCmdGroup,&CGID_MSHTML), "Unexpected pguidCmdGroup\n");
> +    ok(lpMsg != NULL, "Got NULL lpMsg.\n");
> +    return hr_dochost_TranslateAccelerator;
>   }
>
>   static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
> @@ -2483,6 +2496,233 @@ static void test_QueryInterface(IUnknown *unk)
>
>   }
>
> +static void translate_messages(void)
> +{
> +    MSG msg;
> +    UINT i;
> +    for(i = 0; i<  100; i++) {
> +        while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
> +            TranslateMessage(&msg);
> +            DispatchMessage(&msg);
> +        }
> +        Sleep(5);
> +    }
> +}

> +static void test_TranslateAccelerator(IUnknown *unk)
> +{
> +    IWebBrowser2 *pwb2;
> +    IOleObject *pobj;
> +    HRESULT hr;
> +    DWORD keycode;
> +    IDispatch *disp_html;
> +    VARIANT url;
> +    MSG msg_a = {
> +        container_hwnd,
> +        0, 0, 0,
> +        GetTickCount(),
> +        {5, 5}
> +    };
> +
> +    is_downloading = TRUE;
> +
> +    hr = IUnknown_QueryInterface(unk,&IID_IWebBrowser2, (void**)&pwb2);
> +    ok(hr == S_OK, "Got 0x%08x\n", hr);
> +    if(FAILED(hr)) {
> +        skip("Failed to get IWebBrowser2\n"); /* This should never happen */
> +        return;
> +    }
> +
> +    disp_html = (void*)0xdeadbeef;
> +    hr = IWebBrowser2_get_Document(pwb2,&disp_html);
> +    todo_wine ok(hr == S_FALSE || broken(hr == S_OK) /*<  IE7 */, "Got 0x%08x\n", hr);
> +    ok(disp_html == NULL, "Received doc.\n");
> +    if(disp_html != NULL)
> +        IDispatch_Release(disp_html);
> +
> +    /* Activate */
> +    SET_EXPECT(GetContainer);
> +    SET_EXPECT(Site_GetWindow);
> +    SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
> +    SET_EXPECT(Invoke_AMBIENT_SILENT);
> +
> +    hr = IUnknown_QueryInterface(unk,&IID_IOleObject, (void**)&pobj);
> +    ok(hr == S_OK, "Got 0x%08x\n", hr);
> +    if(SUCCEEDED(hr)) {
> +        hr = IOleObject_SetClientSite(pobj,&ClientSite);
> +        ok(hr == S_OK, "SetClientSite failed: %08x\n", hr);
> +
> +        IOleObject_Release(pobj);
> +    }
> +
> +    CHECK_CALLED(GetContainer);
> +    CHECK_CALLED(Site_GetWindow);
> +    CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
> +    CHECK_CALLED(Invoke_AMBIENT_SILENT);

Please use test_ClientSite here. If for some reason you want to avoid its 
additional tests, simply add a flag argument to it.

> +    SET_EXPECT(Invoke_AMBIENT_USERMODE);
> +    SET_EXPECT(Exec_SETDOWNLOADSTATE_1);
> +    SET_EXPECT(GetHostInfo);
> +    SET_EXPECT(Invoke_AMBIENT_DLCONTROL);
> +    SET_EXPECT(Invoke_AMBIENT_USERAGENT);
> +    SET_EXPECT(Invoke_AMBIENT_PALETTE);
> +    SET_EXPECT(GetOptionKeyPath);
> +    SET_EXPECT(GetOverridesKeyPath);
> +    SET_EXPECT(QueryStatus_SETPROGRESSTEXT);
> +    SET_EXPECT(Exec_SETPROGRESSMAX);
> +    SET_EXPECT(Exec_SETPROGRESSPOS);
> +    SET_EXPECT(Exec_SETDOWNLOADSTATE_0);
> +    SET_EXPECT(DocHost_EnableModeless_FALSE);
> +    SET_EXPECT(DocHost_EnableModeless_TRUE);
> +
> +    SET_EXPECT(UpdateUI); /* Wine */
> +
> +    V_VT(&url) = VT_BSTR;
> +    V_BSTR(&url) = a2bstr("about:blank");
> +    current_url = "about:blank";
> +    hr = IWebBrowser2_Navigate2(pwb2,&url, NULL, NULL, NULL, NULL);
> +    ok(hr == S_OK, "Got 0x%08x\n", hr);
> +
> +    translate_messages();

Use test_Navigate2 here.

> +
> +    todo_wine ok(expect_UpdateUI, "UpdateUI called.\n");
> +    CLEAR_CALLED(UpdateUI);

This is not the right way to deal with it. I have a proper fix for test 
failures on Windows that should help here. I need to make it work on Wine 
before sending. I will try to send it today.

> +
> +    CHECK_CALLED(Invoke_AMBIENT_USERMODE);
> +    todo_wine CHECK_CALLED(Exec_SETDOWNLOADSTATE_1);
> +    CHECK_CALLED(GetHostInfo);
> +    CHECK_CALLED(Invoke_AMBIENT_DLCONTROL);
> +    CHECK_CALLED(Invoke_AMBIENT_USERAGENT);
> +    CHECK_CALLED(Invoke_AMBIENT_PALETTE);
> +    CHECK_CALLED(GetOptionKeyPath);
> +    CHECK_CALLED(GetOverridesKeyPath);
> +    todo_wine CHECK_CALLED(QueryStatus_SETPROGRESSTEXT);
> +    todo_wine CHECK_CALLED(Exec_SETPROGRESSMAX);
> +    todo_wine CHECK_CALLED(Exec_SETDOWNLOADSTATE_0);
> +
> +    /* Set the document */
> +    hr = IWebBrowser2_get_Document(pwb2,&disp_html);
> +    ok(hr == S_OK, "Got 0x%08x\n", hr);
> +    ok(disp_html != NULL, "Got %p\n", disp_html);
> +    if(SUCCEEDED(hr)) {
> +        IHTMLDocument2 *doc_html;
> +
> +        hr = IDispatch_QueryInterface(disp_html,&IID_IHTMLDocument2, (void**)&doc_html);
> +        ok(hr == S_OK, "Got 0x%08x\n", hr);
> +        if(SUCCEEDED(hr)) {
> +            IOleDocumentView *odc_view;
> +
> +            hr = IHTMLDocument2_QueryInterface(doc_html,&IID_IOleDocumentView, (void**)&odc_view);
> +            ok(hr == S_OK, "Got 0x%08x\n", hr);
> +            if(SUCCEEDED(hr)) {
> +                SET_EXPECT(Exec_SETPROGRESSMAX);
> +                SET_EXPECT(Exec_SETDOWNLOADSTATE_0);
> +                SET_EXPECT(Exec_SETDOWNLOADSTATE_1);
> +                SET_EXPECT(RequestUIActivate);
> +                SET_EXPECT(ShowUI);
> +                SET_EXPECT(HideUI);
> +                SET_EXPECT(GetDropTarget);
> +                SET_EXPECT(UpdateUI);
> +                SET_EXPECT(QueryStatus_STOP);
> +
> +                hr = IOleDocumentView_UIActivate(odc_view, TRUE);
> +                todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
> +
> +                translate_messages();
> +
> +                todo_wine CHECK_CALLED(Exec_SETPROGRESSMAX);
> +                todo_wine CHECK_CALLED(Exec_SETDOWNLOADSTATE_0);
> +                todo_wine CHECK_CALLED(Exec_SETDOWNLOADSTATE_1);
> +                todo_wine CHECK_CALLED(RequestUIActivate);
> +                todo_wine CHECK_CALLED(ShowUI);
> +                todo_wine CHECK_CALLED(HideUI);
> +                todo_wine CHECK_CALLED(GetDropTarget);
> +                CHECK_CALLED(UpdateUI);
> +                todo_wine CHECK_CALLED(QueryStatus_STOP);
> +
> +                IOleDocumentView_Release(odc_view);
> +            }
> +            IHTMLDocument2_Release(doc_html);
> +        }
> +        IDispatch_Release(disp_html);
> +    }
> +
> +    /* Call shdocvw _TranslateAccelerators from the other side */
> +    disp_html = (void*)0xdeadbeef;
> +    hr = IWebBrowser2_get_Document(pwb2,&disp_html);
> +    ok(hr == S_OK, "Got 0x%08x\n", hr);

Use get_document helper function.

> +    ok(disp_html != NULL, "Got %p\n", disp_html);
> +    if(SUCCEEDED(hr)) {
> +        IHTMLDocument2 *doc_html;
> +        hr = IDispatch_QueryInterface(disp_html,&IID_IHTMLDocument2, (void**)&doc_html);
> +        ok(hr == S_OK, "Got 0x%08x\n", hr);

You don't need it.

> +        if(SUCCEEDED(hr)) {
> +            IOleObject *html_obj;
> +            hr = IHTMLDocument2_QueryInterface(doc_html,&IID_IOleObject, (void**)&html_obj);
> +            ok(hr == S_OK, "Got 0x%08x\n", hr);
> +            if(SUCCEEDED(hr)) {
> +                IOleClientSite *the_site;
> +
> +                hr = IOleObject_GetClientSite(html_obj,&the_site);
> +                ok(hr == S_OK, "Got 0x%08x\n", hr);
> +                if(SUCCEEDED(hr)) {
> +                    IDocHostUIHandler2 *html_dochost;
> +                    IUnknown *punk_test;
> +
> +                    hr = IOleClientSite_QueryInterface(the_site,&IID_IOleInPlaceFrame, (void**)&punk_test);
> +                    ok(hr == E_NOINTERFACE, "Got 0x%08x\n", hr);
> +                    if(SUCCEEDED(hr)) IUnknown_Release(punk_test);
> +
> +                    hr = IOleClientSite_QueryInterface(the_site,&IID_IDocHostShowUI, (void**)&punk_test);
> +                    todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
> +                    if(SUCCEEDED(hr)) IUnknown_Release(punk_test);
> +
> +                    hr = IOleClientSite_QueryInterface(the_site,&IID_IDocHostUIHandler, (void**)&punk_test);
> +                    ok(hr == S_OK, "Got 0x%08x\n", hr);
> +                    if(SUCCEEDED(hr)) IUnknown_Release(punk_test);
> +
> +                    hr = IOleClientSite_QueryInterface(the_site,&IID_IDocHostUIHandler2, (void**)&html_dochost);
> +                    ok(hr == S_OK, "Got 0x%08x\n", hr);
> +                    if(SUCCEEDED(hr)) {
> +
> +                        msg_a.message = WM_KEYDOWN;
> +                        hr_dochost_TranslateAccelerator = 0xdeadbeef;
> +                        for(keycode = 0; keycode<= 0x100; keycode++) {
> +                            msg_a.wParam = keycode;
> +                            SET_EXPECT(DocHost_TranslateAccelerator);
> +                            hr = IDocHostUIHandler_TranslateAccelerator(html_dochost,&msg_a,&CGID_MSHTML, 1234);
> +                            ok(hr == 0xdeadbeef, "Got 0x%08x\n", hr);
> +                            CHECK_CALLED(DocHost_TranslateAccelerator);
> +                        }
> +                        hr_dochost_TranslateAccelerator = E_NOTIMPL;
> +
> +                        SET_EXPECT(DocHost_TranslateAccelerator);
> +                        hr = IDocHostUIHandler_TranslateAccelerator(html_dochost,&msg_a,&CGID_MSHTML, 1234);
> +                        ok(hr == E_NOTIMPL, "Got 0x%08x\n", hr);
> +                        CHECK_CALLED(DocHost_TranslateAccelerator);
> +
> +                        IDocHostUIHandler2_Release(html_dochost);
> +                    }
> +                    IOleClientSite_Release(the_site);
> +                }
> +                IOleObject_Release(html_obj);
> +            }
> +            IHTMLDocument2_Release(doc_html);
> +        }
> +        IDispatch_Release(disp_html);
> +    }
> +
> +    hr = IUnknown_QueryInterface(unk,&IID_IOleObject, (void**)&pobj);
> +    ok(hr == S_OK, "Got 0x%08x\n", hr);
> +    if(SUCCEEDED(hr)) {
> +        hr = IOleObject_SetClientSite(pobj, NULL);
> +        ok(hr == S_OK, "SetClientSite failed: %08x\n", hr);
> +        IOleObject_Release(pobj);
> +    }

Use test_ClientSite here.

Jacek



More information about the wine-devel mailing list