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

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

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

Powered by Google App Engine
This is Rietveld 408576698