BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / chromeos / file_system_provider / operations / add_watcher_unittest.cc
blob5a688d6ed3e50808eb1af4208b21e64dc18825ec
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/add_watcher.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 FileSystemProviderOperationsAddWatcherTest : public testing::Test {
36 protected:
37 FileSystemProviderOperationsAddWatcherTest() {}
38 ~FileSystemProviderOperationsAddWatcherTest() override {}
40 void SetUp() override {
41 file_system_info_ = ProvidedFileSystemInfo(
42 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */),
43 base::FilePath(), false /* configurable */, true /* watchable */,
44 extensions::SOURCE_FILE);
47 ProvidedFileSystemInfo file_system_info_;
50 TEST_F(FileSystemProviderOperationsAddWatcherTest, Execute) {
51 using extensions::api::file_system_provider::AddWatcherRequestedOptions;
53 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
54 util::StatusCallbackLog callback_log;
56 AddWatcher add_watcher(NULL, file_system_info_, base::FilePath(kEntryPath),
57 true /* recursive */,
58 base::Bind(&util::LogStatusCallback, &callback_log));
59 add_watcher.SetDispatchEventImplForTesting(
60 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
61 base::Unretained(&dispatcher)));
63 EXPECT_TRUE(add_watcher.Execute(kRequestId));
65 ASSERT_EQ(1u, dispatcher.events().size());
66 extensions::Event* event = dispatcher.events()[0];
67 EXPECT_EQ(
68 extensions::api::file_system_provider::OnAddWatcherRequested::kEventName,
69 event->event_name);
70 base::ListValue* event_args = event->event_args.get();
71 ASSERT_EQ(1u, event_args->GetSize());
73 const base::DictionaryValue* options_as_value = NULL;
74 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
76 AddWatcherRequestedOptions options;
77 ASSERT_TRUE(
78 AddWatcherRequestedOptions::Populate(*options_as_value, &options));
79 EXPECT_EQ(kFileSystemId, options.file_system_id);
80 EXPECT_EQ(kRequestId, options.request_id);
81 EXPECT_EQ(kEntryPath, options.entry_path);
82 EXPECT_TRUE(options.recursive);
85 TEST_F(FileSystemProviderOperationsAddWatcherTest, Execute_NoListener) {
86 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
87 util::StatusCallbackLog callback_log;
89 AddWatcher add_watcher(NULL, file_system_info_, base::FilePath(kEntryPath),
90 true /* recursive */,
91 base::Bind(&util::LogStatusCallback, &callback_log));
92 add_watcher.SetDispatchEventImplForTesting(
93 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
94 base::Unretained(&dispatcher)));
96 EXPECT_FALSE(add_watcher.Execute(kRequestId));
99 TEST_F(FileSystemProviderOperationsAddWatcherTest, OnSuccess) {
100 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
101 util::StatusCallbackLog callback_log;
103 AddWatcher add_watcher(NULL, file_system_info_, base::FilePath(kEntryPath),
104 true /* recursive */,
105 base::Bind(&util::LogStatusCallback, &callback_log));
106 add_watcher.SetDispatchEventImplForTesting(
107 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
108 base::Unretained(&dispatcher)));
110 EXPECT_TRUE(add_watcher.Execute(kRequestId));
112 add_watcher.OnSuccess(kRequestId,
113 scoped_ptr<RequestValue>(new RequestValue()),
114 false /* has_more */);
115 ASSERT_EQ(1u, callback_log.size());
116 EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
119 TEST_F(FileSystemProviderOperationsAddWatcherTest, OnError) {
120 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
121 util::StatusCallbackLog callback_log;
123 AddWatcher add_watcher(NULL, file_system_info_, base::FilePath(kEntryPath),
124 true /* recursive */,
125 base::Bind(&util::LogStatusCallback, &callback_log));
126 add_watcher.SetDispatchEventImplForTesting(
127 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
128 base::Unretained(&dispatcher)));
130 EXPECT_TRUE(add_watcher.Execute(kRequestId));
132 add_watcher.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