gecko/browser/components/sessionstore/test/browser_label_and_icon.js
Tim Taubert c328b3d5fc Bug 961016 - Fix icon and label for pending tabs with async restore r=billm,dao
From 6028548aa44e6d289c0fb5e756a4004451ea882b Mon Sep 17 00:00:00 2001
2014-01-17 17:17:14 +01:00

56 lines
1.5 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* 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(function test_label_and_icon() {
// Create a new tab.
let tab = gBrowser.addTab("about:robots");
let browser = tab.linkedBrowser;
yield promiseBrowserLoaded(browser);
// Retrieve the tab state.
SyncHandlers.get(browser).flush();
let state = ss.getTabState(tab);
gBrowser.removeTab(tab);
browser = null;
// Open a new tab to restore into.
let 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");
// Cleanup.
gBrowser.removeTab(tab);
});
function promiseTabRestoring(tab) {
let deferred = Promise.defer();
tab.addEventListener("SSTabRestoring", function onRestoring() {
tab.removeEventListener("SSTabRestoring", onRestoring);
deferred.resolve();
});
return deferred.promise;
}