|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 * |
|
5 * Contributor(s): |
|
6 * Mihai Sucan <mihai.sucan@gmail.com> |
|
7 * Raymond Lee <raymond@appcoast.com> |
|
8 */ |
|
9 |
|
10 "use strict"; |
|
11 |
|
12 const TEST_URL = 'data:text/html,<script>window.onbeforeunload=' + |
|
13 'function(e){e.returnValue="?"}</script>'; |
|
14 |
|
15 let contentWindow; |
|
16 let activeGroup; |
|
17 |
|
18 function test() { |
|
19 waitForExplicitFinish(); |
|
20 |
|
21 newWindowWithTabView(win => { |
|
22 contentWindow = win.TabView.getContentWindow(); |
|
23 activeGroup = contentWindow.GroupItems.getActiveGroupItem(); |
|
24 |
|
25 win.gBrowser.browsers[0].loadURI("data:text/html,<p>test for bug 626455, tab1"); |
|
26 |
|
27 let tab = win.gBrowser.addTab(TEST_URL); |
|
28 afterAllTabsLoaded(() => testStayOnPage(win, tab)); |
|
29 }); |
|
30 } |
|
31 |
|
32 function testStayOnPage(win, blockingTab) { |
|
33 let browser = blockingTab.linkedBrowser; |
|
34 waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) { |
|
35 // stay on page |
|
36 btnStay.click(); |
|
37 |
|
38 executeSoon(function () { |
|
39 showTabView(function () { |
|
40 is(win.gBrowser.tabs.length, 1, |
|
41 "The total number of tab is 1 when staying on the page"); |
|
42 |
|
43 // The other initial tab has been closed when trying to close the tab |
|
44 // group. The only tab left is the one with the onbeforeunload dialog. |
|
45 let url = win.gBrowser.browsers[0].currentURI.spec; |
|
46 ok(url.contains("onbeforeunload"), "The open tab is the expected one"); |
|
47 |
|
48 is(contentWindow.GroupItems.getActiveGroupItem(), activeGroup, |
|
49 "Active group is still the same"); |
|
50 |
|
51 is(contentWindow.GroupItems.groupItems.length, 1, |
|
52 "Only one group is open"); |
|
53 |
|
54 // start the next test |
|
55 testLeavePage(win, win.gBrowser.tabs[0]); |
|
56 }, win); |
|
57 }); |
|
58 }); |
|
59 |
|
60 closeGroupItem(activeGroup); |
|
61 } |
|
62 |
|
63 function testLeavePage(win, blockingTab) { |
|
64 let browser = blockingTab.linkedBrowser; |
|
65 waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) { |
|
66 // Leave page |
|
67 btnLeave.click(); |
|
68 }); |
|
69 |
|
70 whenGroupClosed(activeGroup, () => finishTest(win)); |
|
71 closeGroupItem(activeGroup); |
|
72 } |
|
73 |
|
74 function finishTest(win) { |
|
75 is(win.gBrowser.tabs.length, 1, |
|
76 "The total number of tab is 1 after leaving the page"); |
|
77 is(contentWindow.TabItems.getItems().length, 1, |
|
78 "The total number of tab items is 1 after leaving the page"); |
|
79 |
|
80 let location = win.gBrowser.browsers[0].currentURI.spec; |
|
81 is(location, BROWSER_NEW_TAB_URL, "The open tab is the expected one"); |
|
82 |
|
83 isnot(contentWindow.GroupItems.getActiveGroupItem(), activeGroup, |
|
84 "Active group is no longer the same"); |
|
85 |
|
86 is(contentWindow.GroupItems.groupItems.length, 1, |
|
87 "Only one group is open"); |
|
88 |
|
89 contentWindow = null; |
|
90 activeGroup = null; |
|
91 promiseWindowClosed(win).then(finish); |
|
92 } |
|
93 |
|
94 // ---------- |
|
95 function whenGroupClosed(group, callback) { |
|
96 group.addSubscriber("close", function onClose() { |
|
97 group.removeSubscriber("close", onClose); |
|
98 callback(); |
|
99 }); |
|
100 } |