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

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

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

Powered by Google App Engine
This is Rietveld 408576698