]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/webtest.cpp
e20d0bb857f33ca7eeee3a0c8ae4b20dcf37f443
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( Editable
);
44 CPPUNIT_TEST( Selection
);
45 CPPUNIT_TEST_SUITE_END();
55 void LoadUrl(const wxString
& url
, int times
= 1);
59 DECLARE_NO_COPY_CLASS(WebTestCase
)
62 // register in the unnamed registry so that these tests are run by default
63 CPPUNIT_TEST_SUITE_REGISTRATION( WebTestCase
);
65 // also include in its own registry so that these tests can be run alone
66 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( WebTestCase
, "WebTestCase" );
68 void WebTestCase::setUp()
70 m_browser
= wxWebView::New(wxTheApp
->GetTopWindow(), wxID_ANY
);
73 void WebTestCase::tearDown()
78 void WebTestCase::LoadUrl(const wxString
& url
, int times
)
80 for(int i
= 0; i
< times
; i
++)
82 m_browser
->LoadUrl(url
);
87 void WebTestCase::Title()
89 CPPUNIT_ASSERT_EQUAL("", m_browser
->GetCurrentTitle());
91 //Test title after loading raw html
92 m_browser
->SetPage("<html><title>Title</title></html>", "");
93 CPPUNIT_ASSERT_EQUAL("Title", m_browser
->GetCurrentTitle());
95 //Test title after loading a url, we yield to let events process
96 LoadUrl("about:blank");
97 CPPUNIT_ASSERT_EQUAL("", m_browser
->GetCurrentTitle());
100 void WebTestCase::Url()
102 CPPUNIT_ASSERT_EQUAL("", m_browser
->GetCurrentURL());
104 LoadUrl("about:blank");
105 CPPUNIT_ASSERT_EQUAL("about:blank", m_browser
->GetCurrentURL());
108 void WebTestCase::History()
110 //We use about:blank to remove the need for a network connection
111 LoadUrl("about:blank", 3);
113 CPPUNIT_ASSERT(m_browser
->CanGoBack());
114 CPPUNIT_ASSERT(!m_browser
->CanGoForward());
118 CPPUNIT_ASSERT(m_browser
->CanGoBack());
119 CPPUNIT_ASSERT(m_browser
->CanGoForward());
124 //We should now be at the start of the history
125 CPPUNIT_ASSERT(!m_browser
->CanGoBack());
126 CPPUNIT_ASSERT(m_browser
->CanGoForward());
129 void WebTestCase::HistoryEnable()
131 LoadUrl("about:blank");
132 m_browser
->EnableHistory(false);
134 CPPUNIT_ASSERT(!m_browser
->CanGoForward());
135 CPPUNIT_ASSERT(!m_browser
->CanGoBack());
137 LoadUrl("about:blank");
139 CPPUNIT_ASSERT(!m_browser
->CanGoForward());
140 CPPUNIT_ASSERT(!m_browser
->CanGoBack());
143 void WebTestCase::HistoryClear()
145 LoadUrl("about:blank", 2);
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());
159 void WebTestCase::HistoryList()
161 LoadUrl("about:blank", 2);
164 CPPUNIT_ASSERT_EQUAL(1, m_browser
->GetBackwardHistory().size());
165 CPPUNIT_ASSERT_EQUAL(1, m_browser
->GetForwardHistory().size());
167 m_browser
->LoadHistoryItem(m_browser
->GetForwardHistory()[0]);
169 CPPUNIT_ASSERT(!m_browser
->CanGoForward());
170 CPPUNIT_ASSERT_EQUAL(2, m_browser
->GetBackwardHistory().size());
173 void WebTestCase::Editable()
175 CPPUNIT_ASSERT(!m_browser
->IsEditable());
177 m_browser
->SetEditable(true);
179 CPPUNIT_ASSERT(m_browser
->IsEditable());
181 m_browser
->SetEditable(false);
183 CPPUNIT_ASSERT(!m_browser
->IsEditable());
186 void WebTestCase::Selection()
188 m_browser
->SetPage("<html><body>Some <strong>strong</strong> text</body></html>", "");
189 CPPUNIT_ASSERT(!m_browser
->HasSelection());
191 m_browser
->SelectAll();
193 CPPUNIT_ASSERT(m_browser
->HasSelection());
194 CPPUNIT_ASSERT_EQUAL("Some strong text", m_browser
->GetSelectedText());
195 //We lower case the result as ie returns tags in uppercase
196 CPPUNIT_ASSERT_EQUAL("some <strong>strong</strong> text",
197 m_browser
->GetSelectedSource().Lower());
199 m_browser
->DeleteSelection();
201 CPPUNIT_ASSERT(!m_browser
->HasSelection());