browser/components/sessionstore/test/browser_attributes.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/ */
     4 function test() {
     5   TestRunner.run();
     6 }
     8 /**
     9  * This test makes sure that we correctly preserve tab attributes when storing
    10  * and restoring tabs. It also ensures that we skip special attributes like
    11  * 'image' and 'pending' that need to be handled differently or internally.
    12  */
    14 const PREF = "browser.sessionstore.restore_on_demand";
    16 function runTests() {
    17   Services.prefs.setBoolPref(PREF, true)
    18   registerCleanupFunction(() => Services.prefs.clearUserPref(PREF));
    20   // Add a new tab with a nice icon.
    21   let tab = gBrowser.addTab("about:robots");
    22   yield whenBrowserLoaded(tab.linkedBrowser);
    24   // Check that the tab has an 'image' attribute.
    25   ok(tab.hasAttribute("image"), "tab.image exists");
    27   // Make sure we do not persist 'image' attributes.
    28   ss.persistTabAttribute("image");
    29   let {attributes} = JSON.parse(ss.getTabState(tab));
    30   ok(!("image" in attributes), "'image' attribute not saved");
    31   ok(!("custom" in attributes), "'custom' attribute not saved");
    33   // Test persisting a custom attribute.
    34   tab.setAttribute("custom", "foobar");
    35   ss.persistTabAttribute("custom");
    37   let {attributes} = JSON.parse(ss.getTabState(tab));
    38   is(attributes.custom, "foobar", "'custom' attribute is correct");
    40   // Make sure we're backwards compatible and restore old 'image' attributes.
    41   let state = {
    42     entries: [{url: "about:mozilla"}],
    43     attributes: {custom: "foobaz", image: gBrowser.getIcon(tab)}
    44   };
    46   // Prepare a pending tab waiting to be restored.
    47   whenTabRestoring(tab);
    48   yield ss.setTabState(tab, JSON.stringify(state));
    50   ok(tab.hasAttribute("pending"), "tab is pending");
    51   is(gBrowser.getIcon(tab), state.attributes.image, "tab has correct icon");
    53   // Let the pending tab load.
    54   gBrowser.selectedTab = tab;
    55   yield whenTabRestored(tab);
    57   // Ensure no 'image' or 'pending' attributes are stored.
    58   let {attributes} = JSON.parse(ss.getTabState(tab));
    59   ok(!("image" in attributes), "'image' attribute not saved");
    60   ok(!("pending" in attributes), "'pending' attribute not saved");
    61   is(attributes.custom, "foobaz", "'custom' attribute is correct");
    63   // Clean up.
    64   gBrowser.removeTab(tab);
    65 }
    67 function whenTabRestoring(tab) {
    68   tab.addEventListener("SSTabRestoring", function onRestoring() {
    69     tab.removeEventListener("SSTabRestoring", onRestoring);
    70     executeSoon(next);
    71   });
    72 }

mercurial