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_attribute.h" | 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit
ion_attribute.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 EXPECT_EQ(std::string(keys::kResourceTypeKey), result->GetName()); | 77 EXPECT_EQ(std::string(keys::kResourceTypeKey), result->GetName()); |
78 } | 78 } |
79 | 79 |
80 TEST(WebRequestConditionAttributeTest, ResourceType) { | 80 TEST(WebRequestConditionAttributeTest, ResourceType) { |
81 // Necessary for TestURLRequest. | 81 // Necessary for TestURLRequest. |
82 base::MessageLoopForIO message_loop; | 82 base::MessageLoopForIO message_loop; |
83 | 83 |
84 std::string error; | 84 std::string error; |
85 base::ListValue resource_types; | 85 base::ListValue resource_types; |
86 // The 'sub_frame' value is chosen arbitrarily, so as the corresponding | 86 // The 'sub_frame' value is chosen arbitrarily, so as the corresponding |
87 // ResourceType::Type is not 0, the default value. | 87 // content::ResourceType is not 0, the default value. |
88 resource_types.Append(new base::StringValue("sub_frame")); | 88 resource_types.Append(new base::StringValue("sub_frame")); |
89 | 89 |
90 scoped_refptr<const WebRequestConditionAttribute> attribute = | 90 scoped_refptr<const WebRequestConditionAttribute> attribute = |
91 WebRequestConditionAttribute::Create( | 91 WebRequestConditionAttribute::Create( |
92 keys::kResourceTypeKey, &resource_types, &error); | 92 keys::kResourceTypeKey, &resource_types, &error); |
93 EXPECT_EQ("", error); | 93 EXPECT_EQ("", error); |
94 ASSERT_TRUE(attribute.get()); | 94 ASSERT_TRUE(attribute.get()); |
95 EXPECT_EQ(std::string(keys::kResourceTypeKey), attribute->GetName()); | 95 EXPECT_EQ(std::string(keys::kResourceTypeKey), attribute->GetName()); |
96 | 96 |
97 net::TestURLRequestContext context; | 97 net::TestURLRequestContext context; |
98 net::TestURLRequest url_request_ok( | 98 net::TestURLRequest url_request_ok( |
99 GURL("http://www.example.com"), net::DEFAULT_PRIORITY, NULL, &context); | 99 GURL("http://www.example.com"), net::DEFAULT_PRIORITY, NULL, &context); |
100 content::ResourceRequestInfo::AllocateForTesting( | 100 content::ResourceRequestInfo::AllocateForTesting( |
101 &url_request_ok, ResourceType::SUB_FRAME, NULL, -1, -1, -1, false); | 101 &url_request_ok, |
| 102 content::RESOURCE_TYPE_SUB_FRAME, |
| 103 NULL, |
| 104 -1, |
| 105 -1, |
| 106 -1, |
| 107 false); |
102 EXPECT_TRUE(attribute->IsFulfilled(WebRequestData(&url_request_ok, | 108 EXPECT_TRUE(attribute->IsFulfilled(WebRequestData(&url_request_ok, |
103 ON_BEFORE_REQUEST))); | 109 ON_BEFORE_REQUEST))); |
104 | 110 |
105 net::TestURLRequest url_request_fail( | 111 net::TestURLRequest url_request_fail( |
106 GURL("http://www.example.com"), net::DEFAULT_PRIORITY, NULL, &context); | 112 GURL("http://www.example.com"), net::DEFAULT_PRIORITY, NULL, &context); |
107 content::ResourceRequestInfo::AllocateForTesting( | 113 content::ResourceRequestInfo::AllocateForTesting( |
108 &url_request_fail, ResourceType::MAIN_FRAME, NULL, -1, -1, -1, false); | 114 &url_request_fail, |
| 115 content::RESOURCE_TYPE_MAIN_FRAME, |
| 116 NULL, |
| 117 -1, |
| 118 -1, |
| 119 -1, |
| 120 false); |
109 EXPECT_FALSE(attribute->IsFulfilled(WebRequestData(&url_request_fail, | 121 EXPECT_FALSE(attribute->IsFulfilled(WebRequestData(&url_request_fail, |
110 ON_BEFORE_REQUEST))); | 122 ON_BEFORE_REQUEST))); |
111 } | 123 } |
112 | 124 |
113 TEST(WebRequestConditionAttributeTest, ContentType) { | 125 TEST(WebRequestConditionAttributeTest, ContentType) { |
114 // Necessary for TestURLRequest. | 126 // Necessary for TestURLRequest. |
115 base::MessageLoopForIO message_loop; | 127 base::MessageLoopForIO message_loop; |
116 | 128 |
117 std::string error; | 129 std::string error; |
118 scoped_refptr<const WebRequestConditionAttribute> result; | 130 scoped_refptr<const WebRequestConditionAttribute> result; |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 }; | 689 }; |
678 const size_t kExistingSize[] = { arraysize(kExisting) }; | 690 const size_t kExistingSize[] = { arraysize(kExisting) }; |
679 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests); | 691 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests); |
680 MatchAndCheck( | 692 MatchAndCheck( |
681 tests, keys::kExcludeResponseHeadersKey, stage, &url_request, &result); | 693 tests, keys::kExcludeResponseHeadersKey, stage, &url_request, &result); |
682 EXPECT_FALSE(result); | 694 EXPECT_FALSE(result); |
683 } | 695 } |
684 | 696 |
685 } // namespace | 697 } // namespace |
686 } // namespace extensions | 698 } // namespace extensions |
OLD | NEW |