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_change.h" | 7 #include "chrome/browser/chromeos/drive/file_change.h" |
8 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" | 8 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
9 #include "content/public/test/test_utils.h" | 9 #include "content/public/test/test_utils.h" |
10 #include "google_apis/drive/test_util.h" | 10 #include "google_apis/drive/test_util.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace drive { | 13 namespace drive { |
14 namespace file_system { | 14 namespace file_system { |
15 | 15 |
16 typedef OperationTestBase CreateFileOperationTest; | 16 typedef OperationTestBase CreateFileOperationTest; |
17 | 17 |
18 TEST_F(CreateFileOperationTest, CreateFile) { | 18 TEST_F(CreateFileOperationTest, CreateFile) { |
19 CreateFileOperation operation(blocking_task_runner(), | 19 CreateFileOperation operation(blocking_task_runner(), |
20 observer(), | 20 delegate(), |
21 metadata()); | 21 metadata()); |
22 | 22 |
23 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/New File.txt")); | 23 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/New File.txt")); |
24 FileError error = FILE_ERROR_FAILED; | 24 FileError error = FILE_ERROR_FAILED; |
25 operation.CreateFile( | 25 operation.CreateFile( |
26 kFilePath, | 26 kFilePath, |
27 true, // is_exclusive | 27 true, // is_exclusive |
28 std::string(), // no predetermined mime type | 28 std::string(), // no predetermined mime type |
29 google_apis::test_util::CreateCopyResultCallback(&error)); | 29 google_apis::test_util::CreateCopyResultCallback(&error)); |
30 content::RunAllBlockingPoolTasksUntilIdle(); | 30 content::RunAllBlockingPoolTasksUntilIdle(); |
31 EXPECT_EQ(FILE_ERROR_OK, error); | 31 EXPECT_EQ(FILE_ERROR_OK, error); |
32 | 32 |
33 ResourceEntry entry; | 33 ResourceEntry entry; |
34 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath, &entry)); | 34 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath, &entry)); |
35 EXPECT_EQ(ResourceEntry::DIRTY, entry.metadata_edit_state()); | 35 EXPECT_EQ(ResourceEntry::DIRTY, entry.metadata_edit_state()); |
36 EXPECT_FALSE(base::Time::FromInternalValue( | 36 EXPECT_FALSE(base::Time::FromInternalValue( |
37 entry.file_info().last_modified()).is_null()); | 37 entry.file_info().last_modified()).is_null()); |
38 EXPECT_FALSE(base::Time::FromInternalValue( | 38 EXPECT_FALSE(base::Time::FromInternalValue( |
39 entry.file_info().last_accessed()).is_null()); | 39 entry.file_info().last_accessed()).is_null()); |
40 | 40 |
41 EXPECT_EQ(1u, observer()->get_changed_files().size()); | 41 EXPECT_EQ(1u, delegate()->get_changed_files().size()); |
42 EXPECT_EQ(1u, observer()->get_changed_files().count(kFilePath)); | 42 EXPECT_EQ(1u, delegate()->get_changed_files().count(kFilePath)); |
43 EXPECT_EQ(1u, observer()->updated_local_ids().size()); | 43 EXPECT_EQ(1u, delegate()->updated_local_ids().size()); |
44 EXPECT_EQ(1u, observer()->updated_local_ids().count(entry.local_id())); | 44 EXPECT_EQ(1u, delegate()->updated_local_ids().count(entry.local_id())); |
45 } | 45 } |
46 | 46 |
47 TEST_F(CreateFileOperationTest, CreateFileIsExclusive) { | 47 TEST_F(CreateFileOperationTest, CreateFileIsExclusive) { |
48 CreateFileOperation operation(blocking_task_runner(), | 48 CreateFileOperation operation(blocking_task_runner(), |
49 observer(), | 49 delegate(), |
50 metadata()); | 50 metadata()); |
51 | 51 |
52 const base::FilePath kExistingFile( | 52 const base::FilePath kExistingFile( |
53 FILE_PATH_LITERAL("drive/root/File 1.txt")); | 53 FILE_PATH_LITERAL("drive/root/File 1.txt")); |
54 const base::FilePath kExistingDirectory( | 54 const base::FilePath kExistingDirectory( |
55 FILE_PATH_LITERAL("drive/root/Directory 1")); | 55 FILE_PATH_LITERAL("drive/root/Directory 1")); |
56 const base::FilePath kNonExistingFile( | 56 const base::FilePath kNonExistingFile( |
57 FILE_PATH_LITERAL("drive/root/Directory 1/not exist.png")); | 57 FILE_PATH_LITERAL("drive/root/Directory 1/not exist.png")); |
58 const base::FilePath kFileInNonExistingDirectory( | 58 const base::FilePath kFileInNonExistingDirectory( |
59 FILE_PATH_LITERAL("drive/root/not exist/not exist.png")); | 59 FILE_PATH_LITERAL("drive/root/not exist/not exist.png")); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 kFileInNonExistingDirectory, | 100 kFileInNonExistingDirectory, |
101 false, // is_exclusive | 101 false, // is_exclusive |
102 std::string(), // no predetermined mime type | 102 std::string(), // no predetermined mime type |
103 google_apis::test_util::CreateCopyResultCallback(&error)); | 103 google_apis::test_util::CreateCopyResultCallback(&error)); |
104 content::RunAllBlockingPoolTasksUntilIdle(); | 104 content::RunAllBlockingPoolTasksUntilIdle(); |
105 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); | 105 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); |
106 } | 106 } |
107 | 107 |
108 TEST_F(CreateFileOperationTest, CreateFileMimeType) { | 108 TEST_F(CreateFileOperationTest, CreateFileMimeType) { |
109 CreateFileOperation operation(blocking_task_runner(), | 109 CreateFileOperation operation(blocking_task_runner(), |
110 observer(), | 110 delegate(), |
111 metadata()); | 111 metadata()); |
112 | 112 |
113 const base::FilePath kPng1(FILE_PATH_LITERAL("drive/root/1.png")); | 113 const base::FilePath kPng1(FILE_PATH_LITERAL("drive/root/1.png")); |
114 const base::FilePath kPng2(FILE_PATH_LITERAL("drive/root/2.png")); | 114 const base::FilePath kPng2(FILE_PATH_LITERAL("drive/root/2.png")); |
115 const base::FilePath kUnknown(FILE_PATH_LITERAL("drive/root/3.unknown")); | 115 const base::FilePath kUnknown(FILE_PATH_LITERAL("drive/root/3.unknown")); |
116 const std::string kSpecialMimeType("application/x-createfile-test"); | 116 const std::string kSpecialMimeType("application/x-createfile-test"); |
117 | 117 |
118 FileError error = FILE_ERROR_FAILED; | 118 FileError error = FILE_ERROR_FAILED; |
119 operation.CreateFile( | 119 operation.CreateFile( |
120 kPng1, | 120 kPng1, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 EXPECT_EQ(FILE_ERROR_OK, error); | 152 EXPECT_EQ(FILE_ERROR_OK, error); |
153 | 153 |
154 // If the mime type is not set and unknown, default to octet-stream. | 154 // If the mime type is not set and unknown, default to octet-stream. |
155 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kUnknown, &entry)); | 155 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kUnknown, &entry)); |
156 EXPECT_EQ("application/octet-stream", | 156 EXPECT_EQ("application/octet-stream", |
157 entry.file_specific_info().content_mime_type()); | 157 entry.file_specific_info().content_mime_type()); |
158 } | 158 } |
159 | 159 |
160 } // namespace file_system | 160 } // namespace file_system |
161 } // namespace drive | 161 } // namespace drive |
OLD | NEW |