Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/msscript.ocx/tests/msscript.c | 161 +++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+)
diff --git a/dlls/msscript.ocx/tests/msscript.c b/dlls/msscript.ocx/tests/msscript.c index 2e7f14d..5a29c7e 100644 --- a/dlls/msscript.ocx/tests/msscript.c +++ b/dlls/msscript.ocx/tests/msscript.c @@ -1905,6 +1905,166 @@ static void test_AllowUI(void) IScriptControl_Release(sc); }
+static void test_SitehWnd(void) +{ + IScriptControl *sc; + LONG site_hwnd; + HRESULT hr; + HWND hwnd; + BSTR str; + + hwnd = CreateWindowA("static", NULL, WS_OVERLAPPEDWINDOW, 50, 50, 100, 100, NULL, NULL, NULL, NULL); + ok(hwnd != NULL, "failed to create window, error %08x\n", GetLastError()); + + hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, + &IID_IScriptControl, (void**)&sc); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IScriptControl_get_SitehWnd(sc, NULL); + todo_wine ok(hr == E_POINTER, "got 0x%08x\n", hr); + + site_hwnd = 0xdeadbeef; + hr = IScriptControl_get_SitehWnd(sc, &site_hwnd); + todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); + todo_wine ok(!site_hwnd, "got %p\n", (HWND)(LONG_PTR)site_hwnd); + + hr = IScriptControl_put_SitehWnd(sc, 1); + todo_wine ok(hr == CTL_E_INVALIDPROPERTYVALUE, "got 0x%08x\n", hr); + + site_hwnd = 0xdeadbeef; + hr = IScriptControl_get_SitehWnd(sc, &site_hwnd); + todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); + todo_wine ok(!site_hwnd, "got %p\n", (HWND)(LONG_PTR)site_hwnd); + + hr = IScriptControl_put_SitehWnd(sc, 0); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IScriptControl_put_SitehWnd(sc, (LONG)(LONG_PTR)hwnd); + ok(hr == S_OK, "got 0x%08x\n", hr); + + str = SysAllocString(L"vbscript"); + hr = IScriptControl_put_Language(sc, str); + ok(hr == S_OK, "got 0x%08x\n", hr); + SysFreeString(str); + + site_hwnd = 0; + hr = IScriptControl_get_SitehWnd(sc, &site_hwnd); + todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); + todo_wine ok((HWND)(LONG_PTR)site_hwnd == hwnd, "got %p, expected %p\n", (HWND)(LONG_PTR)site_hwnd, hwnd); + + IScriptControl_Release(sc); + + /* custom script engine */ + if (have_custom_engine) + { + IActiveScriptSiteWindow *site_window; + HWND window; + + hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, + &IID_IScriptControl, (void **)&sc); + ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr); + + hr = IScriptControl_put_SitehWnd(sc, (LONG)(LONG_PTR)hwnd); + ok(hr == S_OK, "got 0x%08x\n", hr); + + SET_EXPECT(CreateInstance); + SET_EXPECT(SetInterfaceSafetyOptions); + SET_EXPECT(SetScriptSite); + SET_EXPECT(QI_IActiveScriptParse); + SET_EXPECT(InitNew); + + str = SysAllocString(L"testscript"); + hr = IScriptControl_put_Language(sc, str); + ok(hr == S_OK, "got 0x%08x\n", hr); + SysFreeString(str); + + CHECK_CALLED(CreateInstance); + CHECK_CALLED(SetInterfaceSafetyOptions); + CHECK_CALLED(SetScriptSite); + CHECK_CALLED(QI_IActiveScriptParse); + CHECK_CALLED(InitNew); + + hr = IActiveScriptSite_QueryInterface(site, &IID_IActiveScriptSiteWindow, (void**)&site_window); + ok(hr == S_OK, "got 0x%08x\n", hr); + + site_hwnd = 0; + hr = IScriptControl_get_SitehWnd(sc, &site_hwnd); + todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); + todo_wine ok((HWND)(LONG_PTR)site_hwnd == hwnd, "got %p, expected %p\n", (HWND)(LONG_PTR)site_hwnd, hwnd); + + window = NULL; + hr = IActiveScriptSiteWindow_GetWindow(site_window, NULL); + todo_wine ok(hr == E_POINTER, "got 0x%08x\n", hr); + hr = IActiveScriptSiteWindow_GetWindow(site_window, &window); + todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); + todo_wine ok(window == hwnd, "got %p, expected %p\n", window, hwnd); + + hr = IActiveScriptSiteWindow_EnableModeless(site_window, FALSE); + todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); + hr = IActiveScriptSiteWindow_EnableModeless(site_window, TRUE); + todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); + + site_hwnd = 0xdeadbeef; + hr = IScriptControl_put_SitehWnd(sc, 0); + ok(hr == S_OK, "got 0x%08x\n", hr); + hr = IScriptControl_get_SitehWnd(sc, &site_hwnd); + todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); + todo_wine ok(!site_hwnd, "got %p\n", (HWND)(LONG_PTR)site_hwnd); + + window = (HWND)0xdeadbeef; + hr = IActiveScriptSiteWindow_GetWindow(site_window, &window); + todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); + todo_wine ok(!window, "got %p\n", window); + + site_hwnd = 0; + hr = IScriptControl_put_SitehWnd(sc, (LONG)(LONG_PTR)hwnd); + ok(hr == S_OK, "got 0x%08x\n", hr); + hr = IScriptControl_get_SitehWnd(sc, &site_hwnd); + todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); + todo_wine ok((HWND)(LONG_PTR)site_hwnd == hwnd, "got %p, expected %p\n", (HWND)(LONG_PTR)site_hwnd, hwnd); + + window = NULL; + hr = IActiveScriptSiteWindow_GetWindow(site_window, &window); + todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); + todo_wine ok(window == hwnd, "got %p, expected %p\n", window, hwnd); + + hr = IScriptControl_put_AllowUI(sc, VARIANT_FALSE); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IScriptControl_get_SitehWnd(sc, &site_hwnd); + todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); + todo_wine ok((HWND)(LONG_PTR)site_hwnd == hwnd, "got %p, expected %p\n", (HWND)(LONG_PTR)site_hwnd, hwnd); + + window = NULL; + hr = IActiveScriptSiteWindow_GetWindow(site_window, &window); + todo_wine ok(hr == E_FAIL, "got 0x%08x\n", hr); + ok(!window, "got %p\n", window); + + hr = IScriptControl_put_AllowUI(sc, VARIANT_TRUE); + ok(hr == S_OK, "got 0x%08x\n", hr); + + window = NULL; + hr = IActiveScriptSiteWindow_GetWindow(site_window, &window); + todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); + todo_wine ok(window == hwnd, "got %p, expected %p\n", window, hwnd); + + IActiveScriptSite_Release(site); + + SET_EXPECT(Close); + IScriptControl_Release(sc); + CHECK_CALLED(Close); + + window = NULL; + hr = IActiveScriptSiteWindow_GetWindow(site_window, &window); + todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); + todo_wine ok(window == hwnd, "got %p, expected %p\n", window, hwnd); + + IActiveScriptSiteWindow_Release(site_window); + } + + DestroyWindow(hwnd); +} + static void test_UseSafeSubset(void) { IScriptControl *sc; @@ -4100,6 +4260,7 @@ START_TEST(msscript) test_Reset(); test_AddObject(); test_AllowUI(); + test_SitehWnd(); test_UseSafeSubset(); test_State(); test_IScriptControl_Eval();
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/msscript.ocx/msscript.c | 7 ++++++- dlls/msscript.ocx/tests/msscript.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/dlls/msscript.ocx/msscript.c b/dlls/msscript.ocx/msscript.c index ee0cf25..f096296 100644 --- a/dlls/msscript.ocx/msscript.c +++ b/dlls/msscript.ocx/msscript.c @@ -166,6 +166,7 @@ struct ScriptControl { LONG ref; IOleClientSite *site; SIZEL extent; + LONG site_hwnd; LONG timeout; VARIANT_BOOL allow_ui; VARIANT_BOOL use_safe_subset; @@ -2751,8 +2752,12 @@ static HRESULT WINAPI ScriptControl_put_SitehWnd(IScriptControl *iface, LONG hwn { ScriptControl *This = impl_from_IScriptControl(iface);
- FIXME("(%p)->(%x)\n", This, hwnd); + TRACE("(%p)->(%x)\n", This, hwnd);
+ if (hwnd && !IsWindow((HWND)hwnd)) + return CTL_E_INVALIDPROPERTYVALUE; + + This->site_hwnd = hwnd; return S_OK; }
diff --git a/dlls/msscript.ocx/tests/msscript.c b/dlls/msscript.ocx/tests/msscript.c index 5a29c7e..8b63e97 100644 --- a/dlls/msscript.ocx/tests/msscript.c +++ b/dlls/msscript.ocx/tests/msscript.c @@ -1929,7 +1929,7 @@ static void test_SitehWnd(void) todo_wine ok(!site_hwnd, "got %p\n", (HWND)(LONG_PTR)site_hwnd);
hr = IScriptControl_put_SitehWnd(sc, 1); - todo_wine ok(hr == CTL_E_INVALIDPROPERTYVALUE, "got 0x%08x\n", hr); + ok(hr == CTL_E_INVALIDPROPERTYVALUE, "got 0x%08x\n", hr);
site_hwnd = 0xdeadbeef; hr = IScriptControl_get_SitehWnd(sc, &site_hwnd);
Hi Gabriel,
On 02.09.2020 15:01, Gabriel Ivăncescu wrote:
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com
dlls/msscript.ocx/msscript.c | 7 ++++++- dlls/msscript.ocx/tests/msscript.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/dlls/msscript.ocx/msscript.c b/dlls/msscript.ocx/msscript.c index ee0cf25..f096296 100644 --- a/dlls/msscript.ocx/msscript.c +++ b/dlls/msscript.ocx/msscript.c @@ -166,6 +166,7 @@ struct ScriptControl { LONG ref; IOleClientSite *site; SIZEL extent;
- LONG site_hwnd;
How about storing it as HWND instead?
LONG timeout; VARIANT_BOOL allow_ui; VARIANT_BOOL use_safe_subset;
@@ -2751,8 +2752,12 @@ static HRESULT WINAPI ScriptControl_put_SitehWnd(IScriptControl *iface, LONG hwn { ScriptControl *This = impl_from_IScriptControl(iface);
- FIXME("(%p)->(%x)\n", This, hwnd);
TRACE("(%p)->(%x)\n", This, hwnd);
if (hwnd && !IsWindow((HWND)hwnd))
This causes a warning on 64-bit build. You may use LongToPtr instead.
Thanks,
Jacek
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/msscript.ocx/msscript.c | 9 +++++++-- dlls/msscript.ocx/tests/msscript.c | 30 +++++++++++++++--------------- 2 files changed, 22 insertions(+), 17 deletions(-)
diff --git a/dlls/msscript.ocx/msscript.c b/dlls/msscript.ocx/msscript.c index f096296..55a5621 100644 --- a/dlls/msscript.ocx/msscript.c +++ b/dlls/msscript.ocx/msscript.c @@ -2764,8 +2764,13 @@ static HRESULT WINAPI ScriptControl_put_SitehWnd(IScriptControl *iface, LONG hwn static HRESULT WINAPI ScriptControl_get_SitehWnd(IScriptControl *iface, LONG *p) { ScriptControl *This = impl_from_IScriptControl(iface); - FIXME("(%p)->(%p)\n", This, p); - return E_NOTIMPL; + + TRACE("(%p)->(%p)\n", This, p); + + if (!p) return E_POINTER; + + *p = This->site_hwnd; + return S_OK; }
static HRESULT WINAPI ScriptControl_get_Timeout(IScriptControl *iface, LONG *p) diff --git a/dlls/msscript.ocx/tests/msscript.c b/dlls/msscript.ocx/tests/msscript.c index 8b63e97..8e4fa1b 100644 --- a/dlls/msscript.ocx/tests/msscript.c +++ b/dlls/msscript.ocx/tests/msscript.c @@ -1921,20 +1921,20 @@ static void test_SitehWnd(void) ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IScriptControl_get_SitehWnd(sc, NULL); - todo_wine ok(hr == E_POINTER, "got 0x%08x\n", hr); + ok(hr == E_POINTER, "got 0x%08x\n", hr);
site_hwnd = 0xdeadbeef; hr = IScriptControl_get_SitehWnd(sc, &site_hwnd); - todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); - todo_wine ok(!site_hwnd, "got %p\n", (HWND)(LONG_PTR)site_hwnd); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(!site_hwnd, "got %p\n", (HWND)(LONG_PTR)site_hwnd);
hr = IScriptControl_put_SitehWnd(sc, 1); ok(hr == CTL_E_INVALIDPROPERTYVALUE, "got 0x%08x\n", hr);
site_hwnd = 0xdeadbeef; hr = IScriptControl_get_SitehWnd(sc, &site_hwnd); - todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); - todo_wine ok(!site_hwnd, "got %p\n", (HWND)(LONG_PTR)site_hwnd); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(!site_hwnd, "got %p\n", (HWND)(LONG_PTR)site_hwnd);
hr = IScriptControl_put_SitehWnd(sc, 0); ok(hr == S_OK, "got 0x%08x\n", hr); @@ -1949,8 +1949,8 @@ static void test_SitehWnd(void)
site_hwnd = 0; hr = IScriptControl_get_SitehWnd(sc, &site_hwnd); - todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); - todo_wine ok((HWND)(LONG_PTR)site_hwnd == hwnd, "got %p, expected %p\n", (HWND)(LONG_PTR)site_hwnd, hwnd); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok((HWND)(LONG_PTR)site_hwnd == hwnd, "got %p, expected %p\n", (HWND)(LONG_PTR)site_hwnd, hwnd);
IScriptControl_Release(sc);
@@ -1989,8 +1989,8 @@ static void test_SitehWnd(void)
site_hwnd = 0; hr = IScriptControl_get_SitehWnd(sc, &site_hwnd); - todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); - todo_wine ok((HWND)(LONG_PTR)site_hwnd == hwnd, "got %p, expected %p\n", (HWND)(LONG_PTR)site_hwnd, hwnd); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok((HWND)(LONG_PTR)site_hwnd == hwnd, "got %p, expected %p\n", (HWND)(LONG_PTR)site_hwnd, hwnd);
window = NULL; hr = IActiveScriptSiteWindow_GetWindow(site_window, NULL); @@ -2008,8 +2008,8 @@ static void test_SitehWnd(void) hr = IScriptControl_put_SitehWnd(sc, 0); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IScriptControl_get_SitehWnd(sc, &site_hwnd); - todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); - todo_wine ok(!site_hwnd, "got %p\n", (HWND)(LONG_PTR)site_hwnd); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(!site_hwnd, "got %p\n", (HWND)(LONG_PTR)site_hwnd);
window = (HWND)0xdeadbeef; hr = IActiveScriptSiteWindow_GetWindow(site_window, &window); @@ -2020,8 +2020,8 @@ static void test_SitehWnd(void) hr = IScriptControl_put_SitehWnd(sc, (LONG)(LONG_PTR)hwnd); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IScriptControl_get_SitehWnd(sc, &site_hwnd); - todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); - todo_wine ok((HWND)(LONG_PTR)site_hwnd == hwnd, "got %p, expected %p\n", (HWND)(LONG_PTR)site_hwnd, hwnd); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok((HWND)(LONG_PTR)site_hwnd == hwnd, "got %p, expected %p\n", (HWND)(LONG_PTR)site_hwnd, hwnd);
window = NULL; hr = IActiveScriptSiteWindow_GetWindow(site_window, &window); @@ -2032,8 +2032,8 @@ static void test_SitehWnd(void) ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IScriptControl_get_SitehWnd(sc, &site_hwnd); - todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); - todo_wine ok((HWND)(LONG_PTR)site_hwnd == hwnd, "got %p, expected %p\n", (HWND)(LONG_PTR)site_hwnd, hwnd); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok((HWND)(LONG_PTR)site_hwnd == hwnd, "got %p, expected %p\n", (HWND)(LONG_PTR)site_hwnd, hwnd);
window = NULL; hr = IActiveScriptSiteWindow_GetWindow(site_window, &window);
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com ---
We keep a copy of the site_hwnd since the function works even without the control (it just can't be changed anymore), see last test.
dlls/msscript.ocx/msscript.c | 14 ++++++++++++-- dlls/msscript.ocx/tests/msscript.c | 24 ++++++++++++------------ 2 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/dlls/msscript.ocx/msscript.c b/dlls/msscript.ocx/msscript.c index 55a5621..67d894d 100644 --- a/dlls/msscript.ocx/msscript.c +++ b/dlls/msscript.ocx/msscript.c @@ -148,6 +148,7 @@ struct ScriptHost { IActiveScriptParse *parse; ScriptError *error; SCRIPTSTATE script_state; + LONG site_hwnd; CLSID clsid;
unsigned int module_count; @@ -761,9 +762,13 @@ static HRESULT WINAPI ActiveScriptSiteWindow_GetWindow(IActiveScriptSiteWindow * { ScriptHost *This = impl_from_IActiveScriptSiteWindow(iface);
- FIXME("(%p, %p)\n", This, hwnd); + TRACE("(%p, %p)\n", This, hwnd);
- return E_NOTIMPL; + if (!hwnd) return E_POINTER; + if (This->site_hwnd == -1) return E_FAIL; + + *hwnd = (HWND)This->site_hwnd; + return S_OK; }
static HRESULT WINAPI ActiveScriptSiteWindow_EnableModeless(IActiveScriptSiteWindow *iface, BOOL enable) @@ -2481,6 +2486,7 @@ static HRESULT init_script_host(ScriptControl *control, const CLSID *clsid, Scri goto failed; } host->script_state = SCRIPTSTATE_INITIALIZED; + host->site_hwnd = (control->allow_ui == VARIANT_FALSE) ? -1 : control->site_hwnd; host->error = control->error; IScriptError_AddRef(&host->error->IScriptError_iface);
@@ -2758,6 +2764,8 @@ static HRESULT WINAPI ScriptControl_put_SitehWnd(IScriptControl *iface, LONG hwn return CTL_E_INVALIDPROPERTYVALUE;
This->site_hwnd = hwnd; + if (This->host) + This->host->site_hwnd = (This->allow_ui == VARIANT_FALSE) ? -1 : hwnd; return S_OK; }
@@ -2820,6 +2828,8 @@ static HRESULT WINAPI ScriptControl_put_AllowUI(IScriptControl *iface, VARIANT_B TRACE("(%p)->(%x)\n", This, allow_ui);
This->allow_ui = allow_ui; + if (This->host) + This->host->site_hwnd = (allow_ui == VARIANT_FALSE) ? -1 : This->site_hwnd; return S_OK; }
diff --git a/dlls/msscript.ocx/tests/msscript.c b/dlls/msscript.ocx/tests/msscript.c index 8e4fa1b..2df85ff 100644 --- a/dlls/msscript.ocx/tests/msscript.c +++ b/dlls/msscript.ocx/tests/msscript.c @@ -1994,10 +1994,10 @@ static void test_SitehWnd(void)
window = NULL; hr = IActiveScriptSiteWindow_GetWindow(site_window, NULL); - todo_wine ok(hr == E_POINTER, "got 0x%08x\n", hr); + ok(hr == E_POINTER, "got 0x%08x\n", hr); hr = IActiveScriptSiteWindow_GetWindow(site_window, &window); - todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); - todo_wine ok(window == hwnd, "got %p, expected %p\n", window, hwnd); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(window == hwnd, "got %p, expected %p\n", window, hwnd);
hr = IActiveScriptSiteWindow_EnableModeless(site_window, FALSE); todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); @@ -2013,8 +2013,8 @@ static void test_SitehWnd(void)
window = (HWND)0xdeadbeef; hr = IActiveScriptSiteWindow_GetWindow(site_window, &window); - todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); - todo_wine ok(!window, "got %p\n", window); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(!window, "got %p\n", window);
site_hwnd = 0; hr = IScriptControl_put_SitehWnd(sc, (LONG)(LONG_PTR)hwnd); @@ -2025,8 +2025,8 @@ static void test_SitehWnd(void)
window = NULL; hr = IActiveScriptSiteWindow_GetWindow(site_window, &window); - todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); - todo_wine ok(window == hwnd, "got %p, expected %p\n", window, hwnd); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(window == hwnd, "got %p, expected %p\n", window, hwnd);
hr = IScriptControl_put_AllowUI(sc, VARIANT_FALSE); ok(hr == S_OK, "got 0x%08x\n", hr); @@ -2037,7 +2037,7 @@ static void test_SitehWnd(void)
window = NULL; hr = IActiveScriptSiteWindow_GetWindow(site_window, &window); - todo_wine ok(hr == E_FAIL, "got 0x%08x\n", hr); + ok(hr == E_FAIL, "got 0x%08x\n", hr); ok(!window, "got %p\n", window);
hr = IScriptControl_put_AllowUI(sc, VARIANT_TRUE); @@ -2045,8 +2045,8 @@ static void test_SitehWnd(void)
window = NULL; hr = IActiveScriptSiteWindow_GetWindow(site_window, &window); - todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); - todo_wine ok(window == hwnd, "got %p, expected %p\n", window, hwnd); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(window == hwnd, "got %p, expected %p\n", window, hwnd);
IActiveScriptSite_Release(site);
@@ -2056,8 +2056,8 @@ static void test_SitehWnd(void)
window = NULL; hr = IActiveScriptSiteWindow_GetWindow(site_window, &window); - todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); - todo_wine ok(window == hwnd, "got %p, expected %p\n", window, hwnd); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(window == hwnd, "got %p, expected %p\n", window, hwnd);
IActiveScriptSiteWindow_Release(site_window); }
Hi Gabriel,
On 02.09.2020 15:01, Gabriel Ivăncescu wrote:
@@ -2481,6 +2486,7 @@ static HRESULT init_script_host(ScriptControl *control, const CLSID *clsid, Scri goto failed; } host->script_state = SCRIPTSTATE_INITIALIZED;
- host->site_hwnd = (control->allow_ui == VARIANT_FALSE) ? -1 : control->site_hwnd;
Please avoid direct comparisons of bool-like values. consol->allow_ui ? ... : ...; would be nicer.
Thanks,
Jacek
This is needed so e.g. vbscript can display message boxes when used from the script control.
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/msscript.ocx/msscript.c | 4 ++-- dlls/msscript.ocx/tests/msscript.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/dlls/msscript.ocx/msscript.c b/dlls/msscript.ocx/msscript.c index 67d894d..0fd77fb 100644 --- a/dlls/msscript.ocx/msscript.c +++ b/dlls/msscript.ocx/msscript.c @@ -775,9 +775,9 @@ static HRESULT WINAPI ActiveScriptSiteWindow_EnableModeless(IActiveScriptSiteWin { ScriptHost *This = impl_from_IActiveScriptSiteWindow(iface);
- FIXME("(%p, %d)\n", This, enable); + FIXME("(%p, %d): stub\n", This, enable);
- return E_NOTIMPL; + return S_OK; }
static const IActiveScriptSiteWindowVtbl ActiveScriptSiteWindowVtbl = { diff --git a/dlls/msscript.ocx/tests/msscript.c b/dlls/msscript.ocx/tests/msscript.c index 2df85ff..e6d139f 100644 --- a/dlls/msscript.ocx/tests/msscript.c +++ b/dlls/msscript.ocx/tests/msscript.c @@ -2000,9 +2000,9 @@ static void test_SitehWnd(void) ok(window == hwnd, "got %p, expected %p\n", window, hwnd);
hr = IActiveScriptSiteWindow_EnableModeless(site_window, FALSE); - todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); + ok(hr == S_OK, "got 0x%08x\n", hr); hr = IActiveScriptSiteWindow_EnableModeless(site_window, TRUE); - todo_wine ok(hr == S_OK, "got 0x%08x\n", hr); + ok(hr == S_OK, "got 0x%08x\n", hr);
site_hwnd = 0xdeadbeef; hr = IScriptControl_put_SitehWnd(sc, 0);
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/msscript.ocx/msscript.c | 40 ++++++++----- dlls/msscript.ocx/tests/msscript.c | 93 +++++++++++++++++++++++++++++- 2 files changed, 117 insertions(+), 16 deletions(-)
diff --git a/dlls/msscript.ocx/msscript.c b/dlls/msscript.ocx/msscript.c index 0fd77fb..7917732 100644 --- a/dlls/msscript.ocx/msscript.c +++ b/dlls/msscript.ocx/msscript.c @@ -2426,9 +2426,30 @@ static const IScriptErrorVtbl ScriptErrorVtbl = { ScriptError_Clear };
-static HRESULT init_script_host(ScriptControl *control, const CLSID *clsid, ScriptHost **ret) +static HRESULT set_safety_opts(IActiveScript *script, VARIANT_BOOL use_safe_subset) { IObjectSafety *objsafety; + HRESULT hr; + + hr = IActiveScript_QueryInterface(script, &IID_IObjectSafety, (void**)&objsafety); + if (FAILED(hr)) { + FIXME("Could not get IObjectSafety, %#x\n", hr); + return hr; + } + + hr = IObjectSafety_SetInterfaceSafetyOptions(objsafety, &IID_IActiveScriptParse, INTERFACESAFE_FOR_UNTRUSTED_DATA, + (use_safe_subset == VARIANT_FALSE) ? 0 : INTERFACESAFE_FOR_UNTRUSTED_DATA); + IObjectSafety_Release(objsafety); + if (FAILED(hr)) { + FIXME("SetInterfaceSafetyOptions failed, %#x\n", hr); + return hr; + } + + return hr; +} + +static HRESULT init_script_host(ScriptControl *control, const CLSID *clsid, ScriptHost **ret) +{ ScriptHost *host; HRESULT hr;
@@ -2455,18 +2476,8 @@ static HRESULT init_script_host(ScriptControl *control, const CLSID *clsid, Scri goto failed; }
- hr = IActiveScript_QueryInterface(host->script, &IID_IObjectSafety, (void**)&objsafety); - if (FAILED(hr)) { - FIXME("Could not get IObjectSafety, %#x\n", hr); - goto failed; - } - - hr = IObjectSafety_SetInterfaceSafetyOptions(objsafety, &IID_IActiveScriptParse, INTERFACESAFE_FOR_UNTRUSTED_DATA, 0); - IObjectSafety_Release(objsafety); - if (FAILED(hr)) { - FIXME("SetInterfaceSafetyOptions failed, %#x\n", hr); - goto failed; - } + hr = set_safety_opts(host->script, control->use_safe_subset); + if (FAILED(hr)) goto failed;
hr = IActiveScript_SetScriptSite(host->script, &host->IActiveScriptSite_iface); if (FAILED(hr)) { @@ -2850,6 +2861,9 @@ static HRESULT WINAPI ScriptControl_put_UseSafeSubset(IScriptControl *iface, VAR ScriptControl *This = impl_from_IScriptControl(iface); TRACE("(%p)->(%x)\n", This, use_safe_subset);
+ if (This->host && This->use_safe_subset != use_safe_subset) + set_safety_opts(This->host->script, use_safe_subset); + This->use_safe_subset = use_safe_subset; return S_OK; } diff --git a/dlls/msscript.ocx/tests/msscript.c b/dlls/msscript.ocx/tests/msscript.c index e6d139f..a6ec099 100644 --- a/dlls/msscript.ocx/tests/msscript.c +++ b/dlls/msscript.ocx/tests/msscript.c @@ -91,6 +91,7 @@ static const WCHAR vbW[] = {'V','B','S','c','r','i','p','t',0};
DEFINE_EXPECT(CreateInstance); DEFINE_EXPECT(SetInterfaceSafetyOptions); +DEFINE_EXPECT(SetInterfaceSafetyOptions_UseSafeSubset); DEFINE_EXPECT(InitNew); DEFINE_EXPECT(Close); DEFINE_EXPECT(Bind); @@ -278,12 +279,13 @@ static HRESULT WINAPI ObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *ifac static HRESULT WINAPI ObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid, DWORD mask, DWORD options) { - CHECK_EXPECT(SetInterfaceSafetyOptions); + if (options == INTERFACESAFE_FOR_UNTRUSTED_DATA) + CHECK_EXPECT(SetInterfaceSafetyOptions_UseSafeSubset); + else + CHECK_EXPECT(SetInterfaceSafetyOptions);
ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid)); - ok(mask == INTERFACESAFE_FOR_UNTRUSTED_DATA, "option mask = %x\n", mask); - ok(options == 0, "options = %x\n", options);
return S_OK; } @@ -2100,6 +2102,91 @@ static void test_UseSafeSubset(void) ok(use_safe_subset == VARIANT_TRUE, "got %d\n", use_safe_subset);
IScriptControl_Release(sc); + + /* custom script engine */ + if (have_custom_engine) + { + hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, + &IID_IScriptControl, (void **)&sc); + ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr); + + SET_EXPECT(CreateInstance); + SET_EXPECT(SetInterfaceSafetyOptions); + SET_EXPECT(SetScriptSite); + SET_EXPECT(QI_IActiveScriptParse); + SET_EXPECT(InitNew); + + str = SysAllocString(L"testscript"); + hr = IScriptControl_put_Language(sc, str); + ok(hr == S_OK, "got 0x%08x\n", hr); + SysFreeString(str); + + CHECK_CALLED(CreateInstance); + CHECK_CALLED(SetInterfaceSafetyOptions); + CHECK_CALLED(SetScriptSite); + CHECK_CALLED(QI_IActiveScriptParse); + CHECK_CALLED(InitNew); + + hr = IScriptControl_get_UseSafeSubset(sc, &use_safe_subset); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(use_safe_subset == VARIANT_FALSE, "got %d\n", use_safe_subset); + + SET_EXPECT(SetInterfaceSafetyOptions_UseSafeSubset); + hr = IScriptControl_put_UseSafeSubset(sc, VARIANT_TRUE); + ok(hr == S_OK, "got 0x%08x\n", hr); + CHECK_CALLED(SetInterfaceSafetyOptions_UseSafeSubset); + + hr = IScriptControl_get_UseSafeSubset(sc, &use_safe_subset); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(use_safe_subset == VARIANT_TRUE, "got %d\n", use_safe_subset); + + hr = IScriptControl_put_UseSafeSubset(sc, VARIANT_TRUE); + ok(hr == S_OK, "got 0x%08x\n", hr); + + SET_EXPECT(SetInterfaceSafetyOptions); + hr = IScriptControl_put_UseSafeSubset(sc, VARIANT_FALSE); + ok(hr == S_OK, "got 0x%08x\n", hr); + CHECK_CALLED(SetInterfaceSafetyOptions); + + hr = IScriptControl_put_UseSafeSubset(sc, VARIANT_FALSE); + ok(hr == S_OK, "got 0x%08x\n", hr); + + IActiveScriptSite_Release(site); + + SET_EXPECT(Close); + IScriptControl_Release(sc); + CHECK_CALLED(Close); + + hr = CoCreateInstance(&CLSID_ScriptControl, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, + &IID_IScriptControl, (void **)&sc); + ok(hr == S_OK, "Failed to create IScriptControl interface: 0x%08x.\n", hr); + + hr = IScriptControl_put_UseSafeSubset(sc, VARIANT_TRUE); + ok(hr == S_OK, "got 0x%08x\n", hr); + + SET_EXPECT(CreateInstance); + SET_EXPECT(SetInterfaceSafetyOptions_UseSafeSubset); + SET_EXPECT(SetScriptSite); + SET_EXPECT(QI_IActiveScriptParse); + SET_EXPECT(InitNew); + + str = SysAllocString(L"testscript"); + hr = IScriptControl_put_Language(sc, str); + ok(hr == S_OK, "got 0x%08x\n", hr); + SysFreeString(str); + + CHECK_CALLED(CreateInstance); + CHECK_CALLED(SetInterfaceSafetyOptions_UseSafeSubset); + CHECK_CALLED(SetScriptSite); + CHECK_CALLED(QI_IActiveScriptParse); + CHECK_CALLED(InitNew); + + IActiveScriptSite_Release(site); + + SET_EXPECT(Close); + IScriptControl_Release(sc); + CHECK_CALLED(Close); + } }
static void test_State(void)