Chromium Code Reviews
[email protected] (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: chrome/test/data/extensions/api_test/preference/onchange/test.js

Issue 10559052: Split mode incognito extension can get misleading pref changed events from regular mode (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Deleted commented-out lines in extension_preference_api.cc Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/data/extensions/api_test/preference/onchange/test.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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));
Bernhard Bauer 2012/06/20 20:55:27 Nit: Use single quotes (I realize we did this wron
30 });
31 }
32
23 var pw = chrome.privacy.websites; 33 var pw = chrome.privacy.websites;
24 chrome.test.runTests([ 34 chrome.test.runTests([
35 function openIncognito() {
Bernhard Bauer 2012/06/20 20:55:27 What is this for?
36 chrome.windows.create({incognito: true}, chrome.test.callbackPass());
37 },
25 function changeDefault() { 38 function changeDefault() {
26 // Changing the regular settings when no incognito-specific settings are 39 // Changing the regular settings when no incognito-specific settings are
27 // defined should fire two events. 40 // defined should fire two events.
28 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{ 41 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{
29 'value': false, 42 'value': false,
30 'levelOfControl': 'controlled_by_this_extension' 43 'levelOfControl': 'controlled_by_this_extension'
31 }, 44 },
32 { 45 {
33 'value': false, 46 'value': false,
34 'incognitoSpecific': false, 47 'incognitoSpecific': false,
35 'levelOfControl': 'controlled_by_this_extension' 48 'levelOfControl': 'controlled_by_this_extension'
36 }]); 49 }]);
37 pw.thirdPartyCookiesAllowed.set({ 50 pw.thirdPartyCookiesAllowed.set({
38 'value':false 51 'value': false
39 }, chrome.test.callbackPass()); 52 }, chrome.test.callbackPass());
40 }, 53 },
41 function changeIncognitoOnly() { 54 function changeIncognitoOnly() {
42 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{ 55 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{
43 'value': true, 56 'value': true,
44 'incognitoSpecific': true, 57 'incognitoSpecific': true,
45 'levelOfControl': 'controlled_by_this_extension' 58 'levelOfControl': 'controlled_by_this_extension'
46 }]); 59 }]);
60 var done = listenAndFailWhen(pw.thirdPartyCookiesAllowed.onChange, {
61 'value': true,
62 'levelOfControl': 'controlled_by_this_extension'
63 });
47 pw.thirdPartyCookiesAllowed.set({ 64 pw.thirdPartyCookiesAllowed.set({
48 'value': true, 65 'value': true,
49 'scope': 'incognito_persistent' 66 'scope': 'incognito_session_only'
50 }, chrome.test.callbackPass()); 67 }, done());
51 }, 68 },
52 function changeDefaultOnly() { 69 function changeDefaultOnly() {
53 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{ 70 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{
54 'value': true, 71 'value': true,
55 'levelOfControl': 'controlled_by_this_extension' 72 'levelOfControl': 'controlled_by_this_extension'
56 }]); 73 }]);
74 var done = listenAndFailWhen(pw.thirdPartyCookiesAllowed.onChange, {
75 'value': true,
76 'incognitoSpecific': true,
77 'levelOfControl': 'controlled_by_this_extension'
78 });
57 pw.thirdPartyCookiesAllowed.set({ 79 pw.thirdPartyCookiesAllowed.set({
58 'value': true 80 'value': true
59 }, chrome.test.callbackPass()); 81 }, done());
60 }, 82 },
61 function changeIncognitoOnlyBack() { 83 function changeIncognitoOnlyBack() {
62 // Change the incognito setting back to false so that we get an event when 84 // Change the incognito setting back to false so that we get an event when
63 // clearing the value. 85 // clearing the value.
64 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{ 86 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{
65 'value': false, 87 'value': false,
66 'incognitoSpecific': true, 88 'incognitoSpecific': true,
67 'levelOfControl': 'controlled_by_this_extension' 89 'levelOfControl': 'controlled_by_this_extension'
68 }]); 90 }]);
69 pw.thirdPartyCookiesAllowed.set({ 91 pw.thirdPartyCookiesAllowed.set({
70 'value': false, 92 'value': false,
71 'scope': 'incognito_persistent' 93 'scope': 'incognito_session_only'
72 }, chrome.test.callbackPass()); 94 }, chrome.test.callbackPass());
73 }, 95 },
74 function clearIncognito() { 96 function clearIncognito() {
75 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{ 97 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{
76 'value': true, 98 'value': true,
77 'incognitoSpecific': false, 99 'incognitoSpecific': false,
78 'levelOfControl': 'controlled_by_this_extension' 100 'levelOfControl': 'controlled_by_this_extension'
79 }]); 101 }]);
80 pw.thirdPartyCookiesAllowed.clear({ 102 pw.thirdPartyCookiesAllowed.clear({
81 'scope': 'incognito_persistent' 103 'scope': 'incognito_session_only'
82 }, chrome.test.callbackPass()); 104 }, chrome.test.callbackPass());
83 }, 105 },
84 function clearDefault() { 106 function clearDefault() {
85 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{ 107 listenUntil(pw.thirdPartyCookiesAllowed.onChange, [{
86 'value': true, 108 'value': true,
87 'levelOfControl': 'controllable_by_this_extension' 109 'levelOfControl': 'controllable_by_this_extension'
88 }, 110 },
89 { 111 {
90 'value': true, 112 'value': true,
91 'incognitoSpecific': false, 113 'incognitoSpecific': false,
92 'levelOfControl': 'controllable_by_this_extension' 114 'levelOfControl': 'controllable_by_this_extension'
93 }]); 115 }]);
94 pw.thirdPartyCookiesAllowed.clear({}, chrome.test.callbackPass()); 116 pw.thirdPartyCookiesAllowed.clear({}, chrome.test.callbackPass());
95 } 117 }
96 ]); 118 ]);
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/preference/onchange/test.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698