Title: [229375] trunk
Revision
229375
Author
commit-qu...@webkit.org
Date
2018-03-07 14:09:49 -0800 (Wed, 07 Mar 2018)

Log Message

replaceState cause back/forward malfunction on html page with <base href="" tag
https://bugs.webkit.org/show_bug.cgi?id=182678
<rdar://problem/37517821>

Patch by Sihui Liu <sihui_...@apple.com> on 2018-03-07
Reviewed by Chris Dumez.

Source/WebCore:

replaceState should not change URL when the URL argument is NULL, but should change URL when the URL argument is an empty string.

Test: http/tests/history/replacestate-no-url.html

* page/History.cpp:
(WebCore::History::urlForState):

LayoutTests:

* http/tests/history/replacestate-no-url-expected.txt: Added.
* http/tests/history/replacestate-no-url.html: Added.
Add layout test coverage.

* fast/loader/stateobjects/pushstate-with-fragment-urls-and-hashchange-expected.txt:
Rebaseline a layout test as empty string for URL is handled differently.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (229374 => 229375)


--- trunk/LayoutTests/ChangeLog	2018-03-07 22:00:38 UTC (rev 229374)
+++ trunk/LayoutTests/ChangeLog	2018-03-07 22:09:49 UTC (rev 229375)
@@ -1,3 +1,18 @@
+2018-03-07  Sihui Liu  <sihui_...@apple.com>
+
+        replaceState cause back/forward malfunction on html page with <base href="" tag
+        https://bugs.webkit.org/show_bug.cgi?id=182678
+        <rdar://problem/37517821>
+
+        Reviewed by Chris Dumez.
+
+        * http/tests/history/replacestate-no-url-expected.txt: Added.
+        * http/tests/history/replacestate-no-url.html: Added.
+        Add layout test coverage.
+
+        * fast/loader/stateobjects/pushstate-with-fragment-urls-and-hashchange-expected.txt:
+        Rebaseline a layout test as empty string for URL is handled differently.
+
 2018-03-07  Chris Dumez  <cdu...@apple.com>
 
         http/tests/misc/location-replace-crossdomain.html is failing with async policy delegates

Modified: trunk/LayoutTests/fast/loader/stateobjects/pushstate-with-fragment-urls-and-hashchange-expected.txt (229374 => 229375)


--- trunk/LayoutTests/fast/loader/stateobjects/pushstate-with-fragment-urls-and-hashchange-expected.txt	2018-03-07 22:00:38 UTC (rev 229374)
+++ trunk/LayoutTests/fast/loader/stateobjects/pushstate-with-fragment-urls-and-hashchange-expected.txt	2018-03-07 22:09:49 UTC (rev 229375)
@@ -27,8 +27,9 @@
 Hash change fired and last path component is pushstate-with-fragment-urls-and-hashchange.html#otherhash
 State popped with event null (type object) and last path component pushstate-with-fragment-urls-and-hashchange.html#hash
 Hash change fired and last path component is pushstate-with-fragment-urls-and-hashchange.html#hash
+State popped with event null (type object) and last path component pushstate-with-fragment-urls-and-hashchange.html
+Hash change fired and last path component is pushstate-with-fragment-urls-and-hashchange.html
 State popped with event null (type object) and last path component pushstate-with-fragment-urls-and-hashchange.html#
 Hash change fired and last path component is pushstate-with-fragment-urls-and-hashchange.html#
-State popped with event null (type object) and last path component pushstate-with-fragment-urls-and-hashchange.html#
 State popped with event OriginalEntry (type string) and last path component pushstate-with-fragment-urls-and-hashchange.html
 

Added: trunk/LayoutTests/http/tests/history/replacestate-no-url-expected.txt (0 => 229375)


--- trunk/LayoutTests/http/tests/history/replacestate-no-url-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/history/replacestate-no-url-expected.txt	2018-03-07 22:09:49 UTC (rev 229375)
@@ -0,0 +1,18 @@
+Tests that ReplaceState should not change document URL if URL argument is null.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Push item one
+Replace item one with null url
+Push item two
+Going back to item one
+PASS document.location.href is "http://127.0.0.1:8000/one"
+Replace item one with empty url
+Push item two
+Going back to item one
+PASS document.location.href is "http://127.0.0.1:8000/"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/http/tests/history/replacestate-no-url.html (0 => 229375)


--- trunk/LayoutTests/http/tests/history/replacestate-no-url.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/history/replacestate-no-url.html	2018-03-07 22:09:49 UTC (rev 229375)
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <base href=""
+  <script src=""
+  <script>
+  jsTestIsAsync = true;
+  description('Tests that ReplaceState should not change document URL if URL argument is null.');
+
+  function testNullUrl() {
+    debug('Push item one');
+    history.pushState({}, 'page 1', '/one');
+    debug('Replace item one with null url');
+    history.replaceState({}, 'replaced page 1');
+    debug('Push item two');
+    history.pushState({}, 'page 2', '/two');
+    debug('Going back to item one');
+    history.back();
+  }
+
+  function testEmptyUrl() {
+    debug('Replace item one with empty url');
+    history.replaceState('StopEntry', 'replaced page 1 again', '');
+    debug('Push item two');
+    history.pushState({}, 'page 2', '/two');
+    debug('Going back to item one');
+    history.back();
+  }
+  
+  window._onpopstate_ = function(event) {
+    if (event.state != 'StopEntry') {
+      shouldBeEqualToString('document.location.href', 'http://127.0.0.1:8000/one');
+      setTimeout(testEmptyUrl, 0);
+    } else {
+      shouldBeEqualToString('document.location.href', 'http://127.0.0.1:8000/');
+      finishJSTest();
+    }
+  }
+  </script>
+</head>
+
+<body _onload_="testNullUrl()">
+</body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (229374 => 229375)


--- trunk/Source/WebCore/ChangeLog	2018-03-07 22:00:38 UTC (rev 229374)
+++ trunk/Source/WebCore/ChangeLog	2018-03-07 22:09:49 UTC (rev 229375)
@@ -1,3 +1,18 @@
+2018-03-07  Sihui Liu  <sihui_...@apple.com>
+
+        replaceState cause back/forward malfunction on html page with <base href="" tag
+        https://bugs.webkit.org/show_bug.cgi?id=182678
+        <rdar://problem/37517821>
+
+        Reviewed by Chris Dumez.
+
+        replaceState should not change URL when the URL argument is NULL, but should change URL when the URL argument is an empty string.
+
+        Test: http/tests/history/replacestate-no-url.html
+
+        * page/History.cpp:
+        (WebCore::History::urlForState):
+
 2018-03-07  Antti Koivisto  <an...@apple.com>
 
         Don't invalidate descendants for sibling combinators unless needed

Modified: trunk/Source/WebCore/page/History.cpp (229374 => 229375)


--- trunk/Source/WebCore/page/History.cpp	2018-03-07 22:00:38 UTC (rev 229374)
+++ trunk/Source/WebCore/page/History.cpp	2018-03-07 22:09:49 UTC (rev 229375)
@@ -156,11 +156,9 @@
 
 URL History::urlForState(const String& urlString)
 {
-    URL baseURL = m_frame->document()->baseURL();
-    if (urlString.isEmpty())
-        return baseURL;
-
-    return URL(baseURL, urlString);
+    if (urlString.isNull())
+        return m_frame->document()->url();
+    return m_frame->document()->completeURL(urlString);
 }
 
 ExceptionOr<void> History::stateObjectAdded(RefPtr<SerializedScriptValue>&& data, const String& title, const String& urlString, StateObjectType stateObjectType)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to