Bug 1347823 - Part 3: Add a test case. r?smaug draft
authorSamael Wang <freesamael@gmail.com>
Fri, 28 Apr 2017 17:01:48 +0800
changeset 571857 16995c3acd02f796932ea6cf510d1aea53562269
parent 571856 56a5e0d1dd0075a5d95431611f2f7601a462704d
child 626888 427a432b8fa5cae1f449c7bf7ca66bfa3140eeec
push id56927
push userbmo:sawang@mozilla.com
push dateWed, 03 May 2017 10:23:52 +0000
reviewerssmaug
bugs1347823
milestone55.0a1
Bug 1347823 - Part 3: Add a test case. r?smaug MozReview-Commit-ID: 9zwD0m1tknN
docshell/test/browser/browser.ini
docshell/test/browser/browser_bug1347823.js
--- a/docshell/test/browser/browser.ini
+++ b/docshell/test/browser/browser.ini
@@ -44,16 +44,17 @@ support-files =
   browser_timelineMarkers-frame-03.js
   browser_timelineMarkers-frame-04.js
   browser_timelineMarkers-frame-05.js
   head.js
   frame-head.js
 
 [browser_bug1206879.js]
 [browser_bug1309900_crossProcessHistoryNavigation.js]
+[browser_bug1347823.js]
 [browser_bug134911.js]
 [browser_bug234628-1.js]
 [browser_bug234628-10.js]
 [browser_bug234628-11.js]
 [browser_bug234628-2.js]
 [browser_bug234628-3.js]
 [browser_bug234628-4.js]
 [browser_bug234628-5.js]
new file mode 100644
--- /dev/null
+++ b/docshell/test/browser/browser_bug1347823.js
@@ -0,0 +1,67 @@
+/**
+ * Test that session history's expiration tracker would remove bfcache on
+ * expiration.
+ */
+
+// With bfcache not expired.
+add_task(async function testValidCache() {
+  // Make an unrealistic large timeout.
+  await SpecialPowers.pushPrefEnv({
+    set: [["browser.sessionhistory.contentViewerTimeout", 86400]]
+  });
+
+  await BrowserTestUtils.withNewTab(
+    {gBrowser, url: "data:text/html;charset=utf-8,page1"},
+    async function(browser) {
+      // Make a simple modification for bfcache testing.
+      await ContentTask.spawn(browser, null, () => {
+        content.document.body.textContent = "modified";
+      });
+
+      // Load a random page.
+      BrowserTestUtils.loadURI(browser, "data:text/html;charset=utf-8,page2");
+      await BrowserTestUtils.browserLoaded(browser);
+
+      // Go back and verify text content.
+      let awaitPageShow = BrowserTestUtils.waitForContentEvent(browser, "pageshow");
+      browser.goBack();
+      await awaitPageShow;
+      await ContentTask.spawn(browser, null, () => {
+        is(content.document.body.textContent, "modified");
+      });
+    });
+});
+
+// With bfcache expired.
+add_task(async function testExpiredCache() {
+  // Make bfcache timeout in 1 sec.
+  await SpecialPowers.pushPrefEnv({
+    set: [["browser.sessionhistory.contentViewerTimeout", 1]]
+  });
+
+  await BrowserTestUtils.withNewTab(
+    {gBrowser, url: "data:text/html;charset=utf-8,page1"},
+    async function(browser) {
+      // Make a simple modification for bfcache testing.
+      await ContentTask.spawn(browser, null, () => {
+        content.document.body.textContent = "modified";
+      });
+
+      // Load a random page.
+      BrowserTestUtils.loadURI(browser, "data:text/html;charset=utf-8,page2");
+      await BrowserTestUtils.browserLoaded(browser);
+
+      // Wait for 3 times of expiration timeout, hopefully it's evicted...
+      await new Promise(resolve => {
+        setTimeout(resolve, 3000);
+      });
+
+      // Go back and verify text content.
+      let awaitPageShow = BrowserTestUtils.waitForContentEvent(browser, "pageshow");
+      browser.goBack();
+      await awaitPageShow;
+      await ContentTask.spawn(browser, null, () => {
+        is(content.document.body.textContent, "page1");
+      });
+    });
+});