| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
| 7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/policy/cloud/policy_header_service_factory.h" | 8 #include "chrome/browser/policy/cloud/policy_header_service_factory.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" | 10 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 : ChromeResourceDispatcherHostDelegate(prerender_tracker) { | 57 : ChromeResourceDispatcherHostDelegate(prerender_tracker) { |
| 58 } | 58 } |
| 59 | 59 |
| 60 virtual ~TestDispatcherHostDelegate() {} | 60 virtual ~TestDispatcherHostDelegate() {} |
| 61 | 61 |
| 62 virtual void RequestBeginning( | 62 virtual void RequestBeginning( |
| 63 net::URLRequest* request, | 63 net::URLRequest* request, |
| 64 content::ResourceContext* resource_context, | 64 content::ResourceContext* resource_context, |
| 65 content::AppCacheService* appcache_service, | 65 content::AppCacheService* appcache_service, |
| 66 ResourceType resource_type, | 66 ResourceType resource_type, |
| 67 ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE { | 67 ScopedVector<content::ResourceThrottle>* throttles) override { |
| 68 ChromeResourceDispatcherHostDelegate::RequestBeginning( | 68 ChromeResourceDispatcherHostDelegate::RequestBeginning( |
| 69 request, | 69 request, |
| 70 resource_context, | 70 resource_context, |
| 71 appcache_service, | 71 appcache_service, |
| 72 resource_type, | 72 resource_type, |
| 73 throttles); | 73 throttles); |
| 74 request_headers_.MergeFrom(request->extra_request_headers()); | 74 request_headers_.MergeFrom(request->extra_request_headers()); |
| 75 } | 75 } |
| 76 | 76 |
| 77 virtual void OnRequestRedirected( | 77 virtual void OnRequestRedirected( |
| 78 const GURL& redirect_url, | 78 const GURL& redirect_url, |
| 79 net::URLRequest* request, | 79 net::URLRequest* request, |
| 80 content::ResourceContext* resource_context, | 80 content::ResourceContext* resource_context, |
| 81 content::ResourceResponse* response) OVERRIDE { | 81 content::ResourceResponse* response) override { |
| 82 ChromeResourceDispatcherHostDelegate::OnRequestRedirected( | 82 ChromeResourceDispatcherHostDelegate::OnRequestRedirected( |
| 83 redirect_url, | 83 redirect_url, |
| 84 request, | 84 request, |
| 85 resource_context, | 85 resource_context, |
| 86 response); | 86 response); |
| 87 request_headers_.MergeFrom(request->extra_request_headers()); | 87 request_headers_.MergeFrom(request->extra_request_headers()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 net::HttpRequestHeaders request_headers_; | 90 net::HttpRequestHeaders request_headers_; |
| 91 | 91 |
| 92 private: | 92 private: |
| 93 DISALLOW_COPY_AND_ASSIGN(TestDispatcherHostDelegate); | 93 DISALLOW_COPY_AND_ASSIGN(TestDispatcherHostDelegate); |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 } // namespace | 96 } // namespace |
| 97 | 97 |
| 98 class ChromeResourceDispatcherHostDelegateBrowserTest : | 98 class ChromeResourceDispatcherHostDelegateBrowserTest : |
| 99 public InProcessBrowserTest { | 99 public InProcessBrowserTest { |
| 100 public: | 100 public: |
| 101 ChromeResourceDispatcherHostDelegateBrowserTest() {} | 101 ChromeResourceDispatcherHostDelegateBrowserTest() {} |
| 102 | 102 |
| 103 virtual void SetUpOnMainThread() OVERRIDE { | 103 virtual void SetUpOnMainThread() override { |
| 104 InProcessBrowserTest::SetUpOnMainThread(); | 104 InProcessBrowserTest::SetUpOnMainThread(); |
| 105 // Hook navigations with our delegate. | 105 // Hook navigations with our delegate. |
| 106 dispatcher_host_delegate_.reset(new TestDispatcherHostDelegate( | 106 dispatcher_host_delegate_.reset(new TestDispatcherHostDelegate( |
| 107 g_browser_process->prerender_tracker())); | 107 g_browser_process->prerender_tracker())); |
| 108 content::ResourceDispatcherHost::Get()->SetDelegate( | 108 content::ResourceDispatcherHost::Get()->SetDelegate( |
| 109 dispatcher_host_delegate_.get()); | 109 dispatcher_host_delegate_.get()); |
| 110 | 110 |
| 111 embedded_test_server()->RegisterRequestHandler( | 111 embedded_test_server()->RegisterRequestHandler( |
| 112 base::Bind(&HandleTestRequest)); | 112 base::Bind(&HandleTestRequest)); |
| 113 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 113 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 114 // Tell chrome that this is our DM server. | 114 // Tell chrome that this is our DM server. |
| 115 dm_url_ = embedded_test_server()->GetURL("/DeviceManagement"); | 115 dm_url_ = embedded_test_server()->GetURL("/DeviceManagement"); |
| 116 | 116 |
| 117 // At this point, the Profile is already initialized and it's too | 117 // At this point, the Profile is already initialized and it's too |
| 118 // late to set the DMServer URL via command line flags, so directly | 118 // late to set the DMServer URL via command line flags, so directly |
| 119 // inject it to the PolicyHeaderIOHelper. | 119 // inject it to the PolicyHeaderIOHelper. |
| 120 policy::PolicyHeaderService* policy_header_service = | 120 policy::PolicyHeaderService* policy_header_service = |
| 121 policy::PolicyHeaderServiceFactory::GetForBrowserContext( | 121 policy::PolicyHeaderServiceFactory::GetForBrowserContext( |
| 122 browser()->profile()); | 122 browser()->profile()); |
| 123 std::vector<policy::PolicyHeaderIOHelper*> helpers = | 123 std::vector<policy::PolicyHeaderIOHelper*> helpers = |
| 124 policy_header_service->GetHelpersForTest(); | 124 policy_header_service->GetHelpersForTest(); |
| 125 for (std::vector<policy::PolicyHeaderIOHelper*>::const_iterator it = | 125 for (std::vector<policy::PolicyHeaderIOHelper*>::const_iterator it = |
| 126 helpers.begin(); | 126 helpers.begin(); |
| 127 it != helpers.end(); ++it) { | 127 it != helpers.end(); ++it) { |
| 128 (*it)->SetServerURLForTest(dm_url_.spec()); | 128 (*it)->SetServerURLForTest(dm_url_.spec()); |
| 129 (*it)->UpdateHeader(kTestPolicyHeader); | 129 (*it)->UpdateHeader(kTestPolicyHeader); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 virtual void TearDownOnMainThread() OVERRIDE { | 133 virtual void TearDownOnMainThread() override { |
| 134 content::ResourceDispatcherHost::Get()->SetDelegate(NULL); | 134 content::ResourceDispatcherHost::Get()->SetDelegate(NULL); |
| 135 dispatcher_host_delegate_.reset(); | 135 dispatcher_host_delegate_.reset(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 protected: | 138 protected: |
| 139 // The fake URL for DMServer we are using. | 139 // The fake URL for DMServer we are using. |
| 140 GURL dm_url_; | 140 GURL dm_url_; |
| 141 scoped_ptr<TestDispatcherHostDelegate> dispatcher_host_delegate_; | 141 scoped_ptr<TestDispatcherHostDelegate> dispatcher_host_delegate_; |
| 142 | 142 |
| 143 private: | 143 private: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 redirect_url += kServerRedirectUrl; | 175 redirect_url += kServerRedirectUrl; |
| 176 redirect_url += "?"; | 176 redirect_url += "?"; |
| 177 redirect_url += dm_url_.spec(); | 177 redirect_url += dm_url_.spec(); |
| 178 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL( | 178 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL( |
| 179 redirect_url)); | 179 redirect_url)); |
| 180 std::string value; | 180 std::string value; |
| 181 ASSERT_TRUE(dispatcher_host_delegate_->request_headers_.GetHeader( | 181 ASSERT_TRUE(dispatcher_host_delegate_->request_headers_.GetHeader( |
| 182 policy::kChromePolicyHeader, &value)); | 182 policy::kChromePolicyHeader, &value)); |
| 183 ASSERT_EQ(kTestPolicyHeader, value); | 183 ASSERT_EQ(kTestPolicyHeader, value); |
| 184 } | 184 } |
| OLD | NEW |