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 "content/public/common/previews_state.h" |
18 #include "extensions/browser/api/declarative_webrequest/webrequest_condition.h" | 19 #include "extensions/browser/api/declarative_webrequest/webrequest_condition.h" |
19 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" | 20 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" |
20 #include "net/base/request_priority.h" | 21 #include "net/base/request_priority.h" |
21 #include "net/test/embedded_test_server/embedded_test_server.h" | 22 #include "net/test/embedded_test_server/embedded_test_server.h" |
22 #include "net/url_request/url_request.h" | 23 #include "net/url_request/url_request.h" |
23 #include "net/url_request/url_request_test_util.h" | 24 #include "net/url_request/url_request_test_util.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 using base::DictionaryValue; | 27 using base::DictionaryValue; |
27 using base::FundamentalValue; | 28 using base::FundamentalValue; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 keys::kResourceTypeKey, &resource_types, &error); | 100 keys::kResourceTypeKey, &resource_types, &error); |
100 EXPECT_EQ("", error); | 101 EXPECT_EQ("", error); |
101 ASSERT_TRUE(attribute.get()); | 102 ASSERT_TRUE(attribute.get()); |
102 EXPECT_EQ(std::string(keys::kResourceTypeKey), attribute->GetName()); | 103 EXPECT_EQ(std::string(keys::kResourceTypeKey), attribute->GetName()); |
103 | 104 |
104 net::TestURLRequestContext context; | 105 net::TestURLRequestContext context; |
105 std::unique_ptr<net::URLRequest> url_request_ok(context.CreateRequest( | 106 std::unique_ptr<net::URLRequest> url_request_ok(context.CreateRequest( |
106 GURL("http://www.example.com"), net::DEFAULT_PRIORITY, NULL)); | 107 GURL("http://www.example.com"), net::DEFAULT_PRIORITY, NULL)); |
107 content::ResourceRequestInfo::AllocateForTesting( | 108 content::ResourceRequestInfo::AllocateForTesting( |
108 url_request_ok.get(), content::RESOURCE_TYPE_SUB_FRAME, | 109 url_request_ok.get(), content::RESOURCE_TYPE_SUB_FRAME, |
109 NULL, // context | 110 NULL, // context |
110 -1, // render_process_id | 111 -1, // render_process_id |
111 -1, // render_view_id | 112 -1, // render_view_id |
112 -1, // render_frame_id | 113 -1, // render_frame_id |
113 false, // is_main_frame | 114 false, // is_main_frame |
114 false, // parent_is_main_frame | 115 false, // parent_is_main_frame |
115 true, // allow_download | 116 true, // allow_download |
116 false, // is_async | 117 false, // is_async |
117 false); // is_using_lofi | 118 content::PREVIEWS_OFF); // previews_state |
118 EXPECT_TRUE(attribute->IsFulfilled(WebRequestData(url_request_ok.get(), | 119 EXPECT_TRUE(attribute->IsFulfilled(WebRequestData(url_request_ok.get(), |
119 ON_BEFORE_REQUEST))); | 120 ON_BEFORE_REQUEST))); |
120 | 121 |
121 std::unique_ptr<net::URLRequest> url_request_fail(context.CreateRequest( | 122 std::unique_ptr<net::URLRequest> url_request_fail(context.CreateRequest( |
122 GURL("http://www.example.com"), net::DEFAULT_PRIORITY, NULL)); | 123 GURL("http://www.example.com"), net::DEFAULT_PRIORITY, NULL)); |
123 content::ResourceRequestInfo::AllocateForTesting( | 124 content::ResourceRequestInfo::AllocateForTesting( |
124 url_request_fail.get(), content::RESOURCE_TYPE_MAIN_FRAME, | 125 url_request_fail.get(), content::RESOURCE_TYPE_MAIN_FRAME, |
125 NULL, // context | 126 NULL, // context |
126 -1, // render_process_id | 127 -1, // render_process_id |
127 -1, // render_view_id | 128 -1, // render_view_id |
128 -1, // render_frame_id | 129 -1, // render_frame_id |
129 true, // is_main_frame | 130 true, // is_main_frame |
130 false, // parent_is_main_frame | 131 false, // parent_is_main_frame |
131 true, // allow_download | 132 true, // allow_download |
132 false, // is_async | 133 false, // is_async |
133 false); // is_using_lofi | 134 content::PREVIEWS_OFF); // previews_state |
134 EXPECT_FALSE(attribute->IsFulfilled(WebRequestData(url_request_fail.get(), | 135 EXPECT_FALSE(attribute->IsFulfilled(WebRequestData(url_request_fail.get(), |
135 ON_BEFORE_REQUEST))); | 136 ON_BEFORE_REQUEST))); |
136 } | 137 } |
137 | 138 |
138 TEST(WebRequestConditionAttributeTest, ContentType) { | 139 TEST(WebRequestConditionAttributeTest, ContentType) { |
139 // Necessary for TestURLRequest. | 140 // Necessary for TestURLRequest. |
140 base::MessageLoopForIO message_loop; | 141 base::MessageLoopForIO message_loop; |
141 | 142 |
142 std::string error; | 143 std::string error; |
143 scoped_refptr<const WebRequestConditionAttribute> result; | 144 scoped_refptr<const WebRequestConditionAttribute> result; |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 }; | 715 }; |
715 const size_t kExistingSize[] = { arraysize(kExisting) }; | 716 const size_t kExistingSize[] = { arraysize(kExisting) }; |
716 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests); | 717 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests); |
717 MatchAndCheck(tests, keys::kExcludeResponseHeadersKey, stage, | 718 MatchAndCheck(tests, keys::kExcludeResponseHeadersKey, stage, |
718 url_request.get(), &result); | 719 url_request.get(), &result); |
719 EXPECT_FALSE(result); | 720 EXPECT_FALSE(result); |
720 } | 721 } |
721 | 722 |
722 } // namespace | 723 } // namespace |
723 } // namespace extensions | 724 } // namespace extensions |
OLD | NEW |