browser/devtools/scratchpad/test/browser_scratchpad_browser_last_window_closing.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 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 2 /* Any copyright is dedicated to the Public Domain.
michael@0 3 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 4
michael@0 5 const BUTTON_POSITION_CANCEL = 1;
michael@0 6 const BUTTON_POSITION_DONT_SAVE = 2;
michael@0 7
michael@0 8
michael@0 9 function test()
michael@0 10 {
michael@0 11 waitForExplicitFinish();
michael@0 12
michael@0 13 // Observer must be attached *before* Scratchpad is opened.
michael@0 14 CloseObserver.init();
michael@0 15
michael@0 16 gBrowser.selectedTab = gBrowser.addTab();
michael@0 17 gBrowser.selectedBrowser.addEventListener("load", function onTabLoad() {
michael@0 18 gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true);
michael@0 19 openScratchpad(runTests);
michael@0 20 }, true);
michael@0 21
michael@0 22 content.location = "data:text/html;charset=utf8,<p>test browser last window closing</p>";
michael@0 23 }
michael@0 24
michael@0 25
michael@0 26
michael@0 27 function runTests({ Scratchpad })
michael@0 28 {
michael@0 29 let browser = Services.wm.getEnumerator("navigator:browser").getNext();
michael@0 30 let oldPrompt = Services.prompt;
michael@0 31 let button;
michael@0 32
michael@0 33 Services.prompt = {
michael@0 34 confirmEx: () => button
michael@0 35 };
michael@0 36
michael@0 37
michael@0 38 Scratchpad.dirty = true;
michael@0 39
michael@0 40 // Test canceling close.
michael@0 41 button = BUTTON_POSITION_CANCEL;
michael@0 42 CloseObserver.expectedValue = true;
michael@0 43 browser.BrowserTryToCloseWindow();
michael@0 44
michael@0 45 // Test accepting close.
michael@0 46 button = BUTTON_POSITION_DONT_SAVE;
michael@0 47 CloseObserver.expectedValue = false;
michael@0 48 browser.BrowserTryToCloseWindow();
michael@0 49
michael@0 50 // Test closing without prompt needed.
michael@0 51 Scratchpad.dirty = false;
michael@0 52 browser.BrowserTryToCloseWindow();
michael@0 53
michael@0 54 Services.prompt = oldPrompt;
michael@0 55 CloseObserver.uninit();
michael@0 56 finish();
michael@0 57 }
michael@0 58
michael@0 59
michael@0 60 let CloseObserver = {
michael@0 61 expectedValue: null,
michael@0 62 init: function()
michael@0 63 {
michael@0 64 Services.obs.addObserver(this, "browser-lastwindow-close-requested", false);
michael@0 65 },
michael@0 66
michael@0 67 observe: function(aSubject)
michael@0 68 {
michael@0 69 aSubject.QueryInterface(Ci.nsISupportsPRBool);
michael@0 70 let message = this.expectedValue ? "close" : "stay open";
michael@0 71 ok(this.expectedValue === aSubject.data, "Expected browser to " + message);
michael@0 72 aSubject.data = true;
michael@0 73 },
michael@0 74
michael@0 75 uninit: function()
michael@0 76 {
michael@0 77 Services.obs.removeObserver(this, "browser-lastwindow-close-requested", false);
michael@0 78 },
michael@0 79 };

mercurial