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_action
.h" | 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_action
.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/test/values_test_util.h" | 13 #include "base/test/values_test_util.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/extensions/api/declarative_webrequest/request_stage.h" | 16 #include "chrome/browser/extensions/api/declarative_webrequest/request_stage.h" |
17 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit
ion.h" | 17 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit
ion.h" |
18 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" | 18 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" |
19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
20 #include "chrome/common/extensions/extension_constants.h" | 20 #include "chrome/common/extensions/extension_constants.h" |
21 #include "chrome/common/extensions/extension_test_util.h" | 21 #include "chrome/common/extensions/extension_test_util.h" |
22 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
23 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" | 23 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" |
24 #include "extensions/browser/info_map.h" | 24 #include "extensions/browser/info_map.h" |
25 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
26 #include "net/base/request_priority.h" | 26 #include "net/base/request_priority.h" |
27 #include "net/http/http_response_headers.h" | 27 #include "net/http/http_response_headers.h" |
| 28 #include "net/url_request/url_request.h" |
28 #include "net/url_request/url_request_test_util.h" | 29 #include "net/url_request/url_request_test_util.h" |
29 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
31 | 32 |
32 using base::DictionaryValue; | 33 using base::DictionaryValue; |
33 using base::ListValue; | 34 using base::ListValue; |
34 using extension_test_util::LoadManifestUnchecked; | 35 using extension_test_util::LoadManifestUnchecked; |
35 using testing::HasSubstr; | 36 using testing::HasSubstr; |
36 | 37 |
37 namespace extensions { | 38 namespace extensions { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 base::Time::Now(), | 134 base::Time::Now(), |
134 false /*incognito_enabled*/, | 135 false /*incognito_enabled*/, |
135 false /*notifications_disabled*/); | 136 false /*notifications_disabled*/); |
136 } | 137 } |
137 | 138 |
138 bool WebRequestActionWithThreadsTest::ActionWorksOnRequest( | 139 bool WebRequestActionWithThreadsTest::ActionWorksOnRequest( |
139 const char* url_string, | 140 const char* url_string, |
140 const std::string& extension_id, | 141 const std::string& extension_id, |
141 const WebRequestActionSet* action_set, | 142 const WebRequestActionSet* action_set, |
142 RequestStage stage) { | 143 RequestStage stage) { |
143 net::TestURLRequest regular_request( | 144 scoped_ptr<net::URLRequest> regular_request(context_.CreateRequest( |
144 GURL(url_string), net::DEFAULT_PRIORITY, NULL, &context_); | 145 GURL(url_string), net::DEFAULT_PRIORITY, NULL, NULL)); |
145 std::list<LinkedPtrEventResponseDelta> deltas; | 146 std::list<LinkedPtrEventResponseDelta> deltas; |
146 scoped_refptr<net::HttpResponseHeaders> headers( | 147 scoped_refptr<net::HttpResponseHeaders> headers( |
147 new net::HttpResponseHeaders("")); | 148 new net::HttpResponseHeaders("")); |
148 WebRequestData request_data(®ular_request, stage, headers.get()); | 149 WebRequestData request_data(regular_request.get(), stage, headers.get()); |
149 std::set<std::string> ignored_tags; | 150 std::set<std::string> ignored_tags; |
150 WebRequestAction::ApplyInfo apply_info = { extension_info_map_.get(), | 151 WebRequestAction::ApplyInfo apply_info = { extension_info_map_.get(), |
151 request_data, | 152 request_data, |
152 false /*crosses_incognito*/, | 153 false /*crosses_incognito*/, |
153 &deltas, &ignored_tags }; | 154 &deltas, &ignored_tags }; |
154 action_set->Apply(extension_id, base::Time(), &apply_info); | 155 action_set->Apply(extension_id, base::Time(), &apply_info); |
155 return (1u == deltas.size() || 0u < ignored_tags.size()); | 156 return (1u == deltas.size() || 0u < ignored_tags.size()); |
156 } | 157 } |
157 | 158 |
158 void WebRequestActionWithThreadsTest::CheckActionNeedsAllUrls( | 159 void WebRequestActionWithThreadsTest::CheckActionNeedsAllUrls( |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 for (WebRequestActionSet::Actions::const_iterator it = | 583 for (WebRequestActionSet::Actions::const_iterator it = |
583 action_set->actions().begin(); | 584 action_set->actions().begin(); |
584 it != action_set->actions().end(); | 585 it != action_set->actions().end(); |
585 ++it) { | 586 ++it) { |
586 EXPECT_EQ(kExpectedNames[index], (*it)->GetName()); | 587 EXPECT_EQ(kExpectedNames[index], (*it)->GetName()); |
587 ++index; | 588 ++index; |
588 } | 589 } |
589 } | 590 } |
590 | 591 |
591 } // namespace extensions | 592 } // namespace extensions |
OLD | NEW |