]> git.saurik.com Git - wxWidgets.git/blame - tests/html/htmlwindow.cpp
using button impl
[wxWidgets.git] / tests / html / htmlwindow.cpp
CommitLineData
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
34class HtmlWindowTestCase : public CppUnit::TestCase
35{
36public:
37 HtmlWindowTestCase() { }
38
39 virtual void setUp();
40 virtual void tearDown();
41
42private:
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
65CPPUNIT_TEST_SUITE_REGISTRATION( HtmlWindowTestCase );
66
e3778b4d 67// also include in its own registry so that these tests can be run alone
c39058f6
VS
68CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HtmlWindowTestCase, "HtmlWindowTestCase" );
69
70// ----------------------------------------------------------------------------
71// test initialization
72// ----------------------------------------------------------------------------
73
74void HtmlWindowTestCase::setUp()
75{
232fdc63
VZ
76 m_win = new wxHtmlWindow(wxTheApp->GetTopWindow(), wxID_ANY,
77 wxDefaultPosition, wxSize(400, 200));
c39058f6
VS
78}
79
80void HtmlWindowTestCase::tearDown()
81{
232fdc63 82 wxDELETE(m_win);
c39058f6
VS
83}
84
85// ----------------------------------------------------------------------------
86// tests themselves
87// ----------------------------------------------------------------------------
88
89static 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
97static const char *TEST_MARKUP_LINK =
98 "<html><body>"
99 "<a href=\"link\">link<\\a> "
100 "</body></html>";
101
c39058f6
VS
102static const char *TEST_PLAIN_TEXT =
103 "Title\nA longer line\nand the last line.";
104
105void 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
113void HtmlWindowTestCase::Title()
114{
115 m_win->SetPage(TEST_MARKUP);
116
117 CPPUNIT_ASSERT_EQUAL("Page", m_win->GetOpenedPageTitle());
118}
119
120#if wxUSE_UIACTIONSIMULATOR
121void HtmlWindowTestCase::CellClick()
122{
744d91d4 123 EventCounter clicked(m_win, wxEVT_COMMAND_HTML_CELL_CLICKED);
232fdc63
VZ
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
744d91d4 137 CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount());
232fdc63
VZ
138}
139
140void HtmlWindowTestCase::LinkClick()
141{
744d91d4 142 EventCounter clicked(m_win, wxEVT_COMMAND_HTML_LINK_CLICKED);
232fdc63
VZ
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
744d91d4 156 CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount());
232fdc63
VZ
157}
158#endif // wxUSE_UIACTIONSIMULATOR
159
160void 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