]> git.saurik.com Git - wxWidgets.git/blob - tests/html/htmlwindow.cpp
cocoa needs a special implementation for read-only combo box
[wxWidgets.git] / tests / html / htmlwindow.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/html/htmlwindow.cpp
3 // Purpose: wxHtmlWindow tests
4 // Author: Vaclav Slavik
5 // Created: 2008-10-15
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Vaclav Slavik <vslavik@fastmail.fm>
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 #include "testprec.h"
15
16 #if wxUSE_HTML
17
18 #ifdef __BORLANDC__
19 #pragma hdrstop
20 #endif
21
22 #ifndef WX_PRECOMP
23 #include "wx/app.h"
24 #endif // WX_PRECOMP
25
26 #include "wx/html/htmlwin.h"
27 #include "wx/uiaction.h"
28 #include "testableframe.h"
29
30 // ----------------------------------------------------------------------------
31 // test class
32 // ----------------------------------------------------------------------------
33
34 class HtmlWindowTestCase : public CppUnit::TestCase
35 {
36 public:
37 HtmlWindowTestCase() { }
38
39 virtual void setUp();
40 virtual void tearDown();
41
42 private:
43 CPPUNIT_TEST_SUITE( HtmlWindowTestCase );
44 CPPUNIT_TEST( SelectionToText );
45 CPPUNIT_TEST( Title );
46 #if wxUSE_UIACTIONSIMULATOR
47 WXUISIM_TEST( CellClick );
48 WXUISIM_TEST( LinkClick );
49 #endif // wxUSE_UIACTIONSIMULATOR
50 CPPUNIT_TEST( AppendToPage );
51 CPPUNIT_TEST_SUITE_END();
52
53 void SelectionToText();
54 void Title();
55 void CellClick();
56 void LinkClick();
57 void AppendToPage();
58
59 wxHtmlWindow *m_win;
60
61 DECLARE_NO_COPY_CLASS(HtmlWindowTestCase)
62 };
63
64 // register in the unnamed registry so that these tests are run by default
65 CPPUNIT_TEST_SUITE_REGISTRATION( HtmlWindowTestCase );
66
67 // also include in its own registry so that these tests can be run alone
68 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HtmlWindowTestCase, "HtmlWindowTestCase" );
69
70 // ----------------------------------------------------------------------------
71 // test initialization
72 // ----------------------------------------------------------------------------
73
74 void HtmlWindowTestCase::setUp()
75 {
76 m_win = new wxHtmlWindow(wxTheApp->GetTopWindow(), wxID_ANY,
77 wxDefaultPosition, wxSize(400, 200));
78 }
79
80 void HtmlWindowTestCase::tearDown()
81 {
82 wxDELETE(m_win);
83 }
84
85 // ----------------------------------------------------------------------------
86 // tests themselves
87 // ----------------------------------------------------------------------------
88
89 static const char *TEST_MARKUP =
90 "<html><body>"
91 "<title>Page</title>"
92 " Title<p>"
93 " A longer line<br>"
94 " and the last line."
95 "</body></html>";
96
97 static const char *TEST_MARKUP_LINK =
98 "<html><body>"
99 "<a href=\"link\">link<\\a> "
100 "</body></html>";
101
102 static const char *TEST_PLAIN_TEXT =
103 "Title\nA longer line\nand the last line.";
104
105 void HtmlWindowTestCase::SelectionToText()
106 {
107 m_win->SetPage(TEST_MARKUP);
108 m_win->SelectAll();
109
110 CPPUNIT_ASSERT_EQUAL( TEST_PLAIN_TEXT, m_win->SelectionToText() );
111 }
112
113 void HtmlWindowTestCase::Title()
114 {
115 m_win->SetPage(TEST_MARKUP);
116
117 CPPUNIT_ASSERT_EQUAL("Page", m_win->GetOpenedPageTitle());
118 }
119
120 #if wxUSE_UIACTIONSIMULATOR
121 void HtmlWindowTestCase::CellClick()
122 {
123 EventCounter clicked(m_win, wxEVT_HTML_CELL_CLICKED);
124
125 wxUIActionSimulator sim;
126
127 m_win->SetPage(TEST_MARKUP);
128 m_win->Update();
129 m_win->Refresh();
130
131 sim.MouseMove(m_win->ClientToScreen(wxPoint(15, 15)));
132 wxYield();
133
134 sim.MouseClick();
135 wxYield();
136
137 CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount());
138 }
139
140 void HtmlWindowTestCase::LinkClick()
141 {
142 EventCounter clicked(m_win, wxEVT_HTML_LINK_CLICKED);
143
144 wxUIActionSimulator sim;
145
146 m_win->SetPage(TEST_MARKUP_LINK);
147 m_win->Update();
148 m_win->Refresh();
149
150 sim.MouseMove(m_win->ClientToScreen(wxPoint(15, 15)));
151 wxYield();
152
153 sim.MouseClick();
154 wxYield();
155
156 CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount());
157 }
158 #endif // wxUSE_UIACTIONSIMULATOR
159
160 void HtmlWindowTestCase::AppendToPage()
161 {
162 m_win->SetPage(TEST_MARKUP_LINK);
163 m_win->AppendToPage("A new paragraph");
164
165 CPPUNIT_ASSERT_EQUAL("link A new paragraph", m_win->ToText());
166 }
167
168 #endif //wxUSE_HTML