Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/loader/async_resource_handler.h" | |
| 6 | |
| 7 #include "base/strings/string_util.h" | |
| 8 #include "content/public/common/content_switches.h" | |
| 9 #include "content/public/test/browser_test_utils.h" | |
| 10 #include "content/public/test/content_browser_test.h" | |
| 11 #include "content/public/test/content_browser_test_utils.h" | |
| 12 #include "content/shell/browser/shell.h" | |
| 13 #include "net/test/embedded_test_server/embedded_test_server.h" | |
| 14 #include "net/test/embedded_test_server/http_request.h" | |
| 15 #include "net/test/embedded_test_server/http_response.h" | |
| 16 | |
| 17 namespace content { | |
| 18 | |
| 19 namespace { | |
|
mmenke
2015/08/27 17:21:29
nit: Blank line after start and before end of nam
| |
| 20 const char kPost[] = "/post"; | |
| 21 const char kRedirect[] = "/redirect"; | |
|
mmenke
2015/08/27 17:21:29
Maybe kPostPath / kRedirectPostPath? We post to
| |
| 22 | |
| 23 scoped_ptr<net::test_server::HttpResponse> SimplePost( | |
|
mmenke
2015/08/27 17:21:29
include net/test/embedded_test_server/http_respons
mmenke
2015/08/27 17:21:29
include base/memory/scoped_ptr.h
mmenke
2015/08/27 17:21:29
Do we even need this method? SimplePostRedirect w
| |
| 24 const std::string& path, | |
|
mmenke
2015/08/27 17:21:29
include string.h
| |
| 25 const net::test_server::HttpRequest& request) { | |
|
mmenke
2015/08/27 17:21:29
net/test/embedded_test_server/http_request.h
| |
| 26 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | |
| 27 new net::test_server::BasicHttpResponse()); | |
| 28 http_response->set_content("hello"); | |
| 29 http_response->set_content_type("text/plain"); | |
| 30 return http_response.Pass(); | |
| 31 } | |
| 32 | |
| 33 const size_t payload_size = 28697814; // 2*3^15 | |
|
mmenke
2015/08/27 17:21:29
nit: Two spaces between code and comments.
mmenke
2015/08/27 17:21:29
kPayloadSize
| |
| 34 scoped_ptr<net::test_server::HttpResponse> SimplePostRedirect( | |
|
mmenke
2015/08/27 17:21:29
HandlePostAndRedirectURLs?
| |
| 35 const std::string& request_path, | |
| 36 const net::test_server::HttpRequest& request) { | |
| 37 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | |
| 38 new net::test_server::BasicHttpResponse()); | |
| 39 if (base::StartsWith(request.relative_url, kRedirect, | |
| 40 base::CompareCase::SENSITIVE)) { | |
| 41 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); | |
| 42 http_response->AddCustomHeader("Location", kPost); | |
| 43 EXPECT_EQ(request.content.length(), payload_size);; | |
|
mmenke
2015/08/27 17:21:29
Should explicitly include gtest.h
| |
| 44 return http_response.Pass(); | |
| 45 } else if(base::StartsWith(request.relative_url, kPost, | |
| 46 base::CompareCase::SENSITIVE)) { | |
| 47 http_response->set_content("hello"); | |
| 48 http_response->set_content_type("text/plain"); | |
| 49 EXPECT_EQ(request.content.length(), payload_size); | |
| 50 return http_response.Pass(); | |
| 51 } else { | |
| 52 return scoped_ptr<net::test_server::HttpResponse>(); | |
| 53 } | |
| 54 } | |
| 55 } // namespace | |
|
mmenke
2015/08/27 17:21:29
nit: Blank line after start and before end of nam
| |
| 56 | |
| 57 class AsyncResourceHandlerBrowserTest : public ContentBrowserTest { | |
| 58 }; | |
| 59 | |
| 60 IN_PROC_BROWSER_TEST_F(AsyncResourceHandlerBrowserTest, UploadProgress) { | |
| 61 net::test_server::EmbeddedTestServer *test_server = embedded_test_server(); | |
|
mmenke
2015/08/27 17:21:29
* should be before the space.
| |
| 62 ASSERT_TRUE(test_server->InitializeAndWaitUntilReady()); | |
| 63 test_server->RegisterRequestHandler( | |
| 64 base::Bind(&SimplePost, kPost)); | |
| 65 | |
| 66 NavigateToURL(shell(), | |
| 67 test_server->GetURL("/loader/async_resource_handler.html")); | |
| 68 | |
| 69 bool js_result = false; | |
| 70 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
| 71 shell()->web_contents(), | |
| 72 "WaitForAsyncXHR('/post')", | |
| 73 &js_result)); | |
| 74 EXPECT_TRUE(js_result); | |
| 75 } | |
| 76 | |
| 77 IN_PROC_BROWSER_TEST_F(AsyncResourceHandlerBrowserTest, | |
| 78 UploadProgressRedirect) { | |
| 79 net::test_server::EmbeddedTestServer *test_server = embedded_test_server(); | |
|
mmenke
2015/08/27 17:21:29
* should be before the space.
| |
| 80 ASSERT_TRUE(test_server->InitializeAndWaitUntilReady()); | |
| 81 test_server->RegisterRequestHandler( | |
| 82 base::Bind(&SimplePostRedirect, kRedirect)); | |
| 83 | |
| 84 NavigateToURL(shell(), | |
| 85 test_server->GetURL("/loader/async_resource_handler.html")); | |
| 86 | |
| 87 bool js_result = false; | |
| 88 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
| 89 shell()->web_contents(), | |
| 90 "WaitForAsyncXHR('/redirect')", | |
| 91 &js_result)); | |
| 92 EXPECT_TRUE(js_result); | |
| 93 } | |
| 94 | |
| 95 } // namespace content | |
| OLD | NEW |