Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / file_system_provider / operations / unmount_unittest.cc
blobe53bda4bacc87c39ae1de4844d904884478a4575
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/unmount.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_internal.h"
17 #include "extensions/browser/event_router.h"
18 #include "testing/gtest/include/gtest/gtest.h"
20 namespace chromeos {
21 namespace file_system_provider {
22 namespace operations {
23 namespace {
25 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
26 const char kFileSystemId[] = "testing-file-system";
27 const int kRequestId = 2;
29 } // namespace
31 class FileSystemProviderOperationsUnmountTest : public testing::Test {
32 protected:
33 FileSystemProviderOperationsUnmountTest() {}
34 ~FileSystemProviderOperationsUnmountTest() override {}
36 void SetUp() override {
37 file_system_info_ = ProvidedFileSystemInfo(
38 kExtensionId,
39 MountOptions(kFileSystemId, "" /* display_name */),
40 base::FilePath());
43 ProvidedFileSystemInfo file_system_info_;
46 TEST_F(FileSystemProviderOperationsUnmountTest, Execute) {
47 using extensions::api::file_system_provider::UnmountRequestedOptions;
49 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
50 util::StatusCallbackLog callback_log;
52 Unmount unmount(NULL,
53 file_system_info_,
54 base::Bind(&util::LogStatusCallback, &callback_log));
55 unmount.SetDispatchEventImplForTesting(
56 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
57 base::Unretained(&dispatcher)));
59 EXPECT_TRUE(unmount.Execute(kRequestId));
61 ASSERT_EQ(1u, dispatcher.events().size());
62 extensions::Event* event = dispatcher.events()[0];
63 EXPECT_EQ(
64 extensions::api::file_system_provider::OnUnmountRequested::kEventName,
65 event->event_name);
66 base::ListValue* event_args = event->event_args.get();
67 ASSERT_EQ(1u, event_args->GetSize());
69 const base::DictionaryValue* options_as_value = NULL;
70 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
72 UnmountRequestedOptions options;
73 ASSERT_TRUE(UnmountRequestedOptions::Populate(*options_as_value, &options));
74 EXPECT_EQ(kFileSystemId, options.file_system_id);
75 EXPECT_EQ(kRequestId, options.request_id);
78 TEST_F(FileSystemProviderOperationsUnmountTest, Execute_NoListener) {
79 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
80 util::StatusCallbackLog callback_log;
82 Unmount unmount(NULL,
83 file_system_info_,
84 base::Bind(&util::LogStatusCallback, &callback_log));
85 unmount.SetDispatchEventImplForTesting(
86 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
87 base::Unretained(&dispatcher)));
89 EXPECT_FALSE(unmount.Execute(kRequestId));
92 TEST_F(FileSystemProviderOperationsUnmountTest, OnSuccess) {
93 using extensions::api::file_system_provider_internal::
94 UnmountRequestedSuccess::Params;
96 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
97 util::StatusCallbackLog callback_log;
99 Unmount unmount(NULL,
100 file_system_info_,
101 base::Bind(&util::LogStatusCallback, &callback_log));
102 unmount.SetDispatchEventImplForTesting(
103 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
104 base::Unretained(&dispatcher)));
106 EXPECT_TRUE(unmount.Execute(kRequestId));
108 unmount.OnSuccess(kRequestId,
109 scoped_ptr<RequestValue>(new RequestValue()),
110 false /* has_more */);
111 ASSERT_EQ(1u, callback_log.size());
112 base::File::Error event_result = callback_log[0];
113 EXPECT_EQ(base::File::FILE_OK, event_result);
116 TEST_F(FileSystemProviderOperationsUnmountTest, OnError) {
117 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
118 util::StatusCallbackLog callback_log;
120 Unmount unmount(NULL,
121 file_system_info_,
122 base::Bind(&util::LogStatusCallback, &callback_log));
123 unmount.SetDispatchEventImplForTesting(
124 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
125 base::Unretained(&dispatcher)));
127 EXPECT_TRUE(unmount.Execute(kRequestId));
129 unmount.OnError(kRequestId,
130 scoped_ptr<RequestValue>(new RequestValue()),
131 base::File::FILE_ERROR_NOT_FOUND);
132 ASSERT_EQ(1u, callback_log.size());
133 base::File::Error event_result = callback_log[0];
134 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, event_result);
137 } // namespace operations
138 } // namespace file_system_provider
139 } // namespace chromeos