| Index: chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc
 | 
| ===================================================================
 | 
| --- chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc	(revision 40221)
 | 
| +++ chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc	(working copy)
 | 
| @@ -10,6 +10,8 @@
 | 
|  #include "chrome/browser/child_process_security_policy.h"
 | 
|  #include "chrome/browser/chrome_thread.h"
 | 
|  #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
 | 
| +#include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h"
 | 
| +#include "chrome/browser/renderer_host/resource_handler.h"
 | 
|  #include "chrome/common/chrome_plugin_lib.h"
 | 
|  #include "chrome/common/render_messages.h"
 | 
|  #include "net/base/net_errors.h"
 | 
| @@ -886,3 +888,98 @@
 | 
|    GetResponseHead(msgs[0], &response_head);
 | 
|    ASSERT_EQ("text/plain", response_head.mime_type);
 | 
|  }
 | 
| +
 | 
| +class DummyResourceHandler : public ResourceHandler {
 | 
| + public:
 | 
| +  DummyResourceHandler() {}
 | 
| +
 | 
| +  bool OnRequestRedirected(int request_id, const GURL& url,
 | 
| +                           ResourceResponse* response, bool* defer) {
 | 
| +    return true;
 | 
| +  }
 | 
| +
 | 
| +  bool OnResponseStarted(int request_id, ResourceResponse* response) {
 | 
| +    return true;
 | 
| +  }
 | 
| +
 | 
| +  bool OnWillRead(
 | 
| +      int request_id, net::IOBuffer** buf, int* buf_size, int min_size) {
 | 
| +    return true;
 | 
| +  }
 | 
| +
 | 
| +  bool OnReadCompleted(int request_id, int* bytes_read) { return true; }
 | 
| +
 | 
| +  bool OnResponseCompleted(
 | 
| +    int request_id, const URLRequestStatus& status, const std::string& info) {
 | 
| +    return true;
 | 
| +  }
 | 
| +
 | 
| + private:
 | 
| +  DISALLOW_COPY_AND_ASSIGN(DummyResourceHandler);
 | 
| +};
 | 
| +
 | 
| +class ApplyExtensionMessageFilterPolicyTest : public testing::Test {
 | 
| + protected:
 | 
| +  void SetUp() {
 | 
| +    url_.reset(new GURL(
 | 
| +        "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/popup.html"));
 | 
| +    resource_type_ = ResourceType::STYLESHEET;
 | 
| +    resource_handler_.reset(new DummyResourceHandler());
 | 
| +    request_info_.reset(CreateNewResourceRequestInfo());
 | 
| +  }
 | 
| +
 | 
| +  ResourceDispatcherHostRequestInfo* CreateNewResourceRequestInfo() {
 | 
| +    return new ResourceDispatcherHostRequestInfo(
 | 
| +        resource_handler_.get(), ChildProcessInfo::RENDER_PROCESS, 0, 0, 0,
 | 
| +        "not important", "not important",
 | 
| +        ResourceType::STYLESHEET, 0U, false, false, -1, -1);
 | 
| +  }
 | 
| +
 | 
| +  scoped_ptr<GURL> url_;
 | 
| +  ResourceType::Type resource_type_;
 | 
| +  scoped_ptr<DummyResourceHandler> resource_handler_;
 | 
| +  scoped_ptr<ResourceDispatcherHostRequestInfo> request_info_;
 | 
| +};
 | 
| +
 | 
| +TEST_F(ApplyExtensionMessageFilterPolicyTest, WrongScheme) {
 | 
| +  url_.reset(new GURL("html://behllobkkfkfnphdnhnkndlbkcpglgmj/popup.html"));
 | 
| +  ResourceDispatcherHost::ApplyExtensionMessageFilterPolicy(
 | 
| +      *url_, resource_type_, request_info_.get());
 | 
| +
 | 
| +  EXPECT_EQ(FilterPolicy::DONT_FILTER, request_info_->filter_policy());
 | 
| +}
 | 
| +
 | 
| +TEST_F(ApplyExtensionMessageFilterPolicyTest, GoodScheme) {
 | 
| +  ResourceDispatcherHost::ApplyExtensionMessageFilterPolicy(
 | 
| +      *url_, resource_type_, request_info_.get());
 | 
| +
 | 
| +  EXPECT_EQ(FilterPolicy::FILTER_EXTENSION_MESSAGES,
 | 
| +            request_info_->filter_policy());
 | 
| +}
 | 
| +
 | 
| +TEST_F(ApplyExtensionMessageFilterPolicyTest, GoodSchemeWithSecurityFilter) {
 | 
| +  request_info_->set_filter_policy(FilterPolicy::FILTER_ALL_EXCEPT_IMAGES);
 | 
| +  ResourceDispatcherHost::ApplyExtensionMessageFilterPolicy(
 | 
| +      *url_, resource_type_, request_info_.get());
 | 
| +
 | 
| +  EXPECT_EQ(FilterPolicy::FILTER_ALL_EXCEPT_IMAGES,
 | 
| +            request_info_->filter_policy());
 | 
| +}
 | 
| +
 | 
| +TEST_F(ApplyExtensionMessageFilterPolicyTest, GoodSchemeWrongResourceType) {
 | 
| +  resource_type_ = ResourceType::MAIN_FRAME;
 | 
| +  ResourceDispatcherHost::ApplyExtensionMessageFilterPolicy(
 | 
| +      *url_, resource_type_, request_info_.get());
 | 
| +
 | 
| +  EXPECT_EQ(FilterPolicy::DONT_FILTER, request_info_->filter_policy());
 | 
| +}
 | 
| +
 | 
| +TEST_F(ApplyExtensionMessageFilterPolicyTest, WrongSchemeResourceAndFilter) {
 | 
| +  url_.reset(new GURL("html://behllobkkfkfnphdnhnkndlbkcpglgmj/popup.html"));
 | 
| +  resource_type_ = ResourceType::MEDIA;
 | 
| +  request_info_->set_filter_policy(FilterPolicy::FILTER_ALL);
 | 
| +  ResourceDispatcherHost::ApplyExtensionMessageFilterPolicy(
 | 
| +      *url_, resource_type_, request_info_.get());
 | 
| +
 | 
| +  EXPECT_EQ(FilterPolicy::FILTER_ALL, request_info_->filter_policy());
 | 
| +}
 | 
| 
 |