michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: Components.utils.import("resource://gre/modules/ForgetAboutSite.jsm"); michael@0: michael@0: function waitForClearHistory(aCallback) { michael@0: let observer = { michael@0: observe: function(aSubject, aTopic, aData) { michael@0: Services.obs.removeObserver(this, "browser:purge-domain-data"); michael@0: setTimeout(aCallback, 0); michael@0: } michael@0: }; michael@0: Services.obs.addObserver(observer, "browser:purge-domain-data", false); michael@0: } michael@0: michael@0: function test() { michael@0: /** Test for Bug 464199 **/ michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: const REMEMBER = Date.now(), FORGET = Math.random(); michael@0: let test_state = { windows: [{ "tabs": [{ "entries": [] }], _closedTabs: [ michael@0: { state: { entries: [{ url: "http://www.example.net/" }] }, title: FORGET }, michael@0: { state: { entries: [{ url: "http://www.example.org/" }] }, title: REMEMBER }, michael@0: { state: { entries: [{ url: "http://www.example.net/" }, michael@0: { url: "http://www.example.org/" }] }, title: FORGET }, michael@0: { state: { entries: [{ url: "http://example.net/" }] }, title: FORGET }, michael@0: { state: { entries: [{ url: "http://sub.example.net/" }] }, title: FORGET }, michael@0: { state: { entries: [{ url: "http://www.example.net:8080/" }] }, title: FORGET }, michael@0: { state: { entries: [{ url: "about:license" }] }, title: REMEMBER }, michael@0: { state: { entries: [{ url: "http://www.example.org/frameset", michael@0: children: [ michael@0: { url: "http://www.example.org/frame" }, michael@0: { url: "http://www.example.org:8080/frame2" } michael@0: ] }] }, title: REMEMBER }, michael@0: { state: { entries: [{ url: "http://www.example.org/frameset", michael@0: children: [ michael@0: { url: "http://www.example.org/frame" }, michael@0: { url: "http://www.example.net/frame" } michael@0: ] }] }, title: FORGET }, michael@0: { state: { entries: [{ url: "http://www.example.org/form", michael@0: formdata: { id: { "url": "http://www.example.net/" } } michael@0: }] }, title: REMEMBER }, michael@0: { state: { entries: [{ url: "http://www.example.org/form" }], michael@0: extData: { "setTabValue": "http://example.net:80" } }, title: REMEMBER } michael@0: ] }] }; michael@0: let remember_count = 5; michael@0: michael@0: function countByTitle(aClosedTabList, aTitle) michael@0: aClosedTabList.filter(function(aData) aData.title == aTitle).length; michael@0: michael@0: // open a window and add the above closed tab list michael@0: let newWin = openDialog(location, "", "chrome,all,dialog=no"); michael@0: newWin.addEventListener("load", function(aEvent) { michael@0: newWin.removeEventListener("load", arguments.callee, false); michael@0: michael@0: gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", michael@0: test_state.windows[0]._closedTabs.length); michael@0: ss.setWindowState(newWin, JSON.stringify(test_state), true); michael@0: michael@0: let closedTabs = JSON.parse(ss.getClosedTabData(newWin)); michael@0: is(closedTabs.length, test_state.windows[0]._closedTabs.length, michael@0: "Closed tab list has the expected length"); michael@0: is(countByTitle(closedTabs, FORGET), michael@0: test_state.windows[0]._closedTabs.length - remember_count, michael@0: "The correct amout of tabs are to be forgotten"); michael@0: is(countByTitle(closedTabs, REMEMBER), remember_count, michael@0: "Everything is set up."); michael@0: michael@0: ForgetAboutSite.removeDataFromDomain("example.net"); michael@0: waitForClearHistory(function() { michael@0: closedTabs = JSON.parse(ss.getClosedTabData(newWin)); michael@0: is(closedTabs.length, remember_count, michael@0: "The correct amout of tabs was removed"); michael@0: is(countByTitle(closedTabs, FORGET), 0, michael@0: "All tabs to be forgotten were indeed removed"); michael@0: is(countByTitle(closedTabs, REMEMBER), remember_count, michael@0: "... and tabs to be remembered weren't."); michael@0: michael@0: // clean up michael@0: newWin.close(); michael@0: gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo"); michael@0: finish(); michael@0: }); michael@0: }, false); michael@0: }