| OLD | NEW |
| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 TestURLRequest https_foo_request(https_foo_url, NULL); | 154 TestURLRequest https_foo_request(https_foo_url, NULL); |
| 155 number_matches = 0; | 155 number_matches = 0; |
| 156 for (std::set<URLMatcherConditionSet::ID>::iterator i = url_match_ids.begin(); | 156 for (std::set<URLMatcherConditionSet::ID>::iterator i = url_match_ids.begin(); |
| 157 i != url_match_ids.end(); ++i) { | 157 i != url_match_ids.end(); ++i) { |
| 158 if (result->IsFulfilled(*i, &https_foo_request, ON_BEFORE_REQUEST)) | 158 if (result->IsFulfilled(*i, &https_foo_request, ON_BEFORE_REQUEST)) |
| 159 ++number_matches; | 159 ++number_matches; |
| 160 } | 160 } |
| 161 EXPECT_EQ(0, number_matches); | 161 EXPECT_EQ(0, number_matches); |
| 162 } | 162 } |
| 163 | 163 |
| 164 TEST(WebRequestConditionTest, TestPortFilter) { |
| 165 // Necessary for TestURLRequest. |
| 166 MessageLoop message_loop(MessageLoop::TYPE_IO); |
| 167 URLMatcher matcher; |
| 168 |
| 169 // Allow 80;1000-1010. |
| 170 ListValue* port_range = new ListValue(); |
| 171 port_range->Append(Value::CreateIntegerValue(1000)); |
| 172 port_range->Append(Value::CreateIntegerValue(1010)); |
| 173 ListValue* port_ranges = new ListValue(); |
| 174 port_ranges->Append(Value::CreateIntegerValue(80)); |
| 175 port_ranges->Append(port_range); |
| 176 |
| 177 DictionaryValue condition; |
| 178 condition.Set(keys::kPortsKey, port_ranges); |
| 179 condition.SetString("host_suffix", "example.com"); |
| 180 condition.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType); |
| 181 |
| 182 linked_ptr<json_schema_compiler::any::Any> any_condition = |
| 183 make_linked_ptr(new json_schema_compiler::any::Any); |
| 184 any_condition->Init(condition); |
| 185 WebRequestConditionSet::AnyVector conditions; |
| 186 conditions.push_back(any_condition); |
| 187 |
| 188 // Test insertion |
| 189 std::string error; |
| 190 scoped_ptr<WebRequestConditionSet> result = |
| 191 WebRequestConditionSet::Create(matcher.condition_factory(), |
| 192 conditions, &error); |
| 193 EXPECT_EQ("", error); |
| 194 ASSERT_TRUE(result.get()); |
| 195 EXPECT_EQ(1u, result->conditions().size()); |
| 196 |
| 197 // Tell the URLMatcher about our shiny new patterns. |
| 198 URLMatcherConditionSet::Vector url_matcher_condition_set; |
| 199 result->GetURLMatcherConditionSets(&url_matcher_condition_set); |
| 200 matcher.AddConditionSets(url_matcher_condition_set); |
| 201 |
| 202 std::set<URLMatcherConditionSet::ID> url_match_ids; |
| 203 |
| 204 // Test various URLs. |
| 205 GURL http_url("http://www.example.com"); |
| 206 TestURLRequest http_request(http_url, NULL); |
| 207 url_match_ids = matcher.MatchURL(http_url); |
| 208 ASSERT_EQ(1u, url_match_ids.size()); |
| 209 |
| 210 GURL http_url_80("http://www.example.com:80"); |
| 211 TestURLRequest http_request_80(http_url_80, NULL); |
| 212 url_match_ids = matcher.MatchURL(http_url_80); |
| 213 ASSERT_EQ(1u, url_match_ids.size()); |
| 214 |
| 215 GURL http_url_1000("http://www.example.com:1000"); |
| 216 TestURLRequest http_request_1000(http_url_1000, NULL); |
| 217 url_match_ids = matcher.MatchURL(http_url_1000); |
| 218 ASSERT_EQ(1u, url_match_ids.size()); |
| 219 |
| 220 GURL http_url_2000("http://www.example.com:2000"); |
| 221 TestURLRequest http_request_2000(http_url_2000, NULL); |
| 222 url_match_ids = matcher.MatchURL(http_url_2000); |
| 223 ASSERT_EQ(0u, url_match_ids.size()); |
| 224 } |
| 225 |
| 164 } // namespace extensions | 226 } // namespace extensions |
| OLD | NEW |