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