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

Side by Side Diff: extensions/browser/api/declarative_webrequest/webrequest_condition_unittest.cc

Issue 1003953008: Remove prerender cookie store, part 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@prerender-revert-cookie-store-3
Patch Set: rebase (just in case since this is so huge) Created 5 years, 9 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_condition.h" 5 #include "extensions/browser/api/declarative_webrequest/webrequest_condition.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 &error); 73 &error);
74 EXPECT_EQ("", error); 74 EXPECT_EQ("", error);
75 ASSERT_TRUE(result.get()); 75 ASSERT_TRUE(result.get());
76 76
77 URLMatcherConditionSet::Vector url_matcher_condition_set; 77 URLMatcherConditionSet::Vector url_matcher_condition_set;
78 result->GetURLMatcherConditionSets(&url_matcher_condition_set); 78 result->GetURLMatcherConditionSets(&url_matcher_condition_set);
79 matcher.AddConditionSets(url_matcher_condition_set); 79 matcher.AddConditionSets(url_matcher_condition_set);
80 80
81 net::TestURLRequestContext context; 81 net::TestURLRequestContext context;
82 const GURL http_url("http://www.example.com"); 82 const GURL http_url("http://www.example.com");
83 scoped_ptr<net::URLRequest> match_request(context.CreateRequest( 83 scoped_ptr<net::URLRequest> match_request(
84 http_url, net::DEFAULT_PRIORITY, NULL, NULL)); 84 context.CreateRequest(http_url, net::DEFAULT_PRIORITY, NULL));
85 WebRequestData data(match_request.get(), ON_BEFORE_REQUEST); 85 WebRequestData data(match_request.get(), ON_BEFORE_REQUEST);
86 WebRequestDataWithMatchIds request_data(&data); 86 WebRequestDataWithMatchIds request_data(&data);
87 request_data.url_match_ids = matcher.MatchURL(http_url); 87 request_data.url_match_ids = matcher.MatchURL(http_url);
88 EXPECT_EQ(1u, request_data.url_match_ids.size()); 88 EXPECT_EQ(1u, request_data.url_match_ids.size());
89 content::ResourceRequestInfo::AllocateForTesting( 89 content::ResourceRequestInfo::AllocateForTesting(
90 match_request.get(), 90 match_request.get(),
91 content::RESOURCE_TYPE_MAIN_FRAME, 91 content::RESOURCE_TYPE_MAIN_FRAME,
92 NULL, // context 92 NULL, // context
93 -1, // render_process_id 93 -1, // render_process_id
94 -1, // render_view_id 94 -1, // render_view_id
95 -1, // render_frame_id 95 -1, // render_frame_id
96 true, // is_main_frame 96 true, // is_main_frame
97 false, // parent_is_main_frame 97 false, // parent_is_main_frame
98 true, // allow_download 98 true, // allow_download
99 false); // is_async 99 false); // is_async
100 EXPECT_TRUE(result->IsFulfilled(request_data)); 100 EXPECT_TRUE(result->IsFulfilled(request_data));
101 101
102 const GURL https_url("https://www.example.com"); 102 const GURL https_url("https://www.example.com");
103 scoped_ptr<net::URLRequest> wrong_resource_type(context.CreateRequest( 103 scoped_ptr<net::URLRequest> wrong_resource_type(
104 https_url, net::DEFAULT_PRIORITY, NULL, NULL)); 104 context.CreateRequest(https_url, net::DEFAULT_PRIORITY, NULL));
105 data.request = wrong_resource_type.get(); 105 data.request = wrong_resource_type.get();
106 request_data.url_match_ids = matcher.MatchURL(http_url); 106 request_data.url_match_ids = matcher.MatchURL(http_url);
107 // Make sure IsFulfilled does not fail because of URL matching. 107 // Make sure IsFulfilled does not fail because of URL matching.
108 EXPECT_EQ(1u, request_data.url_match_ids.size()); 108 EXPECT_EQ(1u, request_data.url_match_ids.size());
109 content::ResourceRequestInfo::AllocateForTesting( 109 content::ResourceRequestInfo::AllocateForTesting(
110 wrong_resource_type.get(), 110 wrong_resource_type.get(),
111 content::RESOURCE_TYPE_SUB_FRAME, 111 content::RESOURCE_TYPE_SUB_FRAME,
112 NULL, // context 112 NULL, // context
113 -1, // render_process_id 113 -1, // render_process_id
114 -1, // render_view_id 114 -1, // render_view_id
(...skipping 25 matching lines...) Expand all
140 EXPECT_EQ("", error); 140 EXPECT_EQ("", error);
141 ASSERT_TRUE(result.get()); 141 ASSERT_TRUE(result.get());
142 142
143 URLMatcherConditionSet::Vector url_matcher_condition_set; 143 URLMatcherConditionSet::Vector url_matcher_condition_set;
144 result->GetURLMatcherConditionSets(&url_matcher_condition_set); 144 result->GetURLMatcherConditionSets(&url_matcher_condition_set);
145 matcher.AddConditionSets(url_matcher_condition_set); 145 matcher.AddConditionSets(url_matcher_condition_set);
146 146
147 net::TestURLRequestContext context; 147 net::TestURLRequestContext context;
148 const GURL http_url("http://www.example.com"); 148 const GURL http_url("http://www.example.com");
149 const GURL first_party_url("http://fpfc.example.com"); 149 const GURL first_party_url("http://fpfc.example.com");
150 scoped_ptr<net::URLRequest> match_request(context.CreateRequest( 150 scoped_ptr<net::URLRequest> match_request(
151 http_url, net::DEFAULT_PRIORITY, NULL, NULL)); 151 context.CreateRequest(http_url, net::DEFAULT_PRIORITY, NULL));
152 WebRequestData data(match_request.get(), ON_BEFORE_REQUEST); 152 WebRequestData data(match_request.get(), ON_BEFORE_REQUEST);
153 WebRequestDataWithMatchIds request_data(&data); 153 WebRequestDataWithMatchIds request_data(&data);
154 request_data.url_match_ids = matcher.MatchURL(http_url); 154 request_data.url_match_ids = matcher.MatchURL(http_url);
155 EXPECT_EQ(0u, request_data.url_match_ids.size()); 155 EXPECT_EQ(0u, request_data.url_match_ids.size());
156 request_data.first_party_url_match_ids = matcher.MatchURL(first_party_url); 156 request_data.first_party_url_match_ids = matcher.MatchURL(first_party_url);
157 EXPECT_EQ(1u, request_data.first_party_url_match_ids.size()); 157 EXPECT_EQ(1u, request_data.first_party_url_match_ids.size());
158 content::ResourceRequestInfo::AllocateForTesting( 158 content::ResourceRequestInfo::AllocateForTesting(
159 match_request.get(), 159 match_request.get(),
160 content::RESOURCE_TYPE_MAIN_FRAME, 160 content::RESOURCE_TYPE_MAIN_FRAME,
161 NULL, // context 161 NULL, // context
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", " 223 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", "
224 "\n" 224 "\n"
225 " \"thirdPartyForCookies\": true, \n" 225 " \"thirdPartyForCookies\": true, \n"
226 "}"), 226 "}"),
227 &error); 227 &error);
228 EXPECT_EQ("", error); 228 EXPECT_EQ("", error);
229 ASSERT_TRUE(condition_no_url_false.get()); 229 ASSERT_TRUE(condition_no_url_false.get());
230 230
231 net::TestURLRequestContext context; 231 net::TestURLRequestContext context;
232 scoped_ptr<net::URLRequest> https_request(context.CreateRequest( 232 scoped_ptr<net::URLRequest> https_request(context.CreateRequest(
233 GURL("https://www.example.com"), net::DEFAULT_PRIORITY, NULL, NULL)); 233 GURL("https://www.example.com"), net::DEFAULT_PRIORITY, NULL));
234 234
235 // 1. A non-empty condition without UrlFilter attributes is fulfilled iff its 235 // 1. A non-empty condition without UrlFilter attributes is fulfilled iff its
236 // attributes are fulfilled. 236 // attributes are fulfilled.
237 WebRequestData data(https_request.get(), ON_BEFORE_REQUEST); 237 WebRequestData data(https_request.get(), ON_BEFORE_REQUEST);
238 EXPECT_FALSE( 238 EXPECT_FALSE(
239 condition_no_url_false->IsFulfilled(WebRequestDataWithMatchIds(&data))); 239 condition_no_url_false->IsFulfilled(WebRequestDataWithMatchIds(&data)));
240 240
241 data = WebRequestData(https_request.get(), ON_BEFORE_REQUEST); 241 data = WebRequestData(https_request.get(), ON_BEFORE_REQUEST);
242 EXPECT_TRUE( 242 EXPECT_TRUE(
243 condition_no_url_true->IsFulfilled(WebRequestDataWithMatchIds(&data))); 243 condition_no_url_true->IsFulfilled(WebRequestDataWithMatchIds(&data)));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 282
283 // Tell the URLMatcher about our shiny new patterns. 283 // Tell the URLMatcher about our shiny new patterns.
284 URLMatcherConditionSet::Vector url_matcher_condition_set; 284 URLMatcherConditionSet::Vector url_matcher_condition_set;
285 result->GetURLMatcherConditionSets(&url_matcher_condition_set); 285 result->GetURLMatcherConditionSets(&url_matcher_condition_set);
286 matcher.AddConditionSets(url_matcher_condition_set); 286 matcher.AddConditionSets(url_matcher_condition_set);
287 287
288 // Test that the result is correct and matches http://www.example.com and 288 // Test that the result is correct and matches http://www.example.com and
289 // https://www.example.com 289 // https://www.example.com
290 GURL http_url("http://www.example.com"); 290 GURL http_url("http://www.example.com");
291 net::TestURLRequestContext context; 291 net::TestURLRequestContext context;
292 scoped_ptr<net::URLRequest> http_request(context.CreateRequest( 292 scoped_ptr<net::URLRequest> http_request(
293 http_url, net::DEFAULT_PRIORITY, NULL, NULL)); 293 context.CreateRequest(http_url, net::DEFAULT_PRIORITY, NULL));
294 WebRequestData data(http_request.get(), ON_BEFORE_REQUEST); 294 WebRequestData data(http_request.get(), ON_BEFORE_REQUEST);
295 WebRequestDataWithMatchIds request_data(&data); 295 WebRequestDataWithMatchIds request_data(&data);
296 request_data.url_match_ids = matcher.MatchURL(http_url); 296 request_data.url_match_ids = matcher.MatchURL(http_url);
297 EXPECT_EQ(1u, request_data.url_match_ids.size()); 297 EXPECT_EQ(1u, request_data.url_match_ids.size());
298 EXPECT_TRUE(result->IsFulfilled(*(request_data.url_match_ids.begin()), 298 EXPECT_TRUE(result->IsFulfilled(*(request_data.url_match_ids.begin()),
299 request_data)); 299 request_data));
300 300
301 GURL https_url("https://www.example.com"); 301 GURL https_url("https://www.example.com");
302 request_data.url_match_ids = matcher.MatchURL(https_url); 302 request_data.url_match_ids = matcher.MatchURL(https_url);
303 EXPECT_EQ(1u, request_data.url_match_ids.size()); 303 EXPECT_EQ(1u, request_data.url_match_ids.size());
304 scoped_ptr<net::URLRequest> https_request(context.CreateRequest( 304 scoped_ptr<net::URLRequest> https_request(
305 https_url, net::DEFAULT_PRIORITY, NULL, NULL)); 305 context.CreateRequest(https_url, net::DEFAULT_PRIORITY, NULL));
306 data.request = https_request.get(); 306 data.request = https_request.get();
307 EXPECT_TRUE(result->IsFulfilled(*(request_data.url_match_ids.begin()), 307 EXPECT_TRUE(result->IsFulfilled(*(request_data.url_match_ids.begin()),
308 request_data)); 308 request_data));
309 309
310 // Check that both, hostPrefix and hostSuffix are evaluated. 310 // Check that both, hostPrefix and hostSuffix are evaluated.
311 GURL https_foo_url("https://foo.example.com"); 311 GURL https_foo_url("https://foo.example.com");
312 request_data.url_match_ids = matcher.MatchURL(https_foo_url); 312 request_data.url_match_ids = matcher.MatchURL(https_foo_url);
313 EXPECT_EQ(0u, request_data.url_match_ids.size()); 313 EXPECT_EQ(0u, request_data.url_match_ids.size());
314 scoped_ptr<net::URLRequest> https_foo_request(context.CreateRequest( 314 scoped_ptr<net::URLRequest> https_foo_request(
315 https_foo_url, net::DEFAULT_PRIORITY, NULL, NULL)); 315 context.CreateRequest(https_foo_url, net::DEFAULT_PRIORITY, NULL));
316 data.request = https_foo_request.get(); 316 data.request = https_foo_request.get();
317 EXPECT_FALSE(result->IsFulfilled(-1, request_data)); 317 EXPECT_FALSE(result->IsFulfilled(-1, request_data));
318 } 318 }
319 319
320 TEST(WebRequestConditionTest, TestPortFilter) { 320 TEST(WebRequestConditionTest, TestPortFilter) {
321 // Necessary for TestURLRequest. 321 // Necessary for TestURLRequest.
322 base::MessageLoopForIO message_loop; 322 base::MessageLoopForIO message_loop;
323 URLMatcher matcher; 323 URLMatcher matcher;
324 324
325 WebRequestConditionSet::AnyVector conditions; 325 WebRequestConditionSet::AnyVector conditions;
(...skipping 17 matching lines...) Expand all
343 // Tell the URLMatcher about our shiny new patterns. 343 // Tell the URLMatcher about our shiny new patterns.
344 URLMatcherConditionSet::Vector url_matcher_condition_set; 344 URLMatcherConditionSet::Vector url_matcher_condition_set;
345 result->GetURLMatcherConditionSets(&url_matcher_condition_set); 345 result->GetURLMatcherConditionSets(&url_matcher_condition_set);
346 matcher.AddConditionSets(url_matcher_condition_set); 346 matcher.AddConditionSets(url_matcher_condition_set);
347 347
348 std::set<URLMatcherConditionSet::ID> url_match_ids; 348 std::set<URLMatcherConditionSet::ID> url_match_ids;
349 349
350 // Test various URLs. 350 // Test various URLs.
351 GURL http_url("http://www.example.com"); 351 GURL http_url("http://www.example.com");
352 net::TestURLRequestContext context; 352 net::TestURLRequestContext context;
353 scoped_ptr<net::URLRequest> http_request(context.CreateRequest( 353 scoped_ptr<net::URLRequest> http_request(
354 http_url, net::DEFAULT_PRIORITY, NULL, NULL)); 354 context.CreateRequest(http_url, net::DEFAULT_PRIORITY, NULL));
355 url_match_ids = matcher.MatchURL(http_url); 355 url_match_ids = matcher.MatchURL(http_url);
356 ASSERT_EQ(1u, url_match_ids.size()); 356 ASSERT_EQ(1u, url_match_ids.size());
357 357
358 GURL http_url_80("http://www.example.com:80"); 358 GURL http_url_80("http://www.example.com:80");
359 scoped_ptr<net::URLRequest> http_request_80(context.CreateRequest( 359 scoped_ptr<net::URLRequest> http_request_80(
360 http_url_80, net::DEFAULT_PRIORITY, NULL, NULL)); 360 context.CreateRequest(http_url_80, net::DEFAULT_PRIORITY, NULL));
361 url_match_ids = matcher.MatchURL(http_url_80); 361 url_match_ids = matcher.MatchURL(http_url_80);
362 ASSERT_EQ(1u, url_match_ids.size()); 362 ASSERT_EQ(1u, url_match_ids.size());
363 363
364 GURL http_url_1000("http://www.example.com:1000"); 364 GURL http_url_1000("http://www.example.com:1000");
365 scoped_ptr<net::URLRequest> http_request_1000(context.CreateRequest( 365 scoped_ptr<net::URLRequest> http_request_1000(
366 http_url_1000, net::DEFAULT_PRIORITY, NULL, NULL)); 366 context.CreateRequest(http_url_1000, net::DEFAULT_PRIORITY, NULL));
367 url_match_ids = matcher.MatchURL(http_url_1000); 367 url_match_ids = matcher.MatchURL(http_url_1000);
368 ASSERT_EQ(1u, url_match_ids.size()); 368 ASSERT_EQ(1u, url_match_ids.size());
369 369
370 GURL http_url_2000("http://www.example.com:2000"); 370 GURL http_url_2000("http://www.example.com:2000");
371 scoped_ptr<net::URLRequest> http_request_2000(context.CreateRequest( 371 scoped_ptr<net::URLRequest> http_request_2000(
372 http_url_2000, net::DEFAULT_PRIORITY, NULL, NULL)); 372 context.CreateRequest(http_url_2000, net::DEFAULT_PRIORITY, NULL));
373 url_match_ids = matcher.MatchURL(http_url_2000); 373 url_match_ids = matcher.MatchURL(http_url_2000);
374 ASSERT_EQ(0u, url_match_ids.size()); 374 ASSERT_EQ(0u, url_match_ids.size());
375 } 375 }
376 376
377 // Create a condition with two attributes: one on the request header and one on 377 // Create a condition with two attributes: one on the request header and one on
378 // the response header. The Create() method should fail and complain that it is 378 // the response header. The Create() method should fail and complain that it is
379 // impossible that both conditions are fulfilled at the same time. 379 // impossible that both conditions are fulfilled at the same time.
380 TEST(WebRequestConditionTest, ConditionsWithConflictingStages) { 380 TEST(WebRequestConditionTest, ConditionsWithConflictingStages) {
381 // Necessary for TestURLRequest. 381 // Necessary for TestURLRequest.
382 base::MessageLoopForIO message_loop; 382 base::MessageLoopForIO message_loop;
(...skipping 14 matching lines...) Expand all
397 // filters. 397 // filters.
398 " \"requestHeaders\": [{}], \n" 398 " \"requestHeaders\": [{}], \n"
399 " \"responseHeaders\": [{}], \n" 399 " \"responseHeaders\": [{}], \n"
400 "}"), 400 "}"),
401 &error); 401 &error);
402 EXPECT_FALSE(error.empty()); 402 EXPECT_FALSE(error.empty());
403 EXPECT_FALSE(result.get()); 403 EXPECT_FALSE(result.get());
404 } 404 }
405 405
406 } // namespace extensions 406 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698