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

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

Issue 425653002: content: ResourceType cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: REBASE Created 6 years, 4 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 | Annotate | Revision Log
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 "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit ion.h" 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit ion.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/test/values_test_util.h" 10 #include "base/test/values_test_util.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 net::TestURLRequestContext context; 79 net::TestURLRequestContext context;
80 const GURL http_url("http://www.example.com"); 80 const GURL http_url("http://www.example.com");
81 net::TestURLRequest match_request( 81 net::TestURLRequest match_request(
82 http_url, net::DEFAULT_PRIORITY, NULL, &context); 82 http_url, net::DEFAULT_PRIORITY, NULL, &context);
83 WebRequestData data(&match_request, ON_BEFORE_REQUEST); 83 WebRequestData data(&match_request, ON_BEFORE_REQUEST);
84 WebRequestDataWithMatchIds request_data(&data); 84 WebRequestDataWithMatchIds request_data(&data);
85 request_data.url_match_ids = matcher.MatchURL(http_url); 85 request_data.url_match_ids = matcher.MatchURL(http_url);
86 EXPECT_EQ(1u, request_data.url_match_ids.size()); 86 EXPECT_EQ(1u, request_data.url_match_ids.size());
87 content::ResourceRequestInfo::AllocateForTesting( 87 content::ResourceRequestInfo::AllocateForTesting(
88 &match_request, ResourceType::MAIN_FRAME, NULL, -1, -1, -1, false); 88 &match_request,
89 content::RESOURCE_TYPE_MAIN_FRAME,
90 NULL,
91 -1,
92 -1,
93 -1,
94 false);
89 EXPECT_TRUE(result->IsFulfilled(request_data)); 95 EXPECT_TRUE(result->IsFulfilled(request_data));
90 96
91 const GURL https_url("https://www.example.com"); 97 const GURL https_url("https://www.example.com");
92 net::TestURLRequest wrong_resource_type( 98 net::TestURLRequest wrong_resource_type(
93 https_url, net::DEFAULT_PRIORITY, NULL, &context); 99 https_url, net::DEFAULT_PRIORITY, NULL, &context);
94 data.request = &wrong_resource_type; 100 data.request = &wrong_resource_type;
95 request_data.url_match_ids = matcher.MatchURL(http_url); 101 request_data.url_match_ids = matcher.MatchURL(http_url);
96 // Make sure IsFulfilled does not fail because of URL matching. 102 // Make sure IsFulfilled does not fail because of URL matching.
97 EXPECT_EQ(1u, request_data.url_match_ids.size()); 103 EXPECT_EQ(1u, request_data.url_match_ids.size());
98 content::ResourceRequestInfo::AllocateForTesting( 104 content::ResourceRequestInfo::AllocateForTesting(
99 &wrong_resource_type, ResourceType::SUB_FRAME, NULL, -1, -1, -1, false); 105 &wrong_resource_type,
106 content::RESOURCE_TYPE_SUB_FRAME,
107 NULL,
108 -1,
109 -1,
110 -1,
111 false);
100 EXPECT_FALSE(result->IsFulfilled(request_data)); 112 EXPECT_FALSE(result->IsFulfilled(request_data));
101 } 113 }
102 114
103 TEST(WebRequestConditionTest, CreateConditionFirstPartyForCookies) { 115 TEST(WebRequestConditionTest, CreateConditionFirstPartyForCookies) {
104 // Necessary for TestURLRequest. 116 // Necessary for TestURLRequest.
105 base::MessageLoopForIO message_loop; 117 base::MessageLoopForIO message_loop;
106 URLMatcher matcher; 118 URLMatcher matcher;
107 119
108 std::string error; 120 std::string error;
109 scoped_ptr<WebRequestCondition> result; 121 scoped_ptr<WebRequestCondition> result;
(...skipping 19 matching lines...) Expand all
129 const GURL first_party_url("http://fpfc.example.com"); 141 const GURL first_party_url("http://fpfc.example.com");
130 net::TestURLRequest match_request( 142 net::TestURLRequest match_request(
131 http_url, net::DEFAULT_PRIORITY, NULL, &context); 143 http_url, net::DEFAULT_PRIORITY, NULL, &context);
132 WebRequestData data(&match_request, ON_BEFORE_REQUEST); 144 WebRequestData data(&match_request, ON_BEFORE_REQUEST);
133 WebRequestDataWithMatchIds request_data(&data); 145 WebRequestDataWithMatchIds request_data(&data);
134 request_data.url_match_ids = matcher.MatchURL(http_url); 146 request_data.url_match_ids = matcher.MatchURL(http_url);
135 EXPECT_EQ(0u, request_data.url_match_ids.size()); 147 EXPECT_EQ(0u, request_data.url_match_ids.size());
136 request_data.first_party_url_match_ids = matcher.MatchURL(first_party_url); 148 request_data.first_party_url_match_ids = matcher.MatchURL(first_party_url);
137 EXPECT_EQ(1u, request_data.first_party_url_match_ids.size()); 149 EXPECT_EQ(1u, request_data.first_party_url_match_ids.size());
138 content::ResourceRequestInfo::AllocateForTesting( 150 content::ResourceRequestInfo::AllocateForTesting(
139 &match_request, ResourceType::MAIN_FRAME, NULL, -1, -1, -1, false); 151 &match_request,
152 content::RESOURCE_TYPE_MAIN_FRAME,
153 NULL,
154 -1,
155 -1,
156 -1,
157 false);
140 EXPECT_TRUE(result->IsFulfilled(request_data)); 158 EXPECT_TRUE(result->IsFulfilled(request_data));
141 } 159 }
142 160
143 // Conditions without UrlFilter attributes need to be independent of URL 161 // Conditions without UrlFilter attributes need to be independent of URL
144 // matching results. We test here that: 162 // matching results. We test here that:
145 // 1. A non-empty condition without UrlFilter attributes is fulfilled iff its 163 // 1. A non-empty condition without UrlFilter attributes is fulfilled iff its
146 // attributes are fulfilled. 164 // attributes are fulfilled.
147 // 2. An empty condition (in particular, without UrlFilter attributes) is 165 // 2. An empty condition (in particular, without UrlFilter attributes) is
148 // always fulfilled. 166 // always fulfilled.
149 TEST(WebRequestConditionTest, NoUrlAttributes) { 167 TEST(WebRequestConditionTest, NoUrlAttributes) {
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 // filters. 386 // filters.
369 " \"requestHeaders\": [{}], \n" 387 " \"requestHeaders\": [{}], \n"
370 " \"responseHeaders\": [{}], \n" 388 " \"responseHeaders\": [{}], \n"
371 "}"), 389 "}"),
372 &error); 390 &error);
373 EXPECT_FALSE(error.empty()); 391 EXPECT_FALSE(error.empty());
374 EXPECT_FALSE(result.get()); 392 EXPECT_FALSE(result.get());
375 } 393 }
376 394
377 } // namespace extensions 395 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698