Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: content/browser/loader/async_resource_handler_browsertest.cc

Issue 1301103002: moved upload progress logic from ResourceLoader to AsyncResourceHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added license Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
mmenke 2015/08/26 19:13:12 nit: Don't use (c) in new files.
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 "base/strings/string_util.h"
6 #include "content/browser/loader/async_resource_handler.h"
mmenke 2015/08/26 19:13:12 This should go first, 1 line above the others.
7 #include "content/public/common/content_switches.h"
8 #include "content/public/test/browser_test_utils.h"
9 #include "content/public/test/content_browser_test.h"
10 #include "content/public/test/content_browser_test_utils.h"
11 #include "content/shell/browser/shell.h"
12 #include "net/test/embedded_test_server/embedded_test_server.h"
13 #include "net/test/embedded_test_server/http_request.h"
14 #include "net/test/embedded_test_server/http_response.h"
15
16 namespace content {
17
18 const char kPost[] = "/post";
19 const char kRedirect[] = "/redirect";
mmenke 2015/08/26 19:13:12 These should go in the anonymous namespace
20
21 class AsyncResourceHandlerBrowserTest : public ContentBrowserTest {
22 };
mmenke 2015/08/26 19:13:13 This should go below the anonymous namespace.
23
24 namespace {
25 scoped_ptr<net::test_server::HttpResponse> SimplePost(
26 const std::string& path,
27 const net::test_server::HttpRequest& request) {
28 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
29 new net::test_server::BasicHttpResponse());
30 http_response->set_content("hello");
31 http_response->set_content_type("text/plain");
32 return http_response.Pass();
33 }
34 } // namespace
mmenke 2015/08/26 19:13:12 nit: Should be: namespace { .... } // namespa
35
36 IN_PROC_BROWSER_TEST_F(AsyncResourceHandlerBrowserTest, UploadProgress) {
37 net::test_server::EmbeddedTestServer *test_server = embedded_test_server();
38 ASSERT_TRUE(test_server->InitializeAndWaitUntilReady());
39 test_server->RegisterRequestHandler(
40 base::Bind(&SimplePost, kPost));
mmenke 2015/08/26 19:13:12 nit: +2 indent
41
42 NavigateToURL(shell(), test_server->GetURL("/async_resource_handler.html"));
43
44 bool js_result = false;
45 EXPECT_TRUE(ExecuteScriptAndExtractBool(
46 shell()->web_contents(),
47 "WaitForAsyncXHR('/post')",
48 &js_result));
49 EXPECT_TRUE(js_result);
50
mmenke 2015/08/26 19:13:12 Remove blank line.
51 }
52
53 namespace {
54 const size_t payload_size = 28697814; // 2*3^15
55 scoped_ptr<net::test_server::HttpResponse> SimplePostRedirect(
56 const std::string& request_path,
57 const net::test_server::HttpRequest& request) {
58 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
59 new net::test_server::BasicHttpResponse());
mmenke 2015/08/26 19:13:12 nit: +2 indent
60 if (base::StartsWith(request.relative_url, kRedirect,
61 base::CompareCase::SENSITIVE)) {
62 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT);
63 http_response->AddCustomHeader("Location", kPost);
64 EXPECT_EQ(request.content.length(), payload_size);;
65 return http_response.Pass();
66 } else if(base::StartsWith(request.relative_url, kPost,
67 base::CompareCase::SENSITIVE)) {
68 http_response->set_content("hello");
69 http_response->set_content_type("text/plain");
70 EXPECT_EQ(request.content.length(), payload_size);
71 return http_response.Pass();
72 } else {
73 return scoped_ptr<net::test_server::HttpResponse>();
74 }
75 }
mmenke 2015/08/26 19:13:12 Suggest putting this all in the anonymous namespac
76 } //namespace
77
78 IN_PROC_BROWSER_TEST_F(AsyncResourceHandlerBrowserTest,
79 UploadProgressRedirect) {
80 net::test_server::EmbeddedTestServer *test_server = embedded_test_server();
81 ASSERT_TRUE(test_server->InitializeAndWaitUntilReady());
82 test_server->RegisterRequestHandler(
83 base::Bind(&SimplePostRedirect, kRedirect));
mmenke 2015/08/26 19:13:12 nit: +2 indent
84
85 NavigateToURL(shell(), test_server->GetURL("/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
mmenke 2015/08/26 19:13:12 Remove blank line
94 }
95
96 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698