htmlwindow.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. // headers
  10. // ----------------------------------------------------------------------------
  11. #include "testprec.h"
  12. #if wxUSE_HTML
  13. #ifdef __BORLANDC__
  14. #pragma hdrstop
  15. #endif
  16. #ifndef WX_PRECOMP
  17. #include "wx/app.h"
  18. #endif // WX_PRECOMP
  19. #include "wx/html/htmlwin.h"
  20. #include "wx/uiaction.h"
  21. #include "testableframe.h"
  22. // ----------------------------------------------------------------------------
  23. // test class
  24. // ----------------------------------------------------------------------------
  25. class HtmlWindowTestCase : public CppUnit::TestCase
  26. {
  27. public:
  28. HtmlWindowTestCase() { }
  29. virtual void setUp();
  30. virtual void tearDown();
  31. private:
  32. CPPUNIT_TEST_SUITE( HtmlWindowTestCase );
  33. CPPUNIT_TEST( SelectionToText );
  34. CPPUNIT_TEST( Title );
  35. #if wxUSE_UIACTIONSIMULATOR
  36. WXUISIM_TEST( CellClick );
  37. WXUISIM_TEST( LinkClick );
  38. #endif // wxUSE_UIACTIONSIMULATOR
  39. CPPUNIT_TEST( AppendToPage );
  40. CPPUNIT_TEST_SUITE_END();
  41. void SelectionToText();
  42. void Title();
  43. void CellClick();
  44. void LinkClick();
  45. void AppendToPage();
  46. wxHtmlWindow *m_win;
  47. DECLARE_NO_COPY_CLASS(HtmlWindowTestCase)
  48. };
  49. // register in the unnamed registry so that these tests are run by default
  50. CPPUNIT_TEST_SUITE_REGISTRATION( HtmlWindowTestCase );
  51. // also include in its own registry so that these tests can be run alone
  52. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HtmlWindowTestCase, "HtmlWindowTestCase" );
  53. // ----------------------------------------------------------------------------
  54. // test initialization
  55. // ----------------------------------------------------------------------------
  56. void HtmlWindowTestCase::setUp()
  57. {
  58. m_win = new wxHtmlWindow(wxTheApp->GetTopWindow(), wxID_ANY,
  59. wxDefaultPosition, wxSize(400, 200));
  60. }
  61. void HtmlWindowTestCase::tearDown()
  62. {
  63. wxDELETE(m_win);
  64. }
  65. // ----------------------------------------------------------------------------
  66. // tests themselves
  67. // ----------------------------------------------------------------------------
  68. static const char *TEST_MARKUP =
  69. "<html><body>"
  70. "<title>Page</title>"
  71. " Title<p>"
  72. " A longer line<br>"
  73. " and the last line."
  74. "</body></html>";
  75. static const char *TEST_MARKUP_LINK =
  76. "<html><body>"
  77. "<a href=\"link\">link<\\a> "
  78. "</body></html>";
  79. static const char *TEST_PLAIN_TEXT =
  80. "Title\nA longer line\nand the last line.";
  81. void HtmlWindowTestCase::SelectionToText()
  82. {
  83. m_win->SetPage(TEST_MARKUP);
  84. m_win->SelectAll();
  85. CPPUNIT_ASSERT_EQUAL( TEST_PLAIN_TEXT, m_win->SelectionToText() );
  86. }
  87. void HtmlWindowTestCase::Title()
  88. {
  89. m_win->SetPage(TEST_MARKUP);
  90. CPPUNIT_ASSERT_EQUAL("Page", m_win->GetOpenedPageTitle());
  91. }
  92. #if wxUSE_UIACTIONSIMULATOR
  93. void HtmlWindowTestCase::CellClick()
  94. {
  95. EventCounter clicked(m_win, wxEVT_HTML_CELL_CLICKED);
  96. wxUIActionSimulator sim;
  97. m_win->SetPage(TEST_MARKUP);
  98. m_win->Update();
  99. m_win->Refresh();
  100. sim.MouseMove(m_win->ClientToScreen(wxPoint(15, 15)));
  101. wxYield();
  102. sim.MouseClick();
  103. wxYield();
  104. CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount());
  105. }
  106. void HtmlWindowTestCase::LinkClick()
  107. {
  108. EventCounter clicked(m_win, wxEVT_HTML_LINK_CLICKED);
  109. wxUIActionSimulator sim;
  110. m_win->SetPage(TEST_MARKUP_LINK);
  111. m_win->Update();
  112. m_win->Refresh();
  113. sim.MouseMove(m_win->ClientToScreen(wxPoint(15, 15)));
  114. wxYield();
  115. sim.MouseClick();
  116. wxYield();
  117. CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount());
  118. }
  119. #endif // wxUSE_UIACTIONSIMULATOR
  120. void HtmlWindowTestCase::AppendToPage()
  121. {
  122. m_win->SetPage(TEST_MARKUP_LINK);
  123. m_win->AppendToPage("A new paragraph");
  124. CPPUNIT_ASSERT_EQUAL("link A new paragraph", m_win->ToText());
  125. }
  126. #endif //wxUSE_HTML