Chromium Code Reviews| Index: content/browser/loader/async_resource_handler_browsertest.cc |
| diff --git a/content/browser/loader/async_resource_handler_browsertest.cc b/content/browser/loader/async_resource_handler_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3aeac2cbadfc80eb8ae0874e49e167120a26be60 |
| --- /dev/null |
| +++ b/content/browser/loader/async_resource_handler_browsertest.cc |
| @@ -0,0 +1,96 @@ |
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
|
mmenke
2015/08/26 19:13:12
nit: Don't use (c) in new files.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/strings/string_util.h" |
| +#include "content/browser/loader/async_resource_handler.h" |
|
mmenke
2015/08/26 19:13:12
This should go first, 1 line above the others.
|
| +#include "content/public/common/content_switches.h" |
| +#include "content/public/test/browser_test_utils.h" |
| +#include "content/public/test/content_browser_test.h" |
| +#include "content/public/test/content_browser_test_utils.h" |
| +#include "content/shell/browser/shell.h" |
| +#include "net/test/embedded_test_server/embedded_test_server.h" |
| +#include "net/test/embedded_test_server/http_request.h" |
| +#include "net/test/embedded_test_server/http_response.h" |
| + |
| +namespace content { |
| + |
| +const char kPost[] = "/post"; |
| +const char kRedirect[] = "/redirect"; |
|
mmenke
2015/08/26 19:13:12
These should go in the anonymous namespace
|
| + |
| +class AsyncResourceHandlerBrowserTest : public ContentBrowserTest { |
| +}; |
|
mmenke
2015/08/26 19:13:13
This should go below the anonymous namespace.
|
| + |
| +namespace { |
| +scoped_ptr<net::test_server::HttpResponse> SimplePost( |
| + const std::string& path, |
| + const net::test_server::HttpRequest& request) { |
| + scoped_ptr<net::test_server::BasicHttpResponse> http_response( |
| + new net::test_server::BasicHttpResponse()); |
| + http_response->set_content("hello"); |
| + http_response->set_content_type("text/plain"); |
| + return http_response.Pass(); |
| +} |
| +} // namespace |
|
mmenke
2015/08/26 19:13:12
nit: Should be:
namespace {
....
} // namespa
|
| + |
| +IN_PROC_BROWSER_TEST_F(AsyncResourceHandlerBrowserTest, UploadProgress) { |
| + net::test_server::EmbeddedTestServer *test_server = embedded_test_server(); |
| + ASSERT_TRUE(test_server->InitializeAndWaitUntilReady()); |
| + test_server->RegisterRequestHandler( |
| + base::Bind(&SimplePost, kPost)); |
|
mmenke
2015/08/26 19:13:12
nit: +2 indent
|
| + |
| + NavigateToURL(shell(), test_server->GetURL("/async_resource_handler.html")); |
| + |
| + bool js_result = false; |
| + EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| + shell()->web_contents(), |
| + "WaitForAsyncXHR('/post')", |
| + &js_result)); |
| + EXPECT_TRUE(js_result); |
| + |
|
mmenke
2015/08/26 19:13:12
Remove blank line.
|
| +} |
| + |
| +namespace { |
| +const size_t payload_size = 28697814; // 2*3^15 |
| +scoped_ptr<net::test_server::HttpResponse> SimplePostRedirect( |
| + const std::string& request_path, |
| + const net::test_server::HttpRequest& request) { |
| + scoped_ptr<net::test_server::BasicHttpResponse> http_response( |
| + new net::test_server::BasicHttpResponse()); |
|
mmenke
2015/08/26 19:13:12
nit: +2 indent
|
| + if (base::StartsWith(request.relative_url, kRedirect, |
| + base::CompareCase::SENSITIVE)) { |
| + http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); |
| + http_response->AddCustomHeader("Location", kPost); |
| + EXPECT_EQ(request.content.length(), payload_size);; |
| + return http_response.Pass(); |
| + } else if(base::StartsWith(request.relative_url, kPost, |
| + base::CompareCase::SENSITIVE)) { |
| + http_response->set_content("hello"); |
| + http_response->set_content_type("text/plain"); |
| + EXPECT_EQ(request.content.length(), payload_size); |
| + return http_response.Pass(); |
| + } else { |
| + return scoped_ptr<net::test_server::HttpResponse>(); |
| + } |
| +} |
|
mmenke
2015/08/26 19:13:12
Suggest putting this all in the anonymous namespac
|
| +} //namespace |
| + |
| +IN_PROC_BROWSER_TEST_F(AsyncResourceHandlerBrowserTest, |
| + UploadProgressRedirect) { |
| + net::test_server::EmbeddedTestServer *test_server = embedded_test_server(); |
| + ASSERT_TRUE(test_server->InitializeAndWaitUntilReady()); |
| + test_server->RegisterRequestHandler( |
| + base::Bind(&SimplePostRedirect, kRedirect)); |
|
mmenke
2015/08/26 19:13:12
nit: +2 indent
|
| + |
| + NavigateToURL(shell(), test_server->GetURL("/async_resource_handler.html")); |
| + |
| + bool js_result = false; |
| + EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| + shell()->web_contents(), |
| + "WaitForAsyncXHR('/redirect')", |
| + &js_result)); |
| + EXPECT_TRUE(js_result); |
| + |
|
mmenke
2015/08/26 19:13:12
Remove blank line
|
| +} |
| + |
| +} // namespace content |