1 /* 2 Copyright (C) 2008 Holger Hans Peter Freyther 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Library General Public 6 License as published by the Free Software Foundation; either 7 version 2 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Library General Public License for more details. 13 14 You should have received a copy of the GNU Library General Public License 15 along with this library; see the file COPYING.LIB. If not, write to 16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 Boston, MA 02110-1301, USA. 18 */ 19 20 21 #include <QtTest/QtTest> 22 23 #include <qwebpage.h> 24 #include <qwebview.h> 25 #include <qwebframe.h> 26 #include <qwebhistoryinterface.h> 27 #include <QDebug> 28 29 class tst_QWebHistoryInterface : public QObject 30 { 31 Q_OBJECT 32 33 public: 34 tst_QWebHistoryInterface(); 35 virtual ~tst_QWebHistoryInterface(); 36 37 public slots: 38 void init(); 39 void cleanup(); 40 41 private slots: 42 void visitedLinks(); 43 44 private: 45 46 47 private: 48 QWebView* m_view; 49 QWebPage* m_page; 50 }; 51 52 tst_QWebHistoryInterface::tst_QWebHistoryInterface() 53 { 54 } 55 56 tst_QWebHistoryInterface::~tst_QWebHistoryInterface() 57 { 58 } 59 60 void tst_QWebHistoryInterface::init() 61 { 62 m_view = new QWebView(); 63 m_page = m_view->page(); 64 } 65 66 void tst_QWebHistoryInterface::cleanup() 67 { 68 delete m_view; 69 } 70 71 class FakeHistoryImplementation : public QWebHistoryInterface { 72 public: 73 void addHistoryEntry(const QString&) {} 74 bool historyContains(const QString& url) const { 75 return url == QLatin1String("http://www.trolltech.com/"); 76 } 77 }; 78 79 80 /* 81 * Test that visited links are properly colored. http://www.trolltech.com is marked 82 * as visited, so the below website should have exactly one element in the a:visited 83 * state. 84 */ 85 void tst_QWebHistoryInterface::visitedLinks() 86 { 87 QWebHistoryInterface::setDefaultInterface(new FakeHistoryImplementation); 88 m_view->setHtml("<html><body><a href='http://www.trolltech.com'>Trolltech</a></body></html>"); 89 QCOMPARE(m_page->mainFrame()->evaluateJavaScript("document.querySelectorAll(':visited').length;").toString(), 90 QString::fromLatin1("1")); 91 } 92 93 QTEST_MAIN(tst_QWebHistoryInterface) 94 #include "tst_qwebhistoryinterface.moc" 95