summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_label_and_icon.js
blob: db68eb0429266053c524ef80dc62b4e3411fc7c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* 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(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.
  yield TabStateFlusher.flush(browser);
  let state = ss.getTabState(tab);
  yield promiseRemoveTab(tab);
  browser = null;

  // Open a new tab to restore into.
  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");

  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.
  yield promiseRemoveTab(tab);
});