Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / file_system / create_directory_operation_unittest.cc
blob5152f3117cef43740e535183aadc530d1dc280d4
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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/drive/file_system/create_directory_operation.h"
7 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
8 #include "google_apis/drive/test_util.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace drive {
12 namespace file_system {
14 class CreateDirectoryOperationTest : public OperationTestBase {
15 protected:
16 // Returns FILE_ERROR_OK if a directory is found at |path|.
17 FileError FindDirectory(const base::FilePath& path) {
18 ResourceEntry entry;
19 FileError error = GetLocalResourceEntry(path, &entry);
20 if (error == FILE_ERROR_OK && !entry.file_info().is_directory())
21 error = FILE_ERROR_NOT_A_DIRECTORY;
22 return error;
26 TEST_F(CreateDirectoryOperationTest, CreateDirectory) {
27 CreateDirectoryOperation operation(blocking_task_runner(),
28 observer(),
29 scheduler(),
30 metadata());
32 const base::FilePath kExistingFile(
33 FILE_PATH_LITERAL("drive/root/File 1.txt"));
34 const base::FilePath kExistingDirectory(
35 FILE_PATH_LITERAL("drive/root/Directory 1"));
36 const base::FilePath kNewDirectory1(
37 FILE_PATH_LITERAL("drive/root/New Directory"));
38 const base::FilePath kNewDirectory2 =
39 kNewDirectory1.AppendASCII("New Directory 2/a/b/c");
41 // Create a new directory, not recursively.
42 EXPECT_EQ(FILE_ERROR_NOT_FOUND, FindDirectory(kNewDirectory1));
44 FileError error = FILE_ERROR_FAILED;
45 operation.CreateDirectory(
46 kNewDirectory1,
47 true, // is_exclusive
48 false, // is_recursive
49 google_apis::test_util::CreateCopyResultCallback(&error));
50 test_util::RunBlockingPoolTask();
51 EXPECT_EQ(FILE_ERROR_OK, error);
52 EXPECT_EQ(FILE_ERROR_OK, FindDirectory(kNewDirectory1));
53 EXPECT_EQ(1U, observer()->get_changed_paths().size());
54 EXPECT_EQ(1U,
55 observer()->get_changed_paths().count(kNewDirectory1.DirName()));
57 // Create a new directory recursively.
58 EXPECT_EQ(FILE_ERROR_NOT_FOUND, FindDirectory(kNewDirectory2));
59 operation.CreateDirectory(
60 kNewDirectory2,
61 true, // is_exclusive
62 false, // is_recursive
63 google_apis::test_util::CreateCopyResultCallback(&error));
64 test_util::RunBlockingPoolTask();
65 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
66 EXPECT_EQ(FILE_ERROR_NOT_FOUND, FindDirectory(kNewDirectory2));
68 operation.CreateDirectory(
69 kNewDirectory2,
70 true, // is_exclusive
71 true, // is_recursive
72 google_apis::test_util::CreateCopyResultCallback(&error));
73 test_util::RunBlockingPoolTask();
74 EXPECT_EQ(FILE_ERROR_OK, error);
75 EXPECT_EQ(FILE_ERROR_OK, FindDirectory(kNewDirectory2));
77 // Try to create an existing directory.
78 operation.CreateDirectory(
79 kExistingDirectory,
80 true, // is_exclusive
81 false, // is_recursive
82 google_apis::test_util::CreateCopyResultCallback(&error));
83 test_util::RunBlockingPoolTask();
84 EXPECT_EQ(FILE_ERROR_EXISTS, error);
86 operation.CreateDirectory(
87 kExistingDirectory,
88 false, // is_exclusive
89 false, // is_recursive
90 google_apis::test_util::CreateCopyResultCallback(&error));
91 test_util::RunBlockingPoolTask();
92 EXPECT_EQ(FILE_ERROR_OK, error);
94 // Try to create a directory with a path for an existing file.
95 operation.CreateDirectory(
96 kExistingFile,
97 false, // is_exclusive
98 true, // is_recursive
99 google_apis::test_util::CreateCopyResultCallback(&error));
100 test_util::RunBlockingPoolTask();
101 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
103 // Try to create a directory under a file.
104 operation.CreateDirectory(
105 kExistingFile.AppendASCII("New Directory"),
106 false, // is_exclusive
107 true, // is_recursive
108 google_apis::test_util::CreateCopyResultCallback(&error));
109 test_util::RunBlockingPoolTask();
110 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
113 } // namespace file_system
114 } // namespace drive