OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/google_apis/base_requests.h" | 5 #include "chrome/browser/google_apis/base_requests.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 base::FilePath temp_file; | 86 base::FilePath temp_file; |
87 { | 87 { |
88 base::RunLoop run_loop; | 88 base::RunLoop run_loop; |
89 DownloadFileRequest* request = new DownloadFileRequest( | 89 DownloadFileRequest* request = new DownloadFileRequest( |
90 request_sender_.get(), | 90 request_sender_.get(), |
91 test_util::CreateQuitCallback( | 91 test_util::CreateQuitCallback( |
92 &run_loop, | 92 &run_loop, |
93 test_util::CreateCopyResultCallback(&result_code, &temp_file)), | 93 test_util::CreateCopyResultCallback(&result_code, &temp_file)), |
94 GetContentCallback(), | 94 GetContentCallback(), |
95 ProgressCallback(), | 95 ProgressCallback(), |
96 test_server_.GetURL("/files/chromeos/gdata/testfile.txt"), | 96 test_server_.GetURL("/files/gdata/testfile.txt"), |
97 GetTestCachedFilePath( | 97 GetTestCachedFilePath( |
98 base::FilePath::FromUTF8Unsafe("cached_testfile.txt"))); | 98 base::FilePath::FromUTF8Unsafe("cached_testfile.txt"))); |
99 request_sender_->StartRequestWithRetry(request); | 99 request_sender_->StartRequestWithRetry(request); |
100 run_loop.Run(); | 100 run_loop.Run(); |
101 } | 101 } |
102 | 102 |
103 std::string contents; | 103 std::string contents; |
104 file_util::ReadFileToString(temp_file, &contents); | 104 file_util::ReadFileToString(temp_file, &contents); |
105 base::Delete(temp_file, false); | 105 base::Delete(temp_file, false); |
106 | 106 |
107 EXPECT_EQ(HTTP_SUCCESS, result_code); | 107 EXPECT_EQ(HTTP_SUCCESS, result_code); |
108 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 108 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
109 EXPECT_EQ("/files/chromeos/gdata/testfile.txt", http_request_.relative_url); | 109 EXPECT_EQ("/files/gdata/testfile.txt", http_request_.relative_url); |
110 | 110 |
111 const base::FilePath expected_path = | 111 const base::FilePath expected_path = |
112 test_util::GetTestFilePath("chromeos/gdata/testfile.txt"); | 112 test_util::GetTestFilePath("gdata/testfile.txt"); |
113 std::string expected_contents; | 113 std::string expected_contents; |
114 file_util::ReadFileToString(expected_path, &expected_contents); | 114 file_util::ReadFileToString(expected_path, &expected_contents); |
115 EXPECT_EQ(expected_contents, contents); | 115 EXPECT_EQ(expected_contents, contents); |
116 } | 116 } |
117 | 117 |
118 TEST_F(BaseRequestsServerTest, DownloadFileRequest_NonExistentFile) { | 118 TEST_F(BaseRequestsServerTest, DownloadFileRequest_NonExistentFile) { |
119 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 119 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
120 base::FilePath temp_file; | 120 base::FilePath temp_file; |
121 { | 121 { |
122 base::RunLoop run_loop; | 122 base::RunLoop run_loop; |
123 DownloadFileRequest* request = new DownloadFileRequest( | 123 DownloadFileRequest* request = new DownloadFileRequest( |
124 request_sender_.get(), | 124 request_sender_.get(), |
125 test_util::CreateQuitCallback( | 125 test_util::CreateQuitCallback( |
126 &run_loop, | 126 &run_loop, |
127 test_util::CreateCopyResultCallback(&result_code, &temp_file)), | 127 test_util::CreateCopyResultCallback(&result_code, &temp_file)), |
128 GetContentCallback(), | 128 GetContentCallback(), |
129 ProgressCallback(), | 129 ProgressCallback(), |
130 test_server_.GetURL("/files/chromeos/gdata/no-such-file.txt"), | 130 test_server_.GetURL("/files/gdata/no-such-file.txt"), |
131 GetTestCachedFilePath( | 131 GetTestCachedFilePath( |
132 base::FilePath::FromUTF8Unsafe("cache_no-such-file.txt"))); | 132 base::FilePath::FromUTF8Unsafe("cache_no-such-file.txt"))); |
133 request_sender_->StartRequestWithRetry(request); | 133 request_sender_->StartRequestWithRetry(request); |
134 run_loop.Run(); | 134 run_loop.Run(); |
135 } | 135 } |
136 EXPECT_EQ(HTTP_NOT_FOUND, result_code); | 136 EXPECT_EQ(HTTP_NOT_FOUND, result_code); |
137 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 137 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
138 EXPECT_EQ("/files/chromeos/gdata/no-such-file.txt", | 138 EXPECT_EQ("/files/gdata/no-such-file.txt", |
139 http_request_.relative_url); | 139 http_request_.relative_url); |
140 // Do not verify the not found message. | 140 // Do not verify the not found message. |
141 } | 141 } |
142 | 142 |
143 } // namespace google_apis | 143 } // namespace google_apis |
OLD | NEW |