Bug 1114040 - Test for bug 1114040. r=ttaubert, a=sledru
authorDave Townsend <dtownsend@oxymoronical.com>
Wed, 28 Jan 2015 11:53:45 -0800
changeset 243094 a6f725c23d30
parent 243093 aa4a0caf1dae
child 243095 b0220b627748
push id4402
push userryanvm@gmail.com
push date2015-01-29 16:16 +0000
treeherdermozilla-beta@e25b169e456b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttaubert, sledru
bugs1114040
milestone36.0
Bug 1114040 - Test for bug 1114040. r=ttaubert, a=sledru
browser/components/sessionstore/test/browser.ini
browser/components/sessionstore/test/browser_restore_redirect.js
browser/components/sessionstore/test/content.js
browser/components/sessionstore/test/restore_redirect_http.html
browser/components/sessionstore/test/restore_redirect_http.html^headers^
browser/components/sessionstore/test/restore_redirect_js.html
browser/components/sessionstore/test/restore_redirect_target.html
--- a/browser/components/sessionstore/test/browser.ini
+++ b/browser/components/sessionstore/test/browser.ini
@@ -43,16 +43,20 @@ support-files =
   browser_463206_sample.html
   browser_466937_sample.html
   browser_485482_sample.html
   browser_637020_slow.sjs
   browser_662743_sample.html
   browser_739531_sample.html
   browser_911547_sample.html
   browser_911547_sample.html^headers^
+  restore_redirect_http.html
+  restore_redirect_http.html^headers^
+  restore_redirect_js.html
+  restore_redirect_target.html
 
 #NB: the following are disabled
 #  browser_464620_a.html
 #  browser_464620_b.html 
 #  browser_464620_xd.html
 
 
 #disabled-for-intermittent-failures--bug-766044, browser_459906_empty.html
@@ -80,16 +84,17 @@ skip-if = buildapp == 'mulet'
 [browser_frame_history.js]
 [browser_global_store.js]
 [browser_history_cap.js]
 [browser_history_persist.js]
 [browser_label_and_icon.js]
 [browser_merge_closed_tabs.js]
 [browser_pageStyle.js]
 [browser_privatetabs.js]
+[browser_restore_redirect.js]
 [browser_scrollPositions.js]
 [browser_sessionHistory.js]
 # Disabled because of bug 1077581
 skip-if = e10s
 [browser_sessionStorage.js]
 [browser_swapDocShells.js]
 skip-if = e10s # See bug 918634
 [browser_telemetry.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/browser_restore_redirect.js
@@ -0,0 +1,69 @@
+"use strict";
+
+const BASE = "http://example.com/browser/browser/components/sessionstore/test/";
+const TARGET = BASE + "restore_redirect_target.html";
+
+/**
+ * Ensure that a http redirect leaves a working tab.
+ */
+add_task(function check_http_redirect() {
+  let state = {
+    entries: [{ url: BASE + "restore_redirect_http.html" }]
+  };
+
+  // Open a new tab to restore into.
+  let tab = gBrowser.addTab("about:blank");
+  let browser = tab.linkedBrowser;
+  yield promiseTabState(tab, state);
+
+  info("Restored tab");
+
+  TabState.flush(browser);
+  let data = TabState.collect(tab);
+  is(data.entries.length, 1, "Should be one entry in session history");
+  is(data.entries[0].url, TARGET, "Should be the right session history entry");
+
+  ok(!("__SS_data" in browser), "Temporary restore data should have been cleared");
+
+  // Cleanup.
+  gBrowser.removeTab(tab);
+});
+
+/**
+ * Ensure that a js redirect leaves a working tab.
+ */
+add_task(function check_js_redirect() {
+  let state = {
+    entries: [{ url: BASE + "restore_redirect_js.html" }]
+  };
+
+  let loadPromise = new Promise(resolve => {
+    function listener(msg) {
+      if (msg.data.url.endsWith("restore_redirect_target.html")) {
+        window.messageManager.removeMessageListener("ss-test:loadEvent", listener);
+        resolve();
+      }
+    }
+
+    window.messageManager.addMessageListener("ss-test:loadEvent", listener);
+  });
+
+  // Open a new tab to restore into.
+  let tab = gBrowser.addTab("about:blank");
+  let browser = tab.linkedBrowser;
+  yield promiseTabState(tab, state);
+
+  info("Restored tab");
+
+  yield loadPromise;
+
+  TabState.flush(browser);
+  let data = TabState.collect(tab);
+  is(data.entries.length, 1, "Should be one entry in session history");
+  is(data.entries[0].url, TARGET, "Should be the right session history entry");
+
+  ok(!("__SS_data" in browser), "Temporary restore data should have been cleared");
+
+  // Cleanup.
+  gBrowser.removeTab(tab);
+});
--- a/browser/components/sessionstore/test/content.js
+++ b/browser/components/sessionstore/test/content.js
@@ -256,10 +256,10 @@ addMessageListener("ss-test:historyRepla
 addMessageListener("ss-test:run", function({data, objects}) {
   let f = eval('(' + data.code + ')');
   let result = f(content, objects.arg);
   sendAsyncMessage("ss-test:runFinished", result);
 });
 
 addEventListener("load", function(event) {
   let subframe = event.target != content.document;
-  sendAsyncMessage("ss-test:loadEvent", {subframe: subframe});
+  sendAsyncMessage("ss-test:loadEvent", {subframe: subframe, url: event.target.documentURI});
 }, true);
new file mode 100644
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/restore_redirect_http.html^headers^
@@ -0,0 +1,2 @@
+HTTP 302 Moved Temporarily
+Location: restore_redirect_target.html
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/restore_redirect_js.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+<script>
+var newLocation = window.location.toString().replace("restore_redirect_js.html", "restore_redirect_target.html");
+window.location.replace(newLocation);
+</script>
+</head>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/restore_redirect_target.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+<title>Test page</title>
+</head>
+<body>Test page</body>
+</html>