|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 Components.utils.import("resource://gre/modules/ForgetAboutSite.jsm"); |
|
6 |
|
7 function waitForClearHistory(aCallback) { |
|
8 let observer = { |
|
9 observe: function(aSubject, aTopic, aData) { |
|
10 Services.obs.removeObserver(this, "browser:purge-domain-data"); |
|
11 setTimeout(aCallback, 0); |
|
12 } |
|
13 }; |
|
14 Services.obs.addObserver(observer, "browser:purge-domain-data", false); |
|
15 } |
|
16 |
|
17 function test() { |
|
18 /** Test for Bug 464199 **/ |
|
19 |
|
20 waitForExplicitFinish(); |
|
21 |
|
22 const REMEMBER = Date.now(), FORGET = Math.random(); |
|
23 let test_state = { windows: [{ "tabs": [{ "entries": [] }], _closedTabs: [ |
|
24 { state: { entries: [{ url: "http://www.example.net/" }] }, title: FORGET }, |
|
25 { state: { entries: [{ url: "http://www.example.org/" }] }, title: REMEMBER }, |
|
26 { state: { entries: [{ url: "http://www.example.net/" }, |
|
27 { url: "http://www.example.org/" }] }, title: FORGET }, |
|
28 { state: { entries: [{ url: "http://example.net/" }] }, title: FORGET }, |
|
29 { state: { entries: [{ url: "http://sub.example.net/" }] }, title: FORGET }, |
|
30 { state: { entries: [{ url: "http://www.example.net:8080/" }] }, title: FORGET }, |
|
31 { state: { entries: [{ url: "about:license" }] }, title: REMEMBER }, |
|
32 { state: { entries: [{ url: "http://www.example.org/frameset", |
|
33 children: [ |
|
34 { url: "http://www.example.org/frame" }, |
|
35 { url: "http://www.example.org:8080/frame2" } |
|
36 ] }] }, title: REMEMBER }, |
|
37 { state: { entries: [{ url: "http://www.example.org/frameset", |
|
38 children: [ |
|
39 { url: "http://www.example.org/frame" }, |
|
40 { url: "http://www.example.net/frame" } |
|
41 ] }] }, title: FORGET }, |
|
42 { state: { entries: [{ url: "http://www.example.org/form", |
|
43 formdata: { id: { "url": "http://www.example.net/" } } |
|
44 }] }, title: REMEMBER }, |
|
45 { state: { entries: [{ url: "http://www.example.org/form" }], |
|
46 extData: { "setTabValue": "http://example.net:80" } }, title: REMEMBER } |
|
47 ] }] }; |
|
48 let remember_count = 5; |
|
49 |
|
50 function countByTitle(aClosedTabList, aTitle) |
|
51 aClosedTabList.filter(function(aData) aData.title == aTitle).length; |
|
52 |
|
53 // open a window and add the above closed tab list |
|
54 let newWin = openDialog(location, "", "chrome,all,dialog=no"); |
|
55 newWin.addEventListener("load", function(aEvent) { |
|
56 newWin.removeEventListener("load", arguments.callee, false); |
|
57 |
|
58 gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", |
|
59 test_state.windows[0]._closedTabs.length); |
|
60 ss.setWindowState(newWin, JSON.stringify(test_state), true); |
|
61 |
|
62 let closedTabs = JSON.parse(ss.getClosedTabData(newWin)); |
|
63 is(closedTabs.length, test_state.windows[0]._closedTabs.length, |
|
64 "Closed tab list has the expected length"); |
|
65 is(countByTitle(closedTabs, FORGET), |
|
66 test_state.windows[0]._closedTabs.length - remember_count, |
|
67 "The correct amout of tabs are to be forgotten"); |
|
68 is(countByTitle(closedTabs, REMEMBER), remember_count, |
|
69 "Everything is set up."); |
|
70 |
|
71 ForgetAboutSite.removeDataFromDomain("example.net"); |
|
72 waitForClearHistory(function() { |
|
73 closedTabs = JSON.parse(ss.getClosedTabData(newWin)); |
|
74 is(closedTabs.length, remember_count, |
|
75 "The correct amout of tabs was removed"); |
|
76 is(countByTitle(closedTabs, FORGET), 0, |
|
77 "All tabs to be forgotten were indeed removed"); |
|
78 is(countByTitle(closedTabs, REMEMBER), remember_count, |
|
79 "... and tabs to be remembered weren't."); |
|
80 |
|
81 // clean up |
|
82 newWin.close(); |
|
83 gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo"); |
|
84 finish(); |
|
85 }); |
|
86 }, false); |
|
87 } |