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

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: nits I missed Created 5 years, 3 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 2015 The Chromium Authors. All rights reserved.
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 "content/browser/loader/async_resource_handler.h"
6
7 #include <string>
8
9 #include "base/strings/string_util.h"
10 #include "content/public/common/content_switches.h"
11 #include "content/public/test/browser_test_utils.h"
12 #include "content/public/test/content_browser_test.h"
13 #include "content/public/test/content_browser_test_utils.h"
14 #include "content/shell/browser/shell.h"
15 #include "net/test/embedded_test_server/embedded_test_server.h"
16 #include "net/test/embedded_test_server/http_request.h"
17 #include "net/test/embedded_test_server/http_response.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 namespace content {
21
22 namespace {
23
24 const char kPostPath[] = "/post";
25 const char kRedirectPostPath[] = "/redirect";
26 const size_t kPayloadSize = 28697814; // 2*3^15
27
28 scoped_ptr<net::test_server::HttpResponse> HandlePostAndRedirectURLs(
29 const std::string& request_path,
30 const net::test_server::HttpRequest& request) {
31 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
32 new net::test_server::BasicHttpResponse());
33 if (base::StartsWith(request.relative_url, kRedirectPostPath,
34 base::CompareCase::SENSITIVE)) {
35 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT);
36 http_response->AddCustomHeader("Location", kPostPath);
37 EXPECT_EQ(request.content.length(), kPayloadSize);;
38 return http_response.Pass();
39 } else if(base::StartsWith(request.relative_url, kPostPath,
40 base::CompareCase::SENSITIVE)) {
41 http_response->set_content("hello");
42 http_response->set_content_type("text/plain");
43 EXPECT_EQ(request.content.length(), kPayloadSize);
44 return http_response.Pass();
45 } else {
46 return scoped_ptr<net::test_server::HttpResponse>();
47 }
48 }
49
50 } // namespace
51
52 class AsyncResourceHandlerBrowserTest : public ContentBrowserTest {
53 };
54
55 IN_PROC_BROWSER_TEST_F(AsyncResourceHandlerBrowserTest, UploadProgress) {
56 net::test_server::EmbeddedTestServer* test_server = embedded_test_server();
57 ASSERT_TRUE(test_server->InitializeAndWaitUntilReady());
58 test_server->RegisterRequestHandler(
59 base::Bind(&HandlePostAndRedirectURLs, kPostPath));
60
61 NavigateToURL(shell(),
62 test_server->GetURL("/loader/async_resource_handler.html"));
63
64 std::string js_result;
65 EXPECT_TRUE(ExecuteScriptAndExtractString(
66 shell()->web_contents(),
67 "WaitForAsyncXHR('/post')",
68 &js_result));
69 EXPECT_EQ(js_result, "");
mmenke 2015/08/27 22:46:57 I think it's a better practice to send "success" o
70 }
71
72 IN_PROC_BROWSER_TEST_F(AsyncResourceHandlerBrowserTest,
73 UploadProgressRedirect) {
74 net::test_server::EmbeddedTestServer* test_server = embedded_test_server();
75 ASSERT_TRUE(test_server->InitializeAndWaitUntilReady());
76 test_server->RegisterRequestHandler(
77 base::Bind(&HandlePostAndRedirectURLs, kRedirectPostPath));
78
79 NavigateToURL(shell(),
80 test_server->GetURL("/loader/async_resource_handler.html"));
81
82 std::string js_result;
83 EXPECT_TRUE(ExecuteScriptAndExtractString(
84 shell()->web_contents(),
85 "WaitForAsyncXHR('/redirect')",
86 &js_result));
87 EXPECT_EQ(js_result, "");
88 }
89
90 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698