OLD | NEW |
1 <script> | 1 <script> |
2 // Content settings API test | 2 // Content settings API test |
3 // Run with browser_tests --gtest_filter=ExtensionApiTest.ContentSettingsOnChang
e | 3 // Run with browser_tests --gtest_filter=ExtensionApiTest.ContentSettingsOnChang
e |
4 | 4 |
5 // Listen until |event| has fired with all of the values in |expected|. | 5 // Listen until |event| has fired with all of the values in |expected|. |
6 function listenUntil(event, expected) { | 6 function listenUntil(event, expected) { |
7 var done = chrome.test.listenForever(event, function(value) { | 7 var done = chrome.test.listenForever(event, function(value) { |
8 for (var i = 0; i < expected.length; i++) { | 8 for (var i = 0; i < expected.length; i++) { |
9 if (chrome.test.checkDeepEq(expected[i], value)) { | 9 if (chrome.test.checkDeepEq(expected[i], value)) { |
10 expected.splice(i, 1); | 10 expected.splice(i, 1); |
11 if (expected.length == 0) | 11 if (expected.length == 0) |
12 done(); | 12 done(); |
13 return; | 13 return; |
14 } | 14 } |
15 } | 15 } |
16 chrome.test.fail("Unexpected event: " + JSON.stringify(value)); | 16 chrome.test.fail("Unexpected event: " + JSON.stringify(value)); |
17 }); | 17 }); |
18 } | 18 } |
19 | 19 |
20 var cs = chrome.experimental.contentSettings; | 20 var cs = chrome.experimental.contentSettings; |
21 chrome.test.runTests([ | 21 chrome.test.runTests([ |
22 function changeDefault() { | 22 function changeDefault() { |
23 // Changing the regular settings when no incognito-specific settings are | 23 // Changing the regular settings when no incognito-specific settings are |
24 // defined should fire two events. | 24 // defined should fire two events. |
25 listenUntil(cs.misc.blockThirdPartyCookies.onChange, [{ | 25 listenUntil(cs.global.thirdPartyCookiesAllowed.onChange, [{ |
| 26 'value': false, |
| 27 'levelOfControl': 'controlled_by_this_extension' |
| 28 }, |
| 29 { |
| 30 'value': false, |
| 31 'incognitoSpecific': false, |
| 32 'levelOfControl': 'controlled_by_this_extension' |
| 33 }]); |
| 34 cs.global.thirdPartyCookiesAllowed.set({ |
| 35 'value':false |
| 36 }, chrome.test.callbackPass()); |
| 37 }, |
| 38 function changeIncognitoOnly() { |
| 39 listenUntil(cs.global.thirdPartyCookiesAllowed.onChange, [{ |
| 40 'value': true, |
| 41 'incognitoSpecific': true, |
| 42 'levelOfControl': 'controlled_by_this_extension' |
| 43 }]); |
| 44 cs.global.thirdPartyCookiesAllowed.set({ |
| 45 'value': true, |
| 46 'scope': 'incognito_persistent' |
| 47 }, chrome.test.callbackPass()); |
| 48 }, |
| 49 function changeDefaultOnly() { |
| 50 listenUntil(cs.global.thirdPartyCookiesAllowed.onChange, [{ |
26 'value': true, | 51 'value': true, |
27 'levelOfControl': 'controlled_by_this_extension' | 52 'levelOfControl': 'controlled_by_this_extension' |
| 53 }]); |
| 54 cs.global.thirdPartyCookiesAllowed.set({ |
| 55 'value': true |
| 56 }, chrome.test.callbackPass()); |
| 57 }, |
| 58 function changeIncognitoOnlyBack() { |
| 59 // Change the incognito setting back to false so that we get an event when |
| 60 // clearing the value. |
| 61 listenUntil(cs.global.thirdPartyCookiesAllowed.onChange, [{ |
| 62 'value': false, |
| 63 'incognitoSpecific': true, |
| 64 'levelOfControl': 'controlled_by_this_extension' |
| 65 }]); |
| 66 cs.global.thirdPartyCookiesAllowed.set({ |
| 67 'value': false, |
| 68 'scope': 'incognito_persistent' |
| 69 }, chrome.test.callbackPass()); |
| 70 }, |
| 71 function clearIncognito() { |
| 72 listenUntil(cs.global.thirdPartyCookiesAllowed.onChange, [{ |
| 73 'value': true, |
| 74 'incognitoSpecific': false, |
| 75 'levelOfControl': 'controlled_by_this_extension' |
| 76 }]); |
| 77 cs.global.thirdPartyCookiesAllowed.clear({ |
| 78 'scope': 'incognito_persistent' |
| 79 }, chrome.test.callbackPass()); |
| 80 }, |
| 81 function clearDefault() { |
| 82 listenUntil(cs.global.thirdPartyCookiesAllowed.onChange, [{ |
| 83 'value': true, |
| 84 'levelOfControl': 'controllable_by_this_extension' |
28 }, | 85 }, |
29 { | 86 { |
30 'value': true, | 87 'value': true, |
31 'incognitoSpecific': false, | 88 'incognitoSpecific': false, |
32 'levelOfControl': 'controlled_by_this_extension' | |
33 }]); | |
34 cs.misc.blockThirdPartyCookies.set({ | |
35 'value':true | |
36 }, chrome.test.callbackPass()); | |
37 }, | |
38 function changeIncognitoOnly() { | |
39 listenUntil(cs.misc.blockThirdPartyCookies.onChange, [{ | |
40 'value': false, | |
41 'incognitoSpecific': true, | |
42 'levelOfControl': 'controlled_by_this_extension' | |
43 }]); | |
44 cs.misc.blockThirdPartyCookies.set({ | |
45 'value': false, | |
46 'scope': 'incognito_persistent' | |
47 }, chrome.test.callbackPass()); | |
48 }, | |
49 function changeDefaultOnly() { | |
50 listenUntil(cs.misc.blockThirdPartyCookies.onChange, [{ | |
51 'value': false, | |
52 'levelOfControl': 'controlled_by_this_extension' | |
53 }]); | |
54 cs.misc.blockThirdPartyCookies.set({ | |
55 'value': false | |
56 }, chrome.test.callbackPass()); | |
57 }, | |
58 function changeIncognitoOnlyBack() { | |
59 // Change the incognito setting back to true so that we get an event when | |
60 // clearing the value. | |
61 listenUntil(cs.misc.blockThirdPartyCookies.onChange, [{ | |
62 'value': true, | |
63 'incognitoSpecific': true, | |
64 'levelOfControl': 'controlled_by_this_extension' | |
65 }]); | |
66 cs.misc.blockThirdPartyCookies.set({ | |
67 'value': true, | |
68 'scope': 'incognito_persistent' | |
69 }, chrome.test.callbackPass()); | |
70 }, | |
71 function clearIncognito() { | |
72 listenUntil(cs.misc.blockThirdPartyCookies.onChange, [{ | |
73 'value': false, | |
74 'incognitoSpecific': false, | |
75 'levelOfControl': 'controlled_by_this_extension' | |
76 }]); | |
77 cs.misc.blockThirdPartyCookies.clear({ | |
78 'scope': 'incognito_persistent' | |
79 }, chrome.test.callbackPass()); | |
80 }, | |
81 function clearDefault() { | |
82 listenUntil(cs.misc.blockThirdPartyCookies.onChange, [{ | |
83 'value': false, | |
84 'levelOfControl': 'controllable_by_this_extension' | |
85 }, | |
86 { | |
87 'value': false, | |
88 'incognitoSpecific': false, | |
89 'levelOfControl': 'controllable_by_this_extension' | 89 'levelOfControl': 'controllable_by_this_extension' |
90 }]); | 90 }]); |
91 cs.misc.blockThirdPartyCookies.clear({}, chrome.test.callbackPass()); | 91 cs.global.thirdPartyCookiesAllowed.clear({}, chrome.test.callbackPass()); |
92 } | 92 } |
93 ]); | 93 ]); |
94 | 94 |
95 </script> | 95 </script> |
OLD | NEW |