2011-07-08 04:19:25 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/controls/webtest.cpp
|
|
|
|
// Purpose: wxWebView unit test
|
|
|
|
// Author: Steven Lamerton
|
|
|
|
// Created: 2011-07-08
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2011 Steven Lamerton
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "testprec.h"
|
|
|
|
|
|
|
|
#if wxUSE_WEB
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/app.h"
|
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
|
|
|
#include "testableframe.h"
|
|
|
|
#include "wx/uiaction.h"
|
|
|
|
#include "wx/webview.h"
|
|
|
|
#include "asserthelper.h"
|
|
|
|
|
|
|
|
class WebTestCase : public CppUnit::TestCase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WebTestCase() { }
|
|
|
|
|
|
|
|
void setUp();
|
|
|
|
void tearDown();
|
|
|
|
|
|
|
|
private:
|
|
|
|
CPPUNIT_TEST_SUITE( WebTestCase );
|
2011-07-08 06:51:15 -04:00
|
|
|
CPPUNIT_TEST( Title );
|
2011-07-08 09:11:17 -04:00
|
|
|
CPPUNIT_TEST( Url );
|
|
|
|
CPPUNIT_TEST( History );
|
2011-07-08 10:21:46 -04:00
|
|
|
CPPUNIT_TEST( HistoryEnable );
|
|
|
|
CPPUNIT_TEST( HistoryClear );
|
2011-07-08 10:35:49 -04:00
|
|
|
CPPUNIT_TEST( HistoryList );
|
2011-07-08 15:34:56 -04:00
|
|
|
CPPUNIT_TEST( Editable );
|
2011-07-10 14:11:43 -04:00
|
|
|
CPPUNIT_TEST( Selection );
|
2011-07-08 04:19:25 -04:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
2011-07-08 06:51:15 -04:00
|
|
|
void Title();
|
2011-07-08 09:11:17 -04:00
|
|
|
void Url();
|
|
|
|
void History();
|
2011-07-08 10:21:46 -04:00
|
|
|
void HistoryEnable();
|
|
|
|
void HistoryClear();
|
2011-07-08 10:35:49 -04:00
|
|
|
void HistoryList();
|
2011-07-08 15:34:56 -04:00
|
|
|
void Editable();
|
2011-07-10 14:11:43 -04:00
|
|
|
void Selection();
|
2011-07-08 10:46:51 -04:00
|
|
|
void LoadUrl(const wxString& url, int times = 1);
|
2011-07-08 06:51:15 -04:00
|
|
|
|
2011-07-08 04:19:25 -04:00
|
|
|
wxWebView* m_browser;
|
|
|
|
|
|
|
|
DECLARE_NO_COPY_CLASS(WebTestCase)
|
|
|
|
};
|
|
|
|
|
|
|
|
// register in the unnamed registry so that these tests are run by default
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( WebTestCase );
|
|
|
|
|
|
|
|
// also include in its own registry so that these tests can be run alone
|
|
|
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( WebTestCase, "WebTestCase" );
|
|
|
|
|
|
|
|
void WebTestCase::setUp()
|
|
|
|
{
|
2011-07-08 06:51:15 -04:00
|
|
|
m_browser = wxWebView::New(wxTheApp->GetTopWindow(), wxID_ANY);
|
2011-07-08 04:19:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebTestCase::tearDown()
|
|
|
|
{
|
|
|
|
wxDELETE(m_browser);
|
|
|
|
}
|
|
|
|
|
2011-07-08 10:46:51 -04:00
|
|
|
void WebTestCase::LoadUrl(const wxString& url, int times)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < times; i++)
|
|
|
|
{
|
|
|
|
m_browser->LoadUrl(url);
|
|
|
|
wxYield();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-08 06:51:15 -04:00
|
|
|
void WebTestCase::Title()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_EQUAL("", m_browser->GetCurrentTitle());
|
|
|
|
|
|
|
|
//Test title after loading raw html
|
|
|
|
m_browser->SetPage("<html><title>Title</title></html>", "");
|
|
|
|
CPPUNIT_ASSERT_EQUAL("Title", m_browser->GetCurrentTitle());
|
|
|
|
|
|
|
|
//Test title after loading a url, we yield to let events process
|
2011-07-08 10:46:51 -04:00
|
|
|
LoadUrl("about:blank");
|
2011-07-08 06:51:15 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL("", m_browser->GetCurrentTitle());
|
|
|
|
}
|
|
|
|
|
2011-07-08 09:11:17 -04:00
|
|
|
void WebTestCase::Url()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_EQUAL("", m_browser->GetCurrentURL());
|
|
|
|
|
2011-07-08 10:46:51 -04:00
|
|
|
LoadUrl("about:blank");
|
2011-07-08 09:11:17 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL("about:blank", m_browser->GetCurrentURL());
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebTestCase::History()
|
|
|
|
{
|
|
|
|
//We use about:blank to remove the need for a network connection
|
2011-07-08 10:46:51 -04:00
|
|
|
LoadUrl("about:blank", 3);
|
2011-07-08 09:11:17 -04:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT(m_browser->CanGoBack());
|
|
|
|
CPPUNIT_ASSERT(!m_browser->CanGoForward());
|
|
|
|
|
|
|
|
m_browser->GoBack();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(m_browser->CanGoBack());
|
|
|
|
CPPUNIT_ASSERT(m_browser->CanGoForward());
|
|
|
|
|
|
|
|
m_browser->GoBack();
|
|
|
|
m_browser->GoBack();
|
|
|
|
|
|
|
|
//We should now be at the start of the history
|
|
|
|
CPPUNIT_ASSERT(!m_browser->CanGoBack());
|
|
|
|
CPPUNIT_ASSERT(m_browser->CanGoForward());
|
|
|
|
}
|
|
|
|
|
2011-07-08 10:21:46 -04:00
|
|
|
void WebTestCase::HistoryEnable()
|
|
|
|
{
|
2011-07-08 10:46:51 -04:00
|
|
|
LoadUrl("about:blank");
|
2011-07-08 10:21:46 -04:00
|
|
|
m_browser->EnableHistory(false);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!m_browser->CanGoForward());
|
|
|
|
CPPUNIT_ASSERT(!m_browser->CanGoBack());
|
|
|
|
|
2011-07-08 10:46:51 -04:00
|
|
|
LoadUrl("about:blank");
|
2011-07-08 10:21:46 -04:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!m_browser->CanGoForward());
|
|
|
|
CPPUNIT_ASSERT(!m_browser->CanGoBack());
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebTestCase::HistoryClear()
|
|
|
|
{
|
2011-07-08 10:46:51 -04:00
|
|
|
LoadUrl("about:blank", 2);
|
2011-07-08 10:21:46 -04:00
|
|
|
|
|
|
|
//Now we are in the 'middle' of the history
|
|
|
|
m_browser->GoBack();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(m_browser->CanGoForward());
|
|
|
|
CPPUNIT_ASSERT(m_browser->CanGoBack());
|
|
|
|
|
|
|
|
m_browser->ClearHistory();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!m_browser->CanGoForward());
|
|
|
|
CPPUNIT_ASSERT(!m_browser->CanGoBack());
|
|
|
|
}
|
|
|
|
|
2011-07-08 10:35:49 -04:00
|
|
|
void WebTestCase::HistoryList()
|
|
|
|
{
|
2011-07-08 10:46:51 -04:00
|
|
|
LoadUrl("about:blank", 2);
|
2011-07-08 10:35:49 -04:00
|
|
|
m_browser->GoBack();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, m_browser->GetBackwardHistory().size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, m_browser->GetForwardHistory().size());
|
|
|
|
|
|
|
|
m_browser->LoadHistoryItem(m_browser->GetForwardHistory()[0]);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!m_browser->CanGoForward());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(2, m_browser->GetBackwardHistory().size());
|
|
|
|
}
|
|
|
|
|
2011-07-08 15:34:56 -04:00
|
|
|
void WebTestCase::Editable()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT(!m_browser->IsEditable());
|
|
|
|
|
|
|
|
m_browser->SetEditable(true);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(m_browser->IsEditable());
|
|
|
|
|
|
|
|
m_browser->SetEditable(false);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!m_browser->IsEditable());
|
|
|
|
}
|
|
|
|
|
2011-07-10 14:11:43 -04:00
|
|
|
void WebTestCase::Selection()
|
|
|
|
{
|
|
|
|
m_browser->SetPage("<html><body>Some text</body></html>", "");
|
|
|
|
CPPUNIT_ASSERT(!m_browser->HasSelection());
|
|
|
|
|
|
|
|
m_browser->SelectAll();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(m_browser->HasSelection());
|
|
|
|
CPPUNIT_ASSERT_EQUAL("Some text", m_browser->GetSelectedText());
|
|
|
|
|
|
|
|
m_browser->DeleteSelection();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!m_browser->HasSelection());
|
|
|
|
}
|
|
|
|
|
2011-07-08 04:19:25 -04:00
|
|
|
#endif //wxUSE_WEB
|