| 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_operations.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/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/google_apis/auth_service.h" | 12 #include "chrome/browser/google_apis/auth_service.h" |
| 13 #include "chrome/browser/google_apis/operation_runner.h" | 13 #include "chrome/browser/google_apis/operation_runner.h" |
| 14 #include "chrome/browser/google_apis/task_util.h" | 14 #include "chrome/browser/google_apis/task_util.h" |
| 15 #include "chrome/browser/google_apis/test_util.h" | 15 #include "chrome/browser/google_apis/test_util.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 operation_runner_.reset(new OperationRunner(profile_.get(), | 52 operation_runner_.reset(new OperationRunner(profile_.get(), |
| 53 request_context_getter_.get(), | 53 request_context_getter_.get(), |
| 54 std::vector<std::string>(), | 54 std::vector<std::string>(), |
| 55 kTestUserAgent)); | 55 kTestUserAgent)); |
| 56 operation_runner_->auth_service()->set_access_token_for_testing( | 56 operation_runner_->auth_service()->set_access_token_for_testing( |
| 57 kTestAuthToken); | 57 kTestAuthToken); |
| 58 | 58 |
| 59 ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady()); | 59 ASSERT_TRUE(test_server_.InitializeAndWaitUntilReady()); |
| 60 test_server_.RegisterRequestHandler( | 60 test_server_.RegisterRequestHandler( |
| 61 base::Bind(&test_util::HandleDownloadRequest, | 61 base::Bind(&test_util::HandleDownloadFileRequest, |
| 62 test_server_.base_url(), | 62 test_server_.base_url(), |
| 63 base::Unretained(&http_request_))); | 63 base::Unretained(&http_request_))); |
| 64 } | 64 } |
| 65 | 65 |
| 66 virtual void TearDown() OVERRIDE { | 66 virtual void TearDown() OVERRIDE { |
| 67 EXPECT_TRUE(test_server_.ShutdownAndWaitUntilComplete()); | 67 EXPECT_TRUE(test_server_.ShutdownAndWaitUntilComplete()); |
| 68 request_context_getter_ = NULL; | 68 request_context_getter_ = NULL; |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Returns a temporary file path suitable for storing the cache file. | 71 // Returns a temporary file path suitable for storing the cache file. |
| 72 base::FilePath GetTestCachedFilePath(const base::FilePath& file_name) { | 72 base::FilePath GetTestCachedFilePath(const base::FilePath& file_name) { |
| 73 return profile_->GetPath().Append(file_name); | 73 return profile_->GetPath().Append(file_name); |
| 74 } | 74 } |
| 75 | 75 |
| 76 base::MessageLoopForUI message_loop_; | 76 base::MessageLoopForUI message_loop_; |
| 77 content::TestBrowserThread ui_thread_; | 77 content::TestBrowserThread ui_thread_; |
| 78 content::TestBrowserThread file_thread_; | 78 content::TestBrowserThread file_thread_; |
| 79 content::TestBrowserThread io_thread_; | 79 content::TestBrowserThread io_thread_; |
| 80 net::test_server::EmbeddedTestServer test_server_; | 80 net::test_server::EmbeddedTestServer test_server_; |
| 81 scoped_ptr<TestingProfile> profile_; | 81 scoped_ptr<TestingProfile> profile_; |
| 82 scoped_ptr<OperationRunner> operation_runner_; | 82 scoped_ptr<OperationRunner> operation_runner_; |
| 83 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; | 83 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; |
| 84 | 84 |
| 85 // The incoming HTTP request is saved so tests can verify the request | 85 // The incoming HTTP request is saved so tests can verify the request |
| 86 // parameters like HTTP method (ex. some operations should use DELETE | 86 // parameters like HTTP method (ex. some operations should use DELETE |
| 87 // instead of GET). | 87 // instead of GET). |
| 88 net::test_server::HttpRequest http_request_; | 88 net::test_server::HttpRequest http_request_; |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 TEST_F(BaseOperationsServerTest, DownloadFileOperation_ValidFile) { | 91 TEST_F(BaseOperationsServerTest, DownloadFileRequest_ValidFile) { |
| 92 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 92 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 93 base::FilePath temp_file; | 93 base::FilePath temp_file; |
| 94 DownloadFileOperation* operation = new DownloadFileOperation( | 94 DownloadFileRequest* operation = new DownloadFileRequest( |
| 95 operation_runner_.get(), | 95 operation_runner_.get(), |
| 96 request_context_getter_.get(), | 96 request_context_getter_.get(), |
| 97 CreateComposedCallback( | 97 CreateComposedCallback( |
| 98 base::Bind(&test_util::RunAndQuit), | 98 base::Bind(&test_util::RunAndQuit), |
| 99 test_util::CreateCopyResultCallback(&result_code, &temp_file)), | 99 test_util::CreateCopyResultCallback(&result_code, &temp_file)), |
| 100 GetContentCallback(), | 100 GetContentCallback(), |
| 101 ProgressCallback(), | 101 ProgressCallback(), |
| 102 test_server_.GetURL("/files/chromeos/gdata/testfile.txt"), | 102 test_server_.GetURL("/files/chromeos/gdata/testfile.txt"), |
| 103 base::FilePath::FromUTF8Unsafe("/dummy/gdata/testfile.txt"), | 103 base::FilePath::FromUTF8Unsafe("/dummy/gdata/testfile.txt"), |
| 104 GetTestCachedFilePath( | 104 GetTestCachedFilePath( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 116 | 116 |
| 117 const base::FilePath expected_path = | 117 const base::FilePath expected_path = |
| 118 test_util::GetTestFilePath("chromeos/gdata/testfile.txt"); | 118 test_util::GetTestFilePath("chromeos/gdata/testfile.txt"); |
| 119 std::string expected_contents; | 119 std::string expected_contents; |
| 120 file_util::ReadFileToString(expected_path, &expected_contents); | 120 file_util::ReadFileToString(expected_path, &expected_contents); |
| 121 EXPECT_EQ(expected_contents, contents); | 121 EXPECT_EQ(expected_contents, contents); |
| 122 } | 122 } |
| 123 | 123 |
| 124 // http://crbug.com/169588 | 124 // http://crbug.com/169588 |
| 125 TEST_F(BaseOperationsServerTest, | 125 TEST_F(BaseOperationsServerTest, |
| 126 DISABLED_DownloadFileOperation_NonExistentFile) { | 126 DISABLED_DownloadFileRequest_NonExistentFile) { |
| 127 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 127 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 128 base::FilePath temp_file; | 128 base::FilePath temp_file; |
| 129 DownloadFileOperation* operation = new DownloadFileOperation( | 129 DownloadFileRequest* operation = new DownloadFileRequest( |
| 130 operation_runner_.get(), | 130 operation_runner_.get(), |
| 131 request_context_getter_.get(), | 131 request_context_getter_.get(), |
| 132 CreateComposedCallback( | 132 CreateComposedCallback( |
| 133 base::Bind(&test_util::RunAndQuit), | 133 base::Bind(&test_util::RunAndQuit), |
| 134 test_util::CreateCopyResultCallback(&result_code, &temp_file)), | 134 test_util::CreateCopyResultCallback(&result_code, &temp_file)), |
| 135 GetContentCallback(), | 135 GetContentCallback(), |
| 136 ProgressCallback(), | 136 ProgressCallback(), |
| 137 test_server_.GetURL("/files/chromeos/gdata/no-such-file.txt"), | 137 test_server_.GetURL("/files/chromeos/gdata/no-such-file.txt"), |
| 138 base::FilePath::FromUTF8Unsafe("/dummy/gdata/no-such-file.txt"), | 138 base::FilePath::FromUTF8Unsafe("/dummy/gdata/no-such-file.txt"), |
| 139 GetTestCachedFilePath( | 139 GetTestCachedFilePath( |
| 140 base::FilePath::FromUTF8Unsafe("cache_no-such-file.txt"))); | 140 base::FilePath::FromUTF8Unsafe("cache_no-such-file.txt"))); |
| 141 operation_runner_->StartOperationWithRetry(operation); | 141 operation_runner_->StartOperationWithRetry(operation); |
| 142 base::MessageLoop::current()->Run(); | 142 base::MessageLoop::current()->Run(); |
| 143 | 143 |
| 144 std::string contents; | 144 std::string contents; |
| 145 file_util::ReadFileToString(temp_file, &contents); | 145 file_util::ReadFileToString(temp_file, &contents); |
| 146 file_util::Delete(temp_file, false); | 146 file_util::Delete(temp_file, false); |
| 147 | 147 |
| 148 EXPECT_EQ(HTTP_NOT_FOUND, result_code); | 148 EXPECT_EQ(HTTP_NOT_FOUND, result_code); |
| 149 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 149 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
| 150 EXPECT_EQ("/files/chromeos/gdata/no-such-file.txt", | 150 EXPECT_EQ("/files/chromeos/gdata/no-such-file.txt", |
| 151 http_request_.relative_url); | 151 http_request_.relative_url); |
| 152 // Do not verify the not found message. | 152 // Do not verify the not found message. |
| 153 } | 153 } |
| 154 | 154 |
| 155 } // namespace google_apis | 155 } // namespace google_apis |
| OLD | NEW |