| 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/create_file_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/create_file_operation.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" | 7 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
| 8 #include "google_apis/drive/test_util.h" | 8 #include "google_apis/drive/test_util.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace drive { | 11 namespace drive { |
| 12 namespace file_system { | 12 namespace file_system { |
| 13 | 13 |
| 14 typedef OperationTestBase CreateFileOperationTest; | 14 typedef OperationTestBase CreateFileOperationTest; |
| 15 | 15 |
| 16 TEST_F(CreateFileOperationTest, CreateFile) { | 16 TEST_F(CreateFileOperationTest, CreateFile) { |
| 17 CreateFileOperation operation(blocking_task_runner(), | 17 CreateFileOperation operation(blocking_task_runner(), |
| 18 observer(), | 18 observer(), |
| 19 scheduler(), | 19 metadata()); |
| 20 metadata(), | 20 |
| 21 cache()); | 21 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/New File.txt")); |
| 22 FileError error = FILE_ERROR_FAILED; |
| 23 operation.CreateFile( |
| 24 kFilePath, |
| 25 true, // is_exclusive |
| 26 std::string(), // no predetermined mime type |
| 27 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 28 test_util::RunBlockingPoolTask(); |
| 29 EXPECT_EQ(FILE_ERROR_OK, error); |
| 30 |
| 31 ResourceEntry entry; |
| 32 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath, &entry)); |
| 33 EXPECT_EQ(ResourceEntry::DIRTY, entry.metadata_edit_state()); |
| 34 EXPECT_FALSE(base::Time::FromInternalValue( |
| 35 entry.file_info().last_modified()).is_null()); |
| 36 EXPECT_FALSE(base::Time::FromInternalValue( |
| 37 entry.file_info().last_accessed()).is_null()); |
| 38 |
| 39 EXPECT_EQ(1u, observer()->get_changed_paths().size()); |
| 40 EXPECT_EQ(1u, observer()->get_changed_paths().count(kFilePath.DirName())); |
| 41 EXPECT_EQ(1u, observer()->updated_local_ids().size()); |
| 42 EXPECT_EQ(1u, observer()->updated_local_ids().count(entry.local_id())); |
| 43 } |
| 44 |
| 45 TEST_F(CreateFileOperationTest, CreateFileIsExclusive) { |
| 46 CreateFileOperation operation(blocking_task_runner(), |
| 47 observer(), |
| 48 metadata()); |
| 22 | 49 |
| 23 const base::FilePath kExistingFile( | 50 const base::FilePath kExistingFile( |
| 24 FILE_PATH_LITERAL("drive/root/File 1.txt")); | 51 FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 25 const base::FilePath kExistingDirectory( | 52 const base::FilePath kExistingDirectory( |
| 26 FILE_PATH_LITERAL("drive/root/Directory 1")); | 53 FILE_PATH_LITERAL("drive/root/Directory 1")); |
| 27 const base::FilePath kNonExistingFile( | 54 const base::FilePath kNonExistingFile( |
| 28 FILE_PATH_LITERAL("drive/root/Directory 1/not exist.png")); | 55 FILE_PATH_LITERAL("drive/root/Directory 1/not exist.png")); |
| 29 const base::FilePath kFileInNonExistingDirectory( | 56 const base::FilePath kFileInNonExistingDirectory( |
| 30 FILE_PATH_LITERAL("drive/root/not exist/not exist.png")); | 57 FILE_PATH_LITERAL("drive/root/not exist/not exist.png")); |
| 31 | 58 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 false, // is_exclusive | 99 false, // is_exclusive |
| 73 std::string(), // no predetermined mime type | 100 std::string(), // no predetermined mime type |
| 74 google_apis::test_util::CreateCopyResultCallback(&error)); | 101 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 75 test_util::RunBlockingPoolTask(); | 102 test_util::RunBlockingPoolTask(); |
| 76 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); | 103 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); |
| 77 } | 104 } |
| 78 | 105 |
| 79 TEST_F(CreateFileOperationTest, CreateFileMimeType) { | 106 TEST_F(CreateFileOperationTest, CreateFileMimeType) { |
| 80 CreateFileOperation operation(blocking_task_runner(), | 107 CreateFileOperation operation(blocking_task_runner(), |
| 81 observer(), | 108 observer(), |
| 82 scheduler(), | 109 metadata()); |
| 83 metadata(), | |
| 84 cache()); | |
| 85 | 110 |
| 86 const base::FilePath kPng1(FILE_PATH_LITERAL("drive/root/1.png")); | 111 const base::FilePath kPng1(FILE_PATH_LITERAL("drive/root/1.png")); |
| 87 const base::FilePath kPng2(FILE_PATH_LITERAL("drive/root/2.png")); | 112 const base::FilePath kPng2(FILE_PATH_LITERAL("drive/root/2.png")); |
| 88 const base::FilePath kUnknown(FILE_PATH_LITERAL("drive/root/3.unknown")); | 113 const base::FilePath kUnknown(FILE_PATH_LITERAL("drive/root/3.unknown")); |
| 89 const std::string kSpecialMimeType("application/x-createfile-test"); | 114 const std::string kSpecialMimeType("application/x-createfile-test"); |
| 90 | 115 |
| 91 FileError error = FILE_ERROR_FAILED; | 116 FileError error = FILE_ERROR_FAILED; |
| 92 operation.CreateFile( | 117 operation.CreateFile( |
| 93 kPng1, | 118 kPng1, |
| 94 false, // is_exclusive | 119 false, // is_exclusive |
| (...skipping 28 matching lines...) Expand all Loading... |
| 123 google_apis::test_util::CreateCopyResultCallback(&error)); | 148 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 124 test_util::RunBlockingPoolTask(); | 149 test_util::RunBlockingPoolTask(); |
| 125 EXPECT_EQ(FILE_ERROR_OK, error); | 150 EXPECT_EQ(FILE_ERROR_OK, error); |
| 126 | 151 |
| 127 // If the mime type is not set and unknown, default to octet-stream. | 152 // If the mime type is not set and unknown, default to octet-stream. |
| 128 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kUnknown, &entry)); | 153 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kUnknown, &entry)); |
| 129 EXPECT_EQ("application/octet-stream", | 154 EXPECT_EQ("application/octet-stream", |
| 130 entry.file_specific_info().content_mime_type()); | 155 entry.file_specific_info().content_mime_type()); |
| 131 } | 156 } |
| 132 | 157 |
| 133 | |
| 134 } // namespace file_system | 158 } // namespace file_system |
| 135 } // namespace drive | 159 } // namespace drive |
| OLD | NEW |