Bug 1233771 - Add a UITour API to close the current tab and return to the previous page. r=MattN

--HG--
extra : commitid : LF13b9fyGHJ
extra : rebase_source : bcef2702932a71b2c008da4355eb20d83049a567
extra : amend_source : 71c3d06f74f8e41098d011b9bad96ef7a76cb6cc
This commit is contained in:
Paolo Amadini 2016-01-14 14:52:49 +00:00
Родитель 335ab17e50
Коммит 23cd69eeb5
4 изменённых файлов: 50 добавлений и 0 удалений

Просмотреть файл

@ -305,6 +305,19 @@ if (typeof Mozilla == 'undefined') {
pane: pane
});
};
/**
* Closes the tab where this code is running. As usual, if the tab is in the
* foreground, the tab that was displayed before is selected.
*
* The last tab in the current window will never be closed, in which case
* this call will have no effect. The calling code is expected to take an
* action after a small timeout in order to handle this case, for example by
* displaying a goodbye message or a button to restart the tour.
*/
Mozilla.UITour.closeTab = function() {
_sendEvent('closeTab');
};
})();
// Make this library Require-able.

Просмотреть файл

@ -741,6 +741,18 @@ this.UITour = {
});
break;
}
case "closeTab": {
// Find the <tabbrowser> element of the <browser> for which the event
// was generated originally. If the browser where the UI tour is loaded
// is windowless, just ignore the request to close the tab. The request
// is also ignored if this is the only tab in the window.
let tabBrowser = browser.ownerDocument.defaultView.gBrowser;
if (tabBrowser && tabBrowser.browsers.length > 1) {
tabBrowser.removeTab(tabBrowser.getTabForBrowser(browser));
}
break;
}
}
this.initForBrowser(browser, window);

Просмотреть файл

@ -7,6 +7,8 @@ support-files =
[browser_backgroundTab.js]
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
[browser_closeTab.js]
skip-if = e10s # Bug 1073247 - UITour tests not e10s friendly
[browser_fxa.js]
skip-if = e10s || debug || asan # Bug 1073247 - UITour tests not e10s friendly # updateAppMenuItem leaks
[browser_no_tabs.js]

Просмотреть файл

@ -0,0 +1,23 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
var gTestTab;
var gContentAPI;
var gContentWindow;
function test() {
UITourTest();
}
var tests = [
taskify(function* test_closeTab() {
// Setting gTestTab to null indicates that the tab has already been closed,
// and if this does not happen the test run will fail.
gContentAPI.closeTab();
gTestTab = null;
}),
];