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"); | |
mmenke
2017/01/18 17:00:46
nit: Add braces. (And good job noticing we can n
tzik
2017/01/19 11:53:09
Done.
| |
75 } | |
68 }; | 76 }; |
69 | 77 |
70 IN_PROC_BROWSER_TEST_F(AsyncResourceHandlerBrowserTest, UploadProgress) { | 78 IN_PROC_BROWSER_TEST_P(AsyncResourceHandlerBrowserTest, UploadProgress) { |
71 net::EmbeddedTestServer* test_server = embedded_test_server(); | 79 net::EmbeddedTestServer* test_server = embedded_test_server(); |
72 test_server->RegisterRequestHandler( | 80 test_server->RegisterRequestHandler( |
73 base::Bind(&HandlePostAndRedirectURLs, kPostPath)); | 81 base::Bind(&HandlePostAndRedirectURLs, kPostPath)); |
74 ASSERT_TRUE(test_server->Start()); | 82 ASSERT_TRUE(test_server->Start()); |
75 | 83 |
76 NavigateToURL(shell(), | 84 NavigateToURL(shell(), |
77 test_server->GetURL("/loader/async_resource_handler.html")); | 85 test_server->GetURL("/loader/async_resource_handler.html")); |
78 | 86 |
79 std::string js_result; | 87 std::string js_result; |
80 EXPECT_TRUE(ExecuteScriptAndExtractString( | 88 EXPECT_TRUE(ExecuteScriptAndExtractString( |
81 shell(), base::StringPrintf("WaitForAsyncXHR('%s', %" PRIuS ")", | 89 shell(), base::StringPrintf("WaitForAsyncXHR('%s', %" PRIuS ")", |
82 kPostPath, kPayloadSize), | 90 kPostPath, kPayloadSize), |
83 &js_result)); | 91 &js_result)); |
84 EXPECT_EQ(js_result, "success"); | 92 EXPECT_EQ(js_result, "success"); |
85 } | 93 } |
86 | 94 |
87 IN_PROC_BROWSER_TEST_F(AsyncResourceHandlerBrowserTest, | 95 IN_PROC_BROWSER_TEST_P(AsyncResourceHandlerBrowserTest, |
88 UploadProgressRedirect) { | 96 UploadProgressRedirect) { |
89 net::EmbeddedTestServer* test_server = embedded_test_server(); | 97 net::EmbeddedTestServer* test_server = embedded_test_server(); |
90 test_server->RegisterRequestHandler( | 98 test_server->RegisterRequestHandler( |
91 base::Bind(&HandlePostAndRedirectURLs, kRedirectPostPath)); | 99 base::Bind(&HandlePostAndRedirectURLs, kRedirectPostPath)); |
92 ASSERT_TRUE(test_server->Start()); | 100 ASSERT_TRUE(test_server->Start()); |
93 | 101 |
94 NavigateToURL(shell(), | 102 NavigateToURL(shell(), |
95 test_server->GetURL("/loader/async_resource_handler.html")); | 103 test_server->GetURL("/loader/async_resource_handler.html")); |
96 | 104 |
97 std::string js_result; | 105 std::string js_result; |
98 EXPECT_TRUE(ExecuteScriptAndExtractString( | 106 EXPECT_TRUE(ExecuteScriptAndExtractString( |
99 shell(), base::StringPrintf("WaitForAsyncXHR('%s', %" PRIuS ")", | 107 shell(), base::StringPrintf("WaitForAsyncXHR('%s', %" PRIuS ")", |
100 kRedirectPostPath, kPayloadSize), | 108 kRedirectPostPath, kPayloadSize), |
101 &js_result)); | 109 &js_result)); |
102 EXPECT_EQ(js_result, "success"); | 110 EXPECT_EQ(js_result, "success"); |
103 } | 111 } |
104 | 112 |
113 INSTANTIATE_TEST_CASE_P(AsyncResourceHandlerBrowserTest, | |
114 AsyncResourceHandlerBrowserTest, | |
115 ::testing::Values(false, true)); | |
116 | |
105 } // namespace content | 117 } // namespace content |
OLD | NEW |