зеркало из https://github.com/mozilla/gecko-dev.git
Bug 943820 - Add visibleLabel attribute/property and tests. r=ttaubert
This commit is contained in:
Родитель
ac44257569
Коммит
a10b49c288
|
@ -1447,11 +1447,6 @@
|
||||||
|
|
||||||
var uriIsAboutBlank = !aURI || aURI == "about:blank";
|
var uriIsAboutBlank = !aURI || aURI == "about:blank";
|
||||||
|
|
||||||
if (!aURI || isBlankPageURL(aURI))
|
|
||||||
t.setAttribute("label", this.mStringBundle.getString("tabs.emptyTabTitle"));
|
|
||||||
else
|
|
||||||
t.setAttribute("label", aURI);
|
|
||||||
|
|
||||||
t.setAttribute("crop", "end");
|
t.setAttribute("crop", "end");
|
||||||
t.setAttribute("onerror", "this.removeAttribute('image');");
|
t.setAttribute("onerror", "this.removeAttribute('image');");
|
||||||
t.className = "tabbrowser-tab";
|
t.className = "tabbrowser-tab";
|
||||||
|
@ -1558,6 +1553,14 @@
|
||||||
// initialized by this point.
|
// initialized by this point.
|
||||||
this.mPanelContainer.appendChild(notificationbox);
|
this.mPanelContainer.appendChild(notificationbox);
|
||||||
|
|
||||||
|
// We've waited until the tab is in the DOM to set the label. This
|
||||||
|
// allows the TabLabelModified event to be properly dispatched.
|
||||||
|
if (!aURI || isBlankPageURL(aURI)) {
|
||||||
|
t.label = this.mStringBundle.getString("tabs.emptyTabTitle");
|
||||||
|
} else {
|
||||||
|
t.label = aURI;
|
||||||
|
}
|
||||||
|
|
||||||
this.tabContainer.updateVisibility();
|
this.tabContainer.updateVisibility();
|
||||||
|
|
||||||
// wire up a progress listener for the new browser object.
|
// wire up a progress listener for the new browser object.
|
||||||
|
@ -3345,8 +3348,7 @@
|
||||||
this._closeWindowWithLastTab = Services.prefs.getBoolPref("browser.tabs.closeWindowWithLastTab");
|
this._closeWindowWithLastTab = Services.prefs.getBoolPref("browser.tabs.closeWindowWithLastTab");
|
||||||
|
|
||||||
var tab = this.firstChild;
|
var tab = this.firstChild;
|
||||||
tab.setAttribute("label",
|
tab.label = this.tabbrowser.mStringBundle.getString("tabs.emptyTabTitle");
|
||||||
this.tabbrowser.mStringBundle.getString("tabs.emptyTabTitle"));
|
|
||||||
tab.setAttribute("crop", "end");
|
tab.setAttribute("crop", "end");
|
||||||
tab.setAttribute("onerror", "this.removeAttribute('image');");
|
tab.setAttribute("onerror", "this.removeAttribute('image');");
|
||||||
this.adjustTabstrip();
|
this.adjustTabstrip();
|
||||||
|
@ -4652,7 +4654,8 @@
|
||||||
validate="never"
|
validate="never"
|
||||||
role="presentation"/>
|
role="presentation"/>
|
||||||
<xul:label flex="1"
|
<xul:label flex="1"
|
||||||
xbl:inherits="value=label,crop,accesskey,fadein,pinned,selected"
|
anonid="tab-label"
|
||||||
|
xbl:inherits="value=visibleLabel,crop,accesskey,fadein,pinned,selected"
|
||||||
class="tab-text tab-label"
|
class="tab-text tab-label"
|
||||||
role="presentation"/>
|
role="presentation"/>
|
||||||
<xul:toolbarbutton anonid="close-button"
|
<xul:toolbarbutton anonid="close-button"
|
||||||
|
@ -4663,6 +4666,32 @@
|
||||||
</content>
|
</content>
|
||||||
|
|
||||||
<implementation>
|
<implementation>
|
||||||
|
<property name="label">
|
||||||
|
<getter>
|
||||||
|
return this.getAttribute("label");
|
||||||
|
</getter>
|
||||||
|
<setter>
|
||||||
|
this.setAttribute("label", val);
|
||||||
|
let event = new CustomEvent("TabLabelModified", {
|
||||||
|
bubbles: true,
|
||||||
|
cancelable: true
|
||||||
|
});
|
||||||
|
this.dispatchEvent(event);
|
||||||
|
|
||||||
|
// Let listeners prevent synchronizing the actual label to the
|
||||||
|
// visible label (allowing them to override the visible label).
|
||||||
|
if (!event.defaultPrevented)
|
||||||
|
this.visibleLabel = val;
|
||||||
|
</setter>
|
||||||
|
</property>
|
||||||
|
<property name="visibleLabel">
|
||||||
|
<getter>
|
||||||
|
return this.getAttribute("visibleLabel");
|
||||||
|
</getter>
|
||||||
|
<setter>
|
||||||
|
this.setAttribute("visibleLabel", val);
|
||||||
|
</setter>
|
||||||
|
</property>
|
||||||
<property name="pinned" readonly="true">
|
<property name="pinned" readonly="true">
|
||||||
<getter>
|
<getter>
|
||||||
return this.getAttribute("pinned") == "true";
|
return this.getAttribute("pinned") == "true";
|
||||||
|
|
|
@ -317,6 +317,7 @@ skip-if = os == "linux" # No tabs in titlebar on linux
|
||||||
[browser_urlbar_search_healthreport.js]
|
[browser_urlbar_search_healthreport.js]
|
||||||
[browser_utilityOverlay.js]
|
[browser_utilityOverlay.js]
|
||||||
[browser_visibleFindSelection.js]
|
[browser_visibleFindSelection.js]
|
||||||
|
[browser_visibleLabel.js]
|
||||||
[browser_visibleTabs.js]
|
[browser_visibleTabs.js]
|
||||||
[browser_visibleTabs_bookmarkAllPages.js]
|
[browser_visibleTabs_bookmarkAllPages.js]
|
||||||
[browser_visibleTabs_bookmarkAllTabs.js]
|
[browser_visibleTabs_bookmarkAllTabs.js]
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
/* Tests:
|
||||||
|
* verify that the visibleLabel attribute works
|
||||||
|
* verify the TabLabelModified event works for both existing and new tabs
|
||||||
|
*/
|
||||||
|
|
||||||
|
function test() {
|
||||||
|
waitForExplicitFinish();
|
||||||
|
registerCleanupFunction(function() {
|
||||||
|
gBrowser.removeCurrentTab({animate: false});
|
||||||
|
});
|
||||||
|
let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank",
|
||||||
|
{skipAnimation: true});
|
||||||
|
tab.linkedBrowser.addEventListener("load", function onLoad(event) {
|
||||||
|
event.currentTarget.removeEventListener("load", onLoad, true);
|
||||||
|
executeSoon(afterLoad);
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function afterLoad() {
|
||||||
|
let tab = gBrowser.selectedTab;
|
||||||
|
let xulLabel = document.getAnonymousElementByAttribute(tab, "anonid",
|
||||||
|
"tab-label");
|
||||||
|
// Verify we're starting out on the right foot
|
||||||
|
is(tab.label, "New Tab", "Initial tab label is default");
|
||||||
|
is(xulLabel.value, "New Tab", "Label element is default");
|
||||||
|
is(tab.visibleLabel, "New Tab", "visibleLabel is default");
|
||||||
|
|
||||||
|
// Check that a normal label setting works correctly
|
||||||
|
tab.label = "Hello, world!";
|
||||||
|
is(tab.label, "Hello, world!", "tab label attribute set via tab.label");
|
||||||
|
is(xulLabel.value, "Hello, world!", "xul:label set via tab.label");
|
||||||
|
is(tab.visibleLabel, "Hello, world!", "visibleLabel set via tab.label");
|
||||||
|
|
||||||
|
// Check that setting visibleLabel only affects the label element
|
||||||
|
tab.visibleLabel = "Goodnight, Irene";
|
||||||
|
is(tab.label, "Hello, world!", "Tab.label unaffected by visibleLabel setter");
|
||||||
|
is(xulLabel.value, "Goodnight, Irene",
|
||||||
|
"xul:label set by visibleLabel setter");
|
||||||
|
is(tab.visibleLabel, "Goodnight, Irene",
|
||||||
|
"visibleLabel attribute set by visibleLabel setter");
|
||||||
|
|
||||||
|
// Check that setting the label property hits everything
|
||||||
|
tab.label = "One more label";
|
||||||
|
is(tab.label, "One more label",
|
||||||
|
"Tab label set via label property after diverging from visibleLabel");
|
||||||
|
is(xulLabel.value, "One more label",
|
||||||
|
"xul:label set via label property after diverging from visibleLabel");
|
||||||
|
is(tab.visibleLabel, "One more label",
|
||||||
|
"visibleLabel set from label property after diverging from visibleLabel");
|
||||||
|
|
||||||
|
tab.addEventListener("TabLabelModified", overrideTabLabel, true);
|
||||||
|
tab.label = "This won't be the visibleLabel";
|
||||||
|
}
|
||||||
|
|
||||||
|
function overrideTabLabel(aEvent) {
|
||||||
|
aEvent.target.removeEventListener("TabLabelModified", overrideTabLabel, true);
|
||||||
|
aEvent.preventDefault();
|
||||||
|
aEvent.stopPropagation();
|
||||||
|
aEvent.target.visibleLabel = "Handler set this as the visible label";
|
||||||
|
executeSoon(checkTabLabelModified);
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkTabLabelModified() {
|
||||||
|
let tab = gBrowser.selectedTab;
|
||||||
|
let xulLabel = document.getAnonymousElementByAttribute(tab, "anonid",
|
||||||
|
"tab-label");
|
||||||
|
|
||||||
|
is(tab.label, "This won't be the visibleLabel",
|
||||||
|
"Tab label set via label property that triggered event");
|
||||||
|
is(xulLabel.value, "Handler set this as the visible label",
|
||||||
|
"xul:label set by TabLabelModified handler");
|
||||||
|
is(tab.visibleLabel, "Handler set this as the visible label",
|
||||||
|
"visibleLabel set by TabLabelModified handler");
|
||||||
|
|
||||||
|
gBrowser.removeCurrentTab({animate: false});
|
||||||
|
executeSoon(checkTabLabelModifiedOnNewTab);
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkTabLabelModifiedOnNewTab() {
|
||||||
|
gBrowser.tabContainer.addEventListener("TabLabelModified",
|
||||||
|
handleTabLabelModifiedOnNewTab, true);
|
||||||
|
let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank",
|
||||||
|
{skipAnimation: true});
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleTabLabelModifiedOnNewTab(aEvent) {
|
||||||
|
gBrowser.tabContainer.removeEventListener("TabLabelModified",
|
||||||
|
handleTabLabelModifiedOnNewTab, true);
|
||||||
|
ok(true, "Event received from new tab default being set");
|
||||||
|
executeSoon(finish);
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче