| 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 "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" |
| 6 |
| 5 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> |
| 6 | 9 |
| 7 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 8 #include "base/macros.h" | 11 #include "base/macros.h" |
| 9 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 10 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/policy/cloud/policy_header_service_factory.h" | 14 #include "chrome/browser/policy/cloud/policy_header_service_factory.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" | |
| 14 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 19 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 18 #include "components/policy/core/common/cloud/policy_header_io_helper.h" | 20 #include "components/policy/core/common/cloud/policy_header_io_helper.h" |
| 19 #include "components/policy/core/common/cloud/policy_header_service.h" | 21 #include "components/policy/core/common/cloud/policy_header_service.h" |
| 20 #include "components/policy/core/common/policy_switches.h" | 22 #include "components/policy/core/common/policy_switches.h" |
| 21 #include "content/public/browser/resource_dispatcher_host.h" | 23 #include "content/public/browser/resource_dispatcher_host.h" |
| 22 #include "net/http/http_request_headers.h" | 24 #include "net/http/http_request_headers.h" |
| 23 #include "net/test/embedded_test_server/embedded_test_server.h" | 25 #include "net/test/embedded_test_server/embedded_test_server.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 37 base::CompareCase::SENSITIVE)) { | 39 base::CompareCase::SENSITIVE)) { |
| 38 // Extract the target URL and redirect there. | 40 // Extract the target URL and redirect there. |
| 39 size_t query_string_pos = request.relative_url.find('?'); | 41 size_t query_string_pos = request.relative_url.find('?'); |
| 40 std::string redirect_target = | 42 std::string redirect_target = |
| 41 request.relative_url.substr(query_string_pos + 1); | 43 request.relative_url.substr(query_string_pos + 1); |
| 42 | 44 |
| 43 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | 45 scoped_ptr<net::test_server::BasicHttpResponse> http_response( |
| 44 new net::test_server::BasicHttpResponse); | 46 new net::test_server::BasicHttpResponse); |
| 45 http_response->set_code(net::HTTP_MOVED_PERMANENTLY); | 47 http_response->set_code(net::HTTP_MOVED_PERMANENTLY); |
| 46 http_response->AddCustomHeader("Location", redirect_target); | 48 http_response->AddCustomHeader("Location", redirect_target); |
| 47 return http_response.Pass(); | 49 return std::move(http_response); |
| 48 } else { | 50 } else { |
| 49 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | 51 scoped_ptr<net::test_server::BasicHttpResponse> http_response( |
| 50 new net::test_server::BasicHttpResponse); | 52 new net::test_server::BasicHttpResponse); |
| 51 http_response->set_code(net::HTTP_OK); | 53 http_response->set_code(net::HTTP_OK); |
| 52 http_response->set_content("Success"); | 54 http_response->set_content("Success"); |
| 53 return http_response.Pass(); | 55 return std::move(http_response); |
| 54 } | 56 } |
| 55 } | 57 } |
| 56 | 58 |
| 57 class TestDispatcherHostDelegate : public ChromeResourceDispatcherHostDelegate { | 59 class TestDispatcherHostDelegate : public ChromeResourceDispatcherHostDelegate { |
| 58 public: | 60 public: |
| 59 TestDispatcherHostDelegate() {} | 61 TestDispatcherHostDelegate() {} |
| 60 ~TestDispatcherHostDelegate() override {} | 62 ~TestDispatcherHostDelegate() override {} |
| 61 | 63 |
| 62 void RequestBeginning( | 64 void RequestBeginning( |
| 63 net::URLRequest* request, | 65 net::URLRequest* request, |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 redirect_url += kServerRedirectUrl; | 175 redirect_url += kServerRedirectUrl; |
| 174 redirect_url += "?"; | 176 redirect_url += "?"; |
| 175 redirect_url += dm_url_.spec(); | 177 redirect_url += dm_url_.spec(); |
| 176 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL( | 178 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL( |
| 177 redirect_url)); | 179 redirect_url)); |
| 178 std::string value; | 180 std::string value; |
| 179 ASSERT_TRUE(dispatcher_host_delegate_->request_headers_.GetHeader( | 181 ASSERT_TRUE(dispatcher_host_delegate_->request_headers_.GetHeader( |
| 180 policy::kChromePolicyHeader, &value)); | 182 policy::kChromePolicyHeader, &value)); |
| 181 ASSERT_EQ(kTestPolicyHeader, value); | 183 ASSERT_EQ(kTestPolicyHeader, value); |
| 182 } | 184 } |
| OLD | NEW |