1 // Copyright 2015 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/configure.h"
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"
22 namespace file_system_provider
{
23 namespace operations
{
26 const char kExtensionId
[] = "mbflcebpggnecokmikipoihdbecnjfoj";
27 const char kFileSystemId
[] = "testing-file-system";
28 const int kRequestId
= 2;
32 class FileSystemProviderOperationsConfigureTest
: public testing::Test
{
34 FileSystemProviderOperationsConfigureTest() {}
35 ~FileSystemProviderOperationsConfigureTest() 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(FileSystemProviderOperationsConfigureTest
, Execute
) {
48 using extensions::api::file_system_provider::ConfigureRequestedOptions
;
50 util::LoggingDispatchEventImpl
dispatcher(true /* dispatch_reply */);
51 util::StatusCallbackLog callback_log
;
53 Configure
configure(NULL
, file_system_info_
,
54 base::Bind(&util::LogStatusCallback
, &callback_log
));
55 configure
.SetDispatchEventImplForTesting(
56 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl
,
57 base::Unretained(&dispatcher
)));
59 EXPECT_TRUE(configure
.Execute(kRequestId
));
61 ASSERT_EQ(1u, dispatcher
.events().size());
62 extensions::Event
* event
= dispatcher
.events()[0];
64 extensions::api::file_system_provider::OnConfigureRequested::kEventName
,
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 ConfigureRequestedOptions options
;
73 ASSERT_TRUE(ConfigureRequestedOptions::Populate(*options_as_value
, &options
));
74 EXPECT_EQ(kFileSystemId
, options
.file_system_id
);
75 EXPECT_EQ(kRequestId
, options
.request_id
);
78 TEST_F(FileSystemProviderOperationsConfigureTest
, Execute_NoListener
) {
79 util::LoggingDispatchEventImpl
dispatcher(false /* dispatch_reply */);
80 util::StatusCallbackLog callback_log
;
82 Configure
configure(NULL
, file_system_info_
,
83 base::Bind(&util::LogStatusCallback
, &callback_log
));
84 configure
.SetDispatchEventImplForTesting(
85 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl
,
86 base::Unretained(&dispatcher
)));
88 EXPECT_FALSE(configure
.Execute(kRequestId
));
91 TEST_F(FileSystemProviderOperationsConfigureTest
, OnSuccess
) {
92 util::LoggingDispatchEventImpl
dispatcher(true /* dispatch_reply */);
93 util::StatusCallbackLog callback_log
;
95 Configure
configure(NULL
, file_system_info_
,
96 base::Bind(&util::LogStatusCallback
, &callback_log
));
97 configure
.SetDispatchEventImplForTesting(
98 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl
,
99 base::Unretained(&dispatcher
)));
101 EXPECT_TRUE(configure
.Execute(kRequestId
));
103 configure
.OnSuccess(kRequestId
, scoped_ptr
<RequestValue
>(new RequestValue()),
104 false /* has_more */);
105 ASSERT_EQ(1u, callback_log
.size());
106 base::File::Error event_result
= callback_log
[0];
107 EXPECT_EQ(base::File::FILE_OK
, event_result
);
110 TEST_F(FileSystemProviderOperationsConfigureTest
, OnError
) {
111 util::LoggingDispatchEventImpl
dispatcher(true /* dispatch_reply */);
112 util::StatusCallbackLog callback_log
;
114 Configure
configure(NULL
, file_system_info_
,
115 base::Bind(&util::LogStatusCallback
, &callback_log
));
116 configure
.SetDispatchEventImplForTesting(
117 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl
,
118 base::Unretained(&dispatcher
)));
120 EXPECT_TRUE(configure
.Execute(kRequestId
));
122 configure
.OnError(kRequestId
, scoped_ptr
<RequestValue
>(new RequestValue()),
123 base::File::FILE_ERROR_NOT_FOUND
);
124 ASSERT_EQ(1u, callback_log
.size());
125 base::File::Error event_result
= callback_log
[0];
126 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND
, event_result
);
129 } // namespace operations
130 } // namespace file_system_provider
131 } // namespace chromeos