Bug 1335272 - add barebones functional test for about:cache, r=ckerschb
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 02 Feb 2017 15:40:03 +0000
changeset 341291 54f31b2c699eb3e83ca6a8896727b078543548b2
parent 341290 494c40293b333e818e795482aad8a6c713a1cd48
child 341292 de2b0d90e2dafb22885e63e58a498525e340badc
push id86684
push usercbook@mozilla.com
push dateWed, 08 Feb 2017 10:31:03 +0000
treeherdermozilla-inbound@c5b88e4e70f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1335272
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1335272 - add barebones functional test for about:cache, r=ckerschb MozReview-Commit-ID: 5hlxfmYGgDa
netwerk/test/browser/browser.ini
netwerk/test/browser/browser_about_cache.js
--- a/netwerk/test/browser/browser.ini
+++ b/netwerk/test/browser/browser.ini
@@ -1,10 +1,11 @@
 [DEFAULT]
 support-files =
   dummy.html
 
+[browser_about_cache.js]
 [browser_NetUtil.js]
 [browser_child_resource.js]
 skip-if = e10s && debug && os == "linux" && bits == 64
 [browser_post_file.js]
 [browser_nsIFormPOSTActionChannel.js]
 skip-if = e10s # protocol handler and channel does not work in content process
new file mode 100644
--- /dev/null
+++ b/netwerk/test/browser/browser_about_cache.js
@@ -0,0 +1,71 @@
+"use strict";
+
+/**
+ * Open a dummy page, then open about:cache and verify the opened page shows up in the cache.
+ */
+add_task(function*() {
+  const kRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/",
+                                                    "https://example.com/");
+  const kTestPage = kRoot + "dummy.html";
+  // Open the dummy page to get it cached.
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, kTestPage, true);
+  yield BrowserTestUtils.removeTab(tab);
+
+  tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:cache", true);
+  let expectedPageCheck = function(uri) {
+    info("Saw load for " + uri);
+    // Can't easily use searchParms and new URL() because it's an about: URI...
+    return uri.startsWith("about:cache?") && uri.includes("storage=disk");
+  };
+  let diskPageLoaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, expectedPageCheck);
+  yield ContentTask.spawn(tab.linkedBrowser, null, function() {
+    ok(!content.document.nodePrincipal.isSystemPrincipal,
+       "about:cache should not have system principal");
+    let principalURI = content.document.nodePrincipal.URI;
+    let channel = content.document.docShell.currentDocumentChannel;
+    ok(!channel.loadInfo.loadingPrincipal, "Loading principal should be null.");
+    is(principalURI && principalURI.spec, content.document.location.href, "Principal matches location");
+    let links = [... content.document.querySelectorAll("a[href*=disk]")];
+    is(links.length, 1, "Should have 1 link to the disk entries");
+    links[0].click();
+  });
+  yield diskPageLoaded;
+  info("about:cache disk subpage loaded");
+
+  expectedPageCheck = function(uri) {
+    info("Saw load for " + uri);
+    return uri.startsWith("about:cache-entry") && uri.includes("dummy.html");
+  };
+  let triggeringURISpec = tab.linkedBrowser.currentURI.spec;
+  let entryLoaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, expectedPageCheck);
+  yield ContentTask.spawn(tab.linkedBrowser, kTestPage, function(kTestPage) {
+    ok(!content.document.nodePrincipal.isSystemPrincipal,
+       "about:cache with query params should still not have system principal");
+    let principalURI = content.document.nodePrincipal.URI;
+    is(principalURI && principalURI.spec, content.document.location.href, "Principal matches location");
+    let channel = content.document.docShell.currentDocumentChannel;
+    principalURI = channel.loadInfo.triggeringPrincipal.URI;
+    is(principalURI && principalURI.spec, "about:cache", "Triggering principal matches previous location");
+    ok(!channel.loadInfo.loadingPrincipal, "Loading principal should be null.");
+    let links = [... content.document.querySelectorAll("a[href*='" + kTestPage + "']")];
+    is(links.length, 1, "Should have 1 link to the entry for " + kTestPage);
+    links[0].click();
+  });
+  yield entryLoaded;
+  info("about:cache entry loaded");
+
+
+  yield ContentTask.spawn(tab.linkedBrowser, triggeringURISpec, function(triggeringURISpec) {
+    ok(!content.document.nodePrincipal.isSystemPrincipal,
+       "about:cache-entry should also not have system principal");
+    let principalURI = content.document.nodePrincipal.URI;
+    is(principalURI && principalURI.spec, content.document.location.href, "Principal matches location");
+    let channel = content.document.docShell.currentDocumentChannel;
+    principalURI = channel.loadInfo.triggeringPrincipal.URI;
+    is(principalURI && principalURI.spec, triggeringURISpec, "Triggering principal matches previous location");
+    ok(!channel.loadInfo.loadingPrincipal, "Loading principal should be null.");
+    ok(content.document.querySelectorAll("th").length,
+       "Should have several table headers with data.");
+  });
+  yield BrowserTestUtils.removeTab(tab);
+});