browser/components/sessionstore/test/browser_465223.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/sessionstore/test/browser_465223.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,48 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +function test() {
     1.9 +  /** Test for Bug 465223 **/
    1.10 +
    1.11 +  // test setup
    1.12 +  waitForExplicitFinish();
    1.13 +
    1.14 +  let uniqueKey1 = "bug 465223.1";
    1.15 +  let uniqueKey2 = "bug 465223.2";
    1.16 +  let uniqueValue1 = "unik" + Date.now();
    1.17 +  let uniqueValue2 = "pi != " + Math.random();
    1.18 +
    1.19 +  // open a window and set a value on it
    1.20 +  let newWin = openDialog(location, "_blank", "chrome,all,dialog=no");
    1.21 +  newWin.addEventListener("load", function(aEvent) {
    1.22 +    newWin.removeEventListener("load", arguments.callee, false);
    1.23 +
    1.24 +    ss.setWindowValue(newWin, uniqueKey1, uniqueValue1);
    1.25 +
    1.26 +    let newState = { windows: [{ tabs:[{ entries: [] }], extData: {} }] };
    1.27 +    newState.windows[0].extData[uniqueKey2] = uniqueValue2;
    1.28 +    ss.setWindowState(newWin, JSON.stringify(newState), false);
    1.29 +
    1.30 +    is(newWin.gBrowser.tabs.length, 2,
    1.31 +       "original tab wasn't overwritten");
    1.32 +    is(ss.getWindowValue(newWin, uniqueKey1), uniqueValue1,
    1.33 +       "window value wasn't overwritten when the tabs weren't");
    1.34 +    is(ss.getWindowValue(newWin, uniqueKey2), uniqueValue2,
    1.35 +       "new window value was correctly added");
    1.36 +
    1.37 +    newState.windows[0].extData[uniqueKey2] = uniqueValue1;
    1.38 +    ss.setWindowState(newWin, JSON.stringify(newState), true);
    1.39 +
    1.40 +    is(newWin.gBrowser.tabs.length, 1,
    1.41 +       "original tabs were overwritten");
    1.42 +    is(ss.getWindowValue(newWin, uniqueKey1), "",
    1.43 +       "window value was cleared");
    1.44 +    is(ss.getWindowValue(newWin, uniqueKey2), uniqueValue1,
    1.45 +       "window value was correctly overwritten");
    1.46 +
    1.47 +    // clean up
    1.48 +    newWin.close();
    1.49 +    finish();
    1.50 +  }, false);
    1.51 +}

mercurial