BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / chromeos / file_system_provider / operations / abort_unittest.cc
blob4bf49eaf4e83dc81310c28d4b907799dabfd75f2
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/abort.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 int kOperationRequestId = 3;
32 } // namespace
34 class FileSystemProviderOperationsAbortTest : public testing::Test {
35 protected:
36 FileSystemProviderOperationsAbortTest() {}
37 ~FileSystemProviderOperationsAbortTest() override {}
39 void SetUp() override {
40 file_system_info_ = ProvidedFileSystemInfo(
41 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */),
42 base::FilePath(), false /* configurable */, true /* watchable */,
43 extensions::SOURCE_FILE);
46 ProvidedFileSystemInfo file_system_info_;
49 TEST_F(FileSystemProviderOperationsAbortTest, Execute) {
50 using extensions::api::file_system_provider::AbortRequestedOptions;
52 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
53 util::StatusCallbackLog callback_log;
55 Abort abort(NULL,
56 file_system_info_,
57 kOperationRequestId,
58 base::Bind(&util::LogStatusCallback, &callback_log));
59 abort.SetDispatchEventImplForTesting(
60 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
61 base::Unretained(&dispatcher)));
63 EXPECT_TRUE(abort.Execute(kRequestId));
65 ASSERT_EQ(1u, dispatcher.events().size());
66 extensions::Event* event = dispatcher.events()[0];
67 EXPECT_EQ(extensions::api::file_system_provider::OnAbortRequested::kEventName,
68 event->event_name);
69 base::ListValue* event_args = event->event_args.get();
70 ASSERT_EQ(1u, event_args->GetSize());
72 const base::DictionaryValue* options_as_value = NULL;
73 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
75 AbortRequestedOptions options;
76 ASSERT_TRUE(AbortRequestedOptions::Populate(*options_as_value, &options));
77 EXPECT_EQ(kFileSystemId, options.file_system_id);
78 EXPECT_EQ(kRequestId, options.request_id);
79 EXPECT_EQ(kOperationRequestId, options.operation_request_id);
82 TEST_F(FileSystemProviderOperationsAbortTest, Execute_NoListener) {
83 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
84 util::StatusCallbackLog callback_log;
86 Abort abort(NULL,
87 file_system_info_,
88 kOperationRequestId,
89 base::Bind(&util::LogStatusCallback, &callback_log));
90 abort.SetDispatchEventImplForTesting(
91 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
92 base::Unretained(&dispatcher)));
94 EXPECT_FALSE(abort.Execute(kRequestId));
97 TEST_F(FileSystemProviderOperationsAbortTest, OnSuccess) {
98 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
99 util::StatusCallbackLog callback_log;
101 Abort abort(NULL,
102 file_system_info_,
103 kOperationRequestId,
104 base::Bind(&util::LogStatusCallback, &callback_log));
105 abort.SetDispatchEventImplForTesting(
106 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
107 base::Unretained(&dispatcher)));
109 EXPECT_TRUE(abort.Execute(kRequestId));
111 abort.OnSuccess(kRequestId,
112 scoped_ptr<RequestValue>(new RequestValue()),
113 false /* has_more */);
114 ASSERT_EQ(1u, callback_log.size());
115 EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
118 TEST_F(FileSystemProviderOperationsAbortTest, OnError) {
119 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
120 util::StatusCallbackLog callback_log;
122 Abort abort(NULL,
123 file_system_info_,
124 kOperationRequestId,
125 base::Bind(&util::LogStatusCallback, &callback_log));
126 abort.SetDispatchEventImplForTesting(
127 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
128 base::Unretained(&dispatcher)));
130 EXPECT_TRUE(abort.Execute(kRequestId));
132 abort.OnError(kRequestId,
133 scoped_ptr<RequestValue>(new RequestValue()),
134 base::File::FILE_ERROR_TOO_MANY_OPENED);
135 ASSERT_EQ(1u, callback_log.size());
136 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
139 } // namespace operations
140 } // namespace file_system_provider
141 } // namespace chromeos