Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 const TEST_URL = 'data:text/html,<script>window.onbeforeunload=' +
7 'function(e){e.returnValue="?"}</script>';
9 function test() {
10 waitForExplicitFinish();
11 showTabView(onTabViewShown);
12 }
14 function onTabViewShown() {
15 let contentWindow = TabView.getContentWindow();
16 let groupItemOne = contentWindow.GroupItems.getActiveGroupItem();
17 let groupItemTwo = createGroupItemWithTabs(window, 300, 300, 10, [TEST_URL]);
19 afterAllTabsLoaded(function () {
20 testStayOnPage(contentWindow, groupItemOne, groupItemTwo);
21 });
22 }
24 function testStayOnPage(contentWindow, groupItemOne, groupItemTwo) {
25 // We created a new tab group with a second tab above, so let's
26 // pick that second tab here and wait for its onbeforeunload dialog.
27 let browser = gBrowser.browsers[1];
28 waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) {
29 executeSoon(function () {
30 is(gBrowser.tabs.length, 2,
31 "The total number of tab is 2 when staying on the page");
32 is(contentWindow.TabItems.getItems().length, 2,
33 "The total number of tab items is 2 when staying on the page");
35 showTabView(function () {
36 // start the next test
37 testLeavePage(contentWindow, groupItemOne, groupItemTwo);
38 });
39 });
41 // stay on page
42 btnStay.click();
43 });
45 closeGroupItem(groupItemTwo);
46 }
48 function testLeavePage(contentWindow, groupItemOne, groupItemTwo) {
49 // The second tab hasn't been closed yet because we chose to stay. Wait
50 // for the onbeforeunload dialog again and leave the page this time.
51 let browser = gBrowser.browsers[1];
52 waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) {
53 // clean up and finish the test
54 groupItemTwo.addSubscriber("close", function onClose() {
55 groupItemTwo.removeSubscriber("close", onClose);
57 is(gBrowser.tabs.length, 1,
58 "The total number of tab is 1 after leaving the page");
59 is(contentWindow.TabItems.getItems().length, 1,
60 "The total number of tab items is 1 after leaving the page");
62 hideTabView(finish);
63 });
65 // Leave page
66 btnLeave.click();
67 });
69 closeGroupItem(groupItemTwo);
70 }