<rdar://problem/9251515> and https://bugs.webkit.org/show_bug.cgi?id=58072
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Apr 2011 01:27:57 +0000 (01:27 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Apr 2011 01:27:57 +0000 (01:27 +0000)
URLs accessed as a result of pushState/replaceState should count as "visited" and be in the global history

Reviewed by Maciej Stachowiak.

Source/WebCore:

Test: fast/loader/stateobjects/state-url-sets-links-visited.html

* loader/HistoryController.cpp:
(WebCore::HistoryController::pushState): Notify the history client and add the visited link.
(WebCore::HistoryController::replaceState): Ditto.

LayoutTests:

* fast/loader/stateobjects/state-url-sets-links-visited-expected.txt: Added.
* fast/loader/stateobjects/state-url-sets-links-visited.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/loader/stateobjects/state-url-sets-links-visited-expected.txt [new file with mode: 0644]
LayoutTests/fast/loader/stateobjects/state-url-sets-links-visited.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/loader/HistoryController.cpp

index d29ec05..fc1cf0d 100644 (file)
@@ -1,3 +1,13 @@
+2011-04-11  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Maciej Stachowiak.
+
+        <rdar://problem/9251515> and https://bugs.webkit.org/show_bug.cgi?id=58072
+        URLs accessed as a result of pushState/replaceState should count as "visited" and be in the global history
+
+        * fast/loader/stateobjects/state-url-sets-links-visited-expected.txt: Added.
+        * fast/loader/stateobjects/state-url-sets-links-visited.html: Added.
+
 2011-04-11  Justin Novosad  <junov@chromium.org>
 
         Reviewed by Kenneth Russell.
diff --git a/LayoutTests/fast/loader/stateobjects/state-url-sets-links-visited-expected.txt b/LayoutTests/fast/loader/stateobjects/state-url-sets-links-visited-expected.txt
new file mode 100644 (file)
index 0000000..a3eb0e9
--- /dev/null
@@ -0,0 +1,5 @@
+This link should get colored visited as a result of replaceState() setting it as the current URL
+This link should get colored visited as a result of pushState() adding it to the forward list
+If you're running in a browser, the link should be orange-on-black and you should see "replacedURL.html" in your global history.
+If you're running in DRT, the test will also append "PASS" or "FAIL".
+PASS
diff --git a/LayoutTests/fast/loader/stateobjects/state-url-sets-links-visited.html b/LayoutTests/fast/loader/stateobjects/state-url-sets-links-visited.html
new file mode 100644 (file)
index 0000000..8f03b65
--- /dev/null
@@ -0,0 +1,37 @@
+<script>
+
+if (window.layoutTestController) {
+    layoutTestController.keepWebHistory();
+    layoutTestController.dumpAsText();
+}
+
+function loaded()
+{
+    window.history.replaceState(null, "Title", "replacedURL.html");
+    window.history.pushState(null, "Title", "pushedURL.html");
+
+    if (window.layoutTestController) {
+        var style1 = window.layoutTestController.computedStyleIncludingVisitedInfo(document.getElementById('link1'));
+        var style2 = window.layoutTestController.computedStyleIncludingVisitedInfo(document.getElementById('link2'));
+        var result = document.createElement("p");
+        if (style1.color != "rgb(255, 165, 0)" || style2.color != "rgb(255, 165, 0)")
+            result.innerText = "FAIL";
+        else
+            result.innerText = "PASS";
+        document.body.appendChild(result);
+    }
+}
+
+</script>
+
+<style>
+:link { color: rgb(0, 255, 0); background-color: white }
+:visited { color: rgb(255, 165, 0); background-color: black }
+</style>
+
+<body onload="loaded();">
+<a id="link1" href="replacedURL.html">This link should get colored visited as a result of replaceState() setting it as the current URL</a><br>
+<a id="link2" href="pushedURL.html">This link should get colored visited as a result of pushState() adding it to the forward list</a><br>
+If you're running in a browser, the link should be orange-on-black and you should see "replacedURL.html" in your global history.<br>
+If you're running in DRT, the test will also append "PASS" or "FAIL".<br>
+</body>
index b530c49..51d7485 100644 (file)
@@ -1,3 +1,16 @@
+2011-04-11  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Maciej Stachowiak.
+
+        <rdar://problem/9251515> and https://bugs.webkit.org/show_bug.cgi?id=58072
+        URLs accessed as a result of pushState/replaceState should count as "visited" and be in the global history
+
+        Test: fast/loader/stateobjects/state-url-sets-links-visited.html
+
+        * loader/HistoryController.cpp:
+        (WebCore::HistoryController::pushState): Notify the history client and add the visited link.
+        (WebCore::HistoryController::replaceState): Ditto.
+
 2011-04-11  Dimitri Glazkov  <dglazkov@chromium.org>
 
         Reviewed by Eric Carlson.
index c1c5414..407b6be 100644 (file)
@@ -799,6 +799,10 @@ void HistoryController::pushState(PassRefPtr<SerializedScriptValue> stateObject,
     m_currentItem->setURLString(urlString);
 
     page->backForward()->addItem(topItem.release());
+
+    addVisitedLink(page, KURL(ParsedURLString, urlString));
+    m_frame->loader()->client()->updateGlobalHistory();
+
 }
 
 void HistoryController::replaceState(PassRefPtr<SerializedScriptValue> stateObject, const String& title, const String& urlString)
@@ -810,6 +814,10 @@ void HistoryController::replaceState(PassRefPtr<SerializedScriptValue> stateObje
         m_currentItem->setURLString(urlString);
     m_currentItem->setTitle(title);
     m_currentItem->setStateObject(stateObject);
+
+    ASSERT(m_frame->page());
+    addVisitedLink(m_frame->page(), KURL(ParsedURLString, urlString));
+    m_frame->loader()->client()->updateGlobalHistory();
 }
 
 } // namespace WebCore