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( HistoryList
);
43 CPPUNIT_TEST_SUITE_END();
54 DECLARE_NO_COPY_CLASS(WebTestCase
)
57 // register in the unnamed registry so that these tests are run by default
58 CPPUNIT_TEST_SUITE_REGISTRATION( WebTestCase
);
60 // also include in its own registry so that these tests can be run alone
61 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( WebTestCase
, "WebTestCase" );
63 void WebTestCase
::setUp()
65 m_browser
= wxWebView
::New(wxTheApp
->GetTopWindow(), wxID_ANY
);
68 void WebTestCase
::tearDown()
73 void WebTestCase
::Title()
75 CPPUNIT_ASSERT_EQUAL("", m_browser
->GetCurrentTitle());
77 //Test title after loading raw html
78 m_browser
->SetPage("<html><title>Title</title></html>", "");
79 CPPUNIT_ASSERT_EQUAL("Title", m_browser
->GetCurrentTitle());
81 //Test title after loading a url, we yield to let events process
82 m_browser
->LoadUrl("about:blank");
84 CPPUNIT_ASSERT_EQUAL("", m_browser
->GetCurrentTitle());
87 void WebTestCase
::Url()
89 CPPUNIT_ASSERT_EQUAL("", m_browser
->GetCurrentURL());
91 m_browser
->LoadUrl("about:blank");
93 CPPUNIT_ASSERT_EQUAL("about:blank", m_browser
->GetCurrentURL());
96 void WebTestCase
::History()
98 //We use about:blank to remove the need for a network connection
99 m_browser
->LoadUrl("about:blank");
102 m_browser
->LoadUrl("about:blank");
105 m_browser
->LoadUrl("about:blank");
108 CPPUNIT_ASSERT(m_browser
->CanGoBack());
109 CPPUNIT_ASSERT(!m_browser
->CanGoForward());
113 CPPUNIT_ASSERT(m_browser
->CanGoBack());
114 CPPUNIT_ASSERT(m_browser
->CanGoForward());
119 //We should now be at the start of the history
120 CPPUNIT_ASSERT(!m_browser
->CanGoBack());
121 CPPUNIT_ASSERT(m_browser
->CanGoForward());
124 void WebTestCase
::HistoryEnable()
126 m_browser
->LoadUrl("about:blank");
129 m_browser
->EnableHistory(false);
131 CPPUNIT_ASSERT(!m_browser
->CanGoForward());
132 CPPUNIT_ASSERT(!m_browser
->CanGoBack());
134 m_browser
->LoadUrl("about:blank");
137 CPPUNIT_ASSERT(!m_browser
->CanGoForward());
138 CPPUNIT_ASSERT(!m_browser
->CanGoBack());
141 void WebTestCase
::HistoryClear()
143 m_browser
->LoadUrl("about:blank");
146 m_browser
->LoadUrl("about:blank");
149 //Now we are in the 'middle' of the history
152 CPPUNIT_ASSERT(m_browser
->CanGoForward());
153 CPPUNIT_ASSERT(m_browser
->CanGoBack());
155 m_browser
->ClearHistory();
157 CPPUNIT_ASSERT(!m_browser
->CanGoForward());
158 CPPUNIT_ASSERT(!m_browser
->CanGoBack());
161 void WebTestCase
::HistoryList()
163 m_browser
->LoadUrl("about:blank");
166 m_browser
->LoadUrl("about:blank");
171 CPPUNIT_ASSERT_EQUAL(1, m_browser
->GetBackwardHistory().size());
172 CPPUNIT_ASSERT_EQUAL(1, m_browser
->GetForwardHistory().size());
174 m_browser
->LoadHistoryItem(m_browser
->GetForwardHistory()[0]);
176 CPPUNIT_ASSERT(!m_browser
->CanGoForward());
177 CPPUNIT_ASSERT_EQUAL(2, m_browser
->GetBackwardHistory().size());