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.h" | 11 #include "base/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.h" | 14 #include "base/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/declarative_webrequest/webrequest_consta
nts.h" | 18 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta
nts.h" |
19 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" | 19 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" |
20 #include "chrome/browser/extensions/extension_info_map.h" | 20 #include "chrome/browser/extensions/extension_info_map.h" |
21 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
22 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
23 #include "chrome/common/extensions/extension_constants.h" | 23 #include "chrome/common/extensions/extension_constants.h" |
24 #include "chrome/common/extensions/extension_test_util.h" | 24 #include "chrome/common/extensions/extension_test_util.h" |
25 #include "content/public/test/test_browser_thread.h" | 25 #include "content/public/test/test_browser_thread_bundle.h" |
26 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
27 #include "net/url_request/url_request_test_util.h" | 27 #include "net/url_request/url_request_test_util.h" |
28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
30 | 30 |
31 using base::DictionaryValue; | 31 using base::DictionaryValue; |
32 using base::ListValue; | 32 using base::ListValue; |
33 using extension_test_util::LoadManifestUnchecked; | 33 using extension_test_util::LoadManifestUnchecked; |
34 using testing::HasSubstr; | 34 using testing::HasSubstr; |
35 | 35 |
(...skipping 28 matching lines...) Expand all Loading... |
64 return action_set.Pass(); | 64 return action_set.Pass(); |
65 } | 65 } |
66 | 66 |
67 } // namespace | 67 } // namespace |
68 | 68 |
69 namespace keys = declarative_webrequest_constants; | 69 namespace keys = declarative_webrequest_constants; |
70 | 70 |
71 class WebRequestActionWithThreadsTest : public testing::Test { | 71 class WebRequestActionWithThreadsTest : public testing::Test { |
72 public: | 72 public: |
73 WebRequestActionWithThreadsTest() | 73 WebRequestActionWithThreadsTest() |
74 : io_thread_(content::BrowserThread::IO, &message_loop_) {} | 74 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} |
75 | 75 |
76 protected: | 76 protected: |
77 virtual void SetUp() OVERRIDE; | 77 virtual void SetUp() OVERRIDE; |
78 | 78 |
79 // Creates a URL request for URL |url_string|, and applies the actions from | 79 // Creates a URL request for URL |url_string|, and applies the actions from |
80 // |action_set| as if they were triggered by the extension with | 80 // |action_set| as if they were triggered by the extension with |
81 // |extension_id| during |stage|. | 81 // |extension_id| during |stage|. |
82 bool ActionWorksOnRequest(const char* url_string, | 82 bool ActionWorksOnRequest(const char* url_string, |
83 const std::string& extension_id, | 83 const std::string& extension_id, |
84 const WebRequestActionSet* action_set, | 84 const WebRequestActionSet* action_set, |
85 RequestStage stage); | 85 RequestStage stage); |
86 | 86 |
87 // Expects a JSON description of an |action| requiring <all_urls> host | 87 // Expects a JSON description of an |action| requiring <all_urls> host |
88 // permission, and checks that only an extensions with full host permissions | 88 // permission, and checks that only an extensions with full host permissions |
89 // can execute that action at |stage|. Also checks that the action is not | 89 // can execute that action at |stage|. Also checks that the action is not |
90 // executable for http://clients1.google.com. | 90 // executable for http://clients1.google.com. |
91 void CheckActionNeedsAllUrls(const char* action, RequestStage stage); | 91 void CheckActionNeedsAllUrls(const char* action, RequestStage stage); |
92 | 92 |
93 net::TestURLRequestContext context_; | 93 net::TestURLRequestContext context_; |
94 | 94 |
95 // An extension with *.com host permissions and the DWR permission. | 95 // An extension with *.com host permissions and the DWR permission. |
96 scoped_refptr<Extension> extension_; | 96 scoped_refptr<Extension> extension_; |
97 // An extension with host permissions for all URLs and the DWR permission. | 97 // An extension with host permissions for all URLs and the DWR permission. |
98 scoped_refptr<Extension> extension_all_urls_; | 98 scoped_refptr<Extension> extension_all_urls_; |
99 scoped_refptr<ExtensionInfoMap> extension_info_map_; | 99 scoped_refptr<ExtensionInfoMap> extension_info_map_; |
100 | 100 |
101 private: | 101 private: |
102 base::MessageLoopForIO message_loop_; | 102 content::TestBrowserThreadBundle thread_bundle_; |
103 content::TestBrowserThread io_thread_; | |
104 }; | 103 }; |
105 | 104 |
106 void WebRequestActionWithThreadsTest::SetUp() { | 105 void WebRequestActionWithThreadsTest::SetUp() { |
107 testing::Test::SetUp(); | 106 testing::Test::SetUp(); |
108 | 107 |
109 std::string error; | 108 std::string error; |
110 extension_ = LoadManifestUnchecked("permissions", | 109 extension_ = LoadManifestUnchecked("permissions", |
111 "web_request_com_host_permissions.json", | 110 "web_request_com_host_permissions.json", |
112 Manifest::INVALID_LOCATION, | 111 Manifest::INVALID_LOCATION, |
113 Extension::NO_FLAGS, | 112 Extension::NO_FLAGS, |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 for (WebRequestActionSet::Actions::const_iterator it = | 566 for (WebRequestActionSet::Actions::const_iterator it = |
568 action_set->actions().begin(); | 567 action_set->actions().begin(); |
569 it != action_set->actions().end(); | 568 it != action_set->actions().end(); |
570 ++it) { | 569 ++it) { |
571 EXPECT_EQ(kExpectedNames[index], (*it)->GetName()); | 570 EXPECT_EQ(kExpectedNames[index], (*it)->GetName()); |
572 ++index; | 571 ++index; |
573 } | 572 } |
574 } | 573 } |
575 | 574 |
576 } // namespace extensions | 575 } // namespace extensions |
OLD | NEW |