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 <string> | 7 #include <string> |
8 | 8 |
| 9 #include "base/format_macros.h" |
9 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/stringprintf.h" |
10 #include "content/public/common/content_switches.h" | 12 #include "content/public/common/content_switches.h" |
11 #include "content/public/test/browser_test_utils.h" | 13 #include "content/public/test/browser_test_utils.h" |
12 #include "content/public/test/content_browser_test.h" | 14 #include "content/public/test/content_browser_test.h" |
13 #include "content/public/test/content_browser_test_utils.h" | 15 #include "content/public/test/content_browser_test_utils.h" |
14 #include "content/shell/browser/shell.h" | 16 #include "content/shell/browser/shell.h" |
15 #include "net/test/embedded_test_server/embedded_test_server.h" | 17 #include "net/test/embedded_test_server/embedded_test_server.h" |
16 #include "net/test/embedded_test_server/http_request.h" | 18 #include "net/test/embedded_test_server/http_request.h" |
17 #include "net/test/embedded_test_server/http_response.h" | 19 #include "net/test/embedded_test_server/http_response.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
19 | 21 |
20 namespace content { | 22 namespace content { |
21 | 23 |
22 namespace { | 24 namespace { |
23 | 25 |
24 const char kPostPath[] = "/post"; | 26 const char kPostPath[] = "/post"; |
25 const char kRedirectPostPath[] = "/redirect"; | 27 const char kRedirectPostPath[] = "/redirect"; |
| 28 |
| 29 // ThreadSanitizer is too slow to perform the full upload, so tests |
| 30 // using that build get an easier test which might not show two distinct |
| 31 // progress events. See crbug.com/526985. |
| 32 #if defined(THREAD_SANITIZER) |
| 33 const size_t kPayloadSize = 1062882; // 2*3^12 |
| 34 #else |
26 const size_t kPayloadSize = 28697814; // 2*3^15 | 35 const size_t kPayloadSize = 28697814; // 2*3^15 |
| 36 #endif |
27 | 37 |
28 scoped_ptr<net::test_server::HttpResponse> HandlePostAndRedirectURLs( | 38 scoped_ptr<net::test_server::HttpResponse> HandlePostAndRedirectURLs( |
29 const std::string& request_path, | 39 const std::string& request_path, |
30 const net::test_server::HttpRequest& request) { | 40 const net::test_server::HttpRequest& request) { |
31 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | 41 scoped_ptr<net::test_server::BasicHttpResponse> http_response( |
32 new net::test_server::BasicHttpResponse()); | 42 new net::test_server::BasicHttpResponse()); |
33 if (base::StartsWith(request.relative_url, kRedirectPostPath, | 43 if (base::StartsWith(request.relative_url, kRedirectPostPath, |
34 base::CompareCase::SENSITIVE)) { | 44 base::CompareCase::SENSITIVE)) { |
35 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); | 45 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); |
36 http_response->AddCustomHeader("Location", kPostPath); | 46 http_response->AddCustomHeader("Location", kPostPath); |
(...skipping 20 matching lines...) Expand all Loading... |
57 ASSERT_TRUE(test_server->InitializeAndWaitUntilReady()); | 67 ASSERT_TRUE(test_server->InitializeAndWaitUntilReady()); |
58 test_server->RegisterRequestHandler( | 68 test_server->RegisterRequestHandler( |
59 base::Bind(&HandlePostAndRedirectURLs, kPostPath)); | 69 base::Bind(&HandlePostAndRedirectURLs, kPostPath)); |
60 | 70 |
61 NavigateToURL(shell(), | 71 NavigateToURL(shell(), |
62 test_server->GetURL("/loader/async_resource_handler.html")); | 72 test_server->GetURL("/loader/async_resource_handler.html")); |
63 | 73 |
64 std::string js_result; | 74 std::string js_result; |
65 EXPECT_TRUE(ExecuteScriptAndExtractString( | 75 EXPECT_TRUE(ExecuteScriptAndExtractString( |
66 shell()->web_contents(), | 76 shell()->web_contents(), |
67 "WaitForAsyncXHR('/post')", | 77 base::StringPrintf("WaitForAsyncXHR('%s', %" PRIuS ")", |
| 78 kPostPath, |
| 79 kPayloadSize), |
68 &js_result)); | 80 &js_result)); |
69 EXPECT_EQ(js_result, "success"); | 81 EXPECT_EQ(js_result, "success"); |
70 } | 82 } |
71 | 83 |
72 IN_PROC_BROWSER_TEST_F(AsyncResourceHandlerBrowserTest, | 84 IN_PROC_BROWSER_TEST_F(AsyncResourceHandlerBrowserTest, |
73 UploadProgressRedirect) { | 85 UploadProgressRedirect) { |
74 net::test_server::EmbeddedTestServer* test_server = embedded_test_server(); | 86 net::test_server::EmbeddedTestServer* test_server = embedded_test_server(); |
75 ASSERT_TRUE(test_server->InitializeAndWaitUntilReady()); | 87 ASSERT_TRUE(test_server->InitializeAndWaitUntilReady()); |
76 test_server->RegisterRequestHandler( | 88 test_server->RegisterRequestHandler( |
77 base::Bind(&HandlePostAndRedirectURLs, kRedirectPostPath)); | 89 base::Bind(&HandlePostAndRedirectURLs, kRedirectPostPath)); |
78 | 90 |
79 NavigateToURL(shell(), | 91 NavigateToURL(shell(), |
80 test_server->GetURL("/loader/async_resource_handler.html")); | 92 test_server->GetURL("/loader/async_resource_handler.html")); |
81 | 93 |
82 std::string js_result; | 94 std::string js_result; |
83 EXPECT_TRUE(ExecuteScriptAndExtractString( | 95 EXPECT_TRUE(ExecuteScriptAndExtractString( |
84 shell()->web_contents(), | 96 shell()->web_contents(), |
85 "WaitForAsyncXHR('/redirect')", | 97 base::StringPrintf("WaitForAsyncXHR('%s', %" PRIuS ")", |
| 98 kRedirectPostPath, |
| 99 kPayloadSize), |
86 &js_result)); | 100 &js_result)); |
87 EXPECT_EQ(js_result, "success"); | 101 EXPECT_EQ(js_result, "success"); |
88 } | 102 } |
89 | 103 |
90 } // namespace content | 104 } // namespace content |
OLD | NEW |