Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / chromeos / file_system_provider / operations / remove_watcher_unittest.cc
blobcd03c3a7482493890093fd21bf9593fc4ba598ae
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/remove_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 "base/memory/scoped_vector.h"
14 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h"
15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
16 #include "chrome/common/extensions/api/file_system_provider.h"
17 #include "chrome/common/extensions/api/file_system_provider_capabilities/file_system_provider_capabilities_handler.h"
18 #include "chrome/common/extensions/api/file_system_provider_internal.h"
19 #include "extensions/browser/event_router.h"
20 #include "storage/browser/fileapi/async_file_util.h"
21 #include "testing/gtest/include/gtest/gtest.h"
23 namespace chromeos {
24 namespace file_system_provider {
25 namespace operations {
26 namespace {
28 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
29 const char kFileSystemId[] = "testing-file-system";
30 const int kRequestId = 2;
31 const base::FilePath::CharType kEntryPath[] =
32 FILE_PATH_LITERAL("/kitty/and/puppy/happy");
34 } // namespace
36 class FileSystemProviderOperationsRemoveWatcherTest : public testing::Test {
37 protected:
38 FileSystemProviderOperationsRemoveWatcherTest() {}
39 ~FileSystemProviderOperationsRemoveWatcherTest() override {}
41 void SetUp() override {
42 file_system_info_ = ProvidedFileSystemInfo(
43 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */),
44 base::FilePath(), false /* configurable */, true /* watchable */,
45 extensions::SOURCE_FILE);
48 ProvidedFileSystemInfo file_system_info_;
51 TEST_F(FileSystemProviderOperationsRemoveWatcherTest, Execute) {
52 using extensions::api::file_system_provider::RemoveWatcherRequestedOptions;
54 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
55 util::StatusCallbackLog callback_log;
57 RemoveWatcher remove_watcher(
58 NULL, file_system_info_, base::FilePath(kEntryPath), true /* recursive */,
59 base::Bind(&util::LogStatusCallback, &callback_log));
60 remove_watcher.SetDispatchEventImplForTesting(
61 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
62 base::Unretained(&dispatcher)));
64 EXPECT_TRUE(remove_watcher.Execute(kRequestId));
66 ASSERT_EQ(1u, dispatcher.events().size());
67 extensions::Event* event = dispatcher.events()[0];
68 EXPECT_EQ(extensions::api::file_system_provider::OnRemoveWatcherRequested::
69 kEventName,
70 event->event_name);
71 base::ListValue* event_args = event->event_args.get();
72 ASSERT_EQ(1u, event_args->GetSize());
74 const base::DictionaryValue* options_as_value = NULL;
75 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
77 RemoveWatcherRequestedOptions options;
78 ASSERT_TRUE(
79 RemoveWatcherRequestedOptions::Populate(*options_as_value, &options));
80 EXPECT_EQ(kFileSystemId, options.file_system_id);
81 EXPECT_EQ(kRequestId, options.request_id);
82 EXPECT_EQ(kEntryPath, options.entry_path);
83 EXPECT_TRUE(options.recursive);
86 TEST_F(FileSystemProviderOperationsRemoveWatcherTest, Execute_NoListener) {
87 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
88 util::StatusCallbackLog callback_log;
90 RemoveWatcher remove_watcher(
91 NULL, file_system_info_, base::FilePath(kEntryPath), true /* recursive */,
92 base::Bind(&util::LogStatusCallback, &callback_log));
93 remove_watcher.SetDispatchEventImplForTesting(
94 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
95 base::Unretained(&dispatcher)));
97 EXPECT_FALSE(remove_watcher.Execute(kRequestId));
100 TEST_F(FileSystemProviderOperationsRemoveWatcherTest, OnSuccess) {
101 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
102 util::StatusCallbackLog callback_log;
104 RemoveWatcher remove_watcher(
105 NULL, file_system_info_, base::FilePath(kEntryPath), true /* recursive */,
106 base::Bind(&util::LogStatusCallback, &callback_log));
107 remove_watcher.SetDispatchEventImplForTesting(
108 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
109 base::Unretained(&dispatcher)));
111 EXPECT_TRUE(remove_watcher.Execute(kRequestId));
113 remove_watcher.OnSuccess(kRequestId,
114 scoped_ptr<RequestValue>(new RequestValue()),
115 false /* has_more */);
116 ASSERT_EQ(1u, callback_log.size());
117 EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
120 TEST_F(FileSystemProviderOperationsRemoveWatcherTest, OnError) {
121 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
122 util::StatusCallbackLog callback_log;
124 RemoveWatcher remove_watcher(
125 NULL, file_system_info_, base::FilePath(kEntryPath), true /* recursive */,
126 base::Bind(&util::LogStatusCallback, &callback_log));
127 remove_watcher.SetDispatchEventImplForTesting(
128 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
129 base::Unretained(&dispatcher)));
131 EXPECT_TRUE(remove_watcher.Execute(kRequestId));
133 remove_watcher.OnError(kRequestId,
134 scoped_ptr<RequestValue>(new RequestValue()),
135 base::File::FILE_ERROR_TOO_MANY_OPENED);
136 ASSERT_EQ(1u, callback_log.size());
137 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
140 } // namespace operations
141 } // namespace file_system_provider
142 } // namespace chromeos