Bug 1307736 - Ensure tests performing a history load pass valid triggeringPrincipal. r=bz,mdeboer
☠☠ backed out by 28ace1abfb5c ☠ ☠
authorChristoph Kerschbaumer <ckerschb@christophkerschbaumer.com>
Mon, 16 Jan 2017 18:30:32 +0100
changeset 374608 338dd2c343f839e153cacb1510cbc6d31f71d6fc
parent 374607 1a71a0d9aa90635e6a4ef7e0df5272c52fd0ae54
child 374609 5ad4916d7734f98ddaf2051df694e1b2b11b6cf5
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, mdeboer
bugs1307736
milestone53.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 1307736 - Ensure tests performing a history load pass valid triggeringPrincipal. r=bz,mdeboer
browser/components/preferences/in-content/tests/browser_bug1184989_prevent_scrolling_when_preferences_flipped.js
browser/components/sessionstore/test/browser_393716.js
browser/components/sessionstore/test/browser_394759_purge.js
browser/components/sessionstore/test/browser_447951.js
browser/components/sessionstore/test/browser_463205.js
browser/components/sessionstore/test/browser_467409-backslashplosion.js
browser/components/sessionstore/test/head.js
browser/modules/test/browser_UsageTelemetry_private_and_restore.js
--- a/browser/components/preferences/in-content/tests/browser_bug1184989_prevent_scrolling_when_preferences_flipped.js
+++ b/browser/components/preferences/in-content/tests/browser_bug1184989_prevent_scrolling_when_preferences_flipped.js
@@ -1,10 +1,14 @@
 const ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
 
+const {Utils} = Cu.import("resource://gre/modules/sessionstore/Utils.jsm", {});
+const SYSTEMPRINCIPAL = Services.scriptSecurityManager.getSystemPrincipal();
+const triggeringPrincipal = Utils.serializePrincipal(SYSTEMPRINCIPAL);
+
 add_task(function* () {
   waitForExplicitFinish();
 
   const tabURL = getRootDirectory(gTestPath) + "browser_bug1184989_prevent_scrolling_when_preferences_flipped.xul";
 
   yield BrowserTestUtils.withNewTab({ gBrowser, url: tabURL }, function* (browser) {
     let doc = browser.contentDocument;
     let container = doc.getElementById("container");
@@ -54,17 +58,17 @@ add_task(function* () {
   const CRASH_URL = "about:mozilla";
   const CRASH_FAVICON = "chrome://branding/content/icon32.png";
   const CRASH_SHENTRY = {url: CRASH_URL};
   const CRASH_TAB = {entries: [CRASH_SHENTRY], image: CRASH_FAVICON};
   const CRASH_STATE = {windows: [{tabs: [CRASH_TAB]}]};
 
   const TAB_URL = "about:sessionrestore";
   const TAB_FORMDATA = {url: TAB_URL, id: {sessionData: CRASH_STATE}};
-  const TAB_SHENTRY = {url: TAB_URL};
+  const TAB_SHENTRY = {url: TAB_URL, triggeringPrincipal_base64: triggeringPrincipal};
   const TAB_STATE = {entries: [TAB_SHENTRY], formdata: TAB_FORMDATA};
 
   let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank");
 
   // Fake a post-crash tab
   ss.setTabState(tab, JSON.stringify(TAB_STATE));
 
   yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
--- a/browser/components/sessionstore/test/browser_393716.js
+++ b/browser/components/sessionstore/test/browser_393716.js
@@ -34,17 +34,20 @@ add_task(function test_set_tabstate() {
   // clean up
   gBrowser.removeTab(tab);
 });
 
 add_task(function test_set_tabstate_and_duplicate() {
   let key2 = "key2";
   let value2 = "Value " + Math.random();
   let value3 = "Another value: " + Date.now();
-  let state = { entries: [{ url: URL }], extData: { key2: value2 } };
+  let state = {
+    entries: [{ url: URL, triggeringPrincipal_base64: triggeringPrincipal}],
+    extData: { key2: value2 }
+  };
 
   // create a new tab
   let tab = gBrowser.addTab();
   // set the tab's state
   ss.setTabState(tab, JSON.stringify(state));
   yield promiseBrowserLoaded(tab.linkedBrowser);
 
   // verify the correctness of the restored tab
--- a/browser/components/sessionstore/test/browser_394759_purge.js
+++ b/browser/components/sessionstore/test/browser_394759_purge.js
@@ -29,61 +29,61 @@ function test() {
   let oldState = ss.getBrowserState();
   let oldState_wins = JSON.parse(oldState).windows.length;
   if (oldState_wins != 1)
     ok(false, "oldState in test_purge has " + oldState_wins + " windows instead of 1");
 
   // create a new state for testing
   const REMEMBER = Date.now(), FORGET = Math.random();
   let testState = {
-    windows: [ { tabs: [{ entries: [{ url: "http://example.com/" }] }], selected: 1 } ],
+    windows: [ { tabs: [{ entries: [{ url: "http://example.com/", triggeringPrincipal_base64: triggeringPrincipal }] }], selected: 1 } ],
     _closedWindows : [
       // _closedWindows[0]
       {
         tabs: [
-          { entries: [{ url: "http://example.com/", title: REMEMBER }] },
-          { entries: [{ url: "http://mozilla.org/", title: FORGET }] }
+          { entries: [{ url: "http://example.com/", triggeringPrincipal_base64: triggeringPrincipal, title: REMEMBER }] },
+          { entries: [{ url: "http://mozilla.org/", triggeringPrincipal_base64: triggeringPrincipal, title: FORGET }] }
         ],
         selected: 2,
         title: "mozilla.org",
         _closedTabs: []
       },
       // _closedWindows[1]
       {
         tabs: [
-         { entries: [{ url: "http://mozilla.org/", title: FORGET }] },
-         { entries: [{ url: "http://example.com/", title: REMEMBER }] },
-         { entries: [{ url: "http://example.com/", title: REMEMBER }] },
-         { entries: [{ url: "http://mozilla.org/", title: FORGET }] },
-         { entries: [{ url: "http://example.com/", title: REMEMBER }] }
+         { entries: [{ url: "http://mozilla.org/", triggeringPrincipal_base64: triggeringPrincipal, title: FORGET }] },
+         { entries: [{ url: "http://example.com/", triggeringPrincipal_base64: triggeringPrincipal, title: REMEMBER }] },
+         { entries: [{ url: "http://example.com/", triggeringPrincipal_base64: triggeringPrincipal, title: REMEMBER }] },
+         { entries: [{ url: "http://mozilla.org/", triggeringPrincipal_base64: triggeringPrincipal, title: FORGET }] },
+         { entries: [{ url: "http://example.com/", triggeringPrincipal_base64: triggeringPrincipal, title: REMEMBER }] }
         ],
         selected: 5,
         _closedTabs: []
       },
       // _closedWindows[2]
       {
         tabs: [
-          { entries: [{ url: "http://example.com/", title: REMEMBER }] }
+          { entries: [{ url: "http://example.com/", triggeringPrincipal_base64: triggeringPrincipal, title: REMEMBER }] }
         ],
         selected: 1,
         _closedTabs: [
           {
             state: {
               entries: [
-                { url: "http://mozilla.org/", title: FORGET },
-                { url: "http://mozilla.org/again", title: "doesn't matter" }
+                { url: "http://mozilla.org/", triggeringPrincipal_base64: triggeringPrincipal, title: FORGET },
+                { url: "http://mozilla.org/again", triggeringPrincipal_base64: triggeringPrincipal, title: "doesn't matter" }
               ]
             },
             pos: 1,
             title: FORGET
           },
           {
             state: {
               entries: [
-                { url: "http://example.com", title: REMEMBER }
+                { url: "http://example.com", triggeringPrincipal_base64: triggeringPrincipal, title: REMEMBER }
               ]
             },
             title: REMEMBER
           }
         ]
       }
     ]
   };
--- a/browser/components/sessionstore/test/browser_447951.js
+++ b/browser/components/sessionstore/test/browser_447951.js
@@ -17,17 +17,17 @@ function test() {
     gPrefService.clearUserPref("browser.sessionstore.max_serialize_forward");
   });
 
   let tab = gBrowser.addTab();
   promiseBrowserLoaded(tab.linkedBrowser).then(() => {
     let tabState = { entries: [] };
     let max_entries = gPrefService.getIntPref("browser.sessionhistory.max_entries");
     for (let i = 0; i < max_entries; i++)
-      tabState.entries.push({ url: baseURL + i });
+      tabState.entries.push({ url: baseURL + i, triggeringPrincipal_base64: triggeringPrincipal});
 
     promiseTabState(tab, tabState).then(() => {
       return TabStateFlusher.flush(tab.linkedBrowser);
     }).then(() => {
       tabState = JSON.parse(ss.getTabState(tab));
       is(tabState.entries.length, max_entries, "session history filled to the limit");
       is(tabState.entries[0].url, baseURL + 0, "... but not more");
 
--- a/browser/components/sessionstore/test/browser_463205.js
+++ b/browser/components/sessionstore/test/browser_463205.js
@@ -29,12 +29,12 @@ add_task(function test_check_urls_before
   is(value, "", "value was not restored");
 
   // Cleanup.
   gBrowser.removeTab(tab);
 });
 
 function getState(url) {
   return JSON.stringify({
-    entries: [{url: URL}],
+    entries: [{url: URL, triggeringPrincipal_base64: triggeringPrincipal}],
     formdata: {url: url, id: {text: "foobar"}}
   });
 }
--- a/browser/components/sessionstore/test/browser_467409-backslashplosion.js
+++ b/browser/components/sessionstore/test/browser_467409-backslashplosion.js
@@ -13,24 +13,25 @@
 // 2a. Check that there are no backslashes in the formdata
 // 2b. Check that formdata doesn't require JSON.parse
 //
 // 3.  [backwards compat] Use a stringified state as formdata when opening about:sessionrestore
 // 3a. Make sure there are nodes in the tree on about:sessionrestore (skipped, checking formdata is sufficient)
 // 3b. Check that there are no backslashes in the formdata
 // 3c. Check that formdata doesn't require JSON.parse
 
-const CRASH_STATE = {windows: [{tabs: [{entries: [{url: "about:mozilla" }]}]}]};
+const CRASH_STATE = {windows: [{tabs: [{entries: [{url: "about:mozilla",
+                                                   triggeringPrincipal_base64: triggeringPrincipal }]}]}]};
 const STATE = createEntries(CRASH_STATE);
 const STATE2 = createEntries({windows: [{tabs: [STATE]}]});
 const STATE3 = createEntries(JSON.stringify(CRASH_STATE));
 
 function createEntries(sessionData) {
   return {
-    entries: [{url: "about:sessionrestore"}],
+    entries: [{url: "about:sessionrestore", triggeringPrincipal_base64: triggeringPrincipal}],
     formdata: {id: {sessionData: sessionData}, url: "about:sessionrestore"}
   };
 }
 
 add_task(function test_nested_about_sessionrestore() {
   // Prepare a blank tab.
   let tab = gBrowser.addTab("about:blank");
   let browser = tab.linkedBrowser;
--- a/browser/components/sessionstore/test/head.js
+++ b/browser/components/sessionstore/test/head.js
@@ -1,12 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+const {Utils} = Cu.import("resource://gre/modules/sessionstore/Utils.jsm", {});
+const SYSTEMPRINCIPAL = Services.scriptSecurityManager.getSystemPrincipal();
+const triggeringPrincipal = Utils.serializePrincipal(SYSTEMPRINCIPAL);
+
 const TAB_STATE_NEEDS_RESTORE = 1;
 const TAB_STATE_RESTORING = 2;
 
 const ROOT = getRootDirectory(gTestPath);
 const HTTPROOT = ROOT.replace("chrome://mochitests/content/", "http://example.com/");
 const FRAME_SCRIPTS = [
   ROOT + "content.js",
   ROOT + "content-forms.js"
--- a/browser/modules/test/browser_UsageTelemetry_private_and_restore.js
+++ b/browser/modules/test/browser_UsageTelemetry_private_and_restore.js
@@ -1,10 +1,14 @@
 "use strict";
 
+const {Utils} = Cu.import("resource://gre/modules/sessionstore/Utils.jsm", {});
+const SYSTEMPRINCIPAL = Services.scriptSecurityManager.getSystemPrincipal();
+const triggeringPrincipal = Utils.serializePrincipal(SYSTEMPRINCIPAL);
+
 const MAX_CONCURRENT_TABS = "browser.engagement.max_concurrent_tab_count";
 const TAB_EVENT_COUNT = "browser.engagement.tab_open_event_count";
 const MAX_CONCURRENT_WINDOWS = "browser.engagement.max_concurrent_window_count";
 const WINDOW_OPEN_COUNT = "browser.engagement.window_open_event_count";
 const TOTAL_URI_COUNT = "browser.engagement.total_uri_count";
 const UNFILTERED_URI_COUNT = "browser.engagement.unfiltered_uri_count";
 const UNIQUE_DOMAINS_COUNT = "browser.engagement.unique_domains_count";
 
@@ -52,17 +56,18 @@ add_task(function* test_sessionRestore()
   Services.telemetry.clearScalars();
 
   // The first window will be put into the already open window and the second
   // window will be opened with _openWindowWithState, which is the source of the problem.
   const state = {
     windows: [
       {
         tabs: [
-          { entries: [{ url: "http://example.org" }], extData: { "uniq": 3785 } }
+          { entries: [{ url: "http://example.org", triggeringPrincipal_base64: triggeringPrincipal}],
+            extData: { "uniq": 3785 } }
         ],
         selected: 1
       }
     ]
   };
 
   // Save the current session.
   let SessionStore =