Get rid of CppUnit boilerplate in wxWebView unit test
This not only cuts down on its size, but will make it simpler to skip this test in the environments where web access is unavailable in the upcoming commit.
This commit is contained in:
@@ -25,76 +25,26 @@
|
||||
#include "wx/msw/webview_ie.h"
|
||||
#endif
|
||||
|
||||
class WebTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
WebTestCase() { }
|
||||
|
||||
void setUp() wxOVERRIDE;
|
||||
void tearDown() wxOVERRIDE;
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( WebTestCase );
|
||||
CPPUNIT_TEST( Title );
|
||||
CPPUNIT_TEST( Url );
|
||||
CPPUNIT_TEST( History );
|
||||
#if !wxUSE_WEBVIEW_WEBKIT2
|
||||
//This is not implemented on WEBKIT2. See implementation.
|
||||
CPPUNIT_TEST( HistoryEnable );
|
||||
CPPUNIT_TEST( HistoryClear );
|
||||
#endif
|
||||
CPPUNIT_TEST( HistoryList );
|
||||
CPPUNIT_TEST( Editable );
|
||||
CPPUNIT_TEST( Selection );
|
||||
CPPUNIT_TEST( Zoom );
|
||||
CPPUNIT_TEST( RunScript );
|
||||
CPPUNIT_TEST( SetPage );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void Title();
|
||||
void Url();
|
||||
void History();
|
||||
void HistoryEnable();
|
||||
void HistoryClear();
|
||||
void HistoryList();
|
||||
void Editable();
|
||||
void Selection();
|
||||
void Zoom();
|
||||
void RunScript();
|
||||
void SetPage();
|
||||
void LoadUrl(int times = 1);
|
||||
|
||||
wxWebView* m_browser;
|
||||
EventCounter* m_loaded;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(WebTestCase);
|
||||
};
|
||||
|
||||
//Convenience macro
|
||||
#define ENSURE_LOADED CHECK( m_loaded->WaitEvent() )
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( WebTestCase );
|
||||
|
||||
// also include in its own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( WebTestCase, "WebTestCase" );
|
||||
|
||||
void WebTestCase::setUp()
|
||||
class WebViewTestCase
|
||||
{
|
||||
public:
|
||||
WebViewTestCase()
|
||||
: m_browser(wxWebView::New()),
|
||||
m_loaded(new EventCounter(m_browser, wxEVT_WEBVIEW_LOADED))
|
||||
{
|
||||
m_browser = wxWebView::New();
|
||||
m_loaded = new EventCounter(m_browser, wxEVT_WEBVIEW_LOADED);
|
||||
|
||||
m_browser -> Create(wxTheApp->GetTopWindow(), wxID_ANY);
|
||||
ENSURE_LOADED;
|
||||
}
|
||||
|
||||
void WebTestCase::tearDown()
|
||||
~WebViewTestCase()
|
||||
{
|
||||
wxDELETE(m_loaded);
|
||||
wxDELETE(m_browser);
|
||||
delete m_loaded;
|
||||
delete m_browser;
|
||||
}
|
||||
|
||||
void WebTestCase::LoadUrl(int times)
|
||||
protected:
|
||||
void LoadUrl(int times = 1)
|
||||
{
|
||||
//We alternate between urls as otherwise webkit merges them in the history
|
||||
//we use about and about blank to avoid the need for a network connection
|
||||
@@ -108,7 +58,16 @@ void WebTestCase::LoadUrl(int times)
|
||||
}
|
||||
}
|
||||
|
||||
void WebTestCase::Title()
|
||||
wxWebView* const m_browser;
|
||||
EventCounter* const m_loaded;
|
||||
};
|
||||
|
||||
TEST_CASE_METHOD(WebViewTestCase, "WebView", "[wxWebView]")
|
||||
{
|
||||
m_browser -> Create(wxTheApp->GetTopWindow(), wxID_ANY);
|
||||
ENSURE_LOADED;
|
||||
|
||||
SECTION("Title")
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL("", m_browser->GetCurrentTitle());
|
||||
|
||||
@@ -122,7 +81,7 @@ void WebTestCase::Title()
|
||||
CPPUNIT_ASSERT_EQUAL("", m_browser->GetCurrentTitle());
|
||||
}
|
||||
|
||||
void WebTestCase::Url()
|
||||
SECTION("URL")
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL("about:blank", m_browser->GetCurrentURL());
|
||||
|
||||
@@ -131,7 +90,7 @@ void WebTestCase::Url()
|
||||
CPPUNIT_ASSERT_EQUAL("about:", m_browser->GetCurrentURL());
|
||||
}
|
||||
|
||||
void WebTestCase::History()
|
||||
SECTION("History")
|
||||
{
|
||||
LoadUrl(3);
|
||||
|
||||
@@ -154,7 +113,7 @@ void WebTestCase::History()
|
||||
CPPUNIT_ASSERT(m_browser->CanGoForward());
|
||||
}
|
||||
|
||||
void WebTestCase::HistoryEnable()
|
||||
SECTION("HistoryEnable")
|
||||
{
|
||||
LoadUrl();
|
||||
m_browser->EnableHistory(false);
|
||||
@@ -168,7 +127,7 @@ void WebTestCase::HistoryEnable()
|
||||
CPPUNIT_ASSERT(!m_browser->CanGoBack());
|
||||
}
|
||||
|
||||
void WebTestCase::HistoryClear()
|
||||
SECTION("HistoryClear")
|
||||
{
|
||||
LoadUrl(2);
|
||||
|
||||
@@ -185,7 +144,7 @@ void WebTestCase::HistoryClear()
|
||||
CPPUNIT_ASSERT(!m_browser->CanGoBack());
|
||||
}
|
||||
|
||||
void WebTestCase::HistoryList()
|
||||
SECTION("HistoryList")
|
||||
{
|
||||
LoadUrl(2);
|
||||
m_browser->GoBack();
|
||||
@@ -201,7 +160,7 @@ void WebTestCase::HistoryList()
|
||||
CPPUNIT_ASSERT_EQUAL(2, m_browser->GetBackwardHistory().size());
|
||||
}
|
||||
|
||||
void WebTestCase::Editable()
|
||||
SECTION("Editable")
|
||||
{
|
||||
CPPUNIT_ASSERT(!m_browser->IsEditable());
|
||||
|
||||
@@ -214,7 +173,7 @@ void WebTestCase::Editable()
|
||||
CPPUNIT_ASSERT(!m_browser->IsEditable());
|
||||
}
|
||||
|
||||
void WebTestCase::Selection()
|
||||
SECTION("Selection")
|
||||
{
|
||||
m_browser->SetPage("<html><body>Some <strong>strong</strong> text</body></html>", "");
|
||||
ENSURE_LOADED;
|
||||
@@ -241,7 +200,7 @@ void WebTestCase::Selection()
|
||||
CPPUNIT_ASSERT(!m_browser->HasSelection());
|
||||
}
|
||||
|
||||
void WebTestCase::Zoom()
|
||||
SECTION("Zoom")
|
||||
{
|
||||
if(m_browser->CanSetZoomType(wxWEBVIEW_ZOOM_TYPE_LAYOUT))
|
||||
{
|
||||
@@ -265,7 +224,7 @@ void WebTestCase::Zoom()
|
||||
}
|
||||
}
|
||||
|
||||
void WebTestCase::RunScript()
|
||||
SECTION("RunScript")
|
||||
{
|
||||
m_browser->
|
||||
SetPage("<html><head><script></script></head><body></body></html>", "");
|
||||
@@ -375,7 +334,7 @@ void WebTestCase::RunScript()
|
||||
CPPUNIT_ASSERT(!m_browser->RunScript("x.y.z"));
|
||||
}
|
||||
|
||||
void WebTestCase::SetPage()
|
||||
SECTION("SetPage")
|
||||
{
|
||||
m_browser->SetPage("<html><body>text</body></html>", "");
|
||||
ENSURE_LOADED;
|
||||
@@ -385,5 +344,6 @@ void WebTestCase::SetPage()
|
||||
ENSURE_LOADED;
|
||||
CPPUNIT_ASSERT_EQUAL("other text", m_browser->GetPageText());
|
||||
}
|
||||
}
|
||||
|
||||
#endif //wxUSE_WEBVIEW && (wxUSE_WEBVIEW_WEBKIT || wxUSE_WEBVIEW_WEBKIT2 || wxUSE_WEBVIEW_IE)
|
||||
|
Reference in New Issue
Block a user