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

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

Issue 11365227: Reland 167337 - Move url_request_test_util into net namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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.h" 9 #include "base/message_loop.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 EXPECT_FALSE(error.empty()); 62 EXPECT_FALSE(error.empty());
63 EXPECT_FALSE(result.get()); 63 EXPECT_FALSE(result.get());
64 64
65 // Test success (can we support multiple criteria?) 65 // Test success (can we support multiple criteria?)
66 error.clear(); 66 error.clear();
67 result = WebRequestCondition::Create(matcher.condition_factory(), 67 result = WebRequestCondition::Create(matcher.condition_factory(),
68 valid_condition, &error); 68 valid_condition, &error);
69 EXPECT_EQ("", error); 69 EXPECT_EQ("", error);
70 ASSERT_TRUE(result.get()); 70 ASSERT_TRUE(result.get());
71 71
72 TestURLRequestContext context; 72 net::TestURLRequestContext context;
73 TestURLRequest match_request(GURL("http://www.example.com"), NULL, &context); 73 net::TestURLRequest match_request(
74 GURL("http://www.example.com"), NULL, &context);
74 content::ResourceRequestInfo::AllocateForTesting(&match_request, 75 content::ResourceRequestInfo::AllocateForTesting(&match_request,
75 ResourceType::MAIN_FRAME, NULL, -1, -1); 76 ResourceType::MAIN_FRAME, NULL, -1, -1);
76 EXPECT_TRUE(result->IsFulfilled( 77 EXPECT_TRUE(result->IsFulfilled(
77 WebRequestRule::RequestData(&match_request, ON_BEFORE_REQUEST))); 78 WebRequestRule::RequestData(&match_request, ON_BEFORE_REQUEST)));
78 79
79 TestURLRequest wrong_resource_type( 80 net::TestURLRequest wrong_resource_type(
80 GURL("https://www.example.com"), NULL, &context); 81 GURL("https://www.example.com"), NULL, &context);
81 content::ResourceRequestInfo::AllocateForTesting(&wrong_resource_type, 82 content::ResourceRequestInfo::AllocateForTesting(&wrong_resource_type,
82 ResourceType::SUB_FRAME, NULL, -1, -1); 83 ResourceType::SUB_FRAME, NULL, -1, -1);
83 EXPECT_FALSE(result->IsFulfilled( 84 EXPECT_FALSE(result->IsFulfilled(
84 WebRequestRule::RequestData(&wrong_resource_type, ON_BEFORE_REQUEST))); 85 WebRequestRule::RequestData(&wrong_resource_type, ON_BEFORE_REQUEST)));
85 } 86 }
86 87
87 TEST(WebRequestConditionTest, CreateConditionSet) { 88 TEST(WebRequestConditionTest, CreateConditionSet) {
88 // Necessary for TestURLRequest. 89 // Necessary for TestURLRequest.
89 MessageLoop message_loop(MessageLoop::TYPE_IO); 90 MessageLoop message_loop(MessageLoop::TYPE_IO);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 URLMatcherConditionSet::Vector url_matcher_condition_set; 134 URLMatcherConditionSet::Vector url_matcher_condition_set;
134 result->GetURLMatcherConditionSets(&url_matcher_condition_set); 135 result->GetURLMatcherConditionSets(&url_matcher_condition_set);
135 matcher.AddConditionSets(url_matcher_condition_set); 136 matcher.AddConditionSets(url_matcher_condition_set);
136 137
137 std::set<URLMatcherConditionSet::ID> url_match_ids; 138 std::set<URLMatcherConditionSet::ID> url_match_ids;
138 int number_matches = 0; 139 int number_matches = 0;
139 140
140 // Test that the result is correct and matches http://www.example.com and 141 // Test that the result is correct and matches http://www.example.com and
141 // https://www.example.com 142 // https://www.example.com
142 GURL http_url("http://www.example.com"); 143 GURL http_url("http://www.example.com");
143 TestURLRequestContext context; 144 net::TestURLRequestContext context;
144 TestURLRequest http_request(http_url, NULL, &context); 145 net::TestURLRequest http_request(http_url, NULL, &context);
145 url_match_ids = matcher.MatchURL(http_url); 146 url_match_ids = matcher.MatchURL(http_url);
146 for (std::set<URLMatcherConditionSet::ID>::iterator i = url_match_ids.begin(); 147 for (std::set<URLMatcherConditionSet::ID>::iterator i = url_match_ids.begin();
147 i != url_match_ids.end(); ++i) { 148 i != url_match_ids.end(); ++i) {
148 if (result->IsFulfilled( 149 if (result->IsFulfilled(
149 *i, WebRequestRule::RequestData(&http_request, ON_BEFORE_REQUEST))) 150 *i, WebRequestRule::RequestData(&http_request, ON_BEFORE_REQUEST)))
150 ++number_matches; 151 ++number_matches;
151 } 152 }
152 EXPECT_EQ(1, number_matches); 153 EXPECT_EQ(1, number_matches);
153 154
154 GURL https_url("https://www.example.com"); 155 GURL https_url("https://www.example.com");
155 url_match_ids = matcher.MatchURL(https_url); 156 url_match_ids = matcher.MatchURL(https_url);
156 TestURLRequest https_request(https_url, NULL, &context); 157 net::TestURLRequest https_request(https_url, NULL, &context);
157 number_matches = 0; 158 number_matches = 0;
158 for (std::set<URLMatcherConditionSet::ID>::iterator i = url_match_ids.begin(); 159 for (std::set<URLMatcherConditionSet::ID>::iterator i = url_match_ids.begin();
159 i != url_match_ids.end(); ++i) { 160 i != url_match_ids.end(); ++i) {
160 if (result->IsFulfilled( 161 if (result->IsFulfilled(
161 *i, WebRequestRule::RequestData(&https_request, ON_BEFORE_REQUEST))) 162 *i, WebRequestRule::RequestData(&https_request, ON_BEFORE_REQUEST)))
162 ++number_matches; 163 ++number_matches;
163 } 164 }
164 EXPECT_EQ(1, number_matches); 165 EXPECT_EQ(1, number_matches);
165 166
166 // Check that both, hostPrefix and hostSuffix are evaluated. 167 // Check that both, hostPrefix and hostSuffix are evaluated.
167 GURL https_foo_url("https://foo.example.com"); 168 GURL https_foo_url("https://foo.example.com");
168 url_match_ids = matcher.MatchURL(https_foo_url); 169 url_match_ids = matcher.MatchURL(https_foo_url);
169 TestURLRequest https_foo_request(https_foo_url, NULL, &context); 170 net::TestURLRequest https_foo_request(https_foo_url, NULL, &context);
170 number_matches = 0; 171 number_matches = 0;
171 for (std::set<URLMatcherConditionSet::ID>::iterator i = url_match_ids.begin(); 172 for (std::set<URLMatcherConditionSet::ID>::iterator i = url_match_ids.begin();
172 i != url_match_ids.end(); ++i) { 173 i != url_match_ids.end(); ++i) {
173 if (result->IsFulfilled( 174 if (result->IsFulfilled(
174 *i, WebRequestRule::RequestData( 175 *i, WebRequestRule::RequestData(
175 &https_foo_request, ON_BEFORE_REQUEST))) 176 &https_foo_request, ON_BEFORE_REQUEST)))
176 ++number_matches; 177 ++number_matches;
177 } 178 }
178 EXPECT_EQ(0, number_matches); 179 EXPECT_EQ(0, number_matches);
179 } 180 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 217
217 // Tell the URLMatcher about our shiny new patterns. 218 // Tell the URLMatcher about our shiny new patterns.
218 URLMatcherConditionSet::Vector url_matcher_condition_set; 219 URLMatcherConditionSet::Vector url_matcher_condition_set;
219 result->GetURLMatcherConditionSets(&url_matcher_condition_set); 220 result->GetURLMatcherConditionSets(&url_matcher_condition_set);
220 matcher.AddConditionSets(url_matcher_condition_set); 221 matcher.AddConditionSets(url_matcher_condition_set);
221 222
222 std::set<URLMatcherConditionSet::ID> url_match_ids; 223 std::set<URLMatcherConditionSet::ID> url_match_ids;
223 224
224 // Test various URLs. 225 // Test various URLs.
225 GURL http_url("http://www.example.com"); 226 GURL http_url("http://www.example.com");
226 TestURLRequestContext context; 227 net::TestURLRequestContext context;
227 TestURLRequest http_request(http_url, NULL, &context); 228 net::TestURLRequest http_request(http_url, NULL, &context);
228 url_match_ids = matcher.MatchURL(http_url); 229 url_match_ids = matcher.MatchURL(http_url);
229 ASSERT_EQ(1u, url_match_ids.size()); 230 ASSERT_EQ(1u, url_match_ids.size());
230 231
231 GURL http_url_80("http://www.example.com:80"); 232 GURL http_url_80("http://www.example.com:80");
232 TestURLRequest http_request_80(http_url_80, NULL, &context); 233 net::TestURLRequest http_request_80(http_url_80, NULL, &context);
233 url_match_ids = matcher.MatchURL(http_url_80); 234 url_match_ids = matcher.MatchURL(http_url_80);
234 ASSERT_EQ(1u, url_match_ids.size()); 235 ASSERT_EQ(1u, url_match_ids.size());
235 236
236 GURL http_url_1000("http://www.example.com:1000"); 237 GURL http_url_1000("http://www.example.com:1000");
237 TestURLRequest http_request_1000(http_url_1000, NULL, &context); 238 net::TestURLRequest http_request_1000(http_url_1000, NULL, &context);
238 url_match_ids = matcher.MatchURL(http_url_1000); 239 url_match_ids = matcher.MatchURL(http_url_1000);
239 ASSERT_EQ(1u, url_match_ids.size()); 240 ASSERT_EQ(1u, url_match_ids.size());
240 241
241 GURL http_url_2000("http://www.example.com:2000"); 242 GURL http_url_2000("http://www.example.com:2000");
242 TestURLRequest http_request_2000(http_url_2000, NULL, &context); 243 net::TestURLRequest http_request_2000(http_url_2000, NULL, &context);
243 url_match_ids = matcher.MatchURL(http_url_2000); 244 url_match_ids = matcher.MatchURL(http_url_2000);
244 ASSERT_EQ(0u, url_match_ids.size()); 245 ASSERT_EQ(0u, url_match_ids.size());
245 } 246 }
246 247
247 // Create a condition with two attributes: one on the request header and one on 248 // Create a condition with two attributes: one on the request header and one on
248 // the response header. The Create() method should fail and complain that it is 249 // the response header. The Create() method should fail and complain that it is
249 // impossible that both conditions are fulfilled at the same time. 250 // impossible that both conditions are fulfilled at the same time.
250 TEST(WebRequestConditionTest, ConditionsWithConflictingStages) { 251 TEST(WebRequestConditionTest, ConditionsWithConflictingStages) {
251 // Necessary for TestURLRequest. 252 // Necessary for TestURLRequest.
252 MessageLoop message_loop(MessageLoop::TYPE_IO); 253 MessageLoop message_loop(MessageLoop::TYPE_IO);
(...skipping 19 matching lines...) Expand all
272 273
273 // Test error on incompatible application stages for involved attributes. 274 // Test error on incompatible application stages for involved attributes.
274 error.clear(); 275 error.clear();
275 result = WebRequestCondition::Create(matcher.condition_factory(), 276 result = WebRequestCondition::Create(matcher.condition_factory(),
276 condition_value, &error); 277 condition_value, &error);
277 EXPECT_FALSE(error.empty()); 278 EXPECT_FALSE(error.empty());
278 EXPECT_FALSE(result.get()); 279 EXPECT_FALSE(result.get());
279 } 280 }
280 281
281 } // namespace extensions 282 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698