|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 "use strict"; |
|
5 |
|
6 /** |
|
7 * These tests ensures that disabling features by flipping nsIDocShell.allow* |
|
8 * properties are (re)stored as disabled. Disallowed features must be |
|
9 * re-enabled when the tab is re-used by another tab restoration. |
|
10 */ |
|
11 add_task(function docshell_capabilities() { |
|
12 let tab = yield createTab(); |
|
13 let browser = tab.linkedBrowser; |
|
14 let docShell = browser.docShell; |
|
15 |
|
16 // Get the list of capabilities for docShells. |
|
17 let flags = Object.keys(docShell).filter(k => k.startsWith("allow")); |
|
18 |
|
19 // Check that everything is allowed by default for new tabs. |
|
20 let state = JSON.parse(ss.getTabState(tab)); |
|
21 ok(!("disallow" in state), "everything allowed by default"); |
|
22 ok(flags.every(f => docShell[f]), "all flags set to true"); |
|
23 |
|
24 // Flip a couple of allow* flags. |
|
25 docShell.allowImages = false; |
|
26 docShell.allowMetaRedirects = false; |
|
27 |
|
28 // Now reload the document to ensure that these capabilities |
|
29 // are taken into account. |
|
30 browser.reload(); |
|
31 yield promiseBrowserLoaded(browser); |
|
32 |
|
33 // Flush to make sure chrome received all data. |
|
34 SyncHandlers.get(browser).flush(); |
|
35 |
|
36 // Check that we correctly save disallowed features. |
|
37 let disallowedState = JSON.parse(ss.getTabState(tab)); |
|
38 let disallow = new Set(disallowedState.disallow.split(",")); |
|
39 ok(disallow.has("Images"), "images not allowed"); |
|
40 ok(disallow.has("MetaRedirects"), "meta redirects not allowed"); |
|
41 is(disallow.size, 2, "two capabilities disallowed"); |
|
42 |
|
43 // Reuse the tab to restore a new, clean state into it. |
|
44 ss.setTabState(tab, JSON.stringify({ entries: [{url: "about:robots"}] })); |
|
45 yield promiseTabRestored(tab); |
|
46 |
|
47 // Flush to make sure chrome received all data. |
|
48 SyncHandlers.get(browser).flush(); |
|
49 |
|
50 // After restoring disallowed features must be available again. |
|
51 state = JSON.parse(ss.getTabState(tab)); |
|
52 ok(!("disallow" in state), "everything allowed again"); |
|
53 ok(flags.every(f => docShell[f]), "all flags set to true"); |
|
54 |
|
55 // Restore the state with disallowed features. |
|
56 ss.setTabState(tab, JSON.stringify(disallowedState)); |
|
57 yield promiseTabRestored(tab); |
|
58 |
|
59 // Check that docShell flags are set. |
|
60 ok(!docShell.allowImages, "images not allowed"); |
|
61 ok(!docShell.allowMetaRedirects, "meta redirects not allowed"); |
|
62 |
|
63 // Check that we correctly restored features as disabled. |
|
64 state = JSON.parse(ss.getTabState(tab)); |
|
65 disallow = new Set(state.disallow.split(",")); |
|
66 ok(disallow.has("Images"), "images not allowed anymore"); |
|
67 ok(disallow.has("MetaRedirects"), "meta redirects not allowed anymore"); |
|
68 is(disallow.size, 2, "two capabilities disallowed"); |
|
69 |
|
70 // Clean up after ourselves. |
|
71 gBrowser.removeTab(tab); |
|
72 }); |
|
73 |
|
74 function createTab() { |
|
75 let tab = gBrowser.addTab("about:mozilla"); |
|
76 let browser = tab.linkedBrowser; |
|
77 return promiseBrowserLoaded(browser).then(() => tab); |
|
78 } |