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 <qwebelement.h> 27 #include <qwebhistoryinterface.h> 28 #include <QDebug> 29 30 class tst_QWebHistoryInterface : public QObject 31 { 32 Q_OBJECT 33 34 public: 35 tst_QWebHistoryInterface(); 36 virtual ~tst_QWebHistoryInterface(); 37 38 public slots: 39 void init(); 40 void cleanup(); 41 42 private slots: 43 void visitedLinks(); 44 45 private: 46 47 48 private: 49 QWebView* m_view; 50 QWebPage* m_page; 51 }; 52 53 tst_QWebHistoryInterface::tst_QWebHistoryInterface() 54 { 55 } 56 57 tst_QWebHistoryInterface::~tst_QWebHistoryInterface() 58 { 59 } 60 61 void tst_QWebHistoryInterface::init() 62 { 63 m_view = new QWebView(); 64 m_page = m_view->page(); 65 } 66 67 void tst_QWebHistoryInterface::cleanup() 68 { 69 delete m_view; 70 } 71 72 class FakeHistoryImplementation : public QWebHistoryInterface { 73 public: 74 void addHistoryEntry(const QString&) {} 75 bool historyContains(const QString& url) const { 76 return url == QLatin1String("http://www.trolltech.com/"); 77 } 78 }; 79 80 81 /* 82 * Test that visited links are properly colored. http://www.trolltech.com is marked 83 * as visited, so the below website should have exactly one element in the a:visited 84 * state. 85 */ 86 void tst_QWebHistoryInterface::visitedLinks() 87 { 88 QWebHistoryInterface::setDefaultInterface(new FakeHistoryImplementation); 89 m_view->setHtml("<html><style>:link{color:green}:visited{color:red}</style><body><a href='http://www.trolltech.com' id='vlink'>Trolltech</a></body></html>"); 90 QWebElement anchor = m_view->page()->mainFrame()->findFirstElement("a[id=vlink]"); 91 QString linkColor = anchor.styleProperty("color", QWebElement::ComputedStyle); 92 QCOMPARE(linkColor, QString::fromLatin1("rgb(255, 0, 0)")); 93 } 94 95 QTEST_MAIN(tst_QWebHistoryInterface) 96 #include "tst_qwebhistoryinterface.moc" 97