Bug 1343603 - Part 2 - Test that clearing history clears the cached session store data, too. r?ahunt draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 02 Mar 2017 20:19:58 +0100
changeset 492071 13108723994408f3a8cc61c21bf9870fe9d1cc0d
parent 492070 772c218b9dbd789b9b284a31e47cff7cff22a144
child 547639 71219a2e9270d48b5e65eb63e6ed9fc2293afca5
push id47518
push usermozilla@buttercookie.de
push dateThu, 02 Mar 2017 19:37:09 +0000
reviewersahunt
bugs1343603
milestone54.0a1
Bug 1343603 - Part 2 - Test that clearing history clears the cached session store data, too. r?ahunt MozReview-Commit-ID: 3YhHnmnkgCS
mobile/android/tests/browser/chrome/basic_article_mobile.html
mobile/android/tests/browser/chrome/chrome.ini
mobile/android/tests/browser/chrome/test_session_clear_history.html
--- a/mobile/android/tests/browser/chrome/basic_article_mobile.html
+++ b/mobile/android/tests/browser/chrome/basic_article_mobile.html
@@ -1,12 +1,12 @@
 <!DOCTYPE html>
 <html>
 <head>
-<title>Article title</title>
+<title>Article title - mobile</title>
 <meta name="description" content="This is the article description." />
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 </head>
 <body>
 <header>Site header</header>
 <div>
 <h1>Article title</h1>
 <h2 class="author">by Jane Doe</h2>
--- a/mobile/android/tests/browser/chrome/chrome.ini
+++ b/mobile/android/tests/browser/chrome/chrome.ini
@@ -35,16 +35,17 @@ skip-if = debug
 [test_network_manager.html]
 [test_offline_page.html]
 skip-if = true # Bug 1241478
 [test_reader_view.html]
 [test_resource_substitutions.html]
 [test_restricted_profiles.html]
 [test_select_disabled.html]
 [test_selectoraddtab.html]
+[test_session_clear_history.html]
 [test_session_form_data.html]
 [test_session_parentid.html]
 [test_session_scroll_position.html]
 [test_session_zombification.html]
 [test_shared_preferences.html]
 [test_simple_discovery.html]
 [test_video_discovery.html]
 [test_web_channel.html]
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/browser/chrome/test_session_clear_history.html
@@ -0,0 +1,151 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1343603
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1343603</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">
+
+  /** Test for Bug 1343603 **/
+
+  "use strict";
+
+  const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+
+  Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+  Cu.import("resource://gre/modules/Services.jsm");
+  Cu.import("resource://gre/modules/Messaging.jsm");
+  Cu.import("resource://gre/modules/Task.jsm");
+
+  // The chrome window
+  let chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
+  let BrowserApp = chromeWin.BrowserApp;
+
+  // Track the tabs where the tests are happening
+  let tabBlank;
+  let tabTest;
+
+  function cleanupTabs() {
+    if (tabBlank) {
+      BrowserApp.closeTab(tabBlank);
+      tabBlank = null;
+    }
+
+    if (tabTest) {
+      BrowserApp.closeTab(tabTest);
+      tabTest = null;
+    }
+  }
+
+  SimpleTest.registerCleanupFunction(function() {
+    cleanupTabs();
+  });
+
+
+  const url1 = "http://example.org/chrome/mobile/android/tests/browser/chrome/basic_article_mobile.html";
+  const url2 = "http://example.org/chrome/mobile/android/tests/browser/chrome/basic_article.html";
+  const url3 = "data:text/html;charset=utf-8,It%20was%20a%20dark%20and%20stormy%20night.";
+
+  add_task(function* test_sessionStoreClearTabHistory() {
+    // Add a new tab with some content
+    tabTest = BrowserApp.addTab(url1 , { selected: true, parentId: BrowserApp.selectedTab.id });
+    yield promiseBrowserEvent(tabTest.browser, "DOMTitleChanged");
+
+    // Navigate to create some history
+    tabTest.browser.loadURI(url2);
+    yield promiseBrowserEvent(tabTest.browser, "DOMTitleChanged");
+    tabTest.browser.loadURI(url3);
+    yield promiseBrowserEvent(tabTest.browser, "DOMTitleChanged");
+    is(tabTest.browser.canGoBack, true, "can go back");
+    tabTest.browser.goBack();
+    yield promiseBrowserEvent(tabTest.browser, "DOMTitleChanged");
+
+    // Check that the session store has recorded this history
+    let data = tabTest.browser.__SS_data;
+    is(data.entries.length, 3, "the session store has captured 3 history entries");
+    is(data.index, 2, "history index is correct");
+    is(data.entries[0].url, url1, "URL of first history entry is correct");
+
+    // Clear browsing history
+    let sanitize = { history:true };
+    let notification = promiseNotification("sessionstore-state-purge-complete");
+
+    BrowserApp.sanitize(sanitize);
+    yield notification;
+
+    // Only the current session history entry should remain
+    data = tabTest.browser.__SS_data;
+    is(data.entries.length, 1, "the session store has cleared all previous entries");
+    is(data.index, 1, "history index is correct");
+    is(data.entries[0].url, url2, "URL of first history entry is correct after data clearing");
+
+    cleanupTabs();
+  });
+
+  add_task(function* test_sessionStoreClearZombieTabHistory() {
+    // Add a new tab with some content
+    tabTest = BrowserApp.addTab(url1 , { selected: true, parentId: BrowserApp.selectedTab.id });
+    yield promiseBrowserEvent(tabTest.browser, "DOMTitleChanged");
+
+    // Navigate to create some history
+    tabTest.browser.loadURI(url2);
+    yield promiseBrowserEvent(tabTest.browser, "DOMTitleChanged");
+    tabTest.browser.loadURI(url3);
+    yield promiseBrowserEvent(tabTest.browser, "DOMTitleChanged");
+    is(tabTest.browser.canGoBack, true, "can go back");
+    tabTest.browser.goBack();
+    yield promiseBrowserEvent(tabTest.browser, "DOMTitleChanged");
+
+    // Check that the session store has recorded this history
+    let data = tabTest.browser.__SS_data;
+    is(data.entries.length, 3, "the session store has captured 3 history entries");
+    is(data.index, 2, "history index is correct");
+    is(data.entries[0].url, url1, "URL of first history entry is correct");
+
+    // Open a new tab and zombify the original one
+    tabBlank = BrowserApp.addTab("about:blank", { selected: true, parentId: BrowserApp.selectedTab.id });
+    yield promiseTabEvent(BrowserApp.deck, "TabSelect");
+    is(BrowserApp.selectedTab, tabBlank, "Test tab is in background.");
+
+    // Zombify the backgrounded test tab
+    tabTest.zombify();
+
+    // Check that the test tab is actually zombified
+    ok(tabTest.browser.__SS_restore, "Test tab is set for delay loading.");
+    is(tabTest.browser.currentURI.spec, "about:blank", "Test tab is zombified.");
+
+    // Clear browsing history
+    let sanitize = { history:true };
+    let notification = promiseNotification("sessionstore-state-purge-complete");
+
+    BrowserApp.sanitize(sanitize);
+    yield notification;
+
+    // Only the current session history entry should remain
+    data = tabTest.browser.__SS_data;
+    is(data.entries.length, 1, "the session store has cleared all previous entries");
+    is(data.index, 1, "history index is correct");
+    is(data.entries[0].url, url2, "URL of first history entry is correct after data clearing");
+
+    cleanupTabs();
+  });
+
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1343603">Mozilla Bug 1343603</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>