| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "chrome/browser/extensions/extension_browsertest.h" | 9 #include "chrome/browser/extensions/extension_browsertest.h" |
| 10 #include "chrome/browser/profiles/profile_io_data.h" | 10 #include "chrome/browser/profiles/profile_io_data.h" |
| 11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
| 13 #include "extensions/browser/extension_throttle_manager.h" | 13 #include "extensions/browser/extension_throttle_manager.h" |
| 14 #include "extensions/test/result_catcher.h" | 14 #include "extensions/test/result_catcher.h" |
| 15 #include "net/base/backoff_entry.h" | 15 #include "net/base/backoff_entry.h" |
| 16 #include "net/base/url_util.h" | 16 #include "net/base/url_util.h" |
| 17 #include "net/dns/mock_host_resolver.h" | 17 #include "net/dns/mock_host_resolver.h" |
| 18 #include "net/test/embedded_test_server/embedded_test_server.h" | 18 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 19 #include "net/test/embedded_test_server/http_request.h" | 19 #include "net/test/embedded_test_server/http_request.h" |
| 20 #include "net/test/embedded_test_server/http_response.h" | 20 #include "net/test/embedded_test_server/http_response.h" |
| 21 | 21 |
| 22 namespace extensions { | 22 namespace extensions { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 scoped_ptr<net::test_server::HttpResponse> HandleRequest( | 26 scoped_ptr<net::test_server::HttpResponse> HandleRequest( |
| 27 bool set_cache_header_redirect_page, | 27 bool set_cache_header_redirect_page, |
| 28 bool set_cache_header_test_throttle_page, | 28 bool set_cache_header_test_throttle_page, |
| 29 const net::test_server::HttpRequest& request) { | 29 const net::test_server::HttpRequest& request) { |
| 30 if (base::StartsWithASCII(request.relative_url, "/redirect", true)) { | 30 if (base::StartsWith(request.relative_url, "/redirect", |
| 31 base::CompareCase::SENSITIVE)) { |
| 31 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | 32 scoped_ptr<net::test_server::BasicHttpResponse> http_response( |
| 32 new net::test_server::BasicHttpResponse()); | 33 new net::test_server::BasicHttpResponse()); |
| 33 http_response->set_code(net::HTTP_FOUND); | 34 http_response->set_code(net::HTTP_FOUND); |
| 34 http_response->set_content("Redirecting..."); | 35 http_response->set_content("Redirecting..."); |
| 35 http_response->set_content_type("text/plain"); | 36 http_response->set_content_type("text/plain"); |
| 36 http_response->AddCustomHeader("Location", "/test_throttle"); | 37 http_response->AddCustomHeader("Location", "/test_throttle"); |
| 37 if (set_cache_header_redirect_page) | 38 if (set_cache_header_redirect_page) |
| 38 http_response->AddCustomHeader("Cache-Control", "max-age=3600"); | 39 http_response->AddCustomHeader("Cache-Control", "max-age=3600"); |
| 39 return http_response.Pass(); | 40 return http_response.Pass(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 if (base::StartsWithASCII(request.relative_url, "/test_throttle", true)) { | 43 if (base::StartsWith(request.relative_url, "/test_throttle", |
| 44 base::CompareCase::SENSITIVE)) { |
| 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_SERVICE_UNAVAILABLE); | 47 http_response->set_code(net::HTTP_SERVICE_UNAVAILABLE); |
| 46 http_response->set_content("The server is overloaded right now."); | 48 http_response->set_content("The server is overloaded right now."); |
| 47 http_response->set_content_type("text/plain"); | 49 http_response->set_content_type("text/plain"); |
| 48 if (set_cache_header_test_throttle_page) | 50 if (set_cache_header_test_throttle_page) |
| 49 http_response->AddCustomHeader("Cache-Control", "max-age=3600"); | 51 http_response->AddCustomHeader("Cache-Control", "max-age=3600"); |
| 50 return http_response.Pass(); | 52 return http_response.Pass(); |
| 51 } | 53 } |
| 52 | 54 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 ThrottleRequestDisabled) { | 231 ThrottleRequestDisabled) { |
| 230 embedded_test_server()->RegisterRequestHandler( | 232 embedded_test_server()->RegisterRequestHandler( |
| 231 base::Bind(&HandleRequest, false, false)); | 233 base::Bind(&HandleRequest, false, false)); |
| 232 ASSERT_NO_FATAL_FAILURE( | 234 ASSERT_NO_FATAL_FAILURE( |
| 233 RunTest("test_request_not_throttled.html", | 235 RunTest("test_request_not_throttled.html", |
| 234 base::StringPrintf("http://www.example.com:%d/test_throttle", | 236 base::StringPrintf("http://www.example.com:%d/test_throttle", |
| 235 embedded_test_server()->port()))); | 237 embedded_test_server()->port()))); |
| 236 } | 238 } |
| 237 | 239 |
| 238 } // namespace extensions | 240 } // namespace extensions |
| OLD | NEW |