src/3rdparty/webkit/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp
changeset 19 fcece45ef507
parent 18 2f34d5167611
child 30 5dc02b23752f
equal deleted inserted replaced
18:2f34d5167611 19:fcece45ef507
   604     void hasSetFocus();
   604     void hasSetFocus();
   605     void render();
   605     void render();
   606     void scrollPosition();
   606     void scrollPosition();
   607     void evaluateWillCauseRepaint();
   607     void evaluateWillCauseRepaint();
   608     void qObjectWrapperWithSameIdentity();
   608     void qObjectWrapperWithSameIdentity();
   609     void scrollRecursively();
       
   610 
   609 
   611 private:
   610 private:
   612     QString  evalJS(const QString&s) {
   611     QString  evalJS(const QString&s) {
   613         // Convert an undefined return variant to the string "undefined"
   612         // Convert an undefined return variant to the string "undefined"
   614         QVariant ret = evalJSV(s);
   613         QVariant ret = evalJSV(s);
  2823 
  2822 
  2824     mainFrame->evaluateJavaScript("triggerBug();");
  2823     mainFrame->evaluateJavaScript("triggerBug();");
  2825     QCOMPARE(mainFrame->toPlainText(), QString("test2"));
  2824     QCOMPARE(mainFrame->toPlainText(), QString("test2"));
  2826 }
  2825 }
  2827 
  2826 
  2828 bool QWEBKIT_EXPORT qtwebkit_webframe_scrollRecursively(QWebFrame* qFrame, int dx, int dy);
       
  2829 
       
  2830 void tst_QWebFrame::scrollRecursively()
       
  2831 {
       
  2832     // The test content is 
       
  2833     // a nested frame set
       
  2834     // The main frame scrolls
       
  2835     // and has two children
       
  2836     // an iframe and a div overflow
       
  2837     // both scroll
       
  2838     QWebView webView;
       
  2839     QWebPage* webPage = webView.page();
       
  2840     QSignalSpy loadSpy(webPage, SIGNAL(loadFinished(bool)));
       
  2841     QUrl url = QUrl("qrc:///testiframe.html");
       
  2842     webPage->mainFrame()->load(url);
       
  2843     QTRY_COMPARE(loadSpy.count(), 1);
       
  2844 
       
  2845     QList<QWebFrame*> children =  webPage->mainFrame()->childFrames();
       
  2846     QVERIFY(children.count() == 1);
       
  2847 
       
  2848     // 1st test
       
  2849     // call scrollRecursively over mainframe
       
  2850     // verify scrolled
       
  2851     // verify scroll postion changed
       
  2852     QPoint scrollPosition(webPage->mainFrame()->scrollPosition());
       
  2853     QVERIFY(qtwebkit_webframe_scrollRecursively(webPage->mainFrame(), 10, 10));
       
  2854     QVERIFY(scrollPosition != webPage->mainFrame()->scrollPosition());
       
  2855 
       
  2856     // 2nd test
       
  2857     // call scrollRecursively over child iframe
       
  2858     // verify scrolled
       
  2859     // verify child scroll position changed
       
  2860     // verify parent's scroll position did not change
       
  2861     scrollPosition = webPage->mainFrame()->scrollPosition();
       
  2862     QPoint childScrollPosition = children.at(0)->scrollPosition();
       
  2863     QVERIFY(qtwebkit_webframe_scrollRecursively(children.at(0), 10, 10));
       
  2864     QVERIFY(scrollPosition == webPage->mainFrame()->scrollPosition());
       
  2865     QVERIFY(childScrollPosition != children.at(0)->scrollPosition());
       
  2866 
       
  2867     // 3rd test
       
  2868     // call scrollRecursively over div overflow
       
  2869     // verify scrolled == true
       
  2870     // verify parent and child frame's scroll postion did not change
       
  2871     QWebElement div = webPage->mainFrame()->documentElement().findFirst("#content1");
       
  2872     QMouseEvent evpres(QEvent::MouseMove, div.geometry().center(), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
       
  2873     webPage->event(&evpres);
       
  2874     scrollPosition = webPage->mainFrame()->scrollPosition();
       
  2875     childScrollPosition = children.at(0)->scrollPosition();
       
  2876     QVERIFY(qtwebkit_webframe_scrollRecursively(webPage->mainFrame(), 5, 5));
       
  2877     QVERIFY(childScrollPosition == children.at(0)->scrollPosition());
       
  2878     QVERIFY(scrollPosition == webPage->mainFrame()->scrollPosition());
       
  2879 
       
  2880     // 4th test
       
  2881     // call scrollRecursively twice over childs iframe
       
  2882     // verify scrolled == true first time
       
  2883     // verify parent's scroll == true second time
       
  2884     // verify parent and childs scroll position changed
       
  2885     childScrollPosition = children.at(0)->scrollPosition();
       
  2886     QVERIFY(qtwebkit_webframe_scrollRecursively(children.at(0), -10, -10));
       
  2887     QVERIFY(childScrollPosition != children.at(0)->scrollPosition());
       
  2888     scrollPosition = webPage->mainFrame()->scrollPosition();
       
  2889     QVERIFY(qtwebkit_webframe_scrollRecursively(children.at(0), -10, -10));
       
  2890     QVERIFY(scrollPosition != webPage->mainFrame()->scrollPosition());
       
  2891 
       
  2892 }
       
  2893 
       
  2894 QTEST_MAIN(tst_QWebFrame)
  2827 QTEST_MAIN(tst_QWebFrame)
  2895 #include "tst_qwebframe.moc"
  2828 #include "tst_qwebframe.moc"