BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / chromeos / file_system_provider / operations / create_directory_unittest.cc
blob8dfc0390478c08ed70cff13ba64334145563a6da
1 // Copyright 2014 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/file_system_provider/operations/create_directory.h"
7 #include <string>
8 #include <vector>
10 #include "base/files/file.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h"
14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
15 #include "chrome/common/extensions/api/file_system_provider.h"
16 #include "chrome/common/extensions/api/file_system_provider_capabilities/file_system_provider_capabilities_handler.h"
17 #include "chrome/common/extensions/api/file_system_provider_internal.h"
18 #include "extensions/browser/event_router.h"
19 #include "storage/browser/fileapi/async_file_util.h"
20 #include "testing/gtest/include/gtest/gtest.h"
22 namespace chromeos {
23 namespace file_system_provider {
24 namespace operations {
25 namespace {
27 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
28 const char kFileSystemId[] = "testing-file-system";
29 const int kRequestId = 2;
30 const base::FilePath::CharType kDirectoryPath[] =
31 FILE_PATH_LITERAL("/kitty/and/puppy/happy");
33 } // namespace
35 class FileSystemProviderOperationsCreateDirectoryTest : public testing::Test {
36 protected:
37 FileSystemProviderOperationsCreateDirectoryTest() {}
38 ~FileSystemProviderOperationsCreateDirectoryTest() override {}
40 void SetUp() override {
41 MountOptions mount_options(kFileSystemId, "" /* display_name */);
42 mount_options.writable = true;
43 file_system_info_ = ProvidedFileSystemInfo(
44 kExtensionId, mount_options, base::FilePath(), false /* configurable */,
45 true /* watchable */, extensions::SOURCE_FILE);
48 ProvidedFileSystemInfo file_system_info_;
51 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute) {
52 using extensions::api::file_system_provider::CreateDirectoryRequestedOptions;
54 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
55 util::StatusCallbackLog callback_log;
57 CreateDirectory create_directory(
58 NULL, file_system_info_, base::FilePath(kDirectoryPath),
59 true /* recursive */,
60 base::Bind(&util::LogStatusCallback, &callback_log));
61 create_directory.SetDispatchEventImplForTesting(
62 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
63 base::Unretained(&dispatcher)));
65 EXPECT_TRUE(create_directory.Execute(kRequestId));
67 ASSERT_EQ(1u, dispatcher.events().size());
68 extensions::Event* event = dispatcher.events()[0];
69 EXPECT_EQ(extensions::api::file_system_provider::OnCreateDirectoryRequested::
70 kEventName,
71 event->event_name);
72 base::ListValue* event_args = event->event_args.get();
73 ASSERT_EQ(1u, event_args->GetSize());
75 const base::DictionaryValue* options_as_value = NULL;
76 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
78 CreateDirectoryRequestedOptions options;
79 ASSERT_TRUE(
80 CreateDirectoryRequestedOptions::Populate(*options_as_value, &options));
81 EXPECT_EQ(kFileSystemId, options.file_system_id);
82 EXPECT_EQ(kRequestId, options.request_id);
83 EXPECT_EQ(kDirectoryPath, options.directory_path);
84 EXPECT_TRUE(options.recursive);
87 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute_NoListener) {
88 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
89 util::StatusCallbackLog callback_log;
91 CreateDirectory create_directory(
92 NULL, file_system_info_, base::FilePath(kDirectoryPath),
93 true /* recursive */,
94 base::Bind(&util::LogStatusCallback, &callback_log));
95 create_directory.SetDispatchEventImplForTesting(
96 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
97 base::Unretained(&dispatcher)));
99 EXPECT_FALSE(create_directory.Execute(kRequestId));
102 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute_ReadOnly) {
103 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
104 util::StatusCallbackLog callback_log;
106 const ProvidedFileSystemInfo read_only_file_system_info(
107 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */),
108 base::FilePath() /* mount_path */, false /* configurable */,
109 true /* watchable */, extensions::SOURCE_FILE);
111 CreateDirectory create_directory(
112 NULL, read_only_file_system_info, base::FilePath(kDirectoryPath),
113 true /* recursive */,
114 base::Bind(&util::LogStatusCallback, &callback_log));
115 create_directory.SetDispatchEventImplForTesting(
116 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
117 base::Unretained(&dispatcher)));
119 EXPECT_FALSE(create_directory.Execute(kRequestId));
122 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, OnSuccess) {
123 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
124 util::StatusCallbackLog callback_log;
126 CreateDirectory create_directory(
127 NULL, file_system_info_, base::FilePath(kDirectoryPath),
128 true /* recursive */,
129 base::Bind(&util::LogStatusCallback, &callback_log));
130 create_directory.SetDispatchEventImplForTesting(
131 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
132 base::Unretained(&dispatcher)));
134 EXPECT_TRUE(create_directory.Execute(kRequestId));
136 create_directory.OnSuccess(kRequestId,
137 scoped_ptr<RequestValue>(new RequestValue()),
138 false /* has_more */);
139 ASSERT_EQ(1u, callback_log.size());
140 EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
143 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, OnError) {
144 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
145 util::StatusCallbackLog callback_log;
147 CreateDirectory create_directory(
148 NULL, file_system_info_, base::FilePath(kDirectoryPath),
149 true /* recursive */,
150 base::Bind(&util::LogStatusCallback, &callback_log));
151 create_directory.SetDispatchEventImplForTesting(
152 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
153 base::Unretained(&dispatcher)));
155 EXPECT_TRUE(create_directory.Execute(kRequestId));
157 create_directory.OnError(kRequestId,
158 scoped_ptr<RequestValue>(new RequestValue()),
159 base::File::FILE_ERROR_TOO_MANY_OPENED);
160 ASSERT_EQ(1u, callback_log.size());
161 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
164 } // namespace operations
165 } // namespace file_system_provider
166 } // namespace chromeos