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