BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / chromeos / file_system_provider / operations / unmount_unittest.cc
blob28181caec4ed5fd4549dbc0e345028ff0072f4cb
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_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 "testing/gtest/include/gtest/gtest.h"
21 namespace chromeos {
22 namespace file_system_provider {
23 namespace operations {
24 namespace {
26 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
27 const char kFileSystemId[] = "testing-file-system";
28 const int kRequestId = 2;
30 } // namespace
32 class FileSystemProviderOperationsUnmountTest : public testing::Test {
33 protected:
34 FileSystemProviderOperationsUnmountTest() {}
35 ~FileSystemProviderOperationsUnmountTest() override {}
37 void SetUp() override {
38 file_system_info_ = ProvidedFileSystemInfo(
39 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */),
40 base::FilePath(), false /* configurable */, true /* watchable */,
41 extensions::SOURCE_FILE);
44 ProvidedFileSystemInfo file_system_info_;
47 TEST_F(FileSystemProviderOperationsUnmountTest, Execute) {
48 using extensions::api::file_system_provider::UnmountRequestedOptions;
50 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
51 util::StatusCallbackLog callback_log;
53 Unmount unmount(NULL,
54 file_system_info_,
55 base::Bind(&util::LogStatusCallback, &callback_log));
56 unmount.SetDispatchEventImplForTesting(
57 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
58 base::Unretained(&dispatcher)));
60 EXPECT_TRUE(unmount.Execute(kRequestId));
62 ASSERT_EQ(1u, dispatcher.events().size());
63 extensions::Event* event = dispatcher.events()[0];
64 EXPECT_EQ(
65 extensions::api::file_system_provider::OnUnmountRequested::kEventName,
66 event->event_name);
67 base::ListValue* event_args = event->event_args.get();
68 ASSERT_EQ(1u, event_args->GetSize());
70 const base::DictionaryValue* options_as_value = NULL;
71 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
73 UnmountRequestedOptions options;
74 ASSERT_TRUE(UnmountRequestedOptions::Populate(*options_as_value, &options));
75 EXPECT_EQ(kFileSystemId, options.file_system_id);
76 EXPECT_EQ(kRequestId, options.request_id);
79 TEST_F(FileSystemProviderOperationsUnmountTest, Execute_NoListener) {
80 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
81 util::StatusCallbackLog callback_log;
83 Unmount unmount(NULL,
84 file_system_info_,
85 base::Bind(&util::LogStatusCallback, &callback_log));
86 unmount.SetDispatchEventImplForTesting(
87 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
88 base::Unretained(&dispatcher)));
90 EXPECT_FALSE(unmount.Execute(kRequestId));
93 TEST_F(FileSystemProviderOperationsUnmountTest, OnSuccess) {
94 using extensions::api::file_system_provider_internal::
95 UnmountRequestedSuccess::Params;
97 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
98 util::StatusCallbackLog callback_log;
100 Unmount unmount(NULL,
101 file_system_info_,
102 base::Bind(&util::LogStatusCallback, &callback_log));
103 unmount.SetDispatchEventImplForTesting(
104 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
105 base::Unretained(&dispatcher)));
107 EXPECT_TRUE(unmount.Execute(kRequestId));
109 unmount.OnSuccess(kRequestId,
110 scoped_ptr<RequestValue>(new RequestValue()),
111 false /* has_more */);
112 ASSERT_EQ(1u, callback_log.size());
113 base::File::Error event_result = callback_log[0];
114 EXPECT_EQ(base::File::FILE_OK, event_result);
117 TEST_F(FileSystemProviderOperationsUnmountTest, OnError) {
118 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
119 util::StatusCallbackLog callback_log;
121 Unmount unmount(NULL,
122 file_system_info_,
123 base::Bind(&util::LogStatusCallback, &callback_log));
124 unmount.SetDispatchEventImplForTesting(
125 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
126 base::Unretained(&dispatcher)));
128 EXPECT_TRUE(unmount.Execute(kRequestId));
130 unmount.OnError(kRequestId,
131 scoped_ptr<RequestValue>(new RequestValue()),
132 base::File::FILE_ERROR_NOT_FOUND);
133 ASSERT_EQ(1u, callback_log.size());
134 base::File::Error event_result = callback_log[0];
135 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, event_result);
138 } // namespace operations
139 } // namespace file_system_provider
140 } // namespace chromeos