| 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 "google_apis/drive/files_list_request_runner.h" | 5 #include "google_apis/drive/files_list_request_runner.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 132 |
| 133 // A requests and a response stored for verification in test cases. | 133 // A requests and a response stored for verification in test cases. |
| 134 std::unique_ptr<net::test_server::HttpRequest> http_request_; | 134 std::unique_ptr<net::test_server::HttpRequest> http_request_; |
| 135 std::unique_ptr<DriveApiErrorCode> response_error_; | 135 std::unique_ptr<DriveApiErrorCode> response_error_; |
| 136 std::unique_ptr<FileList> response_entry_; | 136 std::unique_ptr<FileList> response_entry_; |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 TEST_F(FilesListRequestRunnerTest, Success_NoBackoff) { | 139 TEST_F(FilesListRequestRunnerTest, Success_NoBackoff) { |
| 140 SetFakeServerResponse(net::HTTP_OK, kSuccessResource); | 140 SetFakeServerResponse(net::HTTP_OK, kSuccessResource); |
| 141 runner_->CreateAndStartWithSizeBackoff( | 141 runner_->CreateAndStartWithSizeBackoff( |
| 142 kMaxResults, kQuery, kFields, | 142 kMaxResults, CORPORA_DEFAULT, std::string(), kQuery, kFields, |
| 143 base::Bind(&FilesListRequestRunnerTest::OnCompleted, | 143 base::Bind(&FilesListRequestRunnerTest::OnCompleted, |
| 144 base::Unretained(this))); | 144 base::Unretained(this))); |
| 145 | 145 |
| 146 base::RunLoop run_loop; | 146 base::RunLoop run_loop; |
| 147 on_completed_callback_ = run_loop.QuitClosure(); | 147 on_completed_callback_ = run_loop.QuitClosure(); |
| 148 run_loop.Run(); | 148 run_loop.Run(); |
| 149 | 149 |
| 150 ASSERT_TRUE(http_request_.get()); | 150 ASSERT_TRUE(http_request_.get()); |
| 151 EXPECT_EQ( | 151 EXPECT_EQ( |
| 152 "/drive/v2/files?maxResults=4&q=testing-query&fields=testing-fields", | 152 "/drive/v2/files?maxResults=4&q=testing-query&fields=testing-fields", |
| 153 http_request_->relative_url); | 153 http_request_->relative_url); |
| 154 | 154 |
| 155 ASSERT_TRUE(response_error_.get()); | 155 ASSERT_TRUE(response_error_.get()); |
| 156 EXPECT_EQ(HTTP_SUCCESS, *response_error_); | 156 EXPECT_EQ(HTTP_SUCCESS, *response_error_); |
| 157 EXPECT_TRUE(response_entry_.get()); | 157 EXPECT_TRUE(response_entry_.get()); |
| 158 } | 158 } |
| 159 | 159 |
| 160 TEST_F(FilesListRequestRunnerTest, Success_Backoff) { | 160 TEST_F(FilesListRequestRunnerTest, Success_Backoff) { |
| 161 SetFakeServerResponse(net::HTTP_INTERNAL_SERVER_ERROR, | 161 SetFakeServerResponse(net::HTTP_INTERNAL_SERVER_ERROR, |
| 162 kResponseTooLargeErrorResource); | 162 kResponseTooLargeErrorResource); |
| 163 runner_->CreateAndStartWithSizeBackoff( | 163 runner_->CreateAndStartWithSizeBackoff( |
| 164 kMaxResults, kQuery, kFields, | 164 kMaxResults, CORPORA_DEFAULT, std::string(), kQuery, kFields, |
| 165 base::Bind(&FilesListRequestRunnerTest::OnCompleted, | 165 base::Bind(&FilesListRequestRunnerTest::OnCompleted, |
| 166 base::Unretained(this))); | 166 base::Unretained(this))); |
| 167 { | 167 { |
| 168 base::RunLoop run_loop; | 168 base::RunLoop run_loop; |
| 169 runner_->SetRequestCompletedCallbackForTesting(run_loop.QuitClosure()); | 169 runner_->SetRequestCompletedCallbackForTesting(run_loop.QuitClosure()); |
| 170 run_loop.Run(); | 170 run_loop.Run(); |
| 171 | 171 |
| 172 ASSERT_TRUE(http_request_.get()); | 172 ASSERT_TRUE(http_request_.get()); |
| 173 EXPECT_EQ( | 173 EXPECT_EQ( |
| 174 "/drive/v2/files?maxResults=4&q=testing-query&fields=testing-fields", | 174 "/drive/v2/files?maxResults=4&q=testing-query&fields=testing-fields", |
| (...skipping 17 matching lines...) Expand all Loading... |
| 192 ASSERT_TRUE(response_error_.get()); | 192 ASSERT_TRUE(response_error_.get()); |
| 193 EXPECT_EQ(HTTP_SUCCESS, *response_error_); | 193 EXPECT_EQ(HTTP_SUCCESS, *response_error_); |
| 194 EXPECT_TRUE(response_entry_.get()); | 194 EXPECT_TRUE(response_entry_.get()); |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 | 197 |
| 198 TEST_F(FilesListRequestRunnerTest, Failure_TooManyBackoffs) { | 198 TEST_F(FilesListRequestRunnerTest, Failure_TooManyBackoffs) { |
| 199 SetFakeServerResponse(net::HTTP_INTERNAL_SERVER_ERROR, | 199 SetFakeServerResponse(net::HTTP_INTERNAL_SERVER_ERROR, |
| 200 kResponseTooLargeErrorResource); | 200 kResponseTooLargeErrorResource); |
| 201 runner_->CreateAndStartWithSizeBackoff( | 201 runner_->CreateAndStartWithSizeBackoff( |
| 202 kMaxResults, kQuery, kFields, | 202 kMaxResults, CORPORA_DEFAULT, std::string(), kQuery, kFields, |
| 203 base::Bind(&FilesListRequestRunnerTest::OnCompleted, | 203 base::Bind(&FilesListRequestRunnerTest::OnCompleted, |
| 204 base::Unretained(this))); | 204 base::Unretained(this))); |
| 205 { | 205 { |
| 206 base::RunLoop run_loop; | 206 base::RunLoop run_loop; |
| 207 runner_->SetRequestCompletedCallbackForTesting(run_loop.QuitClosure()); | 207 runner_->SetRequestCompletedCallbackForTesting(run_loop.QuitClosure()); |
| 208 run_loop.Run(); | 208 run_loop.Run(); |
| 209 | 209 |
| 210 ASSERT_TRUE(http_request_.get()); | 210 ASSERT_TRUE(http_request_.get()); |
| 211 EXPECT_EQ( | 211 EXPECT_EQ( |
| 212 "/drive/v2/files?maxResults=4&q=testing-query&fields=testing-fields", | 212 "/drive/v2/files?maxResults=4&q=testing-query&fields=testing-fields", |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 ASSERT_TRUE(response_error_.get()); | 248 ASSERT_TRUE(response_error_.get()); |
| 249 EXPECT_EQ(DRIVE_RESPONSE_TOO_LARGE, *response_error_); | 249 EXPECT_EQ(DRIVE_RESPONSE_TOO_LARGE, *response_error_); |
| 250 EXPECT_FALSE(response_entry_.get()); | 250 EXPECT_FALSE(response_entry_.get()); |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 | 253 |
| 254 TEST_F(FilesListRequestRunnerTest, Failure_AnotherError) { | 254 TEST_F(FilesListRequestRunnerTest, Failure_AnotherError) { |
| 255 SetFakeServerResponse(net::HTTP_INTERNAL_SERVER_ERROR, | 255 SetFakeServerResponse(net::HTTP_INTERNAL_SERVER_ERROR, |
| 256 kQuotaExceededErrorResource); | 256 kQuotaExceededErrorResource); |
| 257 runner_->CreateAndStartWithSizeBackoff( | 257 runner_->CreateAndStartWithSizeBackoff( |
| 258 kMaxResults, kQuery, kFields, | 258 kMaxResults, CORPORA_DEFAULT, std::string(), kQuery, kFields, |
| 259 base::Bind(&FilesListRequestRunnerTest::OnCompleted, | 259 base::Bind(&FilesListRequestRunnerTest::OnCompleted, |
| 260 base::Unretained(this))); | 260 base::Unretained(this))); |
| 261 | 261 |
| 262 base::RunLoop run_loop; | 262 base::RunLoop run_loop; |
| 263 on_completed_callback_ = run_loop.QuitClosure(); | 263 on_completed_callback_ = run_loop.QuitClosure(); |
| 264 run_loop.Run(); | 264 run_loop.Run(); |
| 265 | 265 |
| 266 ASSERT_TRUE(http_request_.get()); | 266 ASSERT_TRUE(http_request_.get()); |
| 267 EXPECT_EQ( | 267 EXPECT_EQ( |
| 268 "/drive/v2/files?maxResults=4&q=testing-query&fields=testing-fields", | 268 "/drive/v2/files?maxResults=4&q=testing-query&fields=testing-fields", |
| 269 http_request_->relative_url); | 269 http_request_->relative_url); |
| 270 | 270 |
| 271 // There must be no backoff in case of an error different than | 271 // There must be no backoff in case of an error different than |
| 272 // DRIVE_RESPONSE_TOO_LARGE. | 272 // DRIVE_RESPONSE_TOO_LARGE. |
| 273 ASSERT_TRUE(response_error_.get()); | 273 ASSERT_TRUE(response_error_.get()); |
| 274 EXPECT_EQ(DRIVE_NO_SPACE, *response_error_); | 274 EXPECT_EQ(DRIVE_NO_SPACE, *response_error_); |
| 275 EXPECT_FALSE(response_entry_.get()); | 275 EXPECT_FALSE(response_entry_.get()); |
| 276 } | 276 } |
| 277 | 277 |
| 278 } // namespace google_apis | 278 } // namespace google_apis |
| OLD | NEW |