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

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

Issue 10831150: Refactor request parameters into RequestData struct. Also make RequestStage singular. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: ?? Created 8 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
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"
11 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta nts.h" 11 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta nts.h"
12 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.h "
12 #include "chrome/common/extensions/matcher/url_matcher_constants.h" 13 #include "chrome/common/extensions/matcher/url_matcher_constants.h"
13 #include "content/public/browser/resource_request_info.h" 14 #include "content/public/browser/resource_request_info.h"
14 #include "net/url_request/url_request_test_util.h" 15 #include "net/url_request/url_request_test_util.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 namespace extensions { 18 namespace extensions {
18 19
19 namespace keys = declarative_webrequest_constants; 20 namespace keys = declarative_webrequest_constants;
20 namespace keys2 = url_matcher_constants; 21 namespace keys2 = url_matcher_constants;
21 22
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 error.clear(); 66 error.clear();
66 result = WebRequestCondition::Create(matcher.condition_factory(), 67 result = WebRequestCondition::Create(matcher.condition_factory(),
67 valid_condition, &error); 68 valid_condition, &error);
68 EXPECT_EQ("", error); 69 EXPECT_EQ("", error);
69 ASSERT_TRUE(result.get()); 70 ASSERT_TRUE(result.get());
70 71
71 TestURLRequestContext context; 72 TestURLRequestContext context;
72 TestURLRequest match_request(GURL("http://www.example.com"), NULL, &context); 73 TestURLRequest match_request(GURL("http://www.example.com"), NULL, &context);
73 content::ResourceRequestInfo::AllocateForTesting(&match_request, 74 content::ResourceRequestInfo::AllocateForTesting(&match_request,
74 ResourceType::MAIN_FRAME, NULL, -1, -1); 75 ResourceType::MAIN_FRAME, NULL, -1, -1);
75 EXPECT_TRUE(result->IsFulfilled(&match_request, ON_BEFORE_REQUEST)); 76 EXPECT_TRUE(result->IsFulfilled(
77 WebRequestRule::RequestData(&match_request, ON_BEFORE_REQUEST)));
76 78
77 TestURLRequest wrong_resource_type( 79 TestURLRequest wrong_resource_type(
78 GURL("https://www.example.com"), NULL, &context); 80 GURL("https://www.example.com"), NULL, &context);
79 content::ResourceRequestInfo::AllocateForTesting(&wrong_resource_type, 81 content::ResourceRequestInfo::AllocateForTesting(&wrong_resource_type,
80 ResourceType::SUB_FRAME, NULL, -1, -1); 82 ResourceType::SUB_FRAME, NULL, -1, -1);
81 EXPECT_FALSE(result->IsFulfilled(&wrong_resource_type, ON_BEFORE_REQUEST)); 83 EXPECT_FALSE(result->IsFulfilled(
84 WebRequestRule::RequestData(&wrong_resource_type, ON_BEFORE_REQUEST)));
82 } 85 }
83 86
84 TEST(WebRequestConditionTest, CreateConditionSet) { 87 TEST(WebRequestConditionTest, CreateConditionSet) {
85 // Necessary for TestURLRequest. 88 // Necessary for TestURLRequest.
86 MessageLoop message_loop(MessageLoop::TYPE_IO); 89 MessageLoop message_loop(MessageLoop::TYPE_IO);
87 URLMatcher matcher; 90 URLMatcher matcher;
88 91
89 ListValue* http_scheme_list = new ListValue(); 92 ListValue* http_scheme_list = new ListValue();
90 http_scheme_list->Append(Value::CreateStringValue("http")); 93 http_scheme_list->Append(Value::CreateStringValue("http"));
91 DictionaryValue* http_url_filter = new DictionaryValue(); 94 DictionaryValue* http_url_filter = new DictionaryValue();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 int number_matches = 0; 138 int number_matches = 0;
136 139
137 // 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
138 // https://www.example.com 141 // https://www.example.com
139 GURL http_url("http://www.example.com"); 142 GURL http_url("http://www.example.com");
140 TestURLRequestContext context; 143 TestURLRequestContext context;
141 TestURLRequest http_request(http_url, NULL, &context); 144 TestURLRequest http_request(http_url, NULL, &context);
142 url_match_ids = matcher.MatchURL(http_url); 145 url_match_ids = matcher.MatchURL(http_url);
143 for (std::set<URLMatcherConditionSet::ID>::iterator i = url_match_ids.begin(); 146 for (std::set<URLMatcherConditionSet::ID>::iterator i = url_match_ids.begin();
144 i != url_match_ids.end(); ++i) { 147 i != url_match_ids.end(); ++i) {
145 if (result->IsFulfilled(*i, &http_request, ON_BEFORE_REQUEST)) 148 if (result->IsFulfilled(
149 *i, WebRequestRule::RequestData(&http_request, ON_BEFORE_REQUEST)))
146 ++number_matches; 150 ++number_matches;
147 } 151 }
148 EXPECT_EQ(1, number_matches); 152 EXPECT_EQ(1, number_matches);
149 153
150 GURL https_url("https://www.example.com"); 154 GURL https_url("https://www.example.com");
151 url_match_ids = matcher.MatchURL(https_url); 155 url_match_ids = matcher.MatchURL(https_url);
152 TestURLRequest https_request(https_url, NULL, &context); 156 TestURLRequest https_request(https_url, NULL, &context);
153 number_matches = 0; 157 number_matches = 0;
154 for (std::set<URLMatcherConditionSet::ID>::iterator i = url_match_ids.begin(); 158 for (std::set<URLMatcherConditionSet::ID>::iterator i = url_match_ids.begin();
155 i != url_match_ids.end(); ++i) { 159 i != url_match_ids.end(); ++i) {
156 if (result->IsFulfilled(*i, &https_request, ON_BEFORE_REQUEST)) 160 if (result->IsFulfilled(
161 *i, WebRequestRule::RequestData(&https_request, ON_BEFORE_REQUEST)))
157 ++number_matches; 162 ++number_matches;
158 } 163 }
159 EXPECT_EQ(1, number_matches); 164 EXPECT_EQ(1, number_matches);
160 165
161 // Check that both, hostPrefix and hostSuffix are evaluated. 166 // Check that both, hostPrefix and hostSuffix are evaluated.
162 GURL https_foo_url("https://foo.example.com"); 167 GURL https_foo_url("https://foo.example.com");
163 url_match_ids = matcher.MatchURL(https_foo_url); 168 url_match_ids = matcher.MatchURL(https_foo_url);
164 TestURLRequest https_foo_request(https_foo_url, NULL, &context); 169 TestURLRequest https_foo_request(https_foo_url, NULL, &context);
165 number_matches = 0; 170 number_matches = 0;
166 for (std::set<URLMatcherConditionSet::ID>::iterator i = url_match_ids.begin(); 171 for (std::set<URLMatcherConditionSet::ID>::iterator i = url_match_ids.begin();
167 i != url_match_ids.end(); ++i) { 172 i != url_match_ids.end(); ++i) {
168 if (result->IsFulfilled(*i, &https_foo_request, ON_BEFORE_REQUEST)) 173 if (result->IsFulfilled(
174 *i, WebRequestRule::RequestData(
175 &https_foo_request, ON_BEFORE_REQUEST)))
169 ++number_matches; 176 ++number_matches;
170 } 177 }
171 EXPECT_EQ(0, number_matches); 178 EXPECT_EQ(0, number_matches);
172 } 179 }
173 180
174 TEST(WebRequestConditionTest, TestPortFilter) { 181 TEST(WebRequestConditionTest, TestPortFilter) {
175 // Necessary for TestURLRequest. 182 // Necessary for TestURLRequest.
176 MessageLoop message_loop(MessageLoop::TYPE_IO); 183 MessageLoop message_loop(MessageLoop::TYPE_IO);
177 URLMatcher matcher; 184 URLMatcher matcher;
178 185
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 url_match_ids = matcher.MatchURL(http_url_1000); 238 url_match_ids = matcher.MatchURL(http_url_1000);
232 ASSERT_EQ(1u, url_match_ids.size()); 239 ASSERT_EQ(1u, url_match_ids.size());
233 240
234 GURL http_url_2000("http://www.example.com:2000"); 241 GURL http_url_2000("http://www.example.com:2000");
235 TestURLRequest http_request_2000(http_url_2000, NULL, &context); 242 TestURLRequest http_request_2000(http_url_2000, NULL, &context);
236 url_match_ids = matcher.MatchURL(http_url_2000); 243 url_match_ids = matcher.MatchURL(http_url_2000);
237 ASSERT_EQ(0u, url_match_ids.size()); 244 ASSERT_EQ(0u, url_match_ids.size());
238 } 245 }
239 246
240 } // namespace extensions 247 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698