browser/components/sessionstore/test/browser_394759_basic.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 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 const TEST_URL = "data:text/html;charset=utf-8,<input%20id=txt>" +
michael@0 8 "<input%20type=checkbox%20id=chk>";
michael@0 9
michael@0 10 /**
michael@0 11 * This test ensures that closing a window is a reversible action. We will
michael@0 12 * close the the window, restore it and check that all data has been restored.
michael@0 13 * This includes window-specific data as well as form data for tabs.
michael@0 14 */
michael@0 15 function test() {
michael@0 16 waitForExplicitFinish();
michael@0 17
michael@0 18 let uniqueKey = "bug 394759";
michael@0 19 let uniqueValue = "unik" + Date.now();
michael@0 20 let uniqueText = "pi != " + Math.random();
michael@0 21
michael@0 22 // Clear the list of closed windows.
michael@0 23 while (SessionStore.getClosedWindowCount()) {
michael@0 24 SessionStore.forgetClosedWindow(0);
michael@0 25 }
michael@0 26
michael@0 27 provideWindow(function onTestURLLoaded(newWin) {
michael@0 28 newWin.gBrowser.addTab().linkedBrowser.stop();
michael@0 29
michael@0 30 // mark the window with some unique data to be restored later on
michael@0 31 ss.setWindowValue(newWin, uniqueKey, uniqueValue);
michael@0 32 let [txt, chk] = newWin.content.document.querySelectorAll("#txt, #chk");
michael@0 33 txt.value = uniqueText;
michael@0 34
michael@0 35 let browser = newWin.gBrowser.selectedBrowser;
michael@0 36 setInputChecked(browser, {id: "chk", checked: true}).then(() => {
michael@0 37 newWin.close();
michael@0 38
michael@0 39 // Now give it time to close
michael@0 40 executeSoon(function() {
michael@0 41 is(ss.getClosedWindowCount(), 1,
michael@0 42 "The closed window was added to Recently Closed Windows");
michael@0 43 let data = JSON.parse(ss.getClosedWindowData())[0];
michael@0 44 ok(data.title == TEST_URL && JSON.stringify(data).indexOf(uniqueText) > -1,
michael@0 45 "The closed window data was stored correctly");
michael@0 46
michael@0 47 // reopen the closed window and ensure its integrity
michael@0 48 let newWin2 = ss.undoCloseWindow(0);
michael@0 49
michael@0 50 ok(newWin2 instanceof ChromeWindow,
michael@0 51 "undoCloseWindow actually returned a window");
michael@0 52 is(ss.getClosedWindowCount(), 0,
michael@0 53 "The reopened window was removed from Recently Closed Windows");
michael@0 54
michael@0 55 // SSTabRestored will fire more than once, so we need to make sure we count them
michael@0 56 let restoredTabs = 0;
michael@0 57 let expectedTabs = data.tabs.length;
michael@0 58 newWin2.addEventListener("SSTabRestored", function sstabrestoredListener(aEvent) {
michael@0 59 ++restoredTabs;
michael@0 60 info("Restored tab " + restoredTabs + "/" + expectedTabs);
michael@0 61 if (restoredTabs < expectedTabs) {
michael@0 62 return;
michael@0 63 }
michael@0 64
michael@0 65 is(restoredTabs, expectedTabs, "correct number of tabs restored");
michael@0 66 newWin2.removeEventListener("SSTabRestored", sstabrestoredListener, true);
michael@0 67
michael@0 68 is(newWin2.gBrowser.tabs.length, 2,
michael@0 69 "The window correctly restored 2 tabs");
michael@0 70 is(newWin2.gBrowser.currentURI.spec, TEST_URL,
michael@0 71 "The window correctly restored the URL");
michael@0 72
michael@0 73 let [txt, chk] = newWin2.content.document.querySelectorAll("#txt, #chk");
michael@0 74 ok(txt.value == uniqueText && chk.checked,
michael@0 75 "The window correctly restored the form");
michael@0 76 is(ss.getWindowValue(newWin2, uniqueKey), uniqueValue,
michael@0 77 "The window correctly restored the data associated with it");
michael@0 78
michael@0 79 // clean up
michael@0 80 newWin2.close();
michael@0 81 finish();
michael@0 82 }, true);
michael@0 83 });
michael@0 84 });
michael@0 85 }, TEST_URL);
michael@0 86 }
michael@0 87
michael@0 88 function setInputChecked(browser, data) {
michael@0 89 return sendMessage(browser, "ss-test:setInputChecked", data);
michael@0 90 }

mercurial