Changeset 141598 in webkit
- Timestamp:
- Feb 1, 2013 8:34:05 AM (11 years ago)
- Location:
- trunk/Source/WebKit/qt
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/qt/ChangeLog
r141582 r141598 1 2013-02-01 Simon Hausmann <simon.hausmann@digia.com> 2 3 [Qt] Make QWebHistory unit tests more robust 4 5 Reviewed by Jocelyn Turcotten. 6 7 The tests were using a QEventLoop::exec() call to verify the emission 8 of the loadFinished() signal after calling for example back() or forward(). 9 However sometimes the call to back() may emit the signal immediately and 10 sometimes async, causing instabilities in test runs. The call to exec() 11 also means that if there was a bug then the rest would hang forever because 12 exec() has no timeout. 13 14 This patch introduces a simple SignalBarrier class that solves both issues: 15 16 (1) ensureSignalEmitted() supports the immediate signal emission case as well 17 as the async one. 18 19 (2) Through the use of QSignalSpy's wait() there's an actual timeout. 20 21 * tests/qwebhistory/tst_qwebhistory.cpp: 22 (tst_QWebHistory::init): 23 (tst_QWebHistory::cleanup): 24 (tst_QWebHistory::back): 25 (tst_QWebHistory::forward): 26 (tst_QWebHistory::goToItem): 27 (tst_QWebHistory::serialize_2): 28 * tests/util.h: 29 (waitForSignal): 30 (SignalBarrier): 31 (SignalBarrier::SignalBarrier): 32 (SignalBarrier::ensureSignalEmitted): 33 1 34 2013-02-01 Simon Hausmann <simon.hausmann@digia.com> 2 35 -
trunk/Source/WebKit/qt/tests/qwebhistory/tst_qwebhistory.cpp
r139878 r141598 21 21 #include <QAction> 22 22 23 #include "../util.h" 23 24 #include "qwebpage.h" 24 25 #include "qwebview.h" … … 39 40 { 40 41 frame->load(QUrl("qrc:/resources/page" + QString::number(nr) + ".html")); 41 waitForLoadFinished.exec();42 loadFinishedBarrier->ensureSignalEmitted(); 42 43 } 43 44 … … 73 74 QWebFrame* frame; 74 75 QWebHistory* hist; 75 Q EventLoop waitForLoadFinished; //operation on history are asynchronous!76 QScopedPointer<SignalBarrier> loadFinishedBarrier; 76 77 int histsize; 77 78 }; … … 89 90 page = new QWebPage(this); 90 91 frame = page->mainFrame(); 91 connect(page, SIGNAL(loadFinished(bool)), &waitForLoadFinished, SLOT(quit()), Qt::QueuedConnection);92 loadFinishedBarrier.reset(new SignalBarrier(frame, SIGNAL(loadFinished(bool)))); 92 93 93 94 for (int i = 1;i < 6;i++) { … … 100 101 void tst_QWebHistory::cleanup() 101 102 { 103 loadFinishedBarrier.reset(); 102 104 delete page; 103 105 } … … 127 129 QCOMPARE(page->mainFrame()->toPlainText(), QString("page") + QString::number(i)); 128 130 hist->back(); 129 waitForLoadFinished.exec();131 loadFinishedBarrier->ensureSignalEmitted(); 130 132 } 131 133 //try one more time (too many). crash test … … 142 144 while (hist->canGoBack()) { 143 145 hist->back(); 144 waitForLoadFinished.exec();146 loadFinishedBarrier->ensureSignalEmitted(); 145 147 } 146 148 … … 148 150 QCOMPARE(page->mainFrame()->toPlainText(), QString("page") + QString::number(i)); 149 151 hist->forward(); 150 waitForLoadFinished.exec();152 loadFinishedBarrier->ensureSignalEmitted(); 151 153 } 152 154 //try one more time (too many). crash test … … 176 178 QWebHistoryItem current = hist->currentItem(); 177 179 hist->back(); 178 waitForLoadFinished.exec();180 loadFinishedBarrier->ensureSignalEmitted(); 179 181 hist->back(); 180 waitForLoadFinished.exec();182 loadFinishedBarrier->ensureSignalEmitted(); 181 183 QVERIFY(hist->currentItem().title() != current.title()); 182 184 hist->goToItem(current); 183 waitForLoadFinished.exec();185 loadFinishedBarrier->ensureSignalEmitted(); 184 186 QCOMPARE(hist->currentItem().title(), current.title()); 185 187 } … … 245 247 246 248 hist->back(); 249 loadFinishedBarrier->ensureSignalEmitted(); 247 250 hist->back(); 248 waitForLoadFinished.exec();251 loadFinishedBarrier->ensureSignalEmitted(); 249 252 hist->back(); 250 waitForLoadFinished.exec();253 loadFinishedBarrier->ensureSignalEmitted(); 251 254 //check if current index was changed (make sure that it is not last item) 252 255 QVERIFY(hist->currentItemIndex() != initialCurrentIndex); … … 263 266 264 267 hist->forward(); 265 waitForLoadFinished.exec();268 loadFinishedBarrier->ensureSignalEmitted(); 266 269 hist->forward(); 267 waitForLoadFinished.exec();270 loadFinishedBarrier->ensureSignalEmitted(); 268 271 hist->forward(); 272 loadFinishedBarrier->ensureSignalEmitted(); 269 273 QCOMPARE(hist->currentItemIndex(), initialCurrentIndex); 270 274 } -
trunk/Source/WebKit/qt/tests/util.h
r124879 r141598 39 39 * \p false on timeout 40 40 */ 41 static bool waitForSignal(QObject* obj, const char* signal, int timeout = 10000)41 static inline bool waitForSignal(QObject* obj, const char* signal, int timeout = 10000) 42 42 { 43 43 QEventLoop loop; … … 54 54 } 55 55 56 /** 57 * Just like QSignalSpy but facilitates sync and async 58 * signal emission. For example if you want to verify that 59 * page->foo() emitted a signal, it could be that the 60 * implementation decides to emit the signal asynchronously 61 * - in which case we want to spin a local event loop until 62 * emission - or that the call to foo() emits it right away. 63 */ 64 class SignalBarrier : private QSignalSpy 65 { 66 public: 67 SignalBarrier(const QObject* obj, const char* aSignal) 68 : QSignalSpy(obj, aSignal) 69 { } 70 71 bool ensureSignalEmitted() 72 { 73 bool result = count() > 0; 74 if (!result) 75 result = wait(); 76 clear(); 77 return result; 78 } 79 }; 80 56 81 #define W_QSKIP(a, b) QSKIP(a)
Note: See TracChangeset
for help on using the changeset viewer.