]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/webtest.cpp
Add tests for url and history support
[wxWidgets.git] / tests / controls / webtest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/webtest.cpp
3 // Purpose: wxWebView unit test
4 // Author: Steven Lamerton
5 // Created: 2011-07-08
6 // RCS-ID: $Id$
7 // Copyright: (c) 2011 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #include "testprec.h"
11
12 #if wxUSE_WEB
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #ifndef WX_PRECOMP
19 #include "wx/app.h"
20 #endif // WX_PRECOMP
21
22 #include "testableframe.h"
23 #include "wx/uiaction.h"
24 #include "wx/webview.h"
25 #include "asserthelper.h"
26
27 class WebTestCase : public CppUnit::TestCase
28 {
29 public:
30 WebTestCase() { }
31
32 void setUp();
33 void tearDown();
34
35 private:
36 CPPUNIT_TEST_SUITE( WebTestCase );
37 CPPUNIT_TEST( Title );
38 CPPUNIT_TEST( Url );
39 CPPUNIT_TEST( History );
40 CPPUNIT_TEST_SUITE_END();
41
42 void Title();
43 void Url();
44 void History();
45
46 wxWebView* m_browser;
47
48 DECLARE_NO_COPY_CLASS(WebTestCase)
49 };
50
51 // register in the unnamed registry so that these tests are run by default
52 CPPUNIT_TEST_SUITE_REGISTRATION( WebTestCase );
53
54 // also include in its own registry so that these tests can be run alone
55 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( WebTestCase, "WebTestCase" );
56
57 void WebTestCase::setUp()
58 {
59 m_browser = wxWebView::New(wxTheApp->GetTopWindow(), wxID_ANY);
60 }
61
62 void WebTestCase::tearDown()
63 {
64 wxDELETE(m_browser);
65 }
66
67 void WebTestCase::Title()
68 {
69 CPPUNIT_ASSERT_EQUAL("", m_browser->GetCurrentTitle());
70
71 //Test title after loading raw html
72 m_browser->SetPage("<html><title>Title</title></html>", "");
73 CPPUNIT_ASSERT_EQUAL("Title", m_browser->GetCurrentTitle());
74
75 //Test title after loading a url, we yield to let events process
76 m_browser->LoadUrl("about:blank");
77 wxYield();
78 CPPUNIT_ASSERT_EQUAL("", m_browser->GetCurrentTitle());
79 }
80
81 void WebTestCase::Url()
82 {
83 CPPUNIT_ASSERT_EQUAL("", m_browser->GetCurrentURL());
84
85 m_browser->LoadUrl("about:blank");
86 wxYield();
87 CPPUNIT_ASSERT_EQUAL("about:blank", m_browser->GetCurrentURL());
88 }
89
90 void WebTestCase::History()
91 {
92 //We use about:blank to remove the need for a network connection
93 m_browser->LoadUrl("about:blank");
94 wxYield();
95
96 m_browser->LoadUrl("about:blank");
97 wxYield();
98
99 m_browser->LoadUrl("about:blank");
100 wxYield();
101
102 CPPUNIT_ASSERT(m_browser->CanGoBack());
103 CPPUNIT_ASSERT(!m_browser->CanGoForward());
104
105 m_browser->GoBack();
106
107 CPPUNIT_ASSERT(m_browser->CanGoBack());
108 CPPUNIT_ASSERT(m_browser->CanGoForward());
109
110 m_browser->GoBack();
111 m_browser->GoBack();
112
113 //We should now be at the start of the history
114 CPPUNIT_ASSERT(!m_browser->CanGoBack());
115 CPPUNIT_ASSERT(m_browser->CanGoForward());
116 }
117
118 #endif //wxUSE_WEB