| 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_operations.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/operation_registry.h" | 12 #include "chrome/browser/google_apis/operation_registry.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" |
| 16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 17 #include "content/public/test/test_browser_thread.h" | 17 #include "content/public/test/test_browser_thread.h" |
| 18 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 18 #include "net/test/embedded_test_server/http_request.h" | 19 #include "net/test/embedded_test_server/http_request.h" |
| 19 #include "net/test/embedded_test_server/http_response.h" | 20 #include "net/test/embedded_test_server/http_response.h" |
| 20 #include "net/test/embedded_test_server/http_server.h" | |
| 21 #include "net/url_request/url_request_test_util.h" | 21 #include "net/url_request/url_request_test_util.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 namespace google_apis { | 24 namespace google_apis { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const char kTestAuthToken[] = "testtoken"; | 28 const char kTestAuthToken[] = "testtoken"; |
| 29 const char kTestUserAgent[] = "test-user-agent"; | 29 const char kTestUserAgent[] = "test-user-agent"; |
| 30 | 30 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 // Returns a temporary file path suitable for storing the cache file. | 64 // Returns a temporary file path suitable for storing the cache file. |
| 65 base::FilePath GetTestCachedFilePath(const base::FilePath& file_name) { | 65 base::FilePath GetTestCachedFilePath(const base::FilePath& file_name) { |
| 66 return profile_->GetPath().Append(file_name); | 66 return profile_->GetPath().Append(file_name); |
| 67 } | 67 } |
| 68 | 68 |
| 69 MessageLoopForUI message_loop_; | 69 MessageLoopForUI message_loop_; |
| 70 content::TestBrowserThread ui_thread_; | 70 content::TestBrowserThread ui_thread_; |
| 71 content::TestBrowserThread file_thread_; | 71 content::TestBrowserThread file_thread_; |
| 72 content::TestBrowserThread io_thread_; | 72 content::TestBrowserThread io_thread_; |
| 73 test_server::HttpServer test_server_; | 73 net::test_server::EmbeddedTestServer test_server_; |
| 74 scoped_ptr<TestingProfile> profile_; | 74 scoped_ptr<TestingProfile> profile_; |
| 75 OperationRegistry operation_registry_; | 75 OperationRegistry operation_registry_; |
| 76 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; | 76 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; |
| 77 | 77 |
| 78 // The incoming HTTP request is saved so tests can verify the request | 78 // The incoming HTTP request is saved so tests can verify the request |
| 79 // parameters like HTTP method (ex. some operations should use DELETE | 79 // parameters like HTTP method (ex. some operations should use DELETE |
| 80 // instead of GET). | 80 // instead of GET). |
| 81 test_server::HttpRequest http_request_; | 81 net::test_server::HttpRequest http_request_; |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 TEST_F(BaseOperationsServerTest, DownloadFileOperation_ValidFile) { | 84 TEST_F(BaseOperationsServerTest, DownloadFileOperation_ValidFile) { |
| 85 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 85 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 86 base::FilePath temp_file; | 86 base::FilePath temp_file; |
| 87 DownloadFileOperation* operation = new DownloadFileOperation( | 87 DownloadFileOperation* operation = new DownloadFileOperation( |
| 88 &operation_registry_, | 88 &operation_registry_, |
| 89 request_context_getter_.get(), | 89 request_context_getter_.get(), |
| 90 CreateComposedCallback( | 90 CreateComposedCallback( |
| 91 base::Bind(&test_util::RunAndQuit), | 91 base::Bind(&test_util::RunAndQuit), |
| 92 test_util::CreateCopyResultCallback(&result_code, &temp_file)), | 92 test_util::CreateCopyResultCallback(&result_code, &temp_file)), |
| 93 GetContentCallback(), | 93 GetContentCallback(), |
| 94 ProgressCallback(), | 94 ProgressCallback(), |
| 95 test_server_.GetURL("/files/chromeos/gdata/testfile.txt"), | 95 test_server_.GetURL("/files/chromeos/gdata/testfile.txt"), |
| 96 base::FilePath::FromUTF8Unsafe("/dummy/gdata/testfile.txt"), | 96 base::FilePath::FromUTF8Unsafe("/dummy/gdata/testfile.txt"), |
| 97 GetTestCachedFilePath( | 97 GetTestCachedFilePath( |
| 98 base::FilePath::FromUTF8Unsafe("cached_testfile.txt"))); | 98 base::FilePath::FromUTF8Unsafe("cached_testfile.txt"))); |
| 99 operation->Start(kTestAuthToken, kTestUserAgent, | 99 operation->Start(kTestAuthToken, kTestUserAgent, |
| 100 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | 100 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 101 MessageLoop::current()->Run(); | 101 MessageLoop::current()->Run(); |
| 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 file_util::Delete(temp_file, false); | 105 file_util::Delete(temp_file, false); |
| 106 | 106 |
| 107 EXPECT_EQ(HTTP_SUCCESS, result_code); | 107 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 108 EXPECT_EQ(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/chromeos/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("chromeos/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 // http://crbug.com/169588 | 118 // http://crbug.com/169588 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 134 base::FilePath::FromUTF8Unsafe("cache_no-such-file.txt"))); | 134 base::FilePath::FromUTF8Unsafe("cache_no-such-file.txt"))); |
| 135 operation->Start(kTestAuthToken, kTestUserAgent, | 135 operation->Start(kTestAuthToken, kTestUserAgent, |
| 136 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); | 136 base::Bind(&test_util::DoNothingForReAuthenticateCallback)); |
| 137 MessageLoop::current()->Run(); | 137 MessageLoop::current()->Run(); |
| 138 | 138 |
| 139 std::string contents; | 139 std::string contents; |
| 140 file_util::ReadFileToString(temp_file, &contents); | 140 file_util::ReadFileToString(temp_file, &contents); |
| 141 file_util::Delete(temp_file, false); | 141 file_util::Delete(temp_file, false); |
| 142 | 142 |
| 143 EXPECT_EQ(HTTP_NOT_FOUND, result_code); | 143 EXPECT_EQ(HTTP_NOT_FOUND, result_code); |
| 144 EXPECT_EQ(test_server::METHOD_GET, http_request_.method); | 144 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
| 145 EXPECT_EQ("/files/chromeos/gdata/no-such-file.txt", | 145 EXPECT_EQ("/files/chromeos/gdata/no-such-file.txt", |
| 146 http_request_.relative_url); | 146 http_request_.relative_url); |
| 147 // Do not verify the not found message. | 147 // Do not verify the not found message. |
| 148 } | 148 } |
| 149 | 149 |
| 150 } // namespace google_apis | 150 } // namespace google_apis |
| OLD | NEW |