1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/webtest.cpp
3 // Purpose: wxWebView unit test
4 // Author: Steven Lamerton
7 // Copyright: (c) 2011 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
22 #include "testableframe.h"
23 #include "wx/uiaction.h"
24 #include "wx/webview.h"
25 #include "asserthelper.h"
27 class WebTestCase
: public CppUnit
::TestCase
36 CPPUNIT_TEST_SUITE( WebTestCase
);
37 CPPUNIT_TEST( Title
);
39 CPPUNIT_TEST( History
);
40 CPPUNIT_TEST( HistoryEnable
);
41 CPPUNIT_TEST( HistoryClear
);
42 CPPUNIT_TEST_SUITE_END();
52 DECLARE_NO_COPY_CLASS(WebTestCase
)
55 // register in the unnamed registry so that these tests are run by default
56 CPPUNIT_TEST_SUITE_REGISTRATION( WebTestCase
);
58 // also include in its own registry so that these tests can be run alone
59 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( WebTestCase
, "WebTestCase" );
61 void WebTestCase
::setUp()
63 m_browser
= wxWebView
::New(wxTheApp
->GetTopWindow(), wxID_ANY
);
66 void WebTestCase
::tearDown()
71 void WebTestCase
::Title()
73 CPPUNIT_ASSERT_EQUAL("", m_browser
->GetCurrentTitle());
75 //Test title after loading raw html
76 m_browser
->SetPage("<html><title>Title</title></html>", "");
77 CPPUNIT_ASSERT_EQUAL("Title", m_browser
->GetCurrentTitle());
79 //Test title after loading a url, we yield to let events process
80 m_browser
->LoadUrl("about:blank");
82 CPPUNIT_ASSERT_EQUAL("", m_browser
->GetCurrentTitle());
85 void WebTestCase
::Url()
87 CPPUNIT_ASSERT_EQUAL("", m_browser
->GetCurrentURL());
89 m_browser
->LoadUrl("about:blank");
91 CPPUNIT_ASSERT_EQUAL("about:blank", m_browser
->GetCurrentURL());
94 void WebTestCase
::History()
96 //We use about:blank to remove the need for a network connection
97 m_browser
->LoadUrl("about:blank");
100 m_browser
->LoadUrl("about:blank");
103 m_browser
->LoadUrl("about:blank");
106 CPPUNIT_ASSERT(m_browser
->CanGoBack());
107 CPPUNIT_ASSERT(!m_browser
->CanGoForward());
111 CPPUNIT_ASSERT(m_browser
->CanGoBack());
112 CPPUNIT_ASSERT(m_browser
->CanGoForward());
117 //We should now be at the start of the history
118 CPPUNIT_ASSERT(!m_browser
->CanGoBack());
119 CPPUNIT_ASSERT(m_browser
->CanGoForward());
122 void WebTestCase
::HistoryEnable()
124 m_browser
->LoadUrl("about:blank");
127 m_browser
->EnableHistory(false);
129 CPPUNIT_ASSERT(!m_browser
->CanGoForward());
130 CPPUNIT_ASSERT(!m_browser
->CanGoBack());
132 m_browser
->LoadUrl("about:blank");
135 CPPUNIT_ASSERT(!m_browser
->CanGoForward());
136 CPPUNIT_ASSERT(!m_browser
->CanGoBack());
139 void WebTestCase
::HistoryClear()
141 m_browser
->LoadUrl("about:blank");
144 m_browser
->LoadUrl("about:blank");
147 //Now we are in the 'middle' of the history
150 CPPUNIT_ASSERT(m_browser
->CanGoForward());
151 CPPUNIT_ASSERT(m_browser
->CanGoBack());
153 m_browser
->ClearHistory();
155 CPPUNIT_ASSERT(!m_browser
->CanGoForward());
156 CPPUNIT_ASSERT(!m_browser
->CanGoBack());