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 "extensions/browser/api/declarative_webrequest/webrequest_condition_att
ribute.h" | 5 #include "extensions/browser/api/declarative_webrequest/webrequest_condition_att
ribute.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "content/public/browser/resource_request_info.h" | 18 #include "content/public/browser/resource_request_info.h" |
19 #include "content/public/common/previews_state.h" | 19 #include "content/public/common/previews_state.h" |
20 #include "extensions/browser/api/declarative_webrequest/webrequest_condition.h" | 20 #include "extensions/browser/api/declarative_webrequest/webrequest_condition.h" |
21 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" | 21 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" |
22 #include "net/base/request_priority.h" | 22 #include "net/base/request_priority.h" |
23 #include "net/test/embedded_test_server/embedded_test_server.h" | 23 #include "net/test/embedded_test_server/embedded_test_server.h" |
24 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
25 #include "net/url_request/url_request_test_util.h" | 25 #include "net/url_request/url_request_test_util.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
27 | 27 |
28 using base::DictionaryValue; | 28 using base::DictionaryValue; |
29 using base::FundamentalValue; | |
30 using base::ListValue; | 29 using base::ListValue; |
31 using base::StringValue; | 30 using base::StringValue; |
32 using base::Value; | 31 using base::Value; |
33 | 32 |
34 namespace extensions { | 33 namespace extensions { |
35 | 34 |
36 namespace keys = declarative_webrequest_constants; | 35 namespace keys = declarative_webrequest_constants; |
37 | 36 |
38 namespace { | 37 namespace { |
39 const char kUnknownConditionName[] = "unknownType"; | 38 const char kUnknownConditionName[] = "unknownType"; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 EXPECT_EQ(std::string(keys::kExcludeContentTypeKey), | 200 EXPECT_EQ(std::string(keys::kExcludeContentTypeKey), |
202 attribute_unexcluded->GetName()); | 201 attribute_unexcluded->GetName()); |
203 } | 202 } |
204 | 203 |
205 // Testing WebRequestConditionAttributeThirdParty. | 204 // Testing WebRequestConditionAttributeThirdParty. |
206 TEST(WebRequestConditionAttributeTest, ThirdParty) { | 205 TEST(WebRequestConditionAttributeTest, ThirdParty) { |
207 // Necessary for TestURLRequest. | 206 // Necessary for TestURLRequest. |
208 base::MessageLoopForIO message_loop; | 207 base::MessageLoopForIO message_loop; |
209 | 208 |
210 std::string error; | 209 std::string error; |
211 const FundamentalValue value_true(true); | 210 const Value value_true(true); |
212 // This attribute matches only third party requests. | 211 // This attribute matches only third party requests. |
213 scoped_refptr<const WebRequestConditionAttribute> third_party_attribute = | 212 scoped_refptr<const WebRequestConditionAttribute> third_party_attribute = |
214 WebRequestConditionAttribute::Create(keys::kThirdPartyKey, | 213 WebRequestConditionAttribute::Create(keys::kThirdPartyKey, |
215 &value_true, | 214 &value_true, |
216 &error); | 215 &error); |
217 ASSERT_EQ("", error); | 216 ASSERT_EQ("", error); |
218 ASSERT_TRUE(third_party_attribute.get()); | 217 ASSERT_TRUE(third_party_attribute.get()); |
219 EXPECT_EQ(std::string(keys::kThirdPartyKey), | 218 EXPECT_EQ(std::string(keys::kThirdPartyKey), |
220 third_party_attribute->GetName()); | 219 third_party_attribute->GetName()); |
221 const FundamentalValue value_false(false); | 220 const Value value_false(false); |
222 // This attribute matches only first party requests. | 221 // This attribute matches only first party requests. |
223 scoped_refptr<const WebRequestConditionAttribute> first_party_attribute = | 222 scoped_refptr<const WebRequestConditionAttribute> first_party_attribute = |
224 WebRequestConditionAttribute::Create(keys::kThirdPartyKey, | 223 WebRequestConditionAttribute::Create(keys::kThirdPartyKey, |
225 &value_false, | 224 &value_false, |
226 &error); | 225 &error); |
227 ASSERT_EQ("", error); | 226 ASSERT_EQ("", error); |
228 ASSERT_TRUE(first_party_attribute.get()); | 227 ASSERT_TRUE(first_party_attribute.get()); |
229 EXPECT_EQ(std::string(keys::kThirdPartyKey), | 228 EXPECT_EQ(std::string(keys::kThirdPartyKey), |
230 first_party_attribute->GetName()); | 229 first_party_attribute->GetName()); |
231 | 230 |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 }; | 714 }; |
716 const size_t kExistingSize[] = { arraysize(kExisting) }; | 715 const size_t kExistingSize[] = { arraysize(kExisting) }; |
717 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests); | 716 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests); |
718 MatchAndCheck(tests, keys::kExcludeResponseHeadersKey, stage, | 717 MatchAndCheck(tests, keys::kExcludeResponseHeadersKey, stage, |
719 url_request.get(), &result); | 718 url_request.get(), &result); |
720 EXPECT_FALSE(result); | 719 EXPECT_FALSE(result); |
721 } | 720 } |
722 | 721 |
723 } // namespace | 722 } // namespace |
724 } // namespace extensions | 723 } // namespace extensions |
OLD | NEW |