]>
Commit | Line | Data |
---|---|---|
c39058f6 VS |
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 | ||
232fdc63 VZ |
16 | #if wxUSE_HTML |
17 | ||
c39058f6 VS |
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" | |
232fdc63 VZ |
27 | #include "wx/uiaction.h" |
28 | #include "testableframe.h" | |
c39058f6 VS |
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 ); | |
232fdc63 VZ |
45 | CPPUNIT_TEST( Title ); |
46 | #if wxUSE_UIACTIONSIMULATOR | |
47 | WXUISIM_TEST( CellClick ); | |
48 | WXUISIM_TEST( LinkClick ); | |
49 | #endif // wxUSE_UIACTIONSIMULATOR | |
50 | CPPUNIT_TEST( AppendToPage ); | |
c39058f6 VS |
51 | CPPUNIT_TEST_SUITE_END(); |
52 | ||
53 | void SelectionToText(); | |
232fdc63 VZ |
54 | void Title(); |
55 | void CellClick(); | |
56 | void LinkClick(); | |
57 | void AppendToPage(); | |
c39058f6 VS |
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 | ||
e3778b4d | 67 | // also include in its own registry so that these tests can be run alone |
c39058f6 VS |
68 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HtmlWindowTestCase, "HtmlWindowTestCase" ); |
69 | ||
70 | // ---------------------------------------------------------------------------- | |
71 | // test initialization | |
72 | // ---------------------------------------------------------------------------- | |
73 | ||
74 | void HtmlWindowTestCase::setUp() | |
75 | { | |
232fdc63 VZ |
76 | m_win = new wxHtmlWindow(wxTheApp->GetTopWindow(), wxID_ANY, |
77 | wxDefaultPosition, wxSize(400, 200)); | |
c39058f6 VS |
78 | } |
79 | ||
80 | void HtmlWindowTestCase::tearDown() | |
81 | { | |
232fdc63 | 82 | wxDELETE(m_win); |
c39058f6 VS |
83 | } |
84 | ||
85 | // ---------------------------------------------------------------------------- | |
86 | // tests themselves | |
87 | // ---------------------------------------------------------------------------- | |
88 | ||
89 | static const char *TEST_MARKUP = | |
90 | "<html><body>" | |
232fdc63 | 91 | "<title>Page</title>" |
c39058f6 VS |
92 | " Title<p>" |
93 | " A longer line<br>" | |
94 | " and the last line." | |
95 | "</body></html>"; | |
96 | ||
232fdc63 VZ |
97 | static const char *TEST_MARKUP_LINK = |
98 | "<html><body>" | |
99 | "<a href=\"link\">link<\\a> " | |
100 | "</body></html>"; | |
101 | ||
c39058f6 VS |
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 | } | |
232fdc63 VZ |
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 | wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(), | |
124 | wxTestableFrame); | |
125 | ||
126 | EventCounter count1(m_win, wxEVT_COMMAND_HTML_CELL_CLICKED); | |
127 | ||
128 | wxUIActionSimulator sim; | |
129 | ||
130 | m_win->SetPage(TEST_MARKUP); | |
131 | m_win->Update(); | |
132 | m_win->Refresh(); | |
133 | ||
134 | sim.MouseMove(m_win->ClientToScreen(wxPoint(15, 15))); | |
135 | wxYield(); | |
136 | ||
137 | sim.MouseClick(); | |
138 | wxYield(); | |
139 | ||
140 | CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount()); | |
141 | } | |
142 | ||
143 | void HtmlWindowTestCase::LinkClick() | |
144 | { | |
145 | wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(), | |
146 | wxTestableFrame); | |
147 | ||
148 | EventCounter count1(m_win, wxEVT_COMMAND_HTML_LINK_CLICKED); | |
149 | ||
150 | wxUIActionSimulator sim; | |
151 | ||
152 | m_win->SetPage(TEST_MARKUP_LINK); | |
153 | m_win->Update(); | |
154 | m_win->Refresh(); | |
155 | ||
156 | sim.MouseMove(m_win->ClientToScreen(wxPoint(15, 15))); | |
157 | wxYield(); | |
158 | ||
159 | sim.MouseClick(); | |
160 | wxYield(); | |
161 | ||
162 | CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount()); | |
163 | } | |
164 | #endif // wxUSE_UIACTIONSIMULATOR | |
165 | ||
166 | void HtmlWindowTestCase::AppendToPage() | |
167 | { | |
168 | m_win->SetPage(TEST_MARKUP_LINK); | |
169 | m_win->AppendToPage("A new paragraph"); | |
170 | ||
171 | CPPUNIT_ASSERT_EQUAL("link A new paragraph", m_win->ToText()); | |
172 | } | |
173 | ||
174 | #endif //wxUSE_HTML |