OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_directory_operation.h
" | 5 #include "chrome/browser/chromeos/drive/file_system/create_directory_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 "content/public/test/test_utils.h" | 8 #include "content/public/test/test_utils.h" |
9 #include "google_apis/drive/test_util.h" | 9 #include "google_apis/drive/test_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace drive { | 12 namespace drive { |
13 namespace file_system { | 13 namespace file_system { |
14 | 14 |
15 class CreateDirectoryOperationTest : public OperationTestBase { | 15 class CreateDirectoryOperationTest : public OperationTestBase { |
16 protected: | 16 protected: |
17 // Returns FILE_ERROR_OK if a directory is found at |path|. | 17 // Returns FILE_ERROR_OK if a directory is found at |path|. |
18 FileError FindDirectory(const base::FilePath& path) { | 18 FileError FindDirectory(const base::FilePath& path) { |
19 ResourceEntry entry; | 19 ResourceEntry entry; |
20 FileError error = GetLocalResourceEntry(path, &entry); | 20 FileError error = GetLocalResourceEntry(path, &entry); |
21 if (error == FILE_ERROR_OK && !entry.file_info().is_directory()) | 21 if (error == FILE_ERROR_OK && !entry.file_info().is_directory()) |
22 error = FILE_ERROR_NOT_A_DIRECTORY; | 22 error = FILE_ERROR_NOT_A_DIRECTORY; |
23 return error; | 23 return error; |
24 } | 24 } |
25 }; | 25 }; |
26 | 26 |
27 TEST_F(CreateDirectoryOperationTest, CreateDirectory) { | 27 TEST_F(CreateDirectoryOperationTest, CreateDirectory) { |
28 CreateDirectoryOperation operation(blocking_task_runner(), | 28 CreateDirectoryOperation operation(blocking_task_runner(), |
29 observer(), | 29 delegate(), |
30 metadata()); | 30 metadata()); |
31 | 31 |
32 const base::FilePath kExistingFile( | 32 const base::FilePath kExistingFile( |
33 FILE_PATH_LITERAL("drive/root/File 1.txt")); | 33 FILE_PATH_LITERAL("drive/root/File 1.txt")); |
34 const base::FilePath kExistingDirectory( | 34 const base::FilePath kExistingDirectory( |
35 FILE_PATH_LITERAL("drive/root/Directory 1")); | 35 FILE_PATH_LITERAL("drive/root/Directory 1")); |
36 const base::FilePath kNewDirectory1( | 36 const base::FilePath kNewDirectory1( |
37 FILE_PATH_LITERAL("drive/root/New Directory")); | 37 FILE_PATH_LITERAL("drive/root/New Directory")); |
38 const base::FilePath kNewDirectory2 = | 38 const base::FilePath kNewDirectory2 = |
39 kNewDirectory1.AppendASCII("New Directory 2/a/b/c"); | 39 kNewDirectory1.AppendASCII("New Directory 2/a/b/c"); |
40 | 40 |
41 // Create a new directory, not recursively. | 41 // Create a new directory, not recursively. |
42 EXPECT_EQ(FILE_ERROR_NOT_FOUND, FindDirectory(kNewDirectory1)); | 42 EXPECT_EQ(FILE_ERROR_NOT_FOUND, FindDirectory(kNewDirectory1)); |
43 | 43 |
44 FileError error = FILE_ERROR_FAILED; | 44 FileError error = FILE_ERROR_FAILED; |
45 operation.CreateDirectory( | 45 operation.CreateDirectory( |
46 kNewDirectory1, | 46 kNewDirectory1, |
47 true, // is_exclusive | 47 true, // is_exclusive |
48 false, // is_recursive | 48 false, // is_recursive |
49 google_apis::test_util::CreateCopyResultCallback(&error)); | 49 google_apis::test_util::CreateCopyResultCallback(&error)); |
50 content::RunAllBlockingPoolTasksUntilIdle(); | 50 content::RunAllBlockingPoolTasksUntilIdle(); |
51 EXPECT_EQ(FILE_ERROR_OK, error); | 51 EXPECT_EQ(FILE_ERROR_OK, error); |
52 EXPECT_EQ(FILE_ERROR_OK, FindDirectory(kNewDirectory1)); | 52 EXPECT_EQ(FILE_ERROR_OK, FindDirectory(kNewDirectory1)); |
53 EXPECT_EQ(1U, observer()->get_changed_files().size()); | 53 EXPECT_EQ(1U, delegate()->get_changed_files().size()); |
54 EXPECT_EQ( | 54 EXPECT_EQ( |
55 1U, | 55 1U, |
56 observer()->get_changed_files().CountDirectory(kNewDirectory1.DirName())); | 56 delegate()->get_changed_files().CountDirectory(kNewDirectory1.DirName())); |
57 | 57 |
58 ResourceEntry entry; | 58 ResourceEntry entry; |
59 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kNewDirectory1, &entry)); | 59 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kNewDirectory1, &entry)); |
60 EXPECT_EQ(ResourceEntry::DIRTY, entry.metadata_edit_state()); | 60 EXPECT_EQ(ResourceEntry::DIRTY, entry.metadata_edit_state()); |
61 EXPECT_TRUE(entry.file_info().is_directory()); | 61 EXPECT_TRUE(entry.file_info().is_directory()); |
62 EXPECT_FALSE(base::Time::FromInternalValue( | 62 EXPECT_FALSE(base::Time::FromInternalValue( |
63 entry.file_info().last_modified()).is_null()); | 63 entry.file_info().last_modified()).is_null()); |
64 EXPECT_FALSE(base::Time::FromInternalValue( | 64 EXPECT_FALSE(base::Time::FromInternalValue( |
65 entry.file_info().last_accessed()).is_null()); | 65 entry.file_info().last_accessed()).is_null()); |
66 EXPECT_EQ(1U, observer()->updated_local_ids().size()); | 66 EXPECT_EQ(1U, delegate()->updated_local_ids().size()); |
67 EXPECT_EQ(1U, observer()->updated_local_ids().count(entry.local_id())); | 67 EXPECT_EQ(1U, delegate()->updated_local_ids().count(entry.local_id())); |
68 | 68 |
69 // Create a new directory recursively. | 69 // Create a new directory recursively. |
70 EXPECT_EQ(FILE_ERROR_NOT_FOUND, FindDirectory(kNewDirectory2)); | 70 EXPECT_EQ(FILE_ERROR_NOT_FOUND, FindDirectory(kNewDirectory2)); |
71 operation.CreateDirectory( | 71 operation.CreateDirectory( |
72 kNewDirectory2, | 72 kNewDirectory2, |
73 true, // is_exclusive | 73 true, // is_exclusive |
74 false, // is_recursive | 74 false, // is_recursive |
75 google_apis::test_util::CreateCopyResultCallback(&error)); | 75 google_apis::test_util::CreateCopyResultCallback(&error)); |
76 content::RunAllBlockingPoolTasksUntilIdle(); | 76 content::RunAllBlockingPoolTasksUntilIdle(); |
77 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); | 77 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 kExistingFile.AppendASCII("New Directory"), | 117 kExistingFile.AppendASCII("New Directory"), |
118 false, // is_exclusive | 118 false, // is_exclusive |
119 true, // is_recursive | 119 true, // is_recursive |
120 google_apis::test_util::CreateCopyResultCallback(&error)); | 120 google_apis::test_util::CreateCopyResultCallback(&error)); |
121 content::RunAllBlockingPoolTasksUntilIdle(); | 121 content::RunAllBlockingPoolTasksUntilIdle(); |
122 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); | 122 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); |
123 } | 123 } |
124 | 124 |
125 } // namespace file_system | 125 } // namespace file_system |
126 } // namespace drive | 126 } // namespace drive |
OLD | NEW |