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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
11 #include "content/public/test/browser_test_utils.h" | 11 #include "content/public/test/browser_test_utils.h" |
12 #include "content/public/test/content_browser_test.h" | 12 #include "content/public/test/content_browser_test.h" |
13 #include "content/public/test/content_browser_test_utils.h" | 13 #include "content/public/test/content_browser_test_utils.h" |
14 #include "content/shell/browser/shell.h" | 14 #include "content/shell/browser/shell.h" |
15 #include "net/test/embedded_test_server/embedded_test_server.h" | 15 #include "net/test/embedded_test_server/embedded_test_server.h" |
16 #include "net/test/embedded_test_server/http_request.h" | 16 #include "net/test/embedded_test_server/http_request.h" |
17 #include "net/test/embedded_test_server/http_response.h" | 17 #include "net/test/embedded_test_server/http_response.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 const char kPostPath[] = "/post"; | 24 const char kPostPath[] = "/post"; |
25 const char kRedirectPostPath[] = "/redirect"; | 25 const char kRedirectPostPath[] = "/redirect"; |
26 #if defined(THREAD_SANITIZER) | |
mmenke
2015/09/01 18:37:42
Think this is worth a comment and a bug link
Charlie Harrison
2015/09/01 20:29:57
Done.
| |
27 const size_t kPayloadSize = 9565938; // 2*3^14 | |
mmenke
2015/09/01 18:37:42
Cutting data size by just 1/3rd seems to be cuttin
Charlie Harrison
2015/09/01 20:29:57
Done.
| |
28 const std::string kPostScript = "WaitForAsyncXHR('/post', 'small');"; | |
29 const std::string kRedirectScript = "WaitForAsyncXHR('/redirect', 'small');"; | |
mmenke
2015/09/01 18:37:42
I suggest passing in kPayloadSize instead.
Charlie Harrison
2015/09/01 20:29:57
How do you suggest I do that? Manually via a strin
mmenke
2015/09/01 20:31:39
base::StringPrintf
| |
30 #else | |
26 const size_t kPayloadSize = 28697814; // 2*3^15 | 31 const size_t kPayloadSize = 28697814; // 2*3^15 |
32 const std::string kPostScript = "WaitForAsyncXHR('/post', 'large');"; | |
33 const std::string kRedirectScript = "WaitForAsyncXHR('/redirect', 'large');"; | |
34 #endif | |
27 | 35 |
28 scoped_ptr<net::test_server::HttpResponse> HandlePostAndRedirectURLs( | 36 scoped_ptr<net::test_server::HttpResponse> HandlePostAndRedirectURLs( |
29 const std::string& request_path, | 37 const std::string& request_path, |
30 const net::test_server::HttpRequest& request) { | 38 const net::test_server::HttpRequest& request) { |
31 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | 39 scoped_ptr<net::test_server::BasicHttpResponse> http_response( |
32 new net::test_server::BasicHttpResponse()); | 40 new net::test_server::BasicHttpResponse()); |
33 if (base::StartsWith(request.relative_url, kRedirectPostPath, | 41 if (base::StartsWith(request.relative_url, kRedirectPostPath, |
34 base::CompareCase::SENSITIVE)) { | 42 base::CompareCase::SENSITIVE)) { |
35 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); | 43 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); |
36 http_response->AddCustomHeader("Location", kPostPath); | 44 http_response->AddCustomHeader("Location", kPostPath); |
(...skipping 17 matching lines...) Expand all Loading... | |
54 | 62 |
55 IN_PROC_BROWSER_TEST_F(AsyncResourceHandlerBrowserTest, UploadProgress) { | 63 IN_PROC_BROWSER_TEST_F(AsyncResourceHandlerBrowserTest, UploadProgress) { |
56 net::test_server::EmbeddedTestServer* test_server = embedded_test_server(); | 64 net::test_server::EmbeddedTestServer* test_server = embedded_test_server(); |
57 ASSERT_TRUE(test_server->InitializeAndWaitUntilReady()); | 65 ASSERT_TRUE(test_server->InitializeAndWaitUntilReady()); |
58 test_server->RegisterRequestHandler( | 66 test_server->RegisterRequestHandler( |
59 base::Bind(&HandlePostAndRedirectURLs, kPostPath)); | 67 base::Bind(&HandlePostAndRedirectURLs, kPostPath)); |
60 | 68 |
61 NavigateToURL(shell(), | 69 NavigateToURL(shell(), |
62 test_server->GetURL("/loader/async_resource_handler.html")); | 70 test_server->GetURL("/loader/async_resource_handler.html")); |
63 | 71 |
72 printf("Navigated To URL...\n"); | |
mmenke
2015/09/01 18:37:42
nit: Remove printf
Charlie Harrison
2015/09/01 20:29:57
Done. Oops.
| |
64 std::string js_result; | 73 std::string js_result; |
65 EXPECT_TRUE(ExecuteScriptAndExtractString( | 74 EXPECT_TRUE(ExecuteScriptAndExtractString( |
66 shell()->web_contents(), | 75 shell()->web_contents(), |
67 "WaitForAsyncXHR('/post')", | 76 kPostScript, |
68 &js_result)); | 77 &js_result)); |
69 EXPECT_EQ(js_result, "success"); | 78 EXPECT_EQ(js_result, "success"); |
70 } | 79 } |
71 | 80 |
72 IN_PROC_BROWSER_TEST_F(AsyncResourceHandlerBrowserTest, | 81 IN_PROC_BROWSER_TEST_F(AsyncResourceHandlerBrowserTest, |
73 UploadProgressRedirect) { | 82 UploadProgressRedirect) { |
74 net::test_server::EmbeddedTestServer* test_server = embedded_test_server(); | 83 net::test_server::EmbeddedTestServer* test_server = embedded_test_server(); |
75 ASSERT_TRUE(test_server->InitializeAndWaitUntilReady()); | 84 ASSERT_TRUE(test_server->InitializeAndWaitUntilReady()); |
76 test_server->RegisterRequestHandler( | 85 test_server->RegisterRequestHandler( |
77 base::Bind(&HandlePostAndRedirectURLs, kRedirectPostPath)); | 86 base::Bind(&HandlePostAndRedirectURLs, kRedirectPostPath)); |
78 | 87 |
79 NavigateToURL(shell(), | 88 NavigateToURL(shell(), |
80 test_server->GetURL("/loader/async_resource_handler.html")); | 89 test_server->GetURL("/loader/async_resource_handler.html")); |
81 | 90 |
82 std::string js_result; | 91 std::string js_result; |
83 EXPECT_TRUE(ExecuteScriptAndExtractString( | 92 EXPECT_TRUE(ExecuteScriptAndExtractString( |
84 shell()->web_contents(), | 93 shell()->web_contents(), |
85 "WaitForAsyncXHR('/redirect')", | 94 kRedirectScript, |
86 &js_result)); | 95 &js_result)); |
87 EXPECT_EQ(js_result, "success"); | 96 EXPECT_EQ(js_result, "success"); |
88 } | 97 } |
89 | 98 |
90 } // namespace content | 99 } // namespace content |
OLD | NEW |