Bug 1261225 - Part 3 - Extend session store form data test to cover capturing form data after back/forward navigation. r=margaret draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Wed, 06 Apr 2016 21:30:43 +0200
changeset 348186 ff8367387d5ac940efa28d143bb08b657f05afd4
parent 348166 3b8be583ceebfc25b77971d319108f850a8d6fb7
child 348187 dcf896e19bd6ffa168b3de6903e5271890a31bb5
child 348356 23dbacc41be805f4616935c95fce49319e2c4280
child 349174 8244869cbf6162631e32ef657e0494e8bebb6304
push id14772
push usermozilla@buttercookie.de
push dateWed, 06 Apr 2016 21:25:32 +0000
reviewersmargaret
bugs1261225
milestone48.0a1
Bug 1261225 - Part 3 - Extend session store form data test to cover capturing form data after back/forward navigation. r=margaret MozReview-Commit-ID: 6Euhttmhj4x
mobile/android/tests/browser/chrome/test_session_form_data.html
--- a/mobile/android/tests/browser/chrome/test_session_form_data.html
+++ b/mobile/android/tests/browser/chrome/test_session_form_data.html
@@ -1,17 +1,18 @@
 <!DOCTYPE HTML>
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=671993
+https://bugzilla.mozilla.org/show_bug.cgi?id=1261225
 Migrated from Robocop: https://bugzilla.mozilla.org/show_bug.cgi?id=1184186
 -->
 <head>
   <meta charset="utf-8">
-  <title>Test for Bug 671993</title>
+  <title>Test for Bugs 671993, 1261225</title>
   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
   <link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
   <script type="application/javascript" src="head.js"></script>
   <script type="application/javascript;version=1.7">
 
 "use strict";
@@ -192,20 +193,88 @@ add_task(function* test_formdata2() {
   // Check the form data.
   is(getInputValue(browser, {id: "txt"}), OUTER_VALUE, "outer value restored correctly");
   is(getInputValue(browser, {id: "txt", frame: 0}), INNER_VALUE, "inner value restored correctly");
 
   // Remove the tab.
   gBrowserApp.closeTab(gBrowserApp.getTabForBrowser(browser));
 });
 
+/**
+ * This test ensures that form data collection restores correctly even after
+ * navigating to a different page and then returning via hitting back.
+ */
+add_task(function* test_formdata_navigation() {
+  const URL = "http://example.org/chrome/mobile/android/tests/browser/chrome/session_formdata_sample.html";
+  const otherURL = "http://example.org/chrome/mobile/android/tests/browser/chrome/basic_article.html";
+
+  const OUTER_VALUE = "browser_formdata_" + Math.random();
+  const INNER_VALUE = "browser_formdata_" + Math.random();
+
+  // Creates a tab, loads a page with some form fields, modifies their values,
+  // navigates to a different page and back again and closes the tab.
+  function createNavigateAndRemoveTab() {
+    return Task.spawn(function () {
+      // Create a new tab.
+      let tab = gBrowserApp.addTab(URL);
+      let browser = tab.browser;
+      yield promiseBrowserEvent(browser, "load");
+
+      // Modify form data.
+      setInputValue(browser, {id: "txt", value: OUTER_VALUE});
+      setInputValue(browser, {id: "txt", value: INNER_VALUE, frame: 0});
+
+      // Visit a different page.
+      gBrowserApp.loadURI(otherURL, browser);
+      yield promiseBrowserEvent(browser, "DOMContentLoaded");
+      is(browser.currentURI.spec, otherURL, "navigated to a different page");
+
+      // Go back.
+      is(browser.canGoBack, true, "can go back");
+      browser.goBack();
+      yield promiseTabEvent(gBrowserApp.deck, "pageshow");
+      is(browser.currentURI.spec, URL, "navigated back to form data page");
+
+      // Make sure form data is still present.
+      is(getInputValue(browser, {id: "txt"}), OUTER_VALUE, "outer value present after navigation");
+      is(getInputValue(browser, {id: "txt", frame: 0}), INNER_VALUE, "inner value present after navigation");
+
+      // Allow the session store a bit of time to actually capture the form data.
+      yield sleep(CLOSE_TAB_WAIT);
+
+      // Remove the tab.
+      gBrowserApp.closeTab(tab);
+      yield sleep(CLOSE_TAB_WAIT);
+    });
+  }
+
+  yield createNavigateAndRemoveTab();
+  let state = ss.getClosedTabs(gChromeWin);
+  let [{formdata}] = state;
+  is(formdata.id.txt, OUTER_VALUE, "outer value is correct");
+  is(formdata.children[0].id.txt, INNER_VALUE, "inner value is correct");
+
+  // Restore the closed tab.
+  let closedTabData = ss.getClosedTabs(gChromeWin)[0];
+  let browser = ss.undoCloseTab(gChromeWin, closedTabData);
+  yield promiseBrowserEvent(browser, "load");
+
+  // Check the form data.
+  is(getInputValue(browser, {id: "txt"}), OUTER_VALUE, "outer value restored correctly");
+  is(getInputValue(browser, {id: "txt", frame: 0}), INNER_VALUE, "inner value restored correctly");
+
+  // Remove the tab.
+  gBrowserApp.closeTab(gBrowserApp.getTabForBrowser(browser));
+});
+
   </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=671993">Mozilla Bug 671993</a>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1261225">Mozilla Bug 1261225</a>
 <br>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1184186">Migrated from Robocop testSessionFormData</a>
 <p id="display"></p>
 <div id="content" style="display: none">
 
 </div>
 <pre id="test">
 </pre>