| 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 "content/browser/loader/async_resource_handler.h" | 5 #include "content/browser/loader/async_resource_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/command_line.h" |
| 11 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
| 16 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
| 17 #include "content/public/test/content_browser_test.h" | 18 #include "content/public/test/content_browser_test.h" |
| 18 #include "content/public/test/content_browser_test_utils.h" | 19 #include "content/public/test/content_browser_test_utils.h" |
| 19 #include "content/shell/browser/shell.h" | 20 #include "content/shell/browser/shell.h" |
| 20 #include "net/test/embedded_test_server/embedded_test_server.h" | 21 #include "net/test/embedded_test_server/embedded_test_server.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 http_response->set_content_type("text/plain"); | 58 http_response->set_content_type("text/plain"); |
| 58 EXPECT_EQ(request.content.length(), kPayloadSize); | 59 EXPECT_EQ(request.content.length(), kPayloadSize); |
| 59 return std::move(http_response); | 60 return std::move(http_response); |
| 60 } else { | 61 } else { |
| 61 return std::unique_ptr<net::test_server::HttpResponse>(); | 62 return std::unique_ptr<net::test_server::HttpResponse>(); |
| 62 } | 63 } |
| 63 } | 64 } |
| 64 | 65 |
| 65 } // namespace | 66 } // namespace |
| 66 | 67 |
| 67 class AsyncResourceHandlerBrowserTest : public ContentBrowserTest { | 68 class AsyncResourceHandlerBrowserTest |
| 69 : public ContentBrowserTest, |
| 70 public testing::WithParamInterface<bool> { |
| 71 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 72 if (GetParam()) { |
| 73 command_line->AppendSwitchASCII("--enable-blink-features", |
| 74 "LoadingWithMojo"); |
| 75 } |
| 76 } |
| 68 }; | 77 }; |
| 69 | 78 |
| 70 IN_PROC_BROWSER_TEST_F(AsyncResourceHandlerBrowserTest, UploadProgress) { | 79 IN_PROC_BROWSER_TEST_P(AsyncResourceHandlerBrowserTest, UploadProgress) { |
| 71 net::EmbeddedTestServer* test_server = embedded_test_server(); | 80 net::EmbeddedTestServer* test_server = embedded_test_server(); |
| 72 test_server->RegisterRequestHandler( | 81 test_server->RegisterRequestHandler( |
| 73 base::Bind(&HandlePostAndRedirectURLs, kPostPath)); | 82 base::Bind(&HandlePostAndRedirectURLs, kPostPath)); |
| 74 ASSERT_TRUE(test_server->Start()); | 83 ASSERT_TRUE(test_server->Start()); |
| 75 | 84 |
| 76 NavigateToURL(shell(), | 85 NavigateToURL(shell(), |
| 77 test_server->GetURL("/loader/async_resource_handler.html")); | 86 test_server->GetURL("/loader/async_resource_handler.html")); |
| 78 | 87 |
| 79 std::string js_result; | 88 std::string js_result; |
| 80 EXPECT_TRUE(ExecuteScriptAndExtractString( | 89 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 81 shell(), base::StringPrintf("WaitForAsyncXHR('%s', %" PRIuS ")", | 90 shell(), base::StringPrintf("WaitForAsyncXHR('%s', %" PRIuS ")", |
| 82 kPostPath, kPayloadSize), | 91 kPostPath, kPayloadSize), |
| 83 &js_result)); | 92 &js_result)); |
| 84 EXPECT_EQ(js_result, "success"); | 93 EXPECT_EQ(js_result, "success"); |
| 85 } | 94 } |
| 86 | 95 |
| 87 IN_PROC_BROWSER_TEST_F(AsyncResourceHandlerBrowserTest, | 96 IN_PROC_BROWSER_TEST_P(AsyncResourceHandlerBrowserTest, |
| 88 UploadProgressRedirect) { | 97 UploadProgressRedirect) { |
| 89 net::EmbeddedTestServer* test_server = embedded_test_server(); | 98 net::EmbeddedTestServer* test_server = embedded_test_server(); |
| 90 test_server->RegisterRequestHandler( | 99 test_server->RegisterRequestHandler( |
| 91 base::Bind(&HandlePostAndRedirectURLs, kRedirectPostPath)); | 100 base::Bind(&HandlePostAndRedirectURLs, kRedirectPostPath)); |
| 92 ASSERT_TRUE(test_server->Start()); | 101 ASSERT_TRUE(test_server->Start()); |
| 93 | 102 |
| 94 NavigateToURL(shell(), | 103 NavigateToURL(shell(), |
| 95 test_server->GetURL("/loader/async_resource_handler.html")); | 104 test_server->GetURL("/loader/async_resource_handler.html")); |
| 96 | 105 |
| 97 std::string js_result; | 106 std::string js_result; |
| 98 EXPECT_TRUE(ExecuteScriptAndExtractString( | 107 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 99 shell(), base::StringPrintf("WaitForAsyncXHR('%s', %" PRIuS ")", | 108 shell(), base::StringPrintf("WaitForAsyncXHR('%s', %" PRIuS ")", |
| 100 kRedirectPostPath, kPayloadSize), | 109 kRedirectPostPath, kPayloadSize), |
| 101 &js_result)); | 110 &js_result)); |
| 102 EXPECT_EQ(js_result, "success"); | 111 EXPECT_EQ(js_result, "success"); |
| 103 } | 112 } |
| 104 | 113 |
| 114 INSTANTIATE_TEST_CASE_P(AsyncResourceHandlerBrowserTest, |
| 115 AsyncResourceHandlerBrowserTest, |
| 116 ::testing::Values(false, true)); |
| 117 |
| 105 } // namespace content | 118 } // namespace content |
| OLD | NEW |