ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / chromeos / file_system_provider / operations / create_directory_unittest.cc
blobc5d31797048310f96ecf2fe5153903a42445f1d5
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 "base/memory/scoped_vector.h"
14 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h"
15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
16 #include "chrome/common/extensions/api/file_system_provider.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_ =
44 ProvidedFileSystemInfo(kExtensionId, mount_options, base::FilePath());
47 ProvidedFileSystemInfo file_system_info_;
50 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute) {
51 using extensions::api::file_system_provider::CreateDirectoryRequestedOptions;
53 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
54 util::StatusCallbackLog callback_log;
56 CreateDirectory create_directory(
57 NULL, file_system_info_, base::FilePath(kDirectoryPath),
58 true /* recursive */,
59 base::Bind(&util::LogStatusCallback, &callback_log));
60 create_directory.SetDispatchEventImplForTesting(
61 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
62 base::Unretained(&dispatcher)));
64 EXPECT_TRUE(create_directory.Execute(kRequestId));
66 ASSERT_EQ(1u, dispatcher.events().size());
67 extensions::Event* event = dispatcher.events()[0];
68 EXPECT_EQ(extensions::api::file_system_provider::OnCreateDirectoryRequested::
69 kEventName,
70 event->event_name);
71 base::ListValue* event_args = event->event_args.get();
72 ASSERT_EQ(1u, event_args->GetSize());
74 const base::DictionaryValue* options_as_value = NULL;
75 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
77 CreateDirectoryRequestedOptions options;
78 ASSERT_TRUE(
79 CreateDirectoryRequestedOptions::Populate(*options_as_value, &options));
80 EXPECT_EQ(kFileSystemId, options.file_system_id);
81 EXPECT_EQ(kRequestId, options.request_id);
82 EXPECT_EQ(kDirectoryPath, options.directory_path);
83 EXPECT_TRUE(options.recursive);
86 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute_NoListener) {
87 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
88 util::StatusCallbackLog callback_log;
90 CreateDirectory create_directory(
91 NULL, file_system_info_, base::FilePath(kDirectoryPath),
92 true /* recursive */,
93 base::Bind(&util::LogStatusCallback, &callback_log));
94 create_directory.SetDispatchEventImplForTesting(
95 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
96 base::Unretained(&dispatcher)));
98 EXPECT_FALSE(create_directory.Execute(kRequestId));
101 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute_ReadOnly) {
102 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
103 util::StatusCallbackLog callback_log;
105 const ProvidedFileSystemInfo read_only_file_system_info(
106 kExtensionId,
107 MountOptions(kFileSystemId, "" /* display_name */),
108 base::FilePath() /* mount_path */);
110 CreateDirectory create_directory(
111 NULL, read_only_file_system_info, base::FilePath(kDirectoryPath),
112 true /* recursive */,
113 base::Bind(&util::LogStatusCallback, &callback_log));
114 create_directory.SetDispatchEventImplForTesting(
115 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
116 base::Unretained(&dispatcher)));
118 EXPECT_FALSE(create_directory.Execute(kRequestId));
121 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, OnSuccess) {
122 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
123 util::StatusCallbackLog callback_log;
125 CreateDirectory create_directory(
126 NULL, file_system_info_, base::FilePath(kDirectoryPath),
127 true /* recursive */,
128 base::Bind(&util::LogStatusCallback, &callback_log));
129 create_directory.SetDispatchEventImplForTesting(
130 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
131 base::Unretained(&dispatcher)));
133 EXPECT_TRUE(create_directory.Execute(kRequestId));
135 create_directory.OnSuccess(kRequestId,
136 scoped_ptr<RequestValue>(new RequestValue()),
137 false /* has_more */);
138 ASSERT_EQ(1u, callback_log.size());
139 EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
142 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, OnError) {
143 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
144 util::StatusCallbackLog callback_log;
146 CreateDirectory create_directory(
147 NULL, file_system_info_, base::FilePath(kDirectoryPath),
148 true /* recursive */,
149 base::Bind(&util::LogStatusCallback, &callback_log));
150 create_directory.SetDispatchEventImplForTesting(
151 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
152 base::Unretained(&dispatcher)));
154 EXPECT_TRUE(create_directory.Execute(kRequestId));
156 create_directory.OnError(kRequestId,
157 scoped_ptr<RequestValue>(new RequestValue()),
158 base::File::FILE_ERROR_TOO_MANY_OPENED);
159 ASSERT_EQ(1u, callback_log.size());
160 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
163 } // namespace operations
164 } // namespace file_system_provider
165 } // namespace chromeos