Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: chrome/test/data/extensions/api_test/declarative/api/background.js

Issue 2940133002: [Extensions] Update DeclarativeApiTest.DeclarativeApi (Closed)
Patch Set: Created 3 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 | « no previous file | 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 var declarative = chrome.declarative; 5 var declarative = chrome.declarative;
6 6
7 var RequestMatcher = chrome.declarativeWebRequest.RequestMatcher; 7 var RequestMatcher = chrome.declarativeWebRequest.RequestMatcher;
8 var CancelRequest = chrome.declarativeWebRequest.CancelRequest; 8 var CancelRequest = chrome.declarativeWebRequest.CancelRequest;
9 var RedirectRequest = chrome.declarativeWebRequest.RedirectRequest; 9 var RedirectRequest = chrome.declarativeWebRequest.RedirectRequest;
10 var SetRequestHeader = chrome.declarativeWebRequest.SetRequestHeader; 10 var SetRequestHeader = chrome.declarativeWebRequest.SetRequestHeader;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 function testInvalidAddRules() { 73 function testInvalidAddRules() {
74 try { 74 try {
75 testEvent.addRules(); 75 testEvent.addRules();
76 chrome.test.fail(); 76 chrome.test.fail();
77 } catch(e) { 77 } catch(e) {
78 chrome.test.succeed(); 78 chrome.test.succeed();
79 } 79 }
80 }, 80 },
81 function testInvalidGetRules() { 81 function testInvalidGetRules() {
82 try { 82 try {
83 testEvent.getRules(function() {}); 83 testEvent.getRules(1, function() {});
84 chrome.test.fail(); 84 chrome.test.fail();
85 } catch(e) { 85 } catch(e) {
86 chrome.test.succeed(); 86 chrome.test.succeed();
87 } 87 }
88 }, 88 },
89 function testInvalidRemoveRules() { 89 function testInvalidRemoveRules() {
90 try { 90 try {
91 testEvent.removeRules(function() {}); 91 testEvent.removeRules(1, function() {});
92 chrome.test.fail(); 92 chrome.test.fail();
93 } catch(e) { 93 } catch(e) {
94 chrome.test.succeed(); 94 chrome.test.succeed();
95 } 95 }
96 }, 96 },
97 // Add adding two simple rules and check that their optional fields are set 97 // Add adding two simple rules and check that their optional fields are set
98 // correctly in the call back function. 98 // correctly in the call back function.
99 function testAddRules() { 99 function testAddRules() {
100 var callback = function(rules) { 100 var callback = function(rules) {
101 chrome.test.assertNoLastError(); 101 chrome.test.assertNoLastError();
102 chrome.test.assertEq(2, rules.length); 102 chrome.test.assertEq(2, rules.length);
103 // API should have generated id and priority fields. 103 // API should have generated id and priority fields.
104 chrome.test.assertTrue("id" in rules[0]); 104 chrome.test.assertTrue("id" in rules[0]);
105 chrome.test.assertEq([outputRule0, outputRule1], rules); 105 chrome.test.assertEq([outputRule0, outputRule1], rules);
106 chrome.test.succeed(); 106 chrome.test.succeed();
107 }; 107 };
108 testEvent.addRules([inputRule0, inputRule1], callback); 108 testEvent.addRules([inputRule0, inputRule1], callback);
109 }, 109 },
110 // Check that getRules() returns all rules if no filter is passed. 110 // Check that getRules() returns all rules if no filter is passed.
111 function testGetRules() { 111 function testGetRules() {
112 var callback = function(rules) { 112 var callback = function(rules) {
113 chrome.test.assertNoLastError(); 113 chrome.test.assertNoLastError();
114 // We are not given any gurantee on the order in which rules are returned. 114 // We are not given any gurantee on the order in which rules are returned.
115 chrome.test.assertTrue( 115 chrome.test.assertTrue(
116 chrome.test.checkDeepEq([outputRule0, outputRule1], rules) || 116 chrome.test.checkDeepEq([outputRule0, outputRule1], rules) ||
117 chrome.test.checkDeepEq([outputRule1, outputRule0], rules)); 117 chrome.test.checkDeepEq([outputRule1, outputRule0], rules));
118 chrome.test.succeed(); 118 chrome.test.succeed();
119 } 119 }
120 testEvent.getRules(null, callback); 120 testEvent.getRules(null, callback);
121 }, 121 },
122 // Check that getRules() returns all rules if no filter is passed. 122 // Check that getRules() returns all rules if no filter is passed.
123 function testGetRules2() { 123 function testGetRules2() {
124 var callback = function(rules) { 124 var callback = function(rules) {
125 chrome.test.assertNoLastError(); 125 chrome.test.assertNoLastError();
126 // We are not given any gurantee on the order in which rules are returned. 126 // We are not given any gurantee on the order in which rules are returned.
127 chrome.test.assertTrue( 127 chrome.test.assertTrue(
128 chrome.test.checkDeepEq([outputRule0, outputRule1], rules) || 128 chrome.test.checkDeepEq([outputRule0, outputRule1], rules) ||
129 chrome.test.checkDeepEq([outputRule1, outputRule0], rules)); 129 chrome.test.checkDeepEq([outputRule1, outputRule0], rules));
130 chrome.test.succeed(); 130 chrome.test.succeed();
131 } 131 }
132 testEvent.getRules(undefined, callback); 132 testEvent.getRules(undefined, callback);
133 }, 133 },
134 // Check that getRules() returns no rules if empty filter is passed. 134 // Check that getRules() returns no rules if empty filter is passed.
135 function testGetRules3() { 135 function testGetRules3() {
136 var callback = function(rules) { 136 var callback = function(rules) {
137 chrome.test.assertNoLastError(); 137 chrome.test.assertNoLastError();
138 // We are not given any gurantee on the order in which rules are returned.
139 chrome.test.assertEq([], rules); 138 chrome.test.assertEq([], rules);
140 chrome.test.succeed(); 139 chrome.test.succeed();
141 } 140 }
142 testEvent.getRules([], callback); 141 testEvent.getRules([], callback);
143 }, 142 },
144 // Check that getRules() returns all rules if rules are filtered by ID. 143 // TODO(devlin): The documentation for event.getRules() states that the
144 // filter parameter is optional. However, with JS bindings, we throw an error
145 // if it's omitted. This is fixed with native bindings.
146 // Check that getRules() returns all rules if the filter is omitted.
147 // function testGetRules4() {
148 // var callback = function(rules) {
149 // chrome.test.assertNoLastError();
150 // // We are not given any gurantee on the order in which rules are
151 // // returned.
152 // chrome.test.assertTrue(
153 // chrome.test.checkDeepEq([outputRule0, outputRule1], rules) ||
154 // chrome.test.checkDeepEq([outputRule1, outputRule0], rules));
155 // chrome.test.succeed();
156 // }
157 // testEvent.getRules(callback);
158 // },
159 // Check that getRules() returns matching rules if rules are filtered by ID.
145 function testSelectiveGetRules() { 160 function testSelectiveGetRules() {
146 var callback = function(rules) { 161 var callback = function(rules) {
147 chrome.test.assertNoLastError(); 162 chrome.test.assertNoLastError();
148 chrome.test.assertEq([outputRule1], rules); 163 chrome.test.assertEq([outputRule1], rules);
149 chrome.test.succeed(); 164 chrome.test.succeed();
150 } 165 }
151 testEvent.getRules(["my_rule_id"], callback); 166 testEvent.getRules(["my_rule_id"], callback);
152 }, 167 },
153 // Check that we can remove individual rules. 168 // Check that we can remove individual rules.
154 function testSelectiveRemoveRules() { 169 function testSelectiveRemoveRules() {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // on page unload. 245 // on page unload.
231 function testAddRules() { 246 function testAddRules() {
232 var callback = function(rules) { 247 var callback = function(rules) {
233 chrome.test.assertNoLastError(); 248 chrome.test.assertNoLastError();
234 chrome.test.assertEq(1, rules.length); 249 chrome.test.assertEq(1, rules.length);
235 chrome.test.succeed(); 250 chrome.test.succeed();
236 }; 251 };
237 testEvent.addRules([inputRule0], callback); 252 testEvent.addRules([inputRule0], callback);
238 }, 253 },
239 ]); 254 ]);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698