browser/components/sessionstore/test/browser_464199.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/sessionstore/test/browser_464199.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,87 @@
     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 +Components.utils.import("resource://gre/modules/ForgetAboutSite.jsm");
     1.9 +
    1.10 +function waitForClearHistory(aCallback) {
    1.11 +  let observer = {
    1.12 +    observe: function(aSubject, aTopic, aData) {
    1.13 +      Services.obs.removeObserver(this, "browser:purge-domain-data");
    1.14 +      setTimeout(aCallback, 0);
    1.15 +    }
    1.16 +  };
    1.17 +  Services.obs.addObserver(observer, "browser:purge-domain-data", false);
    1.18 +}
    1.19 +
    1.20 +function test() {
    1.21 +  /** Test for Bug 464199 **/
    1.22 +
    1.23 +  waitForExplicitFinish();
    1.24 +
    1.25 +  const REMEMBER = Date.now(), FORGET = Math.random();
    1.26 +  let test_state = { windows: [{ "tabs": [{ "entries": [] }], _closedTabs: [
    1.27 +    { state: { entries: [{ url: "http://www.example.net/" }] }, title: FORGET },
    1.28 +    { state: { entries: [{ url: "http://www.example.org/" }] }, title: REMEMBER },
    1.29 +    { state: { entries: [{ url: "http://www.example.net/" },
    1.30 +                         { url: "http://www.example.org/" }] }, title: FORGET },
    1.31 +    { state: { entries: [{ url: "http://example.net/" }] }, title: FORGET },
    1.32 +    { state: { entries: [{ url: "http://sub.example.net/" }] }, title: FORGET },
    1.33 +    { state: { entries: [{ url: "http://www.example.net:8080/" }] }, title: FORGET },
    1.34 +    { state: { entries: [{ url: "about:license" }] }, title: REMEMBER },
    1.35 +    { state: { entries: [{ url: "http://www.example.org/frameset",
    1.36 +                           children: [
    1.37 +                             { url: "http://www.example.org/frame" },
    1.38 +                             { url: "http://www.example.org:8080/frame2" }
    1.39 +                           ] }] }, title: REMEMBER },
    1.40 +    { state: { entries: [{ url: "http://www.example.org/frameset",
    1.41 +                           children: [
    1.42 +                             { url: "http://www.example.org/frame" },
    1.43 +                             { url: "http://www.example.net/frame" }
    1.44 +                           ] }] }, title: FORGET },
    1.45 +    { state: { entries: [{ url: "http://www.example.org/form",
    1.46 +                           formdata: { id: { "url": "http://www.example.net/" } }
    1.47 +                         }] }, title: REMEMBER },
    1.48 +    { state: { entries: [{ url: "http://www.example.org/form" }],
    1.49 +               extData: { "setTabValue": "http://example.net:80" } }, title: REMEMBER }
    1.50 +  ] }] };
    1.51 +  let remember_count = 5;
    1.52 +
    1.53 +  function countByTitle(aClosedTabList, aTitle)
    1.54 +    aClosedTabList.filter(function(aData) aData.title == aTitle).length;
    1.55 +
    1.56 +  // open a window and add the above closed tab list
    1.57 +  let newWin = openDialog(location, "", "chrome,all,dialog=no");
    1.58 +  newWin.addEventListener("load", function(aEvent) {
    1.59 +    newWin.removeEventListener("load", arguments.callee, false);
    1.60 +
    1.61 +    gPrefService.setIntPref("browser.sessionstore.max_tabs_undo",
    1.62 +                            test_state.windows[0]._closedTabs.length);
    1.63 +    ss.setWindowState(newWin, JSON.stringify(test_state), true);
    1.64 +
    1.65 +    let closedTabs = JSON.parse(ss.getClosedTabData(newWin));
    1.66 +    is(closedTabs.length, test_state.windows[0]._closedTabs.length,
    1.67 +       "Closed tab list has the expected length");
    1.68 +    is(countByTitle(closedTabs, FORGET),
    1.69 +       test_state.windows[0]._closedTabs.length - remember_count,
    1.70 +       "The correct amout of tabs are to be forgotten");
    1.71 +    is(countByTitle(closedTabs, REMEMBER), remember_count,
    1.72 +       "Everything is set up.");
    1.73 +
    1.74 +    ForgetAboutSite.removeDataFromDomain("example.net");
    1.75 +    waitForClearHistory(function() {
    1.76 +      closedTabs = JSON.parse(ss.getClosedTabData(newWin));
    1.77 +      is(closedTabs.length, remember_count,
    1.78 +         "The correct amout of tabs was removed");
    1.79 +      is(countByTitle(closedTabs, FORGET), 0,
    1.80 +         "All tabs to be forgotten were indeed removed");
    1.81 +      is(countByTitle(closedTabs, REMEMBER), remember_count,
    1.82 +         "... and tabs to be remembered weren't.");
    1.83 +
    1.84 +      // clean up
    1.85 +      newWin.close();
    1.86 +      gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo");
    1.87 +     finish();
    1.88 +    });
    1.89 +  }, false);
    1.90 +}

mercurial