OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/chromeos/drive/file_system/open_file_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/open_file_operation.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 base::FilePath file_path; | 109 base::FilePath file_path; |
110 base::Closure close_callback; | 110 base::Closure close_callback; |
111 operation_->OpenFile( | 111 operation_->OpenFile( |
112 file_in_root, | 112 file_in_root, |
113 CREATE_FILE, | 113 CREATE_FILE, |
114 std::string(), // mime_type | 114 std::string(), // mime_type |
115 google_apis::test_util::CreateCopyResultCallback( | 115 google_apis::test_util::CreateCopyResultCallback( |
116 &error, &file_path, &close_callback)); | 116 &error, &file_path, &close_callback)); |
117 test_util::RunBlockingPoolTask(); | 117 test_util::RunBlockingPoolTask(); |
118 | 118 |
| 119 EXPECT_EQ(1U, observer()->get_changed_paths().size()); |
| 120 EXPECT_TRUE(observer()->get_changed_paths().count(file_in_root.DirName())); |
| 121 |
119 EXPECT_EQ(FILE_ERROR_OK, error); | 122 EXPECT_EQ(FILE_ERROR_OK, error); |
120 ASSERT_TRUE(base::PathExists(file_path)); | 123 ASSERT_TRUE(base::PathExists(file_path)); |
121 int64 local_file_size; | 124 int64 local_file_size; |
122 ASSERT_TRUE(file_util::GetFileSize(file_path, &local_file_size)); | 125 ASSERT_TRUE(file_util::GetFileSize(file_path, &local_file_size)); |
123 EXPECT_EQ(0, local_file_size); // Should be an empty file. | 126 EXPECT_EQ(0, local_file_size); // Should be an empty file. |
124 | 127 |
125 ASSERT_FALSE(close_callback.is_null()); | 128 ASSERT_FALSE(close_callback.is_null()); |
126 close_callback.Run(); | 129 close_callback.Run(); |
127 // Here we don't know about the resource id, so just make sure | 130 // Here we don't know about the resource id, so just make sure |
128 // OnCacheFileUploadNeededByOperation is called actually. | 131 // OnCacheFileUploadNeededByOperation is called actually. |
(...skipping 11 matching lines...) Expand all Loading... |
140 base::FilePath file_path; | 143 base::FilePath file_path; |
141 base::Closure close_callback; | 144 base::Closure close_callback; |
142 operation_->OpenFile( | 145 operation_->OpenFile( |
143 file_in_root, | 146 file_in_root, |
144 OPEN_OR_CREATE_FILE, | 147 OPEN_OR_CREATE_FILE, |
145 std::string(), // mime_type | 148 std::string(), // mime_type |
146 google_apis::test_util::CreateCopyResultCallback( | 149 google_apis::test_util::CreateCopyResultCallback( |
147 &error, &file_path, &close_callback)); | 150 &error, &file_path, &close_callback)); |
148 test_util::RunBlockingPoolTask(); | 151 test_util::RunBlockingPoolTask(); |
149 | 152 |
| 153 // Notified because 'available offline' status of the existing file changes. |
| 154 EXPECT_EQ(1U, observer()->get_changed_paths().size()); |
| 155 EXPECT_TRUE(observer()->get_changed_paths().count(file_in_root.DirName())); |
| 156 |
150 EXPECT_EQ(FILE_ERROR_OK, error); | 157 EXPECT_EQ(FILE_ERROR_OK, error); |
151 ASSERT_TRUE(base::PathExists(file_path)); | 158 ASSERT_TRUE(base::PathExists(file_path)); |
152 int64 local_file_size; | 159 int64 local_file_size; |
153 ASSERT_TRUE(file_util::GetFileSize(file_path, &local_file_size)); | 160 ASSERT_TRUE(file_util::GetFileSize(file_path, &local_file_size)); |
154 EXPECT_EQ(file_size, local_file_size); | 161 EXPECT_EQ(file_size, local_file_size); |
155 | 162 |
156 ASSERT_FALSE(close_callback.is_null()); | 163 ASSERT_FALSE(close_callback.is_null()); |
157 close_callback.Run(); | 164 close_callback.Run(); |
158 EXPECT_EQ( | 165 EXPECT_EQ( |
159 1U, | 166 1U, |
160 observer()->upload_needed_local_ids().count(src_entry.resource_id())); | 167 observer()->upload_needed_local_ids().count(src_entry.resource_id())); |
| 168 |
| 169 bool success = false; |
| 170 FileCacheEntry cache_entry; |
| 171 cache()->GetCacheEntryOnUIThread( |
| 172 src_entry.resource_id(), |
| 173 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); |
| 174 test_util::RunBlockingPoolTask(); |
| 175 EXPECT_TRUE(success); |
| 176 EXPECT_TRUE(cache_entry.is_present()); |
| 177 EXPECT_TRUE(cache_entry.is_dirty()); |
161 } | 178 } |
162 | 179 |
163 TEST_F(OpenFileOperationTest, OpenOrCreateNonExistingFile) { | 180 TEST_F(OpenFileOperationTest, OpenOrCreateNonExistingFile) { |
164 const base::FilePath file_in_root( | 181 const base::FilePath file_in_root( |
165 FILE_PATH_LITERAL("drive/root/not-exist.txt")); | 182 FILE_PATH_LITERAL("drive/root/not-exist.txt")); |
166 | 183 |
167 FileError error = FILE_ERROR_FAILED; | 184 FileError error = FILE_ERROR_FAILED; |
168 base::FilePath file_path; | 185 base::FilePath file_path; |
169 base::Closure close_callback; | 186 base::Closure close_callback; |
170 operation_->OpenFile( | 187 operation_->OpenFile( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 close_callback2.Run(); | 257 close_callback2.Run(); |
241 | 258 |
242 // Here, all the clients close the file, so it should be uploaded then. | 259 // Here, all the clients close the file, so it should be uploaded then. |
243 EXPECT_EQ( | 260 EXPECT_EQ( |
244 1U, | 261 1U, |
245 observer()->upload_needed_local_ids().count(src_entry.resource_id())); | 262 observer()->upload_needed_local_ids().count(src_entry.resource_id())); |
246 } | 263 } |
247 | 264 |
248 } // namespace file_system | 265 } // namespace file_system |
249 } // namespace drive | 266 } // namespace drive |
OLD | NEW |