browser/components/sessionstore/test/browser_label_and_icon.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.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 "use strict";
michael@0 5
michael@0 6 /**
michael@0 7 * Make sure that tabs are restored on demand as otherwise the tab will start
michael@0 8 * loading immediately and we can't check its icon and label.
michael@0 9 */
michael@0 10 add_task(function setup() {
michael@0 11 Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
michael@0 12
michael@0 13 registerCleanupFunction(() => {
michael@0 14 Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
michael@0 15 });
michael@0 16 });
michael@0 17
michael@0 18 /**
michael@0 19 * Ensure that a pending tab has label and icon correctly set.
michael@0 20 */
michael@0 21 add_task(function test_label_and_icon() {
michael@0 22 // Create a new tab.
michael@0 23 let tab = gBrowser.addTab("about:robots");
michael@0 24 let browser = tab.linkedBrowser;
michael@0 25 yield promiseBrowserLoaded(browser);
michael@0 26
michael@0 27 // Retrieve the tab state.
michael@0 28 SyncHandlers.get(browser).flush();
michael@0 29 let state = ss.getTabState(tab);
michael@0 30 gBrowser.removeTab(tab);
michael@0 31 browser = null;
michael@0 32
michael@0 33 // Open a new tab to restore into.
michael@0 34 let tab = gBrowser.addTab("about:blank");
michael@0 35 ss.setTabState(tab, state);
michael@0 36 yield promiseTabRestoring(tab);
michael@0 37
michael@0 38 // Check that label and icon are set for the restoring tab.
michael@0 39 ok(gBrowser.getIcon(tab).startsWith("data:image/png;"), "icon is set");
michael@0 40 is(tab.label, "Gort! Klaatu barada nikto!", "label is set");
michael@0 41
michael@0 42 // Cleanup.
michael@0 43 gBrowser.removeTab(tab);
michael@0 44 });
michael@0 45
michael@0 46 function promiseTabRestoring(tab) {
michael@0 47 let deferred = Promise.defer();
michael@0 48
michael@0 49 tab.addEventListener("SSTabRestoring", function onRestoring() {
michael@0 50 tab.removeEventListener("SSTabRestoring", onRestoring);
michael@0 51 deferred.resolve();
michael@0 52 });
michael@0 53
michael@0 54 return deferred.promise;
michael@0 55 }

mercurial