browser/components/sessionstore/test/browser_644409-scratchpads.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.

     1  /* Any copyright is dedicated to the Public Domain.
     2     http://creativecommons.org/publicdomain/zero/1.0/ */
     4 const testState = {
     5   windows: [{
     6     tabs: [
     7       { entries: [{ url: "about:blank" }] },
     8     ]
     9   }],
    10   scratchpads: [
    11     { text: "text1", executionContext: 1 },
    12     { text: "", executionContext: 2, filename: "test.js" }
    13   ]
    14 };
    16 // only finish() when correct number of windows opened
    17 var restored = [];
    18 function addState(state) {
    19   restored.push(state);
    21   if (restored.length == testState.scratchpads.length) {
    22     ok(statesMatch(restored, testState.scratchpads),
    23       "Two scratchpad windows restored");
    25     Services.ww.unregisterNotification(windowObserver);
    26     finish();
    27   }
    28 }
    30 function test() {
    31   waitForExplicitFinish();
    33   Services.ww.registerNotification(windowObserver);
    35   ss.setBrowserState(JSON.stringify(testState));
    36 }
    38 function windowObserver(aSubject, aTopic, aData) {
    39   if (aTopic == "domwindowopened") {
    40     let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
    41     win.addEventListener("load", function onLoad() {
    42       win.removeEventListener("load", onLoad, false);
    44       if (win.Scratchpad) {
    45         win.Scratchpad.addObserver({
    46           onReady: function() {
    47             win.Scratchpad.removeObserver(this);
    49             let state = win.Scratchpad.getState();
    50             win.close();
    51             addState(state);
    52           },
    53         });
    54       }
    55     }, false);
    56   }
    57 }
    59 function statesMatch(restored, states) {
    60   return states.every(function(state) {
    61     return restored.some(function(restoredState) {
    62       return state.filename == restoredState.filename &&
    63              state.text == restoredState.text &&
    64              state.executionContext == restoredState.executionContext;
    65     })
    66   });
    67 }

mercurial