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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/task_runner_util.h" | 12 #include "base/task_runner_util.h" |
13 #include "chrome/browser/chromeos/drive/drive.pb.h" | 13 #include "chrome/browser/chromeos/drive/drive.pb.h" |
14 #include "chrome/browser/chromeos/drive/file_cache.h" | 14 #include "chrome/browser/chromeos/drive/file_cache.h" |
| 15 #include "chrome/browser/chromeos/drive/file_change.h" |
15 #include "chrome/browser/chromeos/drive/file_errors.h" | 16 #include "chrome/browser/chromeos/drive/file_errors.h" |
16 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" | 17 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
17 #include "google_apis/drive/test_util.h" | 18 #include "google_apis/drive/test_util.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 namespace drive { | 21 namespace drive { |
21 namespace file_system { | 22 namespace file_system { |
22 | 23 |
23 class OpenFileOperationTest : public OperationTestBase { | 24 class OpenFileOperationTest : public OperationTestBase { |
24 protected: | 25 protected: |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 base::FilePath file_path; | 110 base::FilePath file_path; |
110 base::Closure close_callback; | 111 base::Closure close_callback; |
111 operation_->OpenFile( | 112 operation_->OpenFile( |
112 file_in_root, | 113 file_in_root, |
113 CREATE_FILE, | 114 CREATE_FILE, |
114 std::string(), // mime_type | 115 std::string(), // mime_type |
115 google_apis::test_util::CreateCopyResultCallback( | 116 google_apis::test_util::CreateCopyResultCallback( |
116 &error, &file_path, &close_callback)); | 117 &error, &file_path, &close_callback)); |
117 test_util::RunBlockingPoolTask(); | 118 test_util::RunBlockingPoolTask(); |
118 | 119 |
119 EXPECT_EQ(1U, observer()->get_changed_paths().size()); | 120 EXPECT_EQ(1U, observer()->get_changed_files().size()); |
120 EXPECT_TRUE(observer()->get_changed_paths().count(file_in_root.DirName())); | 121 EXPECT_TRUE(observer()->get_changed_files().count(file_in_root)); |
121 | 122 |
122 EXPECT_EQ(FILE_ERROR_OK, error); | 123 EXPECT_EQ(FILE_ERROR_OK, error); |
123 ASSERT_TRUE(base::PathExists(file_path)); | 124 ASSERT_TRUE(base::PathExists(file_path)); |
124 int64 local_file_size; | 125 int64 local_file_size; |
125 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); | 126 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); |
126 EXPECT_EQ(0, local_file_size); // Should be an empty file. | 127 EXPECT_EQ(0, local_file_size); // Should be an empty file. |
127 | 128 |
128 ASSERT_FALSE(close_callback.is_null()); | 129 ASSERT_FALSE(close_callback.is_null()); |
129 close_callback.Run(); | 130 close_callback.Run(); |
130 EXPECT_EQ(1U, | 131 EXPECT_EQ(1U, |
(...skipping 12 matching lines...) Expand all Loading... |
143 base::Closure close_callback; | 144 base::Closure close_callback; |
144 operation_->OpenFile( | 145 operation_->OpenFile( |
145 file_in_root, | 146 file_in_root, |
146 OPEN_OR_CREATE_FILE, | 147 OPEN_OR_CREATE_FILE, |
147 std::string(), // mime_type | 148 std::string(), // mime_type |
148 google_apis::test_util::CreateCopyResultCallback( | 149 google_apis::test_util::CreateCopyResultCallback( |
149 &error, &file_path, &close_callback)); | 150 &error, &file_path, &close_callback)); |
150 test_util::RunBlockingPoolTask(); | 151 test_util::RunBlockingPoolTask(); |
151 | 152 |
152 // Notified because 'available offline' status of the existing file changes. | 153 // Notified because 'available offline' status of the existing file changes. |
153 EXPECT_EQ(1U, observer()->get_changed_paths().size()); | 154 EXPECT_EQ(1U, observer()->get_changed_files().size()); |
154 EXPECT_TRUE(observer()->get_changed_paths().count(file_in_root.DirName())); | 155 EXPECT_TRUE(observer()->get_changed_files().count(file_in_root)); |
155 | 156 |
156 EXPECT_EQ(FILE_ERROR_OK, error); | 157 EXPECT_EQ(FILE_ERROR_OK, error); |
157 ASSERT_TRUE(base::PathExists(file_path)); | 158 ASSERT_TRUE(base::PathExists(file_path)); |
158 int64 local_file_size; | 159 int64 local_file_size; |
159 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); | 160 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); |
160 EXPECT_EQ(file_size, local_file_size); | 161 EXPECT_EQ(file_size, local_file_size); |
161 | 162 |
162 ASSERT_FALSE(close_callback.is_null()); | 163 ASSERT_FALSE(close_callback.is_null()); |
163 close_callback.Run(); | 164 close_callback.Run(); |
164 EXPECT_EQ(1U, observer()->updated_local_ids().count(src_entry.local_id())); | 165 EXPECT_EQ(1U, observer()->updated_local_ids().count(src_entry.local_id())); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 EXPECT_TRUE(observer()->updated_local_ids().empty()); | 247 EXPECT_TRUE(observer()->updated_local_ids().empty()); |
247 | 248 |
248 close_callback2.Run(); | 249 close_callback2.Run(); |
249 | 250 |
250 // Here, all the clients close the file, so it should be uploaded then. | 251 // Here, all the clients close the file, so it should be uploaded then. |
251 EXPECT_EQ(1U, observer()->updated_local_ids().count(src_entry.local_id())); | 252 EXPECT_EQ(1U, observer()->updated_local_ids().count(src_entry.local_id())); |
252 } | 253 } |
253 | 254 |
254 } // namespace file_system | 255 } // namespace file_system |
255 } // namespace drive | 256 } // namespace drive |
OLD | NEW |