2008-10-15 11:55:25 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/html/htmlwindow.cpp
|
|
|
|
// Purpose: wxHtmlWindow tests
|
|
|
|
// Author: Vaclav Slavik
|
|
|
|
// Created: 2008-10-15
|
|
|
|
// Copyright: (c) 2008 Vaclav Slavik <vslavik@fastmail.fm>
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "testprec.h"
|
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
#if wxUSE_HTML
|
|
|
|
|
2008-10-15 11:55:25 -04:00
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/app.h"
|
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
|
|
|
#include "wx/html/htmlwin.h"
|
2010-08-22 18:16:05 -04:00
|
|
|
#include "wx/uiaction.h"
|
|
|
|
#include "testableframe.h"
|
2008-10-15 11:55:25 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// test class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class HtmlWindowTestCase : public CppUnit::TestCase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HtmlWindowTestCase() { }
|
|
|
|
|
2018-07-29 05:09:17 -04:00
|
|
|
virtual void setUp() wxOVERRIDE;
|
|
|
|
virtual void tearDown() wxOVERRIDE;
|
2008-10-15 11:55:25 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
CPPUNIT_TEST_SUITE( HtmlWindowTestCase );
|
|
|
|
CPPUNIT_TEST( SelectionToText );
|
2010-08-22 18:16:05 -04:00
|
|
|
CPPUNIT_TEST( Title );
|
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
|
|
|
WXUISIM_TEST( CellClick );
|
|
|
|
WXUISIM_TEST( LinkClick );
|
|
|
|
#endif // wxUSE_UIACTIONSIMULATOR
|
|
|
|
CPPUNIT_TEST( AppendToPage );
|
2008-10-15 11:55:25 -04:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
void SelectionToText();
|
2010-08-22 18:16:05 -04:00
|
|
|
void Title();
|
|
|
|
void CellClick();
|
|
|
|
void LinkClick();
|
|
|
|
void AppendToPage();
|
2008-10-15 11:55:25 -04:00
|
|
|
|
|
|
|
wxHtmlWindow *m_win;
|
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxDECLARE_NO_COPY_CLASS(HtmlWindowTestCase);
|
2008-10-15 11:55:25 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// register in the unnamed registry so that these tests are run by default
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( HtmlWindowTestCase );
|
|
|
|
|
2011-04-30 06:57:04 -04:00
|
|
|
// also include in its own registry so that these tests can be run alone
|
2008-10-15 11:55:25 -04:00
|
|
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HtmlWindowTestCase, "HtmlWindowTestCase" );
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// test initialization
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void HtmlWindowTestCase::setUp()
|
|
|
|
{
|
2010-08-22 18:16:05 -04:00
|
|
|
m_win = new wxHtmlWindow(wxTheApp->GetTopWindow(), wxID_ANY,
|
|
|
|
wxDefaultPosition, wxSize(400, 200));
|
2008-10-15 11:55:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void HtmlWindowTestCase::tearDown()
|
|
|
|
{
|
2016-06-29 12:22:05 -04:00
|
|
|
DeleteTestWindow(m_win);
|
|
|
|
m_win = NULL;
|
2008-10-15 11:55:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// tests themselves
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static const char *TEST_MARKUP =
|
|
|
|
"<html><body>"
|
2010-08-22 18:16:05 -04:00
|
|
|
"<title>Page</title>"
|
2008-10-15 11:55:25 -04:00
|
|
|
" Title<p>"
|
|
|
|
" A longer line<br>"
|
|
|
|
" and the last line."
|
|
|
|
"</body></html>";
|
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
static const char *TEST_MARKUP_LINK =
|
|
|
|
"<html><body>"
|
|
|
|
"<a href=\"link\">link<\\a> "
|
|
|
|
"</body></html>";
|
|
|
|
|
2008-10-15 11:55:25 -04:00
|
|
|
static const char *TEST_PLAIN_TEXT =
|
|
|
|
"Title\nA longer line\nand the last line.";
|
|
|
|
|
|
|
|
void HtmlWindowTestCase::SelectionToText()
|
|
|
|
{
|
2018-09-18 13:14:12 -04:00
|
|
|
#if wxUSE_CLIPBOARD
|
2008-10-15 11:55:25 -04:00
|
|
|
m_win->SetPage(TEST_MARKUP);
|
|
|
|
m_win->SelectAll();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL( TEST_PLAIN_TEXT, m_win->SelectionToText() );
|
2018-09-18 13:14:12 -04:00
|
|
|
#endif // wxUSE_CLIPBOARD
|
2008-10-15 11:55:25 -04:00
|
|
|
}
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
void HtmlWindowTestCase::Title()
|
|
|
|
{
|
|
|
|
m_win->SetPage(TEST_MARKUP);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL("Page", m_win->GetOpenedPageTitle());
|
|
|
|
}
|
|
|
|
|
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
|
|
|
void HtmlWindowTestCase::CellClick()
|
|
|
|
{
|
2013-04-25 06:11:03 -04:00
|
|
|
EventCounter clicked(m_win, wxEVT_HTML_CELL_CLICKED);
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
wxUIActionSimulator sim;
|
|
|
|
|
|
|
|
m_win->SetPage(TEST_MARKUP);
|
|
|
|
m_win->Update();
|
|
|
|
m_win->Refresh();
|
|
|
|
|
|
|
|
sim.MouseMove(m_win->ClientToScreen(wxPoint(15, 15)));
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
sim.MouseClick();
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount());
|
2010-08-22 18:16:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void HtmlWindowTestCase::LinkClick()
|
|
|
|
{
|
2013-04-25 06:11:03 -04:00
|
|
|
EventCounter clicked(m_win, wxEVT_HTML_LINK_CLICKED);
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
wxUIActionSimulator sim;
|
|
|
|
|
|
|
|
m_win->SetPage(TEST_MARKUP_LINK);
|
|
|
|
m_win->Update();
|
|
|
|
m_win->Refresh();
|
|
|
|
|
|
|
|
sim.MouseMove(m_win->ClientToScreen(wxPoint(15, 15)));
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
sim.MouseClick();
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount());
|
2010-08-22 18:16:05 -04:00
|
|
|
}
|
|
|
|
#endif // wxUSE_UIACTIONSIMULATOR
|
|
|
|
|
|
|
|
void HtmlWindowTestCase::AppendToPage()
|
|
|
|
{
|
2018-09-18 13:14:12 -04:00
|
|
|
#if wxUSE_CLIPBOARD
|
2010-08-22 18:16:05 -04:00
|
|
|
m_win->SetPage(TEST_MARKUP_LINK);
|
|
|
|
m_win->AppendToPage("A new paragraph");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL("link A new paragraph", m_win->ToText());
|
2018-09-18 13:14:12 -04:00
|
|
|
#endif // wxUSE_CLIPBOARD
|
2010-08-22 18:16:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif //wxUSE_HTML
|