browser/base/content/test/general/browser_visibleLabel.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 /* Tests:
michael@0 5 * verify that the visibleLabel attribute works
michael@0 6 * verify the TabLabelModified event works for both existing and new tabs
michael@0 7 */
michael@0 8
michael@0 9 function test() {
michael@0 10 waitForExplicitFinish();
michael@0 11 registerCleanupFunction(function() {
michael@0 12 gBrowser.removeCurrentTab({animate: false});
michael@0 13 });
michael@0 14 let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank",
michael@0 15 {skipAnimation: true});
michael@0 16 tab.linkedBrowser.addEventListener("load", function onLoad(event) {
michael@0 17 event.currentTarget.removeEventListener("load", onLoad, true);
michael@0 18 executeSoon(afterLoad);
michael@0 19 }, true);
michael@0 20 }
michael@0 21
michael@0 22 function afterLoad() {
michael@0 23 let tab = gBrowser.selectedTab;
michael@0 24 let xulLabel = document.getAnonymousElementByAttribute(tab, "anonid",
michael@0 25 "tab-label");
michael@0 26 // Verify we're starting out on the right foot
michael@0 27 is(tab.label, "New Tab", "Initial tab label is default");
michael@0 28 is(xulLabel.value, "New Tab", "Label element is default");
michael@0 29 is(tab.visibleLabel, "New Tab", "visibleLabel is default");
michael@0 30
michael@0 31 // Check that a normal label setting works correctly
michael@0 32 tab.label = "Hello, world!";
michael@0 33 is(tab.label, "Hello, world!", "tab label attribute set via tab.label");
michael@0 34 is(xulLabel.value, "Hello, world!", "xul:label set via tab.label");
michael@0 35 is(tab.visibleLabel, "Hello, world!", "visibleLabel set via tab.label");
michael@0 36
michael@0 37 // Check that setting visibleLabel only affects the label element
michael@0 38 tab.visibleLabel = "Goodnight, Irene";
michael@0 39 is(tab.label, "Hello, world!", "Tab.label unaffected by visibleLabel setter");
michael@0 40 is(xulLabel.value, "Goodnight, Irene",
michael@0 41 "xul:label set by visibleLabel setter");
michael@0 42 is(tab.visibleLabel, "Goodnight, Irene",
michael@0 43 "visibleLabel attribute set by visibleLabel setter");
michael@0 44
michael@0 45 // Check that setting the label property hits everything
michael@0 46 tab.label = "One more label";
michael@0 47 is(tab.label, "One more label",
michael@0 48 "Tab label set via label property after diverging from visibleLabel");
michael@0 49 is(xulLabel.value, "One more label",
michael@0 50 "xul:label set via label property after diverging from visibleLabel");
michael@0 51 is(tab.visibleLabel, "One more label",
michael@0 52 "visibleLabel set from label property after diverging from visibleLabel");
michael@0 53
michael@0 54 tab.addEventListener("TabLabelModified", overrideTabLabel, true);
michael@0 55 tab.label = "This won't be the visibleLabel";
michael@0 56 }
michael@0 57
michael@0 58 function overrideTabLabel(aEvent) {
michael@0 59 aEvent.target.removeEventListener("TabLabelModified", overrideTabLabel, true);
michael@0 60 aEvent.preventDefault();
michael@0 61 aEvent.stopPropagation();
michael@0 62 aEvent.target.visibleLabel = "Handler set this as the visible label";
michael@0 63 executeSoon(checkTabLabelModified);
michael@0 64 }
michael@0 65
michael@0 66 function checkTabLabelModified() {
michael@0 67 let tab = gBrowser.selectedTab;
michael@0 68 let xulLabel = document.getAnonymousElementByAttribute(tab, "anonid",
michael@0 69 "tab-label");
michael@0 70
michael@0 71 is(tab.label, "This won't be the visibleLabel",
michael@0 72 "Tab label set via label property that triggered event");
michael@0 73 is(xulLabel.value, "Handler set this as the visible label",
michael@0 74 "xul:label set by TabLabelModified handler");
michael@0 75 is(tab.visibleLabel, "Handler set this as the visible label",
michael@0 76 "visibleLabel set by TabLabelModified handler");
michael@0 77
michael@0 78 gBrowser.removeCurrentTab({animate: false});
michael@0 79 executeSoon(checkTabLabelModifiedOnNewTab);
michael@0 80 }
michael@0 81
michael@0 82 function checkTabLabelModifiedOnNewTab() {
michael@0 83 gBrowser.tabContainer.addEventListener("TabLabelModified",
michael@0 84 handleTabLabelModifiedOnNewTab, true);
michael@0 85 let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank",
michael@0 86 {skipAnimation: true});
michael@0 87 }
michael@0 88
michael@0 89 function handleTabLabelModifiedOnNewTab(aEvent) {
michael@0 90 gBrowser.tabContainer.removeEventListener("TabLabelModified",
michael@0 91 handleTabLabelModifiedOnNewTab, true);
michael@0 92 ok(true, "Event received from new tab default being set");
michael@0 93 executeSoon(finish);
michael@0 94 }

mercurial