]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/webtest.cpp
23663a2232aefb5cd64cd17e779acbf9eae3ce88
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();
51 void LoadUrl(const wxString
& url
, int times
= 1);
55 DECLARE_NO_COPY_CLASS(WebTestCase
)
58 // register in the unnamed registry so that these tests are run by default
59 CPPUNIT_TEST_SUITE_REGISTRATION( WebTestCase
);
61 // also include in its own registry so that these tests can be run alone
62 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( WebTestCase
, "WebTestCase" );
64 void WebTestCase::setUp()
66 m_browser
= wxWebView::New(wxTheApp
->GetTopWindow(), wxID_ANY
);
69 void WebTestCase::tearDown()
74 void WebTestCase::LoadUrl(const wxString
& url
, int times
)
76 for(int i
= 0; i
< times
; i
++)
78 m_browser
->LoadUrl(url
);
83 void WebTestCase::Title()
85 CPPUNIT_ASSERT_EQUAL("", m_browser
->GetCurrentTitle());
87 //Test title after loading raw html
88 m_browser
->SetPage("<html><title>Title</title></html>", "");
89 CPPUNIT_ASSERT_EQUAL("Title", m_browser
->GetCurrentTitle());
91 //Test title after loading a url, we yield to let events process
92 LoadUrl("about:blank");
93 CPPUNIT_ASSERT_EQUAL("", m_browser
->GetCurrentTitle());
96 void WebTestCase::Url()
98 CPPUNIT_ASSERT_EQUAL("", m_browser
->GetCurrentURL());
100 LoadUrl("about:blank");
101 CPPUNIT_ASSERT_EQUAL("about:blank", m_browser
->GetCurrentURL());
104 void WebTestCase::History()
106 //We use about:blank to remove the need for a network connection
107 LoadUrl("about:blank", 3);
109 CPPUNIT_ASSERT(m_browser
->CanGoBack());
110 CPPUNIT_ASSERT(!m_browser
->CanGoForward());
114 CPPUNIT_ASSERT(m_browser
->CanGoBack());
115 CPPUNIT_ASSERT(m_browser
->CanGoForward());
120 //We should now be at the start of the history
121 CPPUNIT_ASSERT(!m_browser
->CanGoBack());
122 CPPUNIT_ASSERT(m_browser
->CanGoForward());
125 void WebTestCase::HistoryEnable()
127 LoadUrl("about:blank");
128 m_browser
->EnableHistory(false);
130 CPPUNIT_ASSERT(!m_browser
->CanGoForward());
131 CPPUNIT_ASSERT(!m_browser
->CanGoBack());
133 LoadUrl("about:blank");
135 CPPUNIT_ASSERT(!m_browser
->CanGoForward());
136 CPPUNIT_ASSERT(!m_browser
->CanGoBack());
139 void WebTestCase::HistoryClear()
141 LoadUrl("about:blank", 2);
143 //Now we are in the 'middle' of the history
146 CPPUNIT_ASSERT(m_browser
->CanGoForward());
147 CPPUNIT_ASSERT(m_browser
->CanGoBack());
149 m_browser
->ClearHistory();
151 CPPUNIT_ASSERT(!m_browser
->CanGoForward());
152 CPPUNIT_ASSERT(!m_browser
->CanGoBack());
155 void WebTestCase::HistoryList()
157 LoadUrl("about:blank", 2);
160 CPPUNIT_ASSERT_EQUAL(1, m_browser
->GetBackwardHistory().size());
161 CPPUNIT_ASSERT_EQUAL(1, m_browser
->GetForwardHistory().size());
163 m_browser
->LoadHistoryItem(m_browser
->GetForwardHistory()[0]);
165 CPPUNIT_ASSERT(!m_browser
->CanGoForward());
166 CPPUNIT_ASSERT_EQUAL(2, m_browser
->GetBackwardHistory().size());