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

Side by Side Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_action_unittest.cc

Issue 899983002: Revert of Introduce HostID and de-couple Extensions from "script injection System" [browser side] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 10 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
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 #include "extensions/browser/api/declarative_webrequest/webrequest_action.h" 5 #include "extensions/browser/api/declarative_webrequest/webrequest_action.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/json/json_file_value_serializer.h" 8 #include "base/json/json_file_value_serializer.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 ++it) { 51 ++it) {
52 const base::DictionaryValue* dict; 52 const base::DictionaryValue* dict;
53 CHECK((*it)->GetAsDictionary(&dict)); 53 CHECK((*it)->GetAsDictionary(&dict));
54 actions.push_back(linked_ptr<base::Value>(dict->DeepCopy())); 54 actions.push_back(linked_ptr<base::Value>(dict->DeepCopy()));
55 } 55 }
56 56
57 std::string error; 57 std::string error;
58 bool bad_message = false; 58 bool bad_message = false;
59 59
60 scoped_ptr<WebRequestActionSet> action_set( 60 scoped_ptr<WebRequestActionSet> action_set(
61 WebRequestActionSet::Create(NULL, HostID(), NULL, 61 WebRequestActionSet::Create(NULL, NULL, actions, &error, &bad_message));
62 actions, &error, &bad_message));
63 EXPECT_EQ("", error); 62 EXPECT_EQ("", error);
64 EXPECT_FALSE(bad_message); 63 EXPECT_FALSE(bad_message);
65 CHECK(action_set); 64 CHECK(action_set);
66 return action_set.Pass(); 65 return action_set.Pass();
67 } 66 }
68 67
69 } // namespace 68 } // namespace
70 69
71 namespace keys = declarative_webrequest_constants; 70 namespace keys = declarative_webrequest_constants;
72 71
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 180
182 TEST(WebRequestActionTest, CreateAction) { 181 TEST(WebRequestActionTest, CreateAction) {
183 std::string error; 182 std::string error;
184 bool bad_message = false; 183 bool bad_message = false;
185 scoped_refptr<const WebRequestAction> result; 184 scoped_refptr<const WebRequestAction> result;
186 185
187 // Test wrong data type passed. 186 // Test wrong data type passed.
188 error.clear(); 187 error.clear();
189 base::ListValue empty_list; 188 base::ListValue empty_list;
190 result = WebRequestAction::Create( 189 result = WebRequestAction::Create(
191 NULL, HostID(), NULL, empty_list, &error, &bad_message); 190 NULL, NULL, empty_list, &error, &bad_message);
192 EXPECT_TRUE(bad_message); 191 EXPECT_TRUE(bad_message);
193 EXPECT_FALSE(result.get()); 192 EXPECT_FALSE(result.get());
194 193
195 // Test missing instanceType element. 194 // Test missing instanceType element.
196 base::DictionaryValue input; 195 base::DictionaryValue input;
197 error.clear(); 196 error.clear();
198 result = WebRequestAction::Create( 197 result = WebRequestAction::Create(NULL, NULL, input, &error, &bad_message);
199 NULL, HostID(), NULL, input, &error, &bad_message);
200 EXPECT_TRUE(bad_message); 198 EXPECT_TRUE(bad_message);
201 EXPECT_FALSE(result.get()); 199 EXPECT_FALSE(result.get());
202 200
203 // Test wrong instanceType element. 201 // Test wrong instanceType element.
204 input.SetString(keys::kInstanceTypeKey, kUnknownActionType); 202 input.SetString(keys::kInstanceTypeKey, kUnknownActionType);
205 error.clear(); 203 error.clear();
206 result = WebRequestAction::Create( 204 result = WebRequestAction::Create(NULL, NULL, input, &error, &bad_message);
207 NULL, HostID(), NULL, input, &error, &bad_message);
208 EXPECT_NE("", error); 205 EXPECT_NE("", error);
209 EXPECT_FALSE(result.get()); 206 EXPECT_FALSE(result.get());
210 207
211 // Test success 208 // Test success
212 input.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType); 209 input.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType);
213 error.clear(); 210 error.clear();
214 result = WebRequestAction::Create( 211 result = WebRequestAction::Create(NULL, NULL, input, &error, &bad_message);
215 NULL, HostID(), NULL, input, &error, &bad_message);
216 EXPECT_EQ("", error); 212 EXPECT_EQ("", error);
217 EXPECT_FALSE(bad_message); 213 EXPECT_FALSE(bad_message);
218 ASSERT_TRUE(result.get()); 214 ASSERT_TRUE(result.get());
219 EXPECT_EQ(WebRequestAction::ACTION_CANCEL_REQUEST, result->type()); 215 EXPECT_EQ(WebRequestAction::ACTION_CANCEL_REQUEST, result->type());
220 } 216 }
221 217
222 TEST(WebRequestActionTest, CreateActionSet) { 218 TEST(WebRequestActionTest, CreateActionSet) {
223 std::string error; 219 std::string error;
224 bool bad_message = false; 220 bool bad_message = false;
225 scoped_ptr<WebRequestActionSet> result; 221 scoped_ptr<WebRequestActionSet> result;
226 222
227 WebRequestActionSet::AnyVector input; 223 WebRequestActionSet::AnyVector input;
228 224
229 // Test empty input. 225 // Test empty input.
230 error.clear(); 226 error.clear();
231 result = WebRequestActionSet::Create( 227 result = WebRequestActionSet::Create(NULL, NULL, input, &error, &bad_message);
232 NULL, HostID(), NULL, input, &error, &bad_message);
233 EXPECT_TRUE(error.empty()) << error; 228 EXPECT_TRUE(error.empty()) << error;
234 EXPECT_FALSE(bad_message); 229 EXPECT_FALSE(bad_message);
235 ASSERT_TRUE(result.get()); 230 ASSERT_TRUE(result.get());
236 EXPECT_TRUE(result->actions().empty()); 231 EXPECT_TRUE(result->actions().empty());
237 EXPECT_EQ(std::numeric_limits<int>::min(), result->GetMinimumPriority()); 232 EXPECT_EQ(std::numeric_limits<int>::min(), result->GetMinimumPriority());
238 233
239 base::DictionaryValue correct_action; 234 base::DictionaryValue correct_action;
240 correct_action.SetString(keys::kInstanceTypeKey, keys::kIgnoreRulesType); 235 correct_action.SetString(keys::kInstanceTypeKey, keys::kIgnoreRulesType);
241 correct_action.SetInteger(keys::kLowerPriorityThanKey, 10); 236 correct_action.SetInteger(keys::kLowerPriorityThanKey, 10);
242 base::DictionaryValue incorrect_action; 237 base::DictionaryValue incorrect_action;
243 incorrect_action.SetString(keys::kInstanceTypeKey, kUnknownActionType); 238 incorrect_action.SetString(keys::kInstanceTypeKey, kUnknownActionType);
244 239
245 // Test success. 240 // Test success.
246 input.push_back(linked_ptr<base::Value>(correct_action.DeepCopy())); 241 input.push_back(linked_ptr<base::Value>(correct_action.DeepCopy()));
247 error.clear(); 242 error.clear();
248 result = WebRequestActionSet::Create( 243 result = WebRequestActionSet::Create(NULL, NULL, input, &error, &bad_message);
249 NULL, HostID(), NULL, input, &error, &bad_message);
250 EXPECT_TRUE(error.empty()) << error; 244 EXPECT_TRUE(error.empty()) << error;
251 EXPECT_FALSE(bad_message); 245 EXPECT_FALSE(bad_message);
252 ASSERT_TRUE(result.get()); 246 ASSERT_TRUE(result.get());
253 ASSERT_EQ(1u, result->actions().size()); 247 ASSERT_EQ(1u, result->actions().size());
254 EXPECT_EQ(WebRequestAction::ACTION_IGNORE_RULES, 248 EXPECT_EQ(WebRequestAction::ACTION_IGNORE_RULES,
255 result->actions()[0]->type()); 249 result->actions()[0]->type());
256 EXPECT_EQ(10, result->GetMinimumPriority()); 250 EXPECT_EQ(10, result->GetMinimumPriority());
257 251
258 // Test failure. 252 // Test failure.
259 input.push_back(linked_ptr<base::Value>(incorrect_action.DeepCopy())); 253 input.push_back(linked_ptr<base::Value>(incorrect_action.DeepCopy()));
260 error.clear(); 254 error.clear();
261 result = WebRequestActionSet::Create( 255 result = WebRequestActionSet::Create(NULL, NULL, input, &error, &bad_message);
262 NULL, HostID(), NULL, input, &error, &bad_message);
263 EXPECT_NE("", error); 256 EXPECT_NE("", error);
264 EXPECT_FALSE(result.get()); 257 EXPECT_FALSE(result.get());
265 } 258 }
266 259
267 // Test capture group syntax conversions of WebRequestRedirectByRegExAction 260 // Test capture group syntax conversions of WebRequestRedirectByRegExAction
268 TEST(WebRequestActionTest, PerlToRe2Style) { 261 TEST(WebRequestActionTest, PerlToRe2Style) {
269 #define CallPerlToRe2Style WebRequestRedirectByRegExAction::PerlToRe2Style 262 #define CallPerlToRe2Style WebRequestRedirectByRegExAction::PerlToRe2Style
270 // foo$1bar -> foo\1bar 263 // foo$1bar -> foo\1bar
271 EXPECT_EQ("foo\\1bar", CallPerlToRe2Style("foo$1bar")); 264 EXPECT_EQ("foo\\1bar", CallPerlToRe2Style("foo$1bar"));
272 // foo\$1bar -> foo$1bar 265 // foo\$1bar -> foo$1bar
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 for (WebRequestActionSet::Actions::const_iterator it = 582 for (WebRequestActionSet::Actions::const_iterator it =
590 action_set->actions().begin(); 583 action_set->actions().begin();
591 it != action_set->actions().end(); 584 it != action_set->actions().end();
592 ++it) { 585 ++it) {
593 EXPECT_EQ(kExpectedNames[index], (*it)->GetName()); 586 EXPECT_EQ(kExpectedNames[index], (*it)->GetName());
594 ++index; 587 ++index;
595 } 588 }
596 } 589 }
597 590
598 } // namespace extensions 591 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698