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

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

Issue 11547033: Implement declarativeContent API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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"
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 "
13 #include "chrome/common/extensions/matcher/url_matcher_constants.h" 12 #include "chrome/common/extensions/matcher/url_matcher_constants.h"
14 #include "content/public/browser/resource_request_info.h" 13 #include "content/public/browser/resource_request_info.h"
15 #include "net/url_request/url_request_test_util.h" 14 #include "net/url_request/url_request_test_util.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 16
18 namespace extensions { 17 namespace extensions {
19 18
20 namespace keys = declarative_webrequest_constants; 19 namespace keys = declarative_webrequest_constants;
21 namespace keys2 = url_matcher_constants; 20 namespace keys2 = url_matcher_constants;
22 21
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 valid_condition, &error); 67 valid_condition, &error);
69 EXPECT_EQ("", error); 68 EXPECT_EQ("", error);
70 ASSERT_TRUE(result.get()); 69 ASSERT_TRUE(result.get());
71 70
72 net::TestURLRequestContext context; 71 net::TestURLRequestContext context;
73 net::TestURLRequest match_request( 72 net::TestURLRequest match_request(
74 GURL("http://www.example.com"), NULL, &context); 73 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 DeclarativeWebRequestData(&match_request, ON_BEFORE_REQUEST)));
79 78
80 net::TestURLRequest wrong_resource_type( 79 net::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 DeclarativeWebRequestData(&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);
91 URLMatcher matcher; 90 URLMatcher matcher;
92 91
93 ListValue* http_scheme_list = new ListValue(); 92 ListValue* http_scheme_list = new ListValue();
94 http_scheme_list->Append(Value::CreateStringValue("http")); 93 http_scheme_list->Append(Value::CreateStringValue("http"));
95 DictionaryValue* http_url_filter = new DictionaryValue(); 94 DictionaryValue* http_url_filter = new DictionaryValue();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 net::TestURLRequestContext context;
145 net::TestURLRequest http_request(http_url, NULL, &context); 144 net::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, DeclarativeWebRequestData(&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 net::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, DeclarativeWebRequestData(&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 net::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, DeclarativeWebRequestData(
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 }
181 180
182 TEST(WebRequestConditionTest, TestPortFilter) { 181 TEST(WebRequestConditionTest, TestPortFilter) {
183 // Necessary for TestURLRequest. 182 // Necessary for TestURLRequest.
184 MessageLoop message_loop(MessageLoop::TYPE_IO); 183 MessageLoop message_loop(MessageLoop::TYPE_IO);
185 URLMatcher matcher; 184 URLMatcher matcher;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
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