browser/components/tabview/test/browser_tabview_bug599626.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial