Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / chrome / browser / chromeos / file_system_provider / operations / delete_entry_unittest.cc
blobb58f5b29079c3fca4524a0a953e35ba6dbe552e8
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/delete_entry.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 kEntryPath[] =
31 FILE_PATH_LITERAL("/kitty/and/puppy/happy");
33 } // namespace
35 class FileSystemProviderOperationsDeleteEntryTest : public testing::Test {
36 protected:
37 FileSystemProviderOperationsDeleteEntryTest() {}
38 ~FileSystemProviderOperationsDeleteEntryTest() 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(FileSystemProviderOperationsDeleteEntryTest, Execute) {
52 using extensions::api::file_system_provider::DeleteEntryRequestedOptions;
54 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
55 util::StatusCallbackLog callback_log;
57 DeleteEntry delete_entry(NULL, file_system_info_, base::FilePath(kEntryPath),
58 true /* recursive */,
59 base::Bind(&util::LogStatusCallback, &callback_log));
60 delete_entry.SetDispatchEventImplForTesting(
61 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
62 base::Unretained(&dispatcher)));
64 EXPECT_TRUE(delete_entry.Execute(kRequestId));
66 ASSERT_EQ(1u, dispatcher.events().size());
67 extensions::Event* event = dispatcher.events()[0];
68 EXPECT_EQ(
69 extensions::api::file_system_provider::OnDeleteEntryRequested::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 DeleteEntryRequestedOptions options;
78 ASSERT_TRUE(
79 DeleteEntryRequestedOptions::Populate(*options_as_value, &options));
80 EXPECT_EQ(kFileSystemId, options.file_system_id);
81 EXPECT_EQ(kRequestId, options.request_id);
82 EXPECT_EQ(kEntryPath, options.entry_path);
83 EXPECT_TRUE(options.recursive);
86 TEST_F(FileSystemProviderOperationsDeleteEntryTest, Execute_NoListener) {
87 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
88 util::StatusCallbackLog callback_log;
90 DeleteEntry delete_entry(NULL, file_system_info_, base::FilePath(kEntryPath),
91 true /* recursive */,
92 base::Bind(&util::LogStatusCallback, &callback_log));
93 delete_entry.SetDispatchEventImplForTesting(
94 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
95 base::Unretained(&dispatcher)));
97 EXPECT_FALSE(delete_entry.Execute(kRequestId));
100 TEST_F(FileSystemProviderOperationsDeleteEntryTest, Execute_ReadOnly) {
101 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
102 util::StatusCallbackLog callback_log;
104 const ProvidedFileSystemInfo read_only_file_system_info(
105 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */),
106 base::FilePath() /* mount_path */, false /* configurable */,
107 true /* watchable */, extensions::SOURCE_FILE);
109 DeleteEntry delete_entry(NULL, read_only_file_system_info,
110 base::FilePath(kEntryPath), true /* recursive */,
111 base::Bind(&util::LogStatusCallback, &callback_log));
112 delete_entry.SetDispatchEventImplForTesting(
113 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
114 base::Unretained(&dispatcher)));
116 EXPECT_FALSE(delete_entry.Execute(kRequestId));
119 TEST_F(FileSystemProviderOperationsDeleteEntryTest, OnSuccess) {
120 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
121 util::StatusCallbackLog callback_log;
123 DeleteEntry delete_entry(NULL, file_system_info_, base::FilePath(kEntryPath),
124 true /* recursive */,
125 base::Bind(&util::LogStatusCallback, &callback_log));
126 delete_entry.SetDispatchEventImplForTesting(
127 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
128 base::Unretained(&dispatcher)));
130 EXPECT_TRUE(delete_entry.Execute(kRequestId));
132 delete_entry.OnSuccess(kRequestId,
133 scoped_ptr<RequestValue>(new RequestValue()),
134 false /* has_more */);
135 ASSERT_EQ(1u, callback_log.size());
136 EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
139 TEST_F(FileSystemProviderOperationsDeleteEntryTest, OnError) {
140 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
141 util::StatusCallbackLog callback_log;
143 DeleteEntry delete_entry(NULL, file_system_info_, base::FilePath(kEntryPath),
144 true /* recursive */,
145 base::Bind(&util::LogStatusCallback, &callback_log));
146 delete_entry.SetDispatchEventImplForTesting(
147 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
148 base::Unretained(&dispatcher)));
150 EXPECT_TRUE(delete_entry.Execute(kRequestId));
152 delete_entry.OnError(kRequestId,
153 scoped_ptr<RequestValue>(new RequestValue()),
154 base::File::FILE_ERROR_TOO_MANY_OPENED);
155 ASSERT_EQ(1u, callback_log.size());
156 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
159 } // namespace operations
160 } // namespace file_system_provider
161 } // namespace chromeos