Pending API request URL no set when loading Data, Alternate HTML or plain text
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Apr 2016 08:50:21 +0000 (08:50 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Apr 2016 08:50:21 +0000 (08:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=136916

Reviewed by Darin Adler.

Source/WebKit2:

Set pending API request URL for all load methods in
WebPageProxy. This ensures that right after calling those methods,
the active URL is the requested one and that
PageLoadState::isLoading() returns true.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::loadAlternateHTMLString):
(WebKit::WebPageProxy::loadPlainTextString):
(WebKit::WebPageProxy::loadWebArchiveData):

Tools:

Add new test to check that active URL is the requested one right
after calling WKPage load methods.

* TestWebKitAPI/PlatformEfl.cmake:
* TestWebKitAPI/PlatformGTK.cmake:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2/PendingAPIRequestURL.cpp: Added.
(TestWebKitAPI::TEST):
* TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp:
(WebViewTest::loadPlainText): Remove FIXME.
(WebViewTest::loadBytes): Ditto.
(WebViewTest::loadAlternateHTML): Ditto.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/WebPageProxy.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/PlatformEfl.cmake
Tools/TestWebKitAPI/PlatformGTK.cmake
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2/PendingAPIRequestURL.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp

index dd43c9b..85b49ea 100644 (file)
@@ -1,5 +1,22 @@
 2016-04-18  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        Pending API request URL no set when loading Data, Alternate HTML or plain text
+        https://bugs.webkit.org/show_bug.cgi?id=136916
+
+        Reviewed by Darin Adler.
+
+        Set pending API request URL for all load methods in
+        WebPageProxy. This ensures that right after calling those methods,
+        the active URL is the requested one and that
+        PageLoadState::isLoading() returns true.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::loadAlternateHTMLString):
+        (WebKit::WebPageProxy::loadPlainTextString):
+        (WebKit::WebPageProxy::loadWebArchiveData):
+
+2016-04-18  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         [UNIX] Initialize WebKit before the platform initializations
         https://bugs.webkit.org/show_bug.cgi?id=156622
 
index d2f3d2a..09d55d1 100644 (file)
@@ -971,7 +971,7 @@ RefPtr<API::Navigation> WebPageProxy::loadData(API::Data* data, const String& MI
 
     auto transaction = m_pageLoadState.transaction();
 
-    m_pageLoadState.setPendingAPIRequestURL(transaction, !baseURL.isEmpty() ? baseURL : ASCIILiteral("about:blank"));
+    m_pageLoadState.setPendingAPIRequestURL(transaction, !baseURL.isEmpty() ? baseURL : blankURL().string());
 
     if (!isValid())
         reattachToWebProcess();
@@ -993,7 +993,7 @@ RefPtr<API::Navigation> WebPageProxy::loadHTMLString(const String& htmlString, c
 
     auto transaction = m_pageLoadState.transaction();
 
-    m_pageLoadState.setPendingAPIRequestURL(transaction, !baseURL.isEmpty() ? baseURL : ASCIILiteral("about:blank"));
+    m_pageLoadState.setPendingAPIRequestURL(transaction, !baseURL.isEmpty() ? baseURL : blankURL().string());
 
     if (!isValid())
         reattachToWebProcess();
@@ -1021,6 +1021,7 @@ void WebPageProxy::loadAlternateHTMLString(const String& htmlString, const Strin
 
     auto transaction = m_pageLoadState.transaction();
 
+    m_pageLoadState.setPendingAPIRequestURL(transaction, unreachableURL);
     m_pageLoadState.setUnreachableURL(transaction, unreachableURL);
 
     if (m_mainFrame)
@@ -1040,6 +1041,9 @@ void WebPageProxy::loadPlainTextString(const String& string, API::Object* userDa
     if (!isValid())
         reattachToWebProcess();
 
+    auto transaction = m_pageLoadState.transaction();
+    m_pageLoadState.setPendingAPIRequestURL(transaction, blankURL().string());
+
     m_process->send(Messages::WebPage::LoadPlainTextString(string, UserData(process().transformObjectsToHandles(userData).get())), m_pageID);
     m_process->responsivenessTimer().start();
 }
@@ -1052,6 +1056,9 @@ void WebPageProxy::loadWebArchiveData(API::Data* webArchiveData, API::Object* us
     if (!isValid())
         reattachToWebProcess();
 
+    auto transaction = m_pageLoadState.transaction();
+    m_pageLoadState.setPendingAPIRequestURL(transaction, blankURL().string());
+
     m_process->send(Messages::WebPage::LoadWebArchiveData(webArchiveData->dataReference(), UserData(process().transformObjectsToHandles(userData).get())), m_pageID);
     m_process->responsivenessTimer().start();
 }
index 498d1ee..094b16d 100644 (file)
@@ -1,3 +1,23 @@
+2016-04-18  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        Pending API request URL no set when loading Data, Alternate HTML or plain text
+        https://bugs.webkit.org/show_bug.cgi?id=136916
+
+        Reviewed by Darin Adler.
+
+        Add new test to check that active URL is the requested one right
+        after calling WKPage load methods.
+
+        * TestWebKitAPI/PlatformEfl.cmake:
+        * TestWebKitAPI/PlatformGTK.cmake:
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2/PendingAPIRequestURL.cpp: Added.
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp:
+        (WebViewTest::loadPlainText): Remove FIXME.
+        (WebViewTest::loadBytes): Ditto.
+        (WebViewTest::loadAlternateHTML): Ditto.
+
 2016-04-18  Jeremy Huddleston Sequoia  <jeremyhu@apple.com>
 
         Fix incorrect assumption that APPLE implies Mac.
index ec905c9..67e25e7 100644 (file)
@@ -94,6 +94,7 @@ set(test_webkit2_api_BINARIES
     PageLoadBasic
     PageLoadDidChangeLocationWithinPageForFrame
     ParentFrame
+    PendingAPIRequestURL
     PreventEmptyUserAgent
     PrivateBrowsingPushStateNoHistoryCallback
     ResponsivenessTimerDoesntFireEarly
index d928832..f4a6a3a 100644 (file)
@@ -98,6 +98,7 @@ add_executable(TestWebKit2
     ${TESTWEBKITAPI_DIR}/Tests/WebKit2/PageLoadBasic.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebKit2/PageLoadDidChangeLocationWithinPageForFrame.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebKit2/ParentFrame.cpp
+    ${TESTWEBKITAPI_DIR}/Tests/WebKit2/PendingAPIRequestURL.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebKit2/PreventEmptyUserAgent.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebKit2/PrivateBrowsingPushStateNoHistoryCallback.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebKit2/ReloadPageAfterCrash.cpp
index 2b58485..6471985 100644 (file)
@@ -7,6 +7,7 @@
        objects = {
 
 /* Begin PBXBuildFile section */
+               0766DD201A5AD5200023E3BB /* PendingAPIRequestURL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0766DD1F1A5AD5200023E3BB /* PendingAPIRequestURL.cpp */; };
                0F139E771A423A5B00F590F5 /* WeakObjCPtr.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F139E751A423A5300F590F5 /* WeakObjCPtr.mm */; };
                0F139E781A423A6B00F590F5 /* PlatformUtilitiesCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */; };
                0F139E791A42457000F590F5 /* PlatformUtilitiesCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */; };
 /* Begin PBXFileReference section */
                00BC16851680FE810065F1E5 /* PublicSuffix.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PublicSuffix.mm; sourceTree = "<group>"; };
                00CD9F6215BE312C002DA2CE /* BackForwardList.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BackForwardList.mm; sourceTree = "<group>"; };
+               0766DD1F1A5AD5200023E3BB /* PendingAPIRequestURL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PendingAPIRequestURL.cpp; sourceTree = "<group>"; };
                0BCD833414857CE400EA2003 /* HashMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HashMap.cpp; sourceTree = "<group>"; };
                0BCD85691485C98B00EA2003 /* TemporaryChange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TemporaryChange.cpp; sourceTree = "<group>"; };
                0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = PlatformUtilitiesCocoa.mm; path = cocoa/PlatformUtilitiesCocoa.mm; sourceTree = "<group>"; };
                BC9096411255616000083756 /* WebKit2 */ = {
                        isa = PBXGroup;
                        children = (
+                               0766DD1F1A5AD5200023E3BB /* PendingAPIRequestURL.cpp */,
                                0F139E741A423A4600F590F5 /* cocoa */,
                                C0C5D3BB14598B6F00A802A6 /* mac */,
                                BC90977B125571AE00083756 /* Resources */,
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
+                                0766DD201A5AD5200023E3BB /* PendingAPIRequestURL.cpp in Sources */,
                                2D9A53AF1B31FA8D0074D5AA /* ShrinkToFit.mm in Sources */,
                                51B454EC1B4E236B0085EAA6 /* WebViewCloseInsideDidFinishLoadForFrame.mm in Sources */,
                                57901FAD1CAF12C200ED64F9 /* LoadInvalidURLRequest.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/PendingAPIRequestURL.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/PendingAPIRequestURL.cpp
new file mode 100644 (file)
index 0000000..1af01b7
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+#include "Test.h"
+#include <WebKit/WKRetainPtr.h>
+
+namespace TestWebKitAPI {
+
+TEST(WebKit2, PendingAPIRequestURL)
+{
+    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
+    PlatformWebView webView(context.get());
+
+    WKRetainPtr<WKURLRef> activeURL = adoptWK(WKPageCopyActiveURL(webView.page()));
+    EXPECT_NULL(activeURL.get());
+
+    WKRetainPtr<WKURLRef> url = adoptWK(Util::createURLForResource("simple", "html"));
+    WKPageLoadURL(webView.page(), url.get());
+    activeURL = adoptWK(WKPageCopyActiveURL(webView.page()));
+    ASSERT_NOT_NULL(activeURL.get());
+    EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get()));
+    WKPageStopLoading(webView.page());
+
+    WKRetainPtr<WKStringRef> htmlString = Util::toWK("<body>Hello, World</body>");
+    WKRetainPtr<WKURLRef> blankURL = adoptWK(WKURLCreateWithUTF8CString("about:blank"));
+    WKPageLoadHTMLString(webView.page(), htmlString.get(), nullptr);
+    activeURL = adoptWK(WKPageCopyActiveURL(webView.page()));
+    ASSERT_NOT_NULL(activeURL.get());
+    EXPECT_TRUE(WKURLIsEqual(activeURL.get(), blankURL.get()));
+    WKPageStopLoading(webView.page());
+
+    url = adoptWK(WKURLCreateWithUTF8CString("http://www.webkit.org"));
+    WKPageLoadHTMLString(webView.page(), htmlString.get(), url.get());
+    activeURL = adoptWK(WKPageCopyActiveURL(webView.page()));
+    ASSERT_NOT_NULL(activeURL.get());
+    EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get()));
+    WKPageStopLoading(webView.page());
+
+    WKRetainPtr<WKDataRef> data = adoptWK(WKDataCreate(nullptr, 0));
+    WKPageLoadData(webView.page(), data.get(), nullptr, nullptr, nullptr);
+    activeURL = adoptWK(WKPageCopyActiveURL(webView.page()));
+    ASSERT_NOT_NULL(activeURL.get());
+    EXPECT_TRUE(WKURLIsEqual(activeURL.get(), blankURL.get()));
+    WKPageStopLoading(webView.page());
+
+    WKPageLoadData(webView.page(), data.get(), nullptr, nullptr, url.get());
+    activeURL = adoptWK(WKPageCopyActiveURL(webView.page()));
+    ASSERT_NOT_NULL(activeURL.get());
+    EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get()));
+    WKPageStopLoading(webView.page());
+
+    WKPageLoadAlternateHTMLString(webView.page(), htmlString.get(), nullptr, url.get());
+    activeURL = adoptWK(WKPageCopyActiveURL(webView.page()));
+    ASSERT_NOT_NULL(activeURL.get());
+    EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get()));
+    WKPageStopLoading(webView.page());
+
+    WKRetainPtr<WKStringRef> plainTextString = Util::toWK("Hello, World");
+    WKPageLoadPlainTextString(webView.page(), plainTextString.get());
+    activeURL = adoptWK(WKPageCopyActiveURL(webView.page()));
+    ASSERT_NOT_NULL(activeURL.get());
+    EXPECT_TRUE(WKURLIsEqual(activeURL.get(), blankURL.get()));
+    WKPageStopLoading(webView.page());
+
+    url = adoptWK(WKURLCreateWithUTF8CString("file:///tmp/index.html"));
+    WKPageLoadFile(webView.page(), url.get(), nullptr);
+    activeURL = adoptWK(WKPageCopyActiveURL(webView.page()));
+    ASSERT_NOT_NULL(activeURL.get());
+    EXPECT_TRUE(WKURLIsEqual(activeURL.get(), url.get()));
+    WKPageStopLoading(webView.page());
+}
+
+} // namespace TestWebKitAPI
index 7b34830..b0217ae 100644 (file)
@@ -82,12 +82,8 @@ void WebViewTest::loadPlainText(const char* plainText)
 {
     m_activeURI = "about:blank";
     webkit_web_view_load_plain_text(m_webView, plainText);
-#if 0
-    // FIXME: Pending API request URL no set when loading plain text.
-    // See https://bugs.webkit.org/show_bug.cgi?id=136916.
     g_assert(webkit_web_view_is_loading(m_webView));
     g_assert_cmpstr(webkit_web_view_get_uri(m_webView), ==, m_activeURI.data());
-#endif
 }
 
 void WebViewTest::loadBytes(GBytes* bytes, const char* mimeType, const char* encoding, const char* baseURI)
@@ -97,12 +93,8 @@ void WebViewTest::loadBytes(GBytes* bytes, const char* mimeType, const char* enc
     else
         m_activeURI = baseURI;
     webkit_web_view_load_bytes(m_webView, bytes, mimeType, encoding, baseURI);
-#if 0
-    // FIXME: Pending API request URL no set when loading data.
-    // See https://bugs.webkit.org/show_bug.cgi?id=136916.
     g_assert(webkit_web_view_is_loading(m_webView));
     g_assert_cmpstr(webkit_web_view_get_uri(m_webView), ==, m_activeURI.data());
-#endif
 }
 
 void WebViewTest::loadRequest(WebKitURIRequest* request)
@@ -117,11 +109,7 @@ void WebViewTest::loadAlternateHTML(const char* html, const char* contentURI, co
 {
     m_activeURI = contentURI;
     webkit_web_view_load_alternate_html(m_webView, html, contentURI, baseURI);
-#if 0
-    // FIXME: Pending API request URL no set when loading Alternate HTML.
-    // See https://bugs.webkit.org/show_bug.cgi?id=136916.
     g_assert(webkit_web_view_is_loading(m_webView));
-#endif
     g_assert_cmpstr(webkit_web_view_get_uri(m_webView), ==, m_activeURI.data());
 }