Ensure wxWebViewIE::SetPage clears the existing content before writing the new output. Also add a basic unit test to verify correctness in the future.
Fixes #13770 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70041 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -102,43 +102,63 @@ void wxWebViewIE::LoadURL(const wxString& url)
|
|||||||
|
|
||||||
void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
|
void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
|
||||||
{
|
{
|
||||||
BSTR bstr = SysAllocString(html.wc_str());
|
BSTR bstr = SysAllocString(OLESTR(""));
|
||||||
|
|
||||||
// Creates a new one-dimensional array
|
|
||||||
SAFEARRAY *psaStrings = SafeArrayCreateVector(VT_VARIANT, 0, 1);
|
SAFEARRAY *psaStrings = SafeArrayCreateVector(VT_VARIANT, 0, 1);
|
||||||
if (psaStrings != NULL)
|
if (psaStrings != NULL)
|
||||||
{
|
{
|
||||||
VARIANT *param;
|
VARIANT *param;
|
||||||
|
|
||||||
HRESULT hr = SafeArrayAccessData(psaStrings, (LPVOID*)¶m);
|
HRESULT hr = SafeArrayAccessData(psaStrings, (LPVOID*)¶m);
|
||||||
param->vt = VT_BSTR;
|
param->vt = VT_BSTR;
|
||||||
param->bstrVal = bstr;
|
param->bstrVal = bstr;
|
||||||
|
|
||||||
hr = SafeArrayUnaccessData(psaStrings);
|
hr = SafeArrayUnaccessData(psaStrings);
|
||||||
|
|
||||||
IHTMLDocument2* document = GetDocument();
|
IHTMLDocument2* document = GetDocument();
|
||||||
document->write(psaStrings);
|
document->write(psaStrings);
|
||||||
|
document->close();
|
||||||
document->Release();
|
document->Release();
|
||||||
|
|
||||||
// SafeArrayDestroy calls SysFreeString for each BSTR
|
|
||||||
SafeArrayDestroy(psaStrings);
|
SafeArrayDestroy(psaStrings);
|
||||||
|
|
||||||
//We send the events when we are done to mimic webkit
|
bstr = SysAllocString(html.wc_str());
|
||||||
//Navigated event
|
|
||||||
wxWebViewEvent event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED,
|
|
||||||
GetId(), baseUrl, "");
|
|
||||||
event.SetEventObject(this);
|
|
||||||
HandleWindowEvent(event);
|
|
||||||
|
|
||||||
//Document complete event
|
// Creates a new one-dimensional array
|
||||||
event.SetEventType(wxEVT_COMMAND_WEB_VIEW_LOADED);
|
psaStrings = SafeArrayCreateVector(VT_VARIANT, 0, 1);
|
||||||
event.SetEventObject(this);
|
if (psaStrings != NULL)
|
||||||
HandleWindowEvent(event);
|
{
|
||||||
|
hr = SafeArrayAccessData(psaStrings, (LPVOID*)¶m);
|
||||||
|
param->vt = VT_BSTR;
|
||||||
|
param->bstrVal = bstr;
|
||||||
|
hr = SafeArrayUnaccessData(psaStrings);
|
||||||
|
|
||||||
|
document = GetDocument();
|
||||||
|
document->write(psaStrings);
|
||||||
|
document->Release();
|
||||||
|
|
||||||
|
// SafeArrayDestroy calls SysFreeString for each BSTR
|
||||||
|
SafeArrayDestroy(psaStrings);
|
||||||
|
|
||||||
|
//We send the events when we are done to mimic webkit
|
||||||
|
//Navigated event
|
||||||
|
wxWebViewEvent event(wxEVT_COMMAND_WEB_VIEW_NAVIGATED,
|
||||||
|
GetId(), baseUrl, "");
|
||||||
|
event.SetEventObject(this);
|
||||||
|
HandleWindowEvent(event);
|
||||||
|
|
||||||
|
//Document complete event
|
||||||
|
event.SetEventType(wxEVT_COMMAND_WEB_VIEW_LOADED);
|
||||||
|
event.SetEventObject(this);
|
||||||
|
HandleWindowEvent(event);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxLogError("wxWebViewIE::SetPage() : psaStrings is NULL");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxLogError("wxWebViewIE::SetPage() : psaStrings is NULL");
|
wxLogError("wxWebViewIE::SetPage() : psaStrings is NULL during clear");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxWebViewIE::GetPageSource() const
|
wxString wxWebViewIE::GetPageSource() const
|
||||||
|
@@ -44,6 +44,7 @@ private:
|
|||||||
CPPUNIT_TEST( Selection );
|
CPPUNIT_TEST( Selection );
|
||||||
CPPUNIT_TEST( Zoom );
|
CPPUNIT_TEST( Zoom );
|
||||||
CPPUNIT_TEST( RunScript );
|
CPPUNIT_TEST( RunScript );
|
||||||
|
CPPUNIT_TEST( SetPage );
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
void Title();
|
void Title();
|
||||||
@@ -56,6 +57,7 @@ private:
|
|||||||
void Selection();
|
void Selection();
|
||||||
void Zoom();
|
void Zoom();
|
||||||
void RunScript();
|
void RunScript();
|
||||||
|
void SetPage();
|
||||||
void LoadUrl(int times = 1);
|
void LoadUrl(int times = 1);
|
||||||
|
|
||||||
wxWebView* m_browser;
|
wxWebView* m_browser;
|
||||||
@@ -244,4 +246,13 @@ void WebTestCase::RunScript()
|
|||||||
CPPUNIT_ASSERT_EQUAL("Hello World!", m_browser->GetPageText());
|
CPPUNIT_ASSERT_EQUAL("Hello World!", m_browser->GetPageText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebTestCase::SetPage()
|
||||||
|
{
|
||||||
|
m_browser->SetPage("<html><body>text</body></html>", "");
|
||||||
|
CPPUNIT_ASSERT_EQUAL("text", m_browser->GetPageText());
|
||||||
|
|
||||||
|
m_browser->SetPage("<html><body>other text</body></html>", "");
|
||||||
|
CPPUNIT_ASSERT_EQUAL("other text", m_browser->GetPageText());
|
||||||
|
}
|
||||||
|
|
||||||
#endif //wxUSE_WEBVIEW && (wxUSE_WEBVIEW_WEBKIT || wxUSE_WEBVIEW_IE)
|
#endif //wxUSE_WEBVIEW && (wxUSE_WEBVIEW_WEBKIT || wxUSE_WEBVIEW_IE)
|
||||||
|
Reference in New Issue
Block a user