Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Content settings API test | 5 // Content settings API test |
| 6 // Run with browser_tests --gtest_filter=ExtensionApiTest.PreferenceOnChange | 6 // Run with browser_tests --gtest_filter=ExtensionApiTest.PreferenceOnChange |
| 7 | 7 |
| 8 // Listen until |event| has fired with all of the values in |expected|. | 8 // Listen until |event| has fired with all of the values in |expected|. |
| 9 function listenUntil(event, expected) { | 9 function listenUntil(event, expected) { |
| 10 var done = chrome.test.listenForever(event, function(value) { | 10 var done = chrome.test.listenForever(event, function(value) { |
| 11 for (var i = 0; i < expected.length; i++) { | 11 for (var i = 0; i < expected.length; i++) { |
| 12 if (chrome.test.checkDeepEq(expected[i], value)) { | 12 if (chrome.test.checkDeepEq(expected[i], value)) { |
| 13 expected.splice(i, 1); | 13 expected.splice(i, 1); |
| 14 if (expected.length == 0) | 14 if (expected.length == 0) |
| 15 done(); | 15 done(); |
| 16 return; | 16 return; |
| 17 } | 17 } |
| 18 } | 18 } |
| 19 chrome.test.fail("Unexpected event: " + JSON.stringify(value)); | 19 chrome.test.fail("Unexpected event: " + JSON.stringify(value)); |
| 20 }); | 20 }); |
| 21 } | 21 } |
| 22 | 22 |
| 23 // Fail if |event| is fired with |expected|. Because listenUntil stops listening | |
| 24 // when |event| has fired with all the values in |expected|, it may not capture | |
| 25 // superfluous unexpected events. | |
| 26 function listenAndFailWhen(event, expected) { | |
| 27 return chrome.test.listenForever(event, function(value) { | |
| 28 if (chrome.test.checkDeepEq(expected, value)) | |
| 29 chrome.test.fail("Unexpected event: " + JSON.stringify(value)); | |
| 30 }); | |
| 31 } | |
| 32 | |
| 23 var pw = chrome.privacy.websites; | 33 var pw = chrome.privacy.websites; |
| 24 chrome.test.runTests([ | 34 chrome.test.runTests([ |
| 25 function changeDefault() { | 35 function changeDefault() { |
| 26 // Changing the regular settings when no incognito-specific settings are | 36 // Changing the regular settings when no incognito-specific settings are |
| 27 // defined should fire two events. | 37 // defined should fire two events. |
| 28 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{ | 38 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{ |
| 29 'value': false, | 39 'value': false, |
| 30 'levelOfControl': 'controlled_by_this_extension' | 40 'levelOfControl': 'controlled_by_this_extension' |
| 31 }, | 41 }, |
| 32 { | 42 { |
| 33 'value': false, | 43 'value': false, |
| 34 'incognitoSpecific': false, | 44 'incognitoSpecific': false, |
| 35 'levelOfControl': 'controlled_by_this_extension' | 45 'levelOfControl': 'controlled_by_this_extension' |
| 36 }]); | 46 }]); |
| 37 pw.thirdPartyCookiesAllowed.set({ | 47 pw.thirdPartyCookiesAllowed.set({ |
| 38 'value':false | 48 'value': false |
| 39 }, chrome.test.callbackPass()); | 49 }, chrome.test.callbackPass()); |
| 40 }, | 50 }, |
| 41 function changeIncognitoOnly() { | 51 function changeIncognitoOnly() { |
| 42 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{ | 52 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{ |
| 43 'value': true, | 53 'value': true, |
| 44 'incognitoSpecific': true, | 54 'incognitoSpecific': true, |
| 45 'levelOfControl': 'controlled_by_this_extension' | 55 'levelOfControl': 'controlled_by_this_extension' |
| 46 }]); | 56 }]); |
| 57 var done = listenAndFailWhen(pw.thirdPartyCookiesAllowed.onChange, { | |
| 58 'value': true, | |
| 59 'levelOfControl': 'controlled_by_this_extension' | |
| 60 }); | |
| 47 pw.thirdPartyCookiesAllowed.set({ | 61 pw.thirdPartyCookiesAllowed.set({ |
|
Bernhard Bauer
2012/06/20 18:55:36
The problem is that pw.thirdPartyCookiesAllowed.se
| |
| 48 'value': true, | 62 'value': true, |
| 49 'scope': 'incognito_persistent' | 63 'scope': 'incognito_persistent' |
| 50 }, chrome.test.callbackPass()); | 64 }, chrome.test.callbackPass()); |
| 65 done(); | |
| 51 }, | 66 }, |
| 52 function changeDefaultOnly() { | 67 function changeDefaultOnly() { |
| 53 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{ | 68 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{ |
| 54 'value': true, | 69 'value': true, |
| 55 'levelOfControl': 'controlled_by_this_extension' | 70 'levelOfControl': 'controlled_by_this_extension' |
| 56 }]); | 71 }]); |
| 72 var done = listenAndFailWhen(pw.thirdPartyCookiesAllowed.onChange, { | |
| 73 'value': true, | |
| 74 'incognitoSpecific': true, | |
| 75 'levelOfControl': 'controlled_by_this_extension' | |
| 76 }); | |
| 57 pw.thirdPartyCookiesAllowed.set({ | 77 pw.thirdPartyCookiesAllowed.set({ |
| 58 'value': true | 78 'value': true |
| 59 }, chrome.test.callbackPass()); | 79 }, chrome.test.callbackPass()); |
| 80 done(); | |
| 60 }, | 81 }, |
| 61 function changeIncognitoOnlyBack() { | 82 function changeIncognitoOnlyBack() { |
| 62 // Change the incognito setting back to false so that we get an event when | 83 // Change the incognito setting back to false so that we get an event when |
| 63 // clearing the value. | 84 // clearing the value. |
| 64 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{ | 85 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{ |
| 65 'value': false, | 86 'value': false, |
| 66 'incognitoSpecific': true, | 87 'incognitoSpecific': true, |
| 67 'levelOfControl': 'controlled_by_this_extension' | 88 'levelOfControl': 'controlled_by_this_extension' |
| 68 }]); | 89 }]); |
| 69 pw.thirdPartyCookiesAllowed.set({ | 90 pw.thirdPartyCookiesAllowed.set({ |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 87 'levelOfControl': 'controllable_by_this_extension' | 108 'levelOfControl': 'controllable_by_this_extension' |
| 88 }, | 109 }, |
| 89 { | 110 { |
| 90 'value': true, | 111 'value': true, |
| 91 'incognitoSpecific': false, | 112 'incognitoSpecific': false, |
| 92 'levelOfControl': 'controllable_by_this_extension' | 113 'levelOfControl': 'controllable_by_this_extension' |
| 93 }]); | 114 }]); |
| 94 pw.thirdPartyCookiesAllowed.clear({}, chrome.test.callbackPass()); | 115 pw.thirdPartyCookiesAllowed.clear({}, chrome.test.callbackPass()); |
| 95 } | 116 } |
| 96 ]); | 117 ]); |
| OLD | NEW |