diff --git a/packages/addon-kit/docs/tabs.md b/packages/addon-kit/docs/tabs.md
index f1e44dfea..22720595f 100644
--- a/packages/addon-kit/docs/tabs.md
+++ b/packages/addon-kit/docs/tabs.md
@@ -171,7 +171,7 @@ passed the `Tab` object that triggered the event.
@property {string}
-The title of the page currently loaded in the tab.
+The title of the tab (usually the title of the page currently loaded in the tab)
This property can be set to change the tab title.
diff --git a/packages/addon-kit/tests/test-tabs.js b/packages/addon-kit/tests/test-tabs.js
index d74807429..541d23df1 100644
--- a/packages/addon-kit/tests/test-tabs.js
+++ b/packages/addon-kit/tests/test-tabs.js
@@ -29,6 +29,54 @@ exports.testActiveTab_getter = function(test) {
});
};
+// Bug 682681 - tab.title should never be empty
+exports.testBug682681_aboutURI = function(test) {
+ test.waitUntilDone();
+
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+
+ tabs.on('ready', function onReady(tab) {
+ tabs.removeListener('ready', onReady);
+
+ test.assertEqual(tab.title, "New Tab", "title of about: tab is not blank");
+
+ // end of test
+ closeBrowserWindow(window, function() test.done());
+ });
+
+ // open a about: url
+ tabs.open({
+ url: "about:blank",
+ inBackground: true
+ });
+ });
+};
+
+// related to Bug 682681
+exports.testTitleForDataURI = function(test) {
+ test.waitUntilDone();
+
+ openBrowserWindow(function(window, browser) {
+ let tabs = require("tabs");
+
+ tabs.on('ready', function onReady(tab) {
+ tabs.removeListener('ready', onReady);
+
+ test.assertEqual(tab.title, "tab", "data: title is not Connecting...");
+
+ // end of test
+ closeBrowserWindow(window, function() test.done());
+ });
+
+ // open a about: url
+ tabs.open({
+ url: "data:text/html;charset=utf-8,
tab",
+ inBackground: true
+ });
+ });
+};
+
// test 'BrowserWindow' instance creation on tab 'activate' event
// See bug 648244: there was a infinite loop.
exports.testBrowserWindowCreationOnActivate = function(test) {
diff --git a/packages/api-utils/lib/tabs/tab.js b/packages/api-utils/lib/tabs/tab.js
index 246834f3d..1b040cab3 100644
--- a/packages/api-utils/lib/tabs/tab.js
+++ b/packages/api-utils/lib/tabs/tab.js
@@ -11,7 +11,11 @@ const { defer } = require("../functional");
const { EVENTS } = require("./events");
const { getThumbnailURIForWindow } = require("../utils/thumbnail");
const { getFaviconURIForLocation } = require("../utils/data");
-
+const {
+ getOwnerWindow,
+ getBrowserForTab,
+ getTabTitle
+} = require("./utils");
// Array of the inner instances of all the wrapped tabs.
@@ -82,11 +86,11 @@ const TabTrait = Trait.compose(EventEmitter, {
/**
* Browser DOM element where page of this tab is currently loaded.
*/
- get _browser() this._window.gBrowser.getBrowserForTab(this._tab),
+ get _browser() getBrowserForTab(this._tab),
/**
* Window DOM element containing this tab.
*/
- get _window() this._tab.ownerDocument.defaultView,
+ get _window() getOwnerWindow(this._tab),
/**
* Document object of the page that is currently loaded in this tab.
*/
@@ -101,8 +105,8 @@ const TabTrait = Trait.compose(EventEmitter, {
* Changing this property changes an actual title.
* @type {String}
*/
- get title() this._contentDocument.title,
- set title(value) this._contentDocument.title = String(value),
+ get title() getTabTitle(this._tab),
+ set title(value) this._tab.label = String(value),
/**
* Location of the page currently loaded in this tab.
* Changing this property will loads page under under the specified location.
diff --git a/packages/api-utils/lib/tabs/utils.js b/packages/api-utils/lib/tabs/utils.js
index 935ce25ff..adf8b7918 100644
--- a/packages/api-utils/lib/tabs/utils.js
+++ b/packages/api-utils/lib/tabs/utils.js
@@ -49,12 +49,12 @@ function isTabOpen(tab) {
exports.isTabOpen = isTabOpen;
function closeTab(tab) {
- return getOwnerWindow(tab).gBrowser.removeTab(tab);
+ return getGBrowserForTab(tab).removeTab(tab);
}
exports.closeTab = closeTab;
function activateTab(tab) {
- getOwnerWindow(tab).gBrowser.selectedTab = tab;
+ getGBrowserForTab(tab).selectedTab = tab;
}
exports.activateTab = activateTab;
@@ -62,3 +62,18 @@ function getURI(tab) {
return tab.linkedBrowser.currentURI.spec;
}
exports.getURI = getURI;
+
+function getGBrowserForTab(tab) {
+ return getOwnerWindow(tab).gBrowser;
+}
+exports.getGBrowserForTab = getGBrowserForTab;
+
+function getBrowserForTab(tab) {
+ return getGBrowserForTab(tab).getBrowserForTab(tab);
+}
+exports.getBrowserForTab = getBrowserForTab;
+
+function getTabTitle(tab) {
+ return getBrowserForTab(tab).contentDocument.title || tab.label;
+}
+exports.getTabTitle = getTabTitle;