Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Bug 682681 tab.title should never be empty #492

Merged
merged 5 commits into from Jul 24, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/addon-kit/docs/tabs.md
Expand Up @@ -171,7 +171,7 @@ passed the `Tab` object that triggered the event.


<api name="title"> <api name="title">
@property {string} @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. This property can be set to change the tab title.
</api> </api>


Expand Down
48 changes: 48 additions & 0 deletions packages/addon-kit/tests/test-tabs.js
Expand Up @@ -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,<title>tab</title>",
inBackground: true
});
});
};

// test 'BrowserWindow' instance creation on tab 'activate' event // test 'BrowserWindow' instance creation on tab 'activate' event
// See bug 648244: there was a infinite loop. // See bug 648244: there was a infinite loop.
exports.testBrowserWindowCreationOnActivate = function(test) { exports.testBrowserWindowCreationOnActivate = function(test) {
Expand Down
14 changes: 9 additions & 5 deletions packages/api-utils/lib/tabs/tab.js
Expand Up @@ -11,7 +11,11 @@ const { defer } = require("../functional");
const { EVENTS } = require("./events"); const { EVENTS } = require("./events");
const { getThumbnailURIForWindow } = require("../utils/thumbnail"); const { getThumbnailURIForWindow } = require("../utils/thumbnail");
const { getFaviconURIForLocation } = require("../utils/data"); const { getFaviconURIForLocation } = require("../utils/data");

const {
getOwnerWindow,
getBrowserForTab,
getTabTitle
} = require("./utils");




// Array of the inner instances of all the wrapped tabs. // Array of the inner instances of all the wrapped tabs.
Expand Down Expand Up @@ -82,11 +86,11 @@ const TabTrait = Trait.compose(EventEmitter, {
/** /**
* Browser DOM element where page of this tab is currently loaded. * 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. * 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. * Document object of the page that is currently loaded in this tab.
*/ */
Expand All @@ -101,8 +105,8 @@ const TabTrait = Trait.compose(EventEmitter, {
* Changing this property changes an actual title. * Changing this property changes an actual title.
* @type {String} * @type {String}
*/ */
get title() this._contentDocument.title, get title() getTabTitle(this._tab),
set title(value) this._contentDocument.title = String(value), set title(value) this._tab.label = String(value),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add getTabTitle(tab) function to tab/utils and use that from here ?

P.S.: tab is actual tab node not trait or something alike.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k got it

/** /**
* Location of the page currently loaded in this tab. * Location of the page currently loaded in this tab.
* Changing this property will loads page under under the specified location. * Changing this property will loads page under under the specified location.
Expand Down
19 changes: 17 additions & 2 deletions packages/api-utils/lib/tabs/utils.js
Expand Up @@ -49,16 +49,31 @@ function isTabOpen(tab) {
exports.isTabOpen = isTabOpen; exports.isTabOpen = isTabOpen;


function closeTab(tab) { function closeTab(tab) {
return getOwnerWindow(tab).gBrowser.removeTab(tab); return getGBrowserForTab(tab).removeTab(tab);
} }
exports.closeTab = closeTab; exports.closeTab = closeTab;


function activateTab(tab) { function activateTab(tab) {
getOwnerWindow(tab).gBrowser.selectedTab = tab; getGBrowserForTab(tab).selectedTab = tab;
} }
exports.activateTab = activateTab; exports.activateTab = activateTab;


function getURI(tab) { function getURI(tab) {
return tab.linkedBrowser.currentURI.spec; return tab.linkedBrowser.currentURI.spec;
} }
exports.getURI = getURI; 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;