Bug 1294866 - Part 3: Tests to verify contentPrincipal persists during session restore. r=mikedeboer
authorSteven Englehardt <senglehardt@mozilla.com>
Tue, 13 Sep 2016 21:18:38 +0800
changeset 313762 8639daa019b6c8efbcd773bd56bc7dd302984138
parent 313761 dafa284120321bef77f46a0a61c1619b72b3de7d
child 313763 24a5b1c8243ef6d36ef0196ee10eae78f26856b4
push id30697
push usercbook@mozilla.com
push dateWed, 14 Sep 2016 10:04:12 +0000
treeherdermozilla-central@de96dcebba86 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1294866
milestone51.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 1294866 - Part 3: Tests to verify contentPrincipal persists during session restore. r=mikedeboer
browser/components/sessionstore/test/browser_attributes.js
browser/components/sessionstore/test/browser_label_and_icon.js
--- a/browser/components/sessionstore/test/browser_attributes.js
+++ b/browser/components/sessionstore/test/browser_attributes.js
@@ -12,28 +12,31 @@ const PREF = "browser.sessionstore.resto
 add_task(function* test() {
   Services.prefs.setBoolPref(PREF, true)
   registerCleanupFunction(() => Services.prefs.clearUserPref(PREF));
 
   // Add a new tab with a nice icon.
   let tab = gBrowser.addTab("about:robots");
   yield promiseBrowserLoaded(tab.linkedBrowser);
 
-  // Check that the tab has an 'image' attribute.
+  // Check that the tab has 'image' and 'iconLoadingPrincipal' attributes.
   ok(tab.hasAttribute("image"), "tab.image exists");
+  ok(tab.hasAttribute("iconLoadingPrincipal"), "tab.iconLoadingPrincipal exists");
 
   tab.toggleMuteAudio();
   // Check that the tab has a 'muted' attribute.
   ok(tab.hasAttribute("muted"), "tab.muted exists");
 
   // Make sure we do not persist 'image' or 'muted' attributes.
   ss.persistTabAttribute("image");
   ss.persistTabAttribute("muted");
+  ss.persistTabAttribute("iconLoadingPrincipal");
   let {attributes} = JSON.parse(ss.getTabState(tab));
   ok(!("image" in attributes), "'image' attribute not saved");
+  ok(!("iconLoadingPrincipal" in attributes), "'iconLoadingPrincipal' attribute not saved");
   ok(!("muted" in attributes), "'muted' attribute not saved");
   ok(!("custom" in attributes), "'custom' attribute not saved");
 
   // Test persisting a custom attribute.
   tab.setAttribute("custom", "foobar");
   ss.persistTabAttribute("custom");
 
   ({attributes} = JSON.parse(ss.getTabState(tab)));
--- a/browser/components/sessionstore/test/browser_label_and_icon.js
+++ b/browser/components/sessionstore/test/browser_label_and_icon.js
@@ -1,13 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
+const {classes: Cc, interfaces: Ci} = Components;
+
 /**
  * Make sure that tabs are restored on demand as otherwise the tab will start
  * loading immediately and we can't check its icon and label.
  */
 add_task(function setup() {
   Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
 
   registerCleanupFunction(() => {
@@ -34,11 +36,18 @@ add_task(function test_label_and_icon() 
   tab = gBrowser.addTab("about:blank");
   ss.setTabState(tab, state);
   yield promiseTabRestoring(tab);
 
   // Check that label and icon are set for the restoring tab.
   ok(gBrowser.getIcon(tab).startsWith("data:image/png;"), "icon is set");
   is(tab.label, "Gort! Klaatu barada nikto!", "label is set");
 
+  let serhelper = Cc["@mozilla.org/network/serialization-helper;1"]
+                    .getService(Ci.nsISerializationHelper);
+  let serializedPrincipal = tab.getAttribute("iconLoadingPrincipal");
+  let iconLoadingPrincipal = serhelper.deserializeObject(serializedPrincipal)
+                                      .QueryInterface(Ci.nsIPrincipal);
+  is(iconLoadingPrincipal.origin, "about:robots", "correct loadingPrincipal used");
+
   // Cleanup.
   yield promiseRemoveTab(tab);
 });