|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 "use strict"; |
|
5 |
|
6 const TEST_URL = 'data:text/html,<script>window.onbeforeunload=' + |
|
7 'function(e){e.returnValue="?"}</script>'; |
|
8 |
|
9 function test() { |
|
10 waitForExplicitFinish(); |
|
11 showTabView(onTabViewShown); |
|
12 } |
|
13 |
|
14 function onTabViewShown() { |
|
15 let contentWindow = TabView.getContentWindow(); |
|
16 let groupItemOne = contentWindow.GroupItems.getActiveGroupItem(); |
|
17 let groupItemTwo = createGroupItemWithTabs(window, 300, 300, 10, [TEST_URL]); |
|
18 |
|
19 afterAllTabsLoaded(function () { |
|
20 testStayOnPage(contentWindow, groupItemOne, groupItemTwo); |
|
21 }); |
|
22 } |
|
23 |
|
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"); |
|
34 |
|
35 showTabView(function () { |
|
36 // start the next test |
|
37 testLeavePage(contentWindow, groupItemOne, groupItemTwo); |
|
38 }); |
|
39 }); |
|
40 |
|
41 // stay on page |
|
42 btnStay.click(); |
|
43 }); |
|
44 |
|
45 closeGroupItem(groupItemTwo); |
|
46 } |
|
47 |
|
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); |
|
56 |
|
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"); |
|
61 |
|
62 hideTabView(finish); |
|
63 }); |
|
64 |
|
65 // Leave page |
|
66 btnLeave.click(); |
|
67 }); |
|
68 |
|
69 closeGroupItem(groupItemTwo); |
|
70 } |