fune/browser/components/sessionstore/test/browser_label_and_icon.js
Andreas Tolfsen 6935e40966 Bug 1355890 - Move robot favicon to separate file r=Gijs
Robot favicon (image/png) is currently only used in about:robots
(browser/base/content/aboutRobots.xhtml), but we intend to re-use this
resource for indicating that the browser is under remote (robot) control.

MozReview-Commit-ID: 4eTNbAITPQx

--HG--
extra : rebase_source : 765e4e2d7abe95ecc48b6a55582bde73fb689d5e
2017-04-27 22:59:16 +01:00

53 lines
1.8 KiB
JavaScript

/* 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(() => {
Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
});
});
/**
* Ensure that a pending tab has label and icon correctly set.
*/
add_task(async function test_label_and_icon() {
// Create a new tab.
let tab = BrowserTestUtils.addTab(gBrowser, "about:robots");
let browser = tab.linkedBrowser;
await promiseBrowserLoaded(browser);
// Retrieve the tab state.
await TabStateFlusher.flush(browser);
let state = ss.getTabState(tab);
await promiseRemoveTab(tab);
browser = null;
// Open a new tab to restore into.
tab = BrowserTestUtils.addTab(gBrowser, "about:blank");
ss.setTabState(tab, state);
await promiseTabRestoring(tab);
// Check that label and icon are set for the restoring tab.
is(gBrowser.getIcon(tab), "chrome://browser/content/robot.ico", "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.
await promiseRemoveTab(tab);
});