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" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 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 |
(...skipping 10 matching lines...) Expand all Loading... |
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( |
105 base::FilePath::FromUTF8Unsafe("cached_testfile.txt"))); | 105 base::FilePath::FromUTF8Unsafe("cached_testfile.txt"))); |
106 operation_runner_->StartOperationWithRetry(operation); | 106 operation_runner_->StartOperationWithRetry(operation); |
107 MessageLoop::current()->Run(); | 107 base::MessageLoop::current()->Run(); |
108 | 108 |
109 std::string contents; | 109 std::string contents; |
110 file_util::ReadFileToString(temp_file, &contents); | 110 file_util::ReadFileToString(temp_file, &contents); |
111 file_util::Delete(temp_file, false); | 111 file_util::Delete(temp_file, false); |
112 | 112 |
113 EXPECT_EQ(HTTP_SUCCESS, result_code); | 113 EXPECT_EQ(HTTP_SUCCESS, result_code); |
114 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 114 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
115 EXPECT_EQ("/files/chromeos/gdata/testfile.txt", http_request_.relative_url); | 115 EXPECT_EQ("/files/chromeos/gdata/testfile.txt", http_request_.relative_url); |
116 | 116 |
117 const base::FilePath expected_path = | 117 const base::FilePath expected_path = |
(...skipping 14 matching lines...) Expand all Loading... |
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 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 |