| 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/get_file_for_saving_operatio
n.h" | 5 #include "chrome/browser/chromeos/drive/file_system/get_file_for_saving_operatio
n.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "chrome/browser/chromeos/drive/drive.pb.h" | 11 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 12 #include "chrome/browser/chromeos/drive/file_errors.h" | 12 #include "chrome/browser/chromeos/drive/file_errors.h" |
| 13 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" | 13 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
| 14 #include "chrome/browser/chromeos/drive/file_write_watcher.h" | 14 #include "chrome/browser/chromeos/drive/file_write_watcher.h" |
| 15 #include "chrome/browser/google_apis/test_util.h" | 15 #include "chrome/browser/google_apis/test_util.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace drive { | 18 namespace drive { |
| 19 namespace file_system { | 19 namespace file_system { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // If OnCacheFileUploadNeededByOperation is called, records the resource ID and | 23 // If OnCacheFileUploadNeededByOperation is called, records the local ID and |
| 24 // calls |quit_closure|. | 24 // calls |quit_closure|. |
| 25 class TestObserver : public OperationObserver { | 25 class TestObserver : public OperationObserver { |
| 26 public: | 26 public: |
| 27 void set_quit_closure(const base::Closure& quit_closure) { | 27 void set_quit_closure(const base::Closure& quit_closure) { |
| 28 quit_closure_ = quit_closure; | 28 quit_closure_ = quit_closure; |
| 29 } | 29 } |
| 30 | 30 |
| 31 const std::string& observerd_resource_id() const { | 31 const std::string& observerd_local_id() const { |
| 32 return observed_resource_id_; | 32 return observed_local_id_; |
| 33 } | 33 } |
| 34 | 34 |
| 35 // OperationObserver overrides. | 35 // OperationObserver overrides. |
| 36 virtual void OnDirectoryChangedByOperation( | 36 virtual void OnDirectoryChangedByOperation( |
| 37 const base::FilePath& path) OVERRIDE {} | 37 const base::FilePath& path) OVERRIDE {} |
| 38 | 38 |
| 39 virtual void OnCacheFileUploadNeededByOperation( | 39 virtual void OnCacheFileUploadNeededByOperation( |
| 40 const std::string& resource_id) OVERRIDE { | 40 const std::string& local_id) OVERRIDE { |
| 41 observed_resource_id_ = resource_id; | 41 observed_local_id_ = local_id; |
| 42 quit_closure_.Run(); | 42 quit_closure_.Run(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 std::string observed_resource_id_; | 46 std::string observed_local_id_; |
| 47 base::Closure quit_closure_; | 47 base::Closure quit_closure_; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| 52 class GetFileForSavingOperationTest : public OperationTestBase { | 52 class GetFileForSavingOperationTest : public OperationTestBase { |
| 53 protected: | 53 protected: |
| 54 // FileWriteWatcher requires TYPE_IO message loop to run. | 54 // FileWriteWatcher requires TYPE_IO message loop to run. |
| 55 GetFileForSavingOperationTest() | 55 GetFileForSavingOperationTest() |
| 56 : OperationTestBase(content::TestBrowserThreadBundle::IO_MAINLOOP) { | 56 : OperationTestBase(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 86 | 86 |
| 87 // Checks that the file is retrieved. | 87 // Checks that the file is retrieved. |
| 88 EXPECT_EQ(FILE_ERROR_OK, error); | 88 EXPECT_EQ(FILE_ERROR_OK, error); |
| 89 ASSERT_TRUE(entry); | 89 ASSERT_TRUE(entry); |
| 90 EXPECT_EQ(src_entry.resource_id(), entry->resource_id()); | 90 EXPECT_EQ(src_entry.resource_id(), entry->resource_id()); |
| 91 | 91 |
| 92 // Checks that it presents in cache and marked dirty. | 92 // Checks that it presents in cache and marked dirty. |
| 93 bool success = false; | 93 bool success = false; |
| 94 FileCacheEntry cache_entry; | 94 FileCacheEntry cache_entry; |
| 95 cache()->GetCacheEntryOnUIThread( | 95 cache()->GetCacheEntryOnUIThread( |
| 96 src_entry.resource_id(), | 96 GetLocalId(drive_path), |
| 97 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); | 97 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); |
| 98 test_util::RunBlockingPoolTask(); | 98 test_util::RunBlockingPoolTask(); |
| 99 EXPECT_TRUE(success); | 99 EXPECT_TRUE(success); |
| 100 EXPECT_TRUE(cache_entry.is_present()); | 100 EXPECT_TRUE(cache_entry.is_present()); |
| 101 EXPECT_TRUE(cache_entry.is_dirty()); | 101 EXPECT_TRUE(cache_entry.is_dirty()); |
| 102 | 102 |
| 103 // Write something to the cache and checks that the event is reported. | 103 // Write something to the cache and checks that the event is reported. |
| 104 { | 104 { |
| 105 base::RunLoop run_loop; | 105 base::RunLoop run_loop; |
| 106 observer_.set_quit_closure(run_loop.QuitClosure()); | 106 observer_.set_quit_closure(run_loop.QuitClosure()); |
| 107 google_apis::test_util::WriteStringToFile(local_path, "hello"); | 107 google_apis::test_util::WriteStringToFile(local_path, "hello"); |
| 108 run_loop.Run(); | 108 run_loop.Run(); |
| 109 EXPECT_EQ(entry->resource_id(), observer_.observerd_resource_id()); | 109 EXPECT_EQ(GetLocalId(drive_path), observer_.observerd_local_id()); |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 | 112 |
| 113 TEST_F(GetFileForSavingOperationTest, GetFileForSaving_NotExist) { | 113 TEST_F(GetFileForSavingOperationTest, GetFileForSaving_NotExist) { |
| 114 base::FilePath drive_path(FILE_PATH_LITERAL("drive/root/NotExist.txt")); | 114 base::FilePath drive_path(FILE_PATH_LITERAL("drive/root/NotExist.txt")); |
| 115 ResourceEntry src_entry; | 115 ResourceEntry src_entry; |
| 116 ASSERT_EQ(FILE_ERROR_NOT_FOUND, | 116 ASSERT_EQ(FILE_ERROR_NOT_FOUND, |
| 117 GetLocalResourceEntry(drive_path, &src_entry)); | 117 GetLocalResourceEntry(drive_path, &src_entry)); |
| 118 | 118 |
| 119 // Run the operation. | 119 // Run the operation. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 149 google_apis::test_util::CreateCopyResultCallback( | 149 google_apis::test_util::CreateCopyResultCallback( |
| 150 &error, &local_path, &entry)); | 150 &error, &local_path, &entry)); |
| 151 test_util::RunBlockingPoolTask(); | 151 test_util::RunBlockingPoolTask(); |
| 152 | 152 |
| 153 // Checks that an error is returned. | 153 // Checks that an error is returned. |
| 154 EXPECT_EQ(FILE_ERROR_EXISTS, error); | 154 EXPECT_EQ(FILE_ERROR_EXISTS, error); |
| 155 } | 155 } |
| 156 | 156 |
| 157 } // namespace file_system | 157 } // namespace file_system |
| 158 } // namespace drive | 158 } // namespace drive |
| OLD | NEW |