Changeset 90403 in webkit


Ignore:
Timestamp:
Jul 5, 2011 12:45:00 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-07-05 Rafael Brandao <rafael.lobo@openbossa.org>

[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):
Location:
trunk/Source/WebKit/qt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/qt/ChangeLog

    r90341 r90403  
     12011-07-05  Rafael Brandao  <rafael.lobo@openbossa.org>
     2
     3        [Qt] Fix tst_QWebFrame::setHtmlWithResource() API test
     4        https://bugs.webkit.org/show_bug.cgi?id=63235
     5
     6        Modified baseUrl to be a local file in order to get a security origin
     7        that is allowed to request local resources. Removed QSignalSpy from it
     8        as loadFinished always happens, and the original test was split into two.
     9
     10        Reviewed by Benjamin Poulain.
     11
     12        * tests/qwebframe/tst_qwebframe.cpp:
     13        (tst_QWebFrame::setHtmlWithImageResource):
     14        (tst_QWebFrame::setHtmlWithStylesheetResource):
     15        (tst_QWebFrame::setHtmlWithBaseURL):
     16
    1172011-04-02  Robert Hogan  <robert@webkit.org>
    218
  • trunk/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp

    r90181 r90403  
    620620    void javaScriptWindowObjectClearedOnEvaluate();
    621621    void setHtml();
    622     void setHtmlWithResource();
     622    void setHtmlWithImageResource();
     623    void setHtmlWithStylesheetResource();
    623624    void setHtmlWithBaseURL();
    624625    void setHtmlWithJSAlert();
     
    24892490}
    24902491
    2491 void tst_QWebFrame::setHtmlWithResource()
    2492 {
    2493     QString html("<html><body><p>hello world</p><img src='qrc:/image.png'/></body></html>");
    2494 
     2492void tst_QWebFrame::setHtmlWithImageResource()
     2493{
     2494    // By default, only security origins of local files can load local resources.
     2495    // So we should specify baseUrl to be a local file in order to get a proper origin and load the local image.
     2496
     2497    QLatin1String html("<html><body><p>hello world</p><img src='qrc:/image.png'/></body></html>");
    24952498    QWebPage page;
    24962499    QWebFrame* frame = page.mainFrame();
    24972500
    2498     // in few seconds, the image should be completey loaded
    2499     QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
     2501    frame->setHtml(html, QUrl(QLatin1String("file:///path/to/file")));
     2502    waitForSignal(frame, SIGNAL(loadFinished(bool)), 200);
     2503
     2504    QCOMPARE(frame->evaluateJavaScript("document.images.length").toInt(), 1);
     2505    QCOMPARE(frame->evaluateJavaScript("document.images[0].width").toInt(), 128);
     2506    QCOMPARE(frame->evaluateJavaScript("document.images[0].height").toInt(), 128);
     2507
     2508    // Now we test the opposite: without a baseUrl as a local file, we cannot request local resources.
     2509
    25002510    frame->setHtml(html);
    25012511    waitForSignal(frame, SIGNAL(loadFinished(bool)), 200);
    2502     QCOMPARE(spy.count(), 1);
    2503 
    25042512    QCOMPARE(frame->evaluateJavaScript("document.images.length").toInt(), 1);
    2505     QEXPECT_FAIL("", "https://bugs.webkit.org/show_bug.cgi?id=63235", Continue);
    2506     QCOMPARE(frame->evaluateJavaScript("document.images[0].width").toInt(), 128);
    2507     QEXPECT_FAIL("", "https://bugs.webkit.org/show_bug.cgi?id=63235", Continue);
    2508     QCOMPARE(frame->evaluateJavaScript("document.images[0].height").toInt(), 128);
    2509 
    2510     QString html2 =
     2513    QCOMPARE(frame->evaluateJavaScript("document.images[0].width").toInt(), 0);
     2514    QCOMPARE(frame->evaluateJavaScript("document.images[0].height").toInt(), 0);
     2515}
     2516
     2517void tst_QWebFrame::setHtmlWithStylesheetResource()
     2518{
     2519    // By default, only security origins of local files can load local resources.
     2520    // So we should specify baseUrl to be a local file in order to be able to download the local stylesheet.
     2521
     2522    const char* htmlData =
    25112523        "<html>"
    25122524            "<head>"
     
    25172529            "</body>"
    25182530        "</html>";
    2519 
    2520     // in few seconds, the CSS should be completey loaded
    2521     frame->setHtml(html2);
     2531    QLatin1String html(htmlData);
     2532    QWebPage page;
     2533    QWebFrame* frame = page.mainFrame();
     2534    QWebElement webElement;
     2535
     2536    frame->setHtml(html, QUrl(QLatin1String("qrc:///file")));
    25222537    waitForSignal(frame, SIGNAL(loadFinished(bool)), 200);
    2523     QCOMPARE(spy.size(), 2);
    2524 
    2525     QWebElement p = frame->documentElement().findAll("p").at(0);
    2526     QEXPECT_FAIL("", "https://bugs.webkit.org/show_bug.cgi?id=63235", Continue);
    2527     QCOMPARE(p.styleProperty("color", QWebElement::CascadedStyle), QLatin1String("red"));
     2538    webElement = frame->documentElement().findFirst("p");
     2539    QCOMPARE(webElement.styleProperty("color", QWebElement::CascadedStyle), QLatin1String("red"));
     2540
     2541    // Now we test the opposite: without a baseUrl as a local file, we cannot request local resources.
     2542
     2543    frame->setHtml(html, QUrl(QLatin1String("http://www.example.com/")));
     2544    waitForSignal(frame, SIGNAL(loadFinished(bool)), 200);
     2545    webElement = frame->documentElement().findFirst("p");
     2546    QCOMPARE(webElement.styleProperty("color", QWebElement::CascadedStyle), QString());
    25282547}
    25292548
    25302549void tst_QWebFrame::setHtmlWithBaseURL()
    25312550{
     2551    // This tests if baseUrl is indeed affecting the relative paths from resources.
     2552    // As we are using a local file as baseUrl, its security origin should be able to load local resources.
     2553
    25322554    if (!QDir(TESTS_SOURCE_DIR).exists())
    25332555        QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll);
Note: See TracChangeset for help on using the changeset viewer.