Fix progress load reporting for MHTML documents.
authorjcivelli@chromium.org <jcivelli@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Jun 2012 01:12:06 +0000 (01:12 +0000)
committerjcivelli@chromium.org <jcivelli@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Jun 2012 01:12:06 +0000 (01:12 +0000)
MHTML documents containing references to resources they don't include
never finish loading.
https://bugs.webkit.org/show_bug.cgi?id=71859

Reviewed by Nate Chapin.

Source/WebCore:

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::scheduleArchiveLoad):

Source/WebKit/chromium:

* tests/EventListenerTest.cpp:
* tests/FrameTestHelpers.cpp:
(FrameTestHelpers):
(WebKit::FrameTestHelpers::registerMockedURLLoad):
(WebKit::FrameTestHelpers::registerMockedURLLoadAsHTML):
(WebKit::FrameTestHelpers::createWebViewAndLoad):
* tests/FrameTestHelpers.h:
(FrameTestHelpers):
* tests/ListenerLeakTest.cpp:
(WebKit::ListenerLeakTest::RunTest):
* tests/WebFrameTest.cpp:
(WebKit::WebFrameTest::registerMockedHttpURLLoad):
(WebKit::WebFrameTest::registerMockedChromeURLLoad):
* tests/WebViewTest.cpp:
(WebKit::TEST_F):
(WebKit::WebViewTest::testAutoResize):
(WebKit::WebViewTest::testTextInputType):
(TestWebViewClient):
(WebKit::TestWebViewClient::TestWebViewClient):
(WebKit::TestWebViewClient::didStartLoading):
(WebKit::TestWebViewClient::didStopLoading):
(WebKit::TestWebViewClient::didChangeLoadProgress):
(WebKit::TestWebViewClient::loadingStarted):
(WebKit::TestWebViewClient::loadingStopped):
(WebKit::TestWebViewClient::loadProgress):
(WebKit):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@121206 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/loader/DocumentLoader.cpp
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/tests/EventListenerTest.cpp
Source/WebKit/chromium/tests/FrameTestHelpers.cpp
Source/WebKit/chromium/tests/FrameTestHelpers.h
Source/WebKit/chromium/tests/ListenerLeakTest.cpp
Source/WebKit/chromium/tests/WebFrameTest.cpp
Source/WebKit/chromium/tests/WebViewTest.cpp

index aa8cc32..d3b02a5 100644 (file)
@@ -1,3 +1,16 @@
+2012-06-25  Jay Civelli  <jcivelli@chromium.org>
+
+        Fix progress load reporting for MHTML documents.
+
+        MHTML documents containing references to resources they don't include
+        never finish loading.
+        https://bugs.webkit.org/show_bug.cgi?id=71859
+
+        Reviewed by Nate Chapin.
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::scheduleArchiveLoad):
+
 2012-06-25  James Robinson  <jamesr@chromium.org>
 
         [chromium] Use WebGraphicsContext3D in compositor implementation
index 302a7ad..1c4debf 100644 (file)
@@ -689,6 +689,9 @@ bool DocumentLoader::scheduleArchiveLoad(ResourceLoader* loader, const ResourceR
 #endif
 #if ENABLE(MHTML)
     case Archive::MHTML:
+        // Schedule this loader without a resource so that resource completion/failure notifications are still fired (which will trigger a call to ResourceLoader.didFail).
+        m_pendingSubstituteResources.set(loader, 0);
+        deliverSubstituteResourcesAfterDelay();
         return true; // Always fail the load for resources not included in the MHTML.
 #endif
     default:
index 1963f81..eab8c46 100644 (file)
@@ -1,3 +1,40 @@
+2012-06-25  Jay Civelli  <jcivelli@chromium.org>
+
+        Fix progress load reporting for MHTML documents.
+
+        MHTML documents containing references to resources they don't include
+        never finish loading.
+        https://bugs.webkit.org/show_bug.cgi?id=71859
+
+        Reviewed by Nate Chapin.
+
+        * tests/EventListenerTest.cpp:
+        * tests/FrameTestHelpers.cpp:
+        (FrameTestHelpers):
+        (WebKit::FrameTestHelpers::registerMockedURLLoad):
+        (WebKit::FrameTestHelpers::registerMockedURLLoadAsHTML):
+        (WebKit::FrameTestHelpers::createWebViewAndLoad):
+        * tests/FrameTestHelpers.h:
+        (FrameTestHelpers):
+        * tests/ListenerLeakTest.cpp:
+        (WebKit::ListenerLeakTest::RunTest):
+        * tests/WebFrameTest.cpp:
+        (WebKit::WebFrameTest::registerMockedHttpURLLoad):
+        (WebKit::WebFrameTest::registerMockedChromeURLLoad):
+        * tests/WebViewTest.cpp:
+        (WebKit::TEST_F):
+        (WebKit::WebViewTest::testAutoResize):
+        (WebKit::WebViewTest::testTextInputType):
+        (TestWebViewClient):
+        (WebKit::TestWebViewClient::TestWebViewClient):
+        (WebKit::TestWebViewClient::didStartLoading):
+        (WebKit::TestWebViewClient::didStopLoading):
+        (WebKit::TestWebViewClient::didChangeLoadProgress):
+        (WebKit::TestWebViewClient::loadingStarted):
+        (WebKit::TestWebViewClient::loadingStopped):
+        (WebKit::TestWebViewClient::loadProgress):
+        (WebKit):
+
 2012-06-25  James Robinson  <jamesr@chromium.org>
 
         [chromium] Use WebGraphicsContext3D in compositor implementation
index 799ac40..4916b65 100644 (file)
@@ -78,7 +78,7 @@ public:
         std::string baseURL("http://www.example.com/");
         std::string fileName("listener/mutation_event_listener.html");
         bool executeScript = true;
-        FrameTestHelpers::registerMockedURLLoad(baseURL, fileName);
+        FrameTestHelpers::registerMockedURLLoadAsHTML(baseURL, fileName);
         m_webView = FrameTestHelpers::createWebViewAndLoad(baseURL + fileName, executeScript);
     }
 
index e406413..6fa383e 100644 (file)
 namespace WebKit {
 namespace FrameTestHelpers {
 
-void registerMockedURLLoad(const std::string& base, const std::string& fileName)
+
+void registerMockedURLLoad(const std::string& base, const std::string& fileName, const std::string& mimeType)
 {
-    registerMockedURLLoad(GURL(base + fileName), fileName);
+    registerMockedURLLoad(GURL(base + fileName), fileName, mimeType);
 }
 
-void registerMockedURLLoad(GURL url, const std::string& fileName)
+void registerMockedURLLoad(const GURL& url, const std::string& fileName, const std::string& mimeType)
 {
-    WebURLResponse response;
-    response.initialize();
-    response.setMIMEType("text/html");
+    WebURLResponse response(url);
+    response.setMIMEType(WebString::fromUTF8(mimeType));
 
     std::string filePath = webkit_support::GetWebKitRootDir().utf8();
     filePath += "/Source/WebKit/chromium/tests/data/";
@@ -64,6 +64,16 @@ void registerMockedURLLoad(GURL url, const std::string& fileName)
     webkit_support::RegisterMockedURL(url, response, WebString::fromUTF8(filePath));
 }
 
+void registerMockedURLLoadAsHTML(const std::string& base, const std::string& fileName)
+{
+    registerMockedURLLoadAsHTML(GURL(base + fileName), fileName);
+}
+
+void registerMockedURLLoadAsHTML(const GURL& url, const std::string& fileName)
+{
+    registerMockedURLLoad(url, fileName, "text/html");
+}
+
 void loadFrame(WebFrame* frame, const std::string& url)
 {
     WebURLRequest urlRequest;
@@ -97,6 +107,8 @@ WebView* createWebViewAndLoad(const std::string& url, bool enableJavascript, Web
     if (!webViewClient)
         webViewClient = defaultWebViewClient();
     WebView* webView = WebView::create(webViewClient);
+    webView->settings()->setImagesEnabled(true);
+    webView->settings()->setLoadsImagesAutomatically(true);
     webView->settings()->setJavaScriptEnabled(enableJavascript);
     webView->initializeMainFrame(webFrameClient);
 
index fc2fa2d..9f73142 100644 (file)
@@ -44,9 +44,11 @@ class WebViewClient;
 
 namespace FrameTestHelpers {
 
-void registerMockedURLLoad(const std::string& base, const std::string& fileName);
+void registerMockedURLLoadAsHTML(const std::string& base, const std::string& fileName);
 // Like the previous overload, but it allows more flexibility in the url since it is given by the caller.
-void registerMockedURLLoad(GURL, const std::string& fileName);
+void registerMockedURLLoadAsHTML(const GURL&, const std::string& fileName);
+void registerMockedURLLoad(const std::string& base, const std::string& fileName, const std::string& mimeType);
+void registerMockedURLLoad(const GURL&, const std::string& fileName, const std::string& mimeType);
 
 void loadFrame(WebFrame*, const std::string& url);
 
index 5e321c7..d6ac26a 100644 (file)
@@ -90,7 +90,7 @@ public:
         std::string baseURL("http://www.example.com/");
         std::string fileName(filename);
         bool executeScript = true;
-        FrameTestHelpers::registerMockedURLLoad(baseURL, fileName);
+        FrameTestHelpers::registerMockedURLLoadAsHTML(baseURL, fileName);
         m_webView = FrameTestHelpers::createWebViewAndLoad(baseURL + fileName, executeScript);
     }
 
index 4070580..b884733 100644 (file)
@@ -73,12 +73,12 @@ public:
 
     void registerMockedHttpURLLoad(const std::string& fileName)
     {
-        FrameTestHelpers::registerMockedURLLoad(m_baseURL, fileName);
+        FrameTestHelpers::registerMockedURLLoadAsHTML(m_baseURL, fileName);
     }
 
     void registerMockedChromeURLLoad(const std::string& fileName)
     {
-        FrameTestHelpers::registerMockedURLLoad(m_chromeURL, fileName);
+        FrameTestHelpers::registerMockedURLLoadAsHTML(m_chromeURL, fileName);
     }
 
 protected:
index f858fe7..a6c9e04 100644 (file)
@@ -117,7 +117,7 @@ protected:
 
 TEST_F(WebViewTest, FocusIsInactive)
 {
-    FrameTestHelpers::registerMockedURLLoad(m_baseURL, "visible_iframe.html");
+    FrameTestHelpers::registerMockedURLLoadAsHTML(m_baseURL, "visible_iframe.html");
     WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "visible_iframe.html");
 
     webView->setFocus(true);
@@ -145,7 +145,7 @@ TEST_F(WebViewTest, FocusIsInactive)
 
 TEST_F(WebViewTest, ActiveState)
 {
-    FrameTestHelpers::registerMockedURLLoad(m_baseURL, "visible_iframe.html");
+    FrameTestHelpers::registerMockedURLLoadAsHTML(m_baseURL, "visible_iframe.html");
     WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "visible_iframe.html");
 
     ASSERT_TRUE(webView);
@@ -169,7 +169,7 @@ void WebViewTest::testAutoResize(const WebSize& minAutoResize, const WebSize& ma
 {
     AutoResizeWebViewClient client;
     std::string url = m_baseURL + "specify_size.html?" + pageWidth + ":" + pageHeight;
-    FrameTestHelpers::registerMockedURLLoad(GURL(url), "specify_size.html");
+    FrameTestHelpers::registerMockedURLLoadAsHTML(GURL(url), "specify_size.html");
     WebView* webView = FrameTestHelpers::createWebViewAndLoad(url, true, 0, &client);
     client.testData().setWebView(webView);
 
@@ -268,7 +268,7 @@ TEST_F(WebViewTest, AutoResizeMaxSize)
 
 void WebViewTest::testTextInputType(WebTextInputType expectedType, const std::string& htmlFile)
 {
-    FrameTestHelpers::registerMockedURLLoad(m_baseURL, htmlFile);
+    FrameTestHelpers::registerMockedURLLoadAsHTML(m_baseURL, htmlFile);
     WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + htmlFile);
     webView->setInitialFocus(false);
     EXPECT_EQ(expectedType, webView->textInputType());
@@ -308,7 +308,7 @@ TEST_F(WebViewTest, DISABLED_TextInputType)
 
 TEST_F(WebViewTest, SetEditableSelectionOffsets)
 {
-    FrameTestHelpers::registerMockedURLLoad(m_baseURL, "input_field_populated.html");
+    FrameTestHelpers::registerMockedURLLoadAsHTML(m_baseURL, "input_field_populated.html");
     WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_populated.html");
     webView->setInitialFocus(false);
     webView->setEditableSelectionOffsets(5, 13);
@@ -316,7 +316,7 @@ TEST_F(WebViewTest, SetEditableSelectionOffsets)
     EXPECT_EQ("56789abc", frame->selectionAsText());
     webView->close();
 
-    FrameTestHelpers::registerMockedURLLoad(m_baseURL, "content_editable_populated.html");
+    FrameTestHelpers::registerMockedURLLoadAsHTML(m_baseURL, "content_editable_populated.html");
     webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "content_editable_populated.html");
     webView->setInitialFocus(false);
     webView->setEditableSelectionOffsets(8, 19);
@@ -325,4 +325,42 @@ TEST_F(WebViewTest, SetEditableSelectionOffsets)
     webView->close();
 }
 
+class TestWebViewClient : public WebViewClient {
+public:
+    TestWebViewClient() : m_didStartLoading(false), m_didStopLoading(false), m_loadProgress(0) { }
+    virtual void didStartLoading() { m_didStartLoading = true; }
+    virtual void didStopLoading() { m_didStopLoading = true; }
+    virtual void didChangeLoadProgress(WebFrame*, double loadProgress) { m_loadProgress = loadProgress; }
+
+    bool loadingStarted() const { return m_didStartLoading; }
+    bool loadingStopped() const { return m_didStopLoading; }
+    double loadProgress() const { return m_loadProgress; }
+
+private:
+    bool m_didStartLoading;
+    bool m_didStopLoading;
+    double m_loadProgress;
+};
+
+TEST_F(WebViewTest, MHTMLWithMissingResourceFinishesLoading)
+{
+    TestWebViewClient webViewClient;
+
+    std::string fileName = "page_with_image.mht";
+    std::string fileDir = webkit_support::GetWebKitRootDir().utf8();
+    fileDir.append("/Source/WebKit/chromium/tests/data/");
+    // Making file loading works in unit-tests would require some additional work.
+    // Mocking them as regular URLs works fine in the meantime.
+    FrameTestHelpers::registerMockedURLLoad("file://" + fileDir, fileName, "multipart/related");
+    WebView* webView = FrameTestHelpers::createWebViewAndLoad("file://" + fileDir + fileName, true, 0, &webViewClient);
+    webkit_support::RunAllPendingMessages();
+
+    EXPECT_TRUE(webViewClient.loadingStarted());
+    EXPECT_TRUE(webViewClient.loadingStopped());
+    EXPECT_EQ(1.0, webViewClient.loadProgress());
+
+    // Close the WebView after checking the loading state and progress, as the close() call triggers a stop loading callback.
+    webView->close();
+}
+
 }