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/test/values_test_util.h" | 10 #include "base/test/values_test_util.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 EXPECT_FALSE(result->IsFulfilled( | 84 EXPECT_FALSE(result->IsFulfilled( |
85 WebRequestRule::RequestData(&wrong_resource_type, ON_BEFORE_REQUEST))); | 85 WebRequestRule::RequestData(&wrong_resource_type, ON_BEFORE_REQUEST))); |
86 } | 86 } |
87 | 87 |
88 TEST(WebRequestConditionTest, CreateConditionSet) { | 88 TEST(WebRequestConditionTest, CreateConditionSet) { |
89 // Necessary for TestURLRequest. | 89 // Necessary for TestURLRequest. |
90 MessageLoop message_loop(MessageLoop::TYPE_IO); | 90 MessageLoop message_loop(MessageLoop::TYPE_IO); |
91 URLMatcher matcher; | 91 URLMatcher matcher; |
92 | 92 |
93 WebRequestConditionSet::AnyVector conditions; | 93 WebRequestConditionSet::AnyVector conditions; |
94 | 94 conditions.push_back(linked_ptr<base::Value>(base::test::ParseJson( |
95 linked_ptr<json_schema_compiler::any::Any> condition1 = make_linked_ptr( | |
96 new json_schema_compiler::any::Any); | |
97 condition1->Init(*base::test::ParseJson( | |
98 "{ \n" | 95 "{ \n" |
99 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" | 96 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" |
100 " \"url\": { \n" | 97 " \"url\": { \n" |
101 " \"hostSuffix\": \"example.com\", \n" | 98 " \"hostSuffix\": \"example.com\", \n" |
102 " \"schemes\": [\"http\"], \n" | 99 " \"schemes\": [\"http\"], \n" |
103 " }, \n" | 100 " }, \n" |
104 "}")); | 101 "}").release())); |
105 conditions.push_back(condition1); | 102 conditions.push_back(linked_ptr<base::Value>(base::test::ParseJson( |
106 | |
107 linked_ptr<json_schema_compiler::any::Any> condition2 = make_linked_ptr( | |
108 new json_schema_compiler::any::Any); | |
109 condition2->Init(*base::test::ParseJson( | |
110 "{ \n" | 103 "{ \n" |
111 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" | 104 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" |
112 " \"url\": { \n" | 105 " \"url\": { \n" |
113 " \"hostSuffix\": \"example.com\", \n" | 106 " \"hostSuffix\": \"example.com\", \n" |
114 " \"hostPrefix\": \"www\", \n" | 107 " \"hostPrefix\": \"www\", \n" |
115 " \"schemes\": [\"https\"], \n" | 108 " \"schemes\": [\"https\"], \n" |
116 " }, \n" | 109 " }, \n" |
117 "}")); | 110 "}").release())); |
118 conditions.push_back(condition2); | |
119 | 111 |
120 // Test insertion | 112 // Test insertion |
121 std::string error; | 113 std::string error; |
122 scoped_ptr<WebRequestConditionSet> result = | 114 scoped_ptr<WebRequestConditionSet> result = |
123 WebRequestConditionSet::Create(matcher.condition_factory(), | 115 WebRequestConditionSet::Create(matcher.condition_factory(), |
124 conditions, &error); | 116 conditions, &error); |
125 EXPECT_EQ("", error); | 117 EXPECT_EQ("", error); |
126 ASSERT_TRUE(result.get()); | 118 ASSERT_TRUE(result.get()); |
127 EXPECT_EQ(2u, result->conditions().size()); | 119 EXPECT_EQ(2u, result->conditions().size()); |
128 | 120 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 ++number_matches; | 165 ++number_matches; |
174 } | 166 } |
175 EXPECT_EQ(0, number_matches); | 167 EXPECT_EQ(0, number_matches); |
176 } | 168 } |
177 | 169 |
178 TEST(WebRequestConditionTest, TestPortFilter) { | 170 TEST(WebRequestConditionTest, TestPortFilter) { |
179 // Necessary for TestURLRequest. | 171 // Necessary for TestURLRequest. |
180 MessageLoop message_loop(MessageLoop::TYPE_IO); | 172 MessageLoop message_loop(MessageLoop::TYPE_IO); |
181 URLMatcher matcher; | 173 URLMatcher matcher; |
182 | 174 |
183 linked_ptr<json_schema_compiler::any::Any> any_condition = | 175 WebRequestConditionSet::AnyVector conditions; |
184 make_linked_ptr(new json_schema_compiler::any::Any); | 176 conditions.push_back(linked_ptr<base::Value>(base::test::ParseJson( |
185 any_condition->Init(*base::test::ParseJson( | |
186 "{ \n" | 177 "{ \n" |
187 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" | 178 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" |
188 " \"url\": { \n" | 179 " \"url\": { \n" |
189 " \"ports\": [80, [1000, 1010]], \n" // Allow 80;1000-1010. | 180 " \"ports\": [80, [1000, 1010]], \n" // Allow 80;1000-1010. |
190 " \"hostSuffix\": \"example.com\", \n" | 181 " \"hostSuffix\": \"example.com\", \n" |
191 " }, \n" | 182 " }, \n" |
192 "}")); | 183 "}").release())); |
193 WebRequestConditionSet::AnyVector conditions; | |
194 conditions.push_back(any_condition); | |
195 | 184 |
196 // Test insertion | 185 // Test insertion |
197 std::string error; | 186 std::string error; |
198 scoped_ptr<WebRequestConditionSet> result = | 187 scoped_ptr<WebRequestConditionSet> result = |
199 WebRequestConditionSet::Create(matcher.condition_factory(), | 188 WebRequestConditionSet::Create(matcher.condition_factory(), |
200 conditions, &error); | 189 conditions, &error); |
201 EXPECT_EQ("", error); | 190 EXPECT_EQ("", error); |
202 ASSERT_TRUE(result.get()); | 191 ASSERT_TRUE(result.get()); |
203 EXPECT_EQ(1u, result->conditions().size()); | 192 EXPECT_EQ(1u, result->conditions().size()); |
204 | 193 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 // filters. | 247 // filters. |
259 " \"requestHeaders\": [{}], \n" | 248 " \"requestHeaders\": [{}], \n" |
260 " \"responseHeaders\": [{}], \n" | 249 " \"responseHeaders\": [{}], \n" |
261 "}"), | 250 "}"), |
262 &error); | 251 &error); |
263 EXPECT_FALSE(error.empty()); | 252 EXPECT_FALSE(error.empty()); |
264 EXPECT_FALSE(result.get()); | 253 EXPECT_FALSE(result.get()); |
265 } | 254 } |
266 | 255 |
267 } // namespace extensions | 256 } // namespace extensions |
OLD | NEW |