OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
10 #include "chrome/browser/child_process_security_policy.h" | 10 #include "chrome/browser/child_process_security_policy.h" |
11 #include "chrome/browser/chrome_thread.h" | 11 #include "chrome/browser/chrome_thread.h" |
12 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 12 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 13 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" |
| 14 #include "chrome/browser/renderer_host/resource_handler.h" |
13 #include "chrome/common/chrome_plugin_lib.h" | 15 #include "chrome/common/chrome_plugin_lib.h" |
14 #include "chrome/common/render_messages.h" | 16 #include "chrome/common/render_messages.h" |
15 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
16 #include "net/http/http_util.h" | 18 #include "net/http/http_util.h" |
17 #include "net/url_request/url_request.h" | 19 #include "net/url_request/url_request.h" |
18 #include "net/url_request/url_request_job.h" | 20 #include "net/url_request/url_request_job.h" |
19 #include "net/url_request/url_request_test_job.h" | 21 #include "net/url_request/url_request_test_job.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "webkit/appcache/appcache_interfaces.h" | 23 #include "webkit/appcache/appcache_interfaces.h" |
22 | 24 |
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 | 881 |
880 // Sorts out all the messages we saw by request. | 882 // Sorts out all the messages we saw by request. |
881 ResourceIPCAccumulator::ClassifiedMessages msgs; | 883 ResourceIPCAccumulator::ClassifiedMessages msgs; |
882 accum_.GetClassifiedMessages(&msgs); | 884 accum_.GetClassifiedMessages(&msgs); |
883 ASSERT_EQ(1U, msgs.size()); | 885 ASSERT_EQ(1U, msgs.size()); |
884 | 886 |
885 ResourceResponseHead response_head; | 887 ResourceResponseHead response_head; |
886 GetResponseHead(msgs[0], &response_head); | 888 GetResponseHead(msgs[0], &response_head); |
887 ASSERT_EQ("text/plain", response_head.mime_type); | 889 ASSERT_EQ("text/plain", response_head.mime_type); |
888 } | 890 } |
| 891 |
| 892 class DummyResourceHandler : public ResourceHandler { |
| 893 public: |
| 894 DummyResourceHandler() {} |
| 895 |
| 896 bool OnRequestRedirected(int request_id, const GURL& url, |
| 897 ResourceResponse* response, bool* defer) { |
| 898 return true; |
| 899 } |
| 900 |
| 901 bool OnResponseStarted(int request_id, ResourceResponse* response) { |
| 902 return true; |
| 903 } |
| 904 |
| 905 bool OnWillRead( |
| 906 int request_id, net::IOBuffer** buf, int* buf_size, int min_size) { |
| 907 return true; |
| 908 } |
| 909 |
| 910 bool OnReadCompleted(int request_id, int* bytes_read) { return true; } |
| 911 |
| 912 bool OnResponseCompleted( |
| 913 int request_id, const URLRequestStatus& status, const std::string& info) { |
| 914 return true; |
| 915 } |
| 916 |
| 917 private: |
| 918 DISALLOW_COPY_AND_ASSIGN(DummyResourceHandler); |
| 919 }; |
| 920 |
| 921 class ApplyExtensionMessageFilterPolicyTest : public testing::Test { |
| 922 protected: |
| 923 void SetUp() { |
| 924 url_.reset(new GURL( |
| 925 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/popup.html")); |
| 926 resource_type_ = ResourceType::STYLESHEET; |
| 927 resource_handler_.reset(new DummyResourceHandler()); |
| 928 request_info_.reset(CreateNewResourceRequestInfo()); |
| 929 } |
| 930 |
| 931 ResourceDispatcherHostRequestInfo* CreateNewResourceRequestInfo() { |
| 932 return new ResourceDispatcherHostRequestInfo( |
| 933 resource_handler_.get(), ChildProcessInfo::RENDER_PROCESS, 0, 0, 0, |
| 934 "not important", "not important", |
| 935 ResourceType::STYLESHEET, 0U, false, false, -1, -1); |
| 936 } |
| 937 |
| 938 scoped_ptr<GURL> url_; |
| 939 ResourceType::Type resource_type_; |
| 940 scoped_ptr<DummyResourceHandler> resource_handler_; |
| 941 scoped_ptr<ResourceDispatcherHostRequestInfo> request_info_; |
| 942 }; |
| 943 |
| 944 TEST_F(ApplyExtensionMessageFilterPolicyTest, WrongScheme) { |
| 945 url_.reset(new GURL("html://behllobkkfkfnphdnhnkndlbkcpglgmj/popup.html")); |
| 946 ResourceDispatcherHost::ApplyExtensionMessageFilterPolicy( |
| 947 *url_, resource_type_, request_info_.get()); |
| 948 |
| 949 EXPECT_EQ(FilterPolicy::DONT_FILTER, request_info_->filter_policy()); |
| 950 } |
| 951 |
| 952 TEST_F(ApplyExtensionMessageFilterPolicyTest, GoodScheme) { |
| 953 ResourceDispatcherHost::ApplyExtensionMessageFilterPolicy( |
| 954 *url_, resource_type_, request_info_.get()); |
| 955 |
| 956 EXPECT_EQ(FilterPolicy::FILTER_EXTENSION_MESSAGES, |
| 957 request_info_->filter_policy()); |
| 958 } |
| 959 |
| 960 TEST_F(ApplyExtensionMessageFilterPolicyTest, GoodSchemeWithSecurityFilter) { |
| 961 request_info_->set_filter_policy(FilterPolicy::FILTER_ALL_EXCEPT_IMAGES); |
| 962 ResourceDispatcherHost::ApplyExtensionMessageFilterPolicy( |
| 963 *url_, resource_type_, request_info_.get()); |
| 964 |
| 965 EXPECT_EQ(FilterPolicy::FILTER_ALL_EXCEPT_IMAGES, |
| 966 request_info_->filter_policy()); |
| 967 } |
| 968 |
| 969 TEST_F(ApplyExtensionMessageFilterPolicyTest, GoodSchemeWrongResourceType) { |
| 970 resource_type_ = ResourceType::MAIN_FRAME; |
| 971 ResourceDispatcherHost::ApplyExtensionMessageFilterPolicy( |
| 972 *url_, resource_type_, request_info_.get()); |
| 973 |
| 974 EXPECT_EQ(FilterPolicy::DONT_FILTER, request_info_->filter_policy()); |
| 975 } |
| 976 |
| 977 TEST_F(ApplyExtensionMessageFilterPolicyTest, WrongSchemeResourceAndFilter) { |
| 978 url_.reset(new GURL("html://behllobkkfkfnphdnhnkndlbkcpglgmj/popup.html")); |
| 979 resource_type_ = ResourceType::MEDIA; |
| 980 request_info_->set_filter_policy(FilterPolicy::FILTER_ALL); |
| 981 ResourceDispatcherHost::ApplyExtensionMessageFilterPolicy( |
| 982 *url_, resource_type_, request_info_.get()); |
| 983 |
| 984 EXPECT_EQ(FilterPolicy::FILTER_ALL, request_info_->filter_policy()); |
| 985 } |
OLD | NEW |