Title: [90403] trunk/Source/WebKit/qt
Revision
90403
Author
[email protected]
Date
2011-07-05 12:45:00 -0700 (Tue, 05 Jul 2011)

Log Message

2011-07-05  Rafael Brandao  <[email protected]>

        [Qt] Fix tst_QWebFrame::setHtmlWithResource() API test
        https://bugs.webkit.org/show_bug.cgi?id=63235

        Modified baseUrl to be a local file in order to get a security origin
        that is allowed to request local resources. Removed QSignalSpy from it
        as loadFinished always happens, and the original test was split into two.

        Reviewed by Benjamin Poulain.

        * tests/qwebframe/tst_qwebframe.cpp:
        (tst_QWebFrame::setHtmlWithImageResource):
        (tst_QWebFrame::setHtmlWithStylesheetResource):
        (tst_QWebFrame::setHtmlWithBaseURL):

Modified Paths

Diff

Modified: trunk/Source/WebKit/qt/ChangeLog (90402 => 90403)


--- trunk/Source/WebKit/qt/ChangeLog	2011-07-05 19:02:44 UTC (rev 90402)
+++ trunk/Source/WebKit/qt/ChangeLog	2011-07-05 19:45:00 UTC (rev 90403)
@@ -1,3 +1,19 @@
+2011-07-05  Rafael Brandao  <[email protected]>
+
+        [Qt] Fix tst_QWebFrame::setHtmlWithResource() API test
+        https://bugs.webkit.org/show_bug.cgi?id=63235
+
+        Modified baseUrl to be a local file in order to get a security origin
+        that is allowed to request local resources. Removed QSignalSpy from it
+        as loadFinished always happens, and the original test was split into two.
+
+        Reviewed by Benjamin Poulain.
+
+        * tests/qwebframe/tst_qwebframe.cpp:
+        (tst_QWebFrame::setHtmlWithImageResource):
+        (tst_QWebFrame::setHtmlWithStylesheetResource):
+        (tst_QWebFrame::setHtmlWithBaseURL):
+
 2011-04-02  Robert Hogan  <[email protected]>
 
         Reviewed by Benjamin Poulain.

Modified: trunk/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp (90402 => 90403)


--- trunk/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp	2011-07-05 19:02:44 UTC (rev 90402)
+++ trunk/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp	2011-07-05 19:45:00 UTC (rev 90403)
@@ -619,7 +619,8 @@
     void _javascript_WindowObjectCleared();
     void _javascript_WindowObjectClearedOnEvaluate();
     void setHtml();
-    void setHtmlWithResource();
+    void setHtmlWithImageResource();
+    void setHtmlWithStylesheetResource();
     void setHtmlWithBaseURL();
     void setHtmlWithJSAlert();
     void ipv6HostEncoding();
@@ -2488,26 +2489,37 @@
     QCOMPARE(spy.count(), 1);
 }
 
-void tst_QWebFrame::setHtmlWithResource()
+void tst_QWebFrame::setHtmlWithImageResource()
 {
-    QString html("<html><body><p>hello world</p><img src=''/></body></html>");
+    // By default, only security origins of local files can load local resources.
+    // So we should specify baseUrl to be a local file in order to get a proper origin and load the local image.
 
+    QLatin1String html("<html><body><p>hello world</p><img src=''/></body></html>");
     QWebPage page;
     QWebFrame* frame = page.mainFrame();
 
-    // in few seconds, the image should be completey loaded
-    QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
-    frame->setHtml(html);
+    frame->setHtml(html, QUrl(QLatin1String("file:///path/to/file")));
     waitForSignal(frame, SIGNAL(loadFinished(bool)), 200);
-    QCOMPARE(spy.count(), 1);
 
     QCOMPARE(frame->evaluateJavaScript("document.images.length").toInt(), 1);
-    QEXPECT_FAIL("", "https://bugs.webkit.org/show_bug.cgi?id=63235", Continue);
     QCOMPARE(frame->evaluateJavaScript("document.images[0].width").toInt(), 128);
-    QEXPECT_FAIL("", "https://bugs.webkit.org/show_bug.cgi?id=63235", Continue);
     QCOMPARE(frame->evaluateJavaScript("document.images[0].height").toInt(), 128);
 
-    QString html2 =
+    // Now we test the opposite: without a baseUrl as a local file, we cannot request local resources.
+
+    frame->setHtml(html);
+    waitForSignal(frame, SIGNAL(loadFinished(bool)), 200);
+    QCOMPARE(frame->evaluateJavaScript("document.images.length").toInt(), 1);
+    QCOMPARE(frame->evaluateJavaScript("document.images[0].width").toInt(), 0);
+    QCOMPARE(frame->evaluateJavaScript("document.images[0].height").toInt(), 0);
+}
+
+void tst_QWebFrame::setHtmlWithStylesheetResource()
+{
+    // By default, only security origins of local files can load local resources.
+    // So we should specify baseUrl to be a local file in order to be able to download the local stylesheet.
+
+    const char* htmlData =
         "<html>"
             "<head>"
                 "<link rel='stylesheet' href='' type='text/css' />"
@@ -2516,19 +2528,29 @@
                 "<p id='idP'>some text</p>"
             "</body>"
         "</html>";
+    QLatin1String html(htmlData);
+    QWebPage page;
+    QWebFrame* frame = page.mainFrame();
+    QWebElement webElement;
 
-    // in few seconds, the CSS should be completey loaded
-    frame->setHtml(html2);
+    frame->setHtml(html, QUrl(QLatin1String("qrc:///file")));
     waitForSignal(frame, SIGNAL(loadFinished(bool)), 200);
-    QCOMPARE(spy.size(), 2);
+    webElement = frame->documentElement().findFirst("p");
+    QCOMPARE(webElement.styleProperty("color", QWebElement::CascadedStyle), QLatin1String("red"));
 
-    QWebElement p = frame->documentElement().findAll("p").at(0);
-    QEXPECT_FAIL("", "https://bugs.webkit.org/show_bug.cgi?id=63235", Continue);
-    QCOMPARE(p.styleProperty("color", QWebElement::CascadedStyle), QLatin1String("red"));
+    // Now we test the opposite: without a baseUrl as a local file, we cannot request local resources.
+
+    frame->setHtml(html, QUrl(QLatin1String("http://www.example.com/")));
+    waitForSignal(frame, SIGNAL(loadFinished(bool)), 200);
+    webElement = frame->documentElement().findFirst("p");
+    QCOMPARE(webElement.styleProperty("color", QWebElement::CascadedStyle), QString());
 }
 
 void tst_QWebFrame::setHtmlWithBaseURL()
 {
+    // This tests if baseUrl is indeed affecting the relative paths from resources.
+    // As we are using a local file as baseUrl, its security origin should be able to load local resources.
+
     if (!QDir(TESTS_SOURCE_DIR).exists())
         QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll);
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to