Title: [232323] trunk
Revision
232323
Author
beid...@apple.com
Date
2018-05-30 17:20:16 -0700 (Wed, 30 May 2018)

Log Message

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.

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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (232322 => 232323)


--- trunk/LayoutTests/ChangeLog	2018-05-31 00:18:46 UTC (rev 232322)
+++ trunk/LayoutTests/ChangeLog	2018-05-31 00:20:16 UTC (rev 232323)
@@ -1,3 +1,17 @@
+2018-05-30  Brady Eidson  <beid...@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  <daba...@apple.com>
 
         Web Inspector: Annotate Same-Site cookies

Modified: trunk/LayoutTests/TestExpectations (232322 => 232323)


--- trunk/LayoutTests/TestExpectations	2018-05-31 00:18:46 UTC (rev 232322)
+++ trunk/LayoutTests/TestExpectations	2018-05-31 00:20:16 UTC (rev 232323)
@@ -117,6 +117,7 @@
 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 ]

Added: trunk/LayoutTests/http/tests/navigation/resources/user-agent-script.php (0 => 232323)


--- trunk/LayoutTests/http/tests/navigation/resources/user-agent-script.php	                        (rev 0)
+++ trunk/LayoutTests/http/tests/navigation/resources/user-agent-script.php	2018-05-31 00:20:16 UTC (rev 232323)
@@ -0,0 +1,6 @@
+<?php
+  header('Content-Type: application/_javascript_');
+?>
+window.subresourceUserAgent = "<?php 
+echo $_SERVER['HTTP_USER_AGENT'];
+?>";

Added: trunk/LayoutTests/http/tests/navigation/useragent-reload-expected.txt (0 => 232323)


--- trunk/LayoutTests/http/tests/navigation/useragent-reload-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/navigation/useragent-reload-expected.txt	2018-05-31 00:20:16 UTC (rev 232323)
@@ -0,0 +1 @@
+Passed

Added: trunk/LayoutTests/http/tests/navigation/useragent-reload.php (0 => 232323)


--- trunk/LayoutTests/http/tests/navigation/useragent-reload.php	                        (rev 0)
+++ trunk/LayoutTests/http/tests/navigation/useragent-reload.php	2018-05-31 00:20:16 UTC (rev 232323)
@@ -0,0 +1,40 @@
+<body>
+</body>
+<script>
+if (window.testRunner) {
+	testRunner.dumpAsText();
+} else {
+	alert("Test can only be run in WebKitTestRunner");
+}
+</script>
+<script src=""
+<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>

Modified: trunk/LayoutTests/platform/wk2/TestExpectations (232322 => 232323)


--- trunk/LayoutTests/platform/wk2/TestExpectations	2018-05-31 00:18:46 UTC (rev 232322)
+++ trunk/LayoutTests/platform/wk2/TestExpectations	2018-05-31 00:20:16 UTC (rev 232323)
@@ -713,6 +713,8 @@
 # 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.
 ########################################
 

Modified: trunk/Source/WebCore/ChangeLog (232322 => 232323)


--- trunk/Source/WebCore/ChangeLog	2018-05-31 00:18:46 UTC (rev 232322)
+++ trunk/Source/WebCore/ChangeLog	2018-05-31 00:20:16 UTC (rev 232323)
@@ -1,3 +1,19 @@
+2018-05-30  Brady Eidson  <beid...@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  <d...@apple.com>
 
         WebContent crashes with system preview content

Modified: trunk/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp (232322 => 232323)


--- trunk/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp	2018-05-31 00:18:46 UTC (rev 232322)
+++ trunk/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp	2018-05-31 00:20:16 UTC (rev 232323)
@@ -259,7 +259,7 @@
         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;
 }

Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (232322 => 232323)


--- trunk/Source/WebCore/loader/DocumentLoader.cpp	2018-05-31 00:18:46 UTC (rev 232322)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp	2018-05-31 00:20:16 UTC (rev 232323)
@@ -1690,12 +1690,9 @@
     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());

Modified: trunk/Tools/ChangeLog (232322 => 232323)


--- trunk/Tools/ChangeLog	2018-05-31 00:18:46 UTC (rev 232322)
+++ trunk/Tools/ChangeLog	2018-05-31 00:20:16 UTC (rev 232323)
@@ -1,3 +1,19 @@
+2018-05-30  Brady Eidson  <beid...@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  <you...@apple.com>
 
         Rename CrossOriginResourcePolicy same to same-origin

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl (232322 => 232323)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2018-05-31 00:18:46 UTC (rev 232322)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2018-05-31 00:20:16 UTC (rev 232323)
@@ -323,6 +323,7 @@
 
     void setWebRTCLegacyAPIEnabled(boolean value);
     void setMDNSICECandidatesEnabled(boolean value);
+    void setCustomUserAgent(DOMString userAgent);
 
     void terminateNetworkProcess();
     void terminateServiceWorkerProcess();

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (232322 => 232323)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2018-05-31 00:18:46 UTC (rev 232322)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2018-05-31 00:20:16 UTC (rev 232323)
@@ -439,6 +439,12 @@
     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"));

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h (232322 => 232323)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2018-05-31 00:18:46 UTC (rev 232322)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2018-05-31 00:20:16 UTC (rev 232323)
@@ -131,6 +131,7 @@
     void setMediaDevicesEnabled(bool);
     void setWebRTCLegacyAPIEnabled(bool);
     void setMDNSICECandidatesEnabled(bool);
+    void setCustomUserAgent(JSStringRef);
 
     // Special DOM functions.
     void clearBackForwardList();

Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (232322 => 232323)


--- trunk/Tools/WebKitTestRunner/TestController.cpp	2018-05-31 00:18:46 UTC (rev 232322)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp	2018-05-31 00:20:16 UTC (rev 232323)
@@ -786,6 +786,8 @@
     // 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());
 

Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (232322 => 232323)


--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2018-05-31 00:18:46 UTC (rev 232322)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2018-05-31 00:20:16 UTC (rev 232323)
@@ -877,6 +877,12 @@
         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));
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to