REGRESSION (r224684): User-agent seen by page does not change when modified by the...
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 May 2018 00:20:16 +0000 (00:20 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 May 2018 00:20:16 +0000 (00:20 +0000)
<rdar://problem/34918109> and https://bugs.webkit.org/show_bug.cgi?id=186111

Reviewed by Andy Estes.

Source/WebCore:

Test: http/tests/navigation/useragent-reload.php

* Modules/websockets/WebSocketHandshake.cpp:
(WebCore::WebSocketHandshake::clientHandshakeRequest const): Use setUserAgent() for consistency.

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::startLoadingMainResource): Clear the user agent from the original DocumentLoader request
  before adding additional fields, as reloads should pick up user agent changes.

Tools:

* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::setCustomUserAgent):
* WebKitTestRunner/InjectedBundle/TestRunner.h:
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::resetStateToConsistentValues):
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):

LayoutTests:

* TestExpectations: Skip in WK1
* platform/wk2/TestExpectations: Enable in WK2

* http/tests/navigation/resources/user-agent-script.php: Added.
* http/tests/navigation/useragent-reload-expected.txt: Added.
* http/tests/navigation/useragent-reload.php: Added.

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

15 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/http/tests/navigation/resources/user-agent-script.php [new file with mode: 0644]
LayoutTests/http/tests/navigation/useragent-reload-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/navigation/useragent-reload.php [new file with mode: 0644]
LayoutTests/platform/wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/Modules/websockets/WebSocketHandshake.cpp
Source/WebCore/loader/DocumentLoader.cpp
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/TestInvocation.cpp

index e43d674..8eae0a5 100644 (file)
@@ -1,3 +1,17 @@
+2018-05-30  Brady Eidson  <beidson@apple.com>
+
+        REGRESSION (r224684): User-agent seen by page does not change when modified by the develop menu options after reloading.
+        <rdar://problem/34918109> and https://bugs.webkit.org/show_bug.cgi?id=186111
+
+        Reviewed by Andy Estes.
+
+        * TestExpectations: Skip in WK1
+        * platform/wk2/TestExpectations: Enable in WK2
+
+        * http/tests/navigation/resources/user-agent-script.php: Added.
+        * http/tests/navigation/useragent-reload-expected.txt: Added.
+        * http/tests/navigation/useragent-reload.php: Added.
+
 2018-05-30  Daniel Bates  <dabates@apple.com>
 
         Web Inspector: Annotate Same-Site cookies
index 6adb191..bc2a90e 100644 (file)
@@ -117,6 +117,7 @@ http/tests/loading/resourceLoadStatistics/ [ Skip ]
 http/tests/resourceLoadStatistics/ [ Skip ]
 http/tests/storageAccess/ [ Skip ]
 http/tests/navigation/process-swap-window-open.html [ Skip ]
+http/tests/navigation/useragent-reload.php [ Skip ]
 
 # Only Mac and iOS have an implementation of UIScriptController::doAsyncTask().
 fast/harness/uiscriptcontroller [ Skip ]
diff --git a/LayoutTests/http/tests/navigation/resources/user-agent-script.php b/LayoutTests/http/tests/navigation/resources/user-agent-script.php
new file mode 100644 (file)
index 0000000..aeeaabc
--- /dev/null
@@ -0,0 +1,6 @@
+<?php
+  header('Content-Type: application/javascript');
+?>
+window.subresourceUserAgent = "<?php 
+echo $_SERVER['HTTP_USER_AGENT'];
+?>";
diff --git a/LayoutTests/http/tests/navigation/useragent-reload-expected.txt b/LayoutTests/http/tests/navigation/useragent-reload-expected.txt
new file mode 100644 (file)
index 0000000..863339f
--- /dev/null
@@ -0,0 +1 @@
+Passed
diff --git a/LayoutTests/http/tests/navigation/useragent-reload.php b/LayoutTests/http/tests/navigation/useragent-reload.php
new file mode 100644 (file)
index 0000000..68b7310
--- /dev/null
@@ -0,0 +1,40 @@
+<body>
+</body>
+<script>
+if (window.testRunner) {
+       testRunner.dumpAsText();
+} else {
+       alert("Test can only be run in WebKitTestRunner");
+}
+</script>
+<script src="resources/user-agent-script.php"></script>
+<script>
+window.mainResourceUserAgent = "<?php 
+echo $_SERVER['HTTP_USER_AGENT'];
+?>";
+
+if (!sessionStorage.savedUserAgent) {
+       sessionStorage.savedUserAgent = navigator.userAgent;
+       testRunner.setCustomUserAgent("WebKitRules");
+       testRunner.queueReload();
+} else {
+       errorFound = false;
+       if (mainResourceUserAgent != subresourceUserAgent) {
+               errorFound = true;
+               document.body.innerHTML = "Error: Main resource and subresource were fetched with different user agent strings.";
+    }
+       if (mainResourceUserAgent == sessionStorage.savedUserAgent) {
+               errorFound = true;
+               document.body.innerHTML += "Error: Main resource was fetched with the same user agent string on the reload as was used on the first load.";
+       }
+    if (subresourceUserAgent == sessionStorage.savedUserAgent) {
+               errorFound = true;
+               document.body.innerHTML += "Error: Subresource was fetched with the same user agent string on the reload as was used on the first load.";
+       }
+       
+       if (!errorFound)
+               document.body.innerHTML = "Passed";
+       
+       testRunner.notifyDone();
+}
+</script>
index 5a5614f..4fa1a40 100644 (file)
@@ -713,6 +713,8 @@ http/tests/navigation/process-swap-window-open.html [ Pass ]
 # Cross-Origin-Resource-Policy response header is only implemented in WebKit2.
 http/wpt/cross-origin-resource-policy/ [ Pass ]
 
+http/tests/navigation/useragent-reload.php [ Pass ]
+
 ### END OF (5) Progressions, expected successes that are expected failures in WebKit1.
 ########################################
 
index 8d84c70..669883a 100644 (file)
@@ -1,3 +1,19 @@
+2018-05-30  Brady Eidson  <beidson@apple.com>
+
+        REGRESSION (r224684): User-agent seen by page does not change when modified by the develop menu options after reloading.
+        <rdar://problem/34918109> and https://bugs.webkit.org/show_bug.cgi?id=186111
+
+        Reviewed by Andy Estes.
+
+        Test: http/tests/navigation/useragent-reload.php
+
+        * Modules/websockets/WebSocketHandshake.cpp:
+        (WebCore::WebSocketHandshake::clientHandshakeRequest const): Use setUserAgent() for consistency.
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::startLoadingMainResource): Clear the user agent from the original DocumentLoader request
+          before adding additional fields, as reloads should pick up user agent changes.
+
 2018-05-30  Dean Jackson  <dino@apple.com>
 
         WebContent crashes with system preview content
index 5455cd1..b8b7337 100644 (file)
@@ -259,7 +259,7 @@ ResourceRequest WebSocketHandshake::clientHandshakeRequest() const
         request.setHTTPHeaderField(HTTPHeaderName::SecWebSocketExtensions, extensionValue);
 
     // Add a User-Agent header.
-    request.setHTTPHeaderField(HTTPHeaderName::UserAgent, m_document->userAgent(m_document->url()));
+    request.setHTTPUserAgent(m_document->userAgent(m_document->url()));
 
     return request;
 }
index 7ed4f64..a6e4a01 100644 (file)
@@ -1690,12 +1690,9 @@ void DocumentLoader::startLoadingMainResource(ShouldContinue shouldContinue)
     m_contentFilter = !m_substituteData.isValid() ? ContentFilter::create(*this) : nullptr;
 #endif
 
-    // FIXME: Is there any way the extra fields could have not been added by now?
-    // If not, it would be great to remove this line of code.
-    // Note that currently, some requests may have incorrect extra fields even if this function has been called,
-    // because we pass a wrong loadType (see FIXME in addExtraFieldsToMainResourceRequest()).
-    // If we remove this line of code then ResourceRequestBase does not need to track whether isSameSite
-    // is unspecified.
+    // Make sure we re-apply the user agent to the Document's ResourceRequest upon reload in case the embedding
+    // application has changed it.
+    m_request.clearHTTPUserAgent();
     frameLoader()->addExtraFieldsToMainResourceRequest(m_request);
 
     ASSERT(timing().startTime());
index 4d0b8d9..42b0a1f 100644 (file)
@@ -1,3 +1,19 @@
+2018-05-30  Brady Eidson  <beidson@apple.com>
+
+        REGRESSION (r224684): User-agent seen by page does not change when modified by the develop menu options after reloading.
+        <rdar://problem/34918109> and https://bugs.webkit.org/show_bug.cgi?id=186111
+
+        Reviewed by Andy Estes.
+
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::setCustomUserAgent):
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::resetStateToConsistentValues):
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
+
 2018-05-30  Youenn Fablet  <youenn@apple.com>
 
         Rename CrossOriginResourcePolicy same to same-origin
index 7baa854..4e3fd3c 100644 (file)
@@ -323,6 +323,7 @@ interface TestRunner {
 
     void setWebRTCLegacyAPIEnabled(boolean value);
     void setMDNSICECandidatesEnabled(boolean value);
+    void setCustomUserAgent(DOMString userAgent);
 
     void terminateNetworkProcess();
     void terminateServiceWorkerProcess();
index db8f2ff..95ffbae 100644 (file)
@@ -439,6 +439,12 @@ void TestRunner::setMDNSICECandidatesEnabled(bool enabled)
     WKBundleOverrideBoolPreferenceForTestRunner(injectedBundle.bundle(), injectedBundle.pageGroup(), key.get(), enabled);
 }
 
+void TestRunner::setCustomUserAgent(JSStringRef userAgent)
+{
+    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetCustomUserAgent"));
+    WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), toWK(userAgent).get(), nullptr);
+}
+
 void TestRunner::setWebRTCLegacyAPIEnabled(bool enabled)
 {
     WKRetainPtr<WKStringRef> key(AdoptWK, WKStringCreateWithUTF8CString("WebKitWebRTCLegacyAPIEnabled"));
index bb6ab44..41883ce 100644 (file)
@@ -131,6 +131,7 @@ public:
     void setMediaDevicesEnabled(bool);
     void setWebRTCLegacyAPIEnabled(bool);
     void setMDNSICECandidatesEnabled(bool);
+    void setCustomUserAgent(JSStringRef);
 
     // Special DOM functions.
     void clearBackForwardList();
index bc34c3d..2ac9ec6 100644 (file)
@@ -786,6 +786,8 @@ bool TestController::resetStateToConsistentValues(const TestOptions& options)
     // FIXME: We should be testing the default.
     WKPageSetBackgroundExtendsBeyondPage(m_mainWebView->page(), false);
 
+    WKPageSetCustomUserAgent(m_mainWebView->page(), nullptr);
+
     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("Reset"));
     WKRetainPtr<WKMutableDictionaryRef> resetMessageBody = adoptWK(WKMutableDictionaryCreate());
 
index f199f7e..94c8a2d 100644 (file)
@@ -877,6 +877,12 @@ WKRetainPtr<WKTypeRef> TestInvocation::didReceiveSynchronousMessageFromInjectedB
         return nullptr;
     }
 
+    if (WKStringIsEqualToUTF8CString(messageName, "SetCustomUserAgent")) {
+        WKStringRef userAgent = static_cast<WKStringRef>(messageBody);
+        WKPageSetCustomUserAgent(TestController::singleton().mainWebView()->page(), userAgent);
+        return nullptr;
+    }
+
     if (WKStringIsEqualToUTF8CString(messageName, "SetStorageAccessAPIEnabled")) {
         WKBooleanRef accept = static_cast<WKBooleanRef>(messageBody);
         WKCookieManagerSetStorageAccessAPIEnabled(WKContextGetCookieManager(TestController::singleton().context()), WKBooleanGetValue(accept));