Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: chrome/browser/chromeos/file_system_provider/operations/remove_watcher_unittest.cc

Issue 674413002: [fsp] Rename ObserveEntry with AddWatcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/file_system_provider/operations/unobserve_entr y.h" 5 #include "chrome/browser/chromeos/file_system_provider/operations/remove_watcher .h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/files/file.h" 10 #include "base/files/file.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" 14 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h"
15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h" 15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h"
16 #include "chrome/common/extensions/api/file_system_provider.h" 16 #include "chrome/common/extensions/api/file_system_provider.h"
17 #include "chrome/common/extensions/api/file_system_provider_internal.h" 17 #include "chrome/common/extensions/api/file_system_provider_internal.h"
18 #include "extensions/browser/event_router.h" 18 #include "extensions/browser/event_router.h"
19 #include "storage/browser/fileapi/async_file_util.h" 19 #include "storage/browser/fileapi/async_file_util.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 namespace chromeos { 22 namespace chromeos {
23 namespace file_system_provider { 23 namespace file_system_provider {
24 namespace operations { 24 namespace operations {
25 namespace { 25 namespace {
26 26
27 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; 27 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
28 const char kFileSystemId[] = "testing-file-system"; 28 const char kFileSystemId[] = "testing-file-system";
29 const int kRequestId = 2; 29 const int kRequestId = 2;
30 const base::FilePath::CharType kEntryPath[] = "/kitty/and/puppy/happy"; 30 const base::FilePath::CharType kEntryPath[] = "/kitty/and/puppy/happy";
31 31
32 } // namespace 32 } // namespace
33 33
34 class FileSystemProviderOperationsUnobserveEntryTest : public testing::Test { 34 class FileSystemProviderOperationsRemoveWatcherTest : public testing::Test {
35 protected: 35 protected:
36 FileSystemProviderOperationsUnobserveEntryTest() {} 36 FileSystemProviderOperationsRemoveWatcherTest() {}
37 virtual ~FileSystemProviderOperationsUnobserveEntryTest() {} 37 virtual ~FileSystemProviderOperationsRemoveWatcherTest() {}
38 38
39 virtual void SetUp() override { 39 virtual void SetUp() override {
40 file_system_info_ = ProvidedFileSystemInfo( 40 file_system_info_ = ProvidedFileSystemInfo(
41 kExtensionId, 41 kExtensionId,
42 MountOptions(kFileSystemId, "" /* display_name */), 42 MountOptions(kFileSystemId, "" /* display_name */),
43 base::FilePath()); 43 base::FilePath());
44 } 44 }
45 45
46 ProvidedFileSystemInfo file_system_info_; 46 ProvidedFileSystemInfo file_system_info_;
47 }; 47 };
48 48
49 TEST_F(FileSystemProviderOperationsUnobserveEntryTest, Execute) { 49 TEST_F(FileSystemProviderOperationsRemoveWatcherTest, Execute) {
50 using extensions::api::file_system_provider::UnobserveEntryRequestedOptions; 50 using extensions::api::file_system_provider::RemoveWatcherRequestedOptions;
51 51
52 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 52 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
53 util::StatusCallbackLog callback_log; 53 util::StatusCallbackLog callback_log;
54 54
55 UnobserveEntry unobserve_entry( 55 RemoveWatcher remove_watcher(
56 NULL, 56 NULL,
57 file_system_info_, 57 file_system_info_,
58 base::FilePath::FromUTF8Unsafe(kEntryPath), 58 base::FilePath::FromUTF8Unsafe(kEntryPath),
59 true /* recursive */, 59 true /* recursive */,
60 base::Bind(&util::LogStatusCallback, &callback_log)); 60 base::Bind(&util::LogStatusCallback, &callback_log));
61 unobserve_entry.SetDispatchEventImplForTesting( 61 remove_watcher.SetDispatchEventImplForTesting(
62 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 62 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
63 base::Unretained(&dispatcher))); 63 base::Unretained(&dispatcher)));
64 64
65 EXPECT_TRUE(unobserve_entry.Execute(kRequestId)); 65 EXPECT_TRUE(remove_watcher.Execute(kRequestId));
66 66
67 ASSERT_EQ(1u, dispatcher.events().size()); 67 ASSERT_EQ(1u, dispatcher.events().size());
68 extensions::Event* event = dispatcher.events()[0]; 68 extensions::Event* event = dispatcher.events()[0];
69 EXPECT_EQ(extensions::api::file_system_provider::OnUnobserveEntryRequested:: 69 EXPECT_EQ(extensions::api::file_system_provider::OnRemoveWatcherRequested::
70 kEventName, 70 kEventName,
71 event->event_name); 71 event->event_name);
72 base::ListValue* event_args = event->event_args.get(); 72 base::ListValue* event_args = event->event_args.get();
73 ASSERT_EQ(1u, event_args->GetSize()); 73 ASSERT_EQ(1u, event_args->GetSize());
74 74
75 const base::DictionaryValue* options_as_value = NULL; 75 const base::DictionaryValue* options_as_value = NULL;
76 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); 76 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
77 77
78 UnobserveEntryRequestedOptions options; 78 RemoveWatcherRequestedOptions options;
79 ASSERT_TRUE( 79 ASSERT_TRUE(
80 UnobserveEntryRequestedOptions::Populate(*options_as_value, &options)); 80 RemoveWatcherRequestedOptions::Populate(*options_as_value, &options));
81 EXPECT_EQ(kFileSystemId, options.file_system_id); 81 EXPECT_EQ(kFileSystemId, options.file_system_id);
82 EXPECT_EQ(kRequestId, options.request_id); 82 EXPECT_EQ(kRequestId, options.request_id);
83 EXPECT_EQ(kEntryPath, options.entry_path); 83 EXPECT_EQ(kEntryPath, options.entry_path);
84 EXPECT_TRUE(options.recursive); 84 EXPECT_TRUE(options.recursive);
85 } 85 }
86 86
87 TEST_F(FileSystemProviderOperationsUnobserveEntryTest, Execute_NoListener) { 87 TEST_F(FileSystemProviderOperationsRemoveWatcherTest, Execute_NoListener) {
88 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); 88 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
89 util::StatusCallbackLog callback_log; 89 util::StatusCallbackLog callback_log;
90 90
91 UnobserveEntry unobserve_entry( 91 RemoveWatcher remove_watcher(
92 NULL, 92 NULL,
93 file_system_info_, 93 file_system_info_,
94 base::FilePath::FromUTF8Unsafe(kEntryPath), 94 base::FilePath::FromUTF8Unsafe(kEntryPath),
95 true /* recursive */, 95 true /* recursive */,
96 base::Bind(&util::LogStatusCallback, &callback_log)); 96 base::Bind(&util::LogStatusCallback, &callback_log));
97 unobserve_entry.SetDispatchEventImplForTesting( 97 remove_watcher.SetDispatchEventImplForTesting(
98 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 98 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
99 base::Unretained(&dispatcher))); 99 base::Unretained(&dispatcher)));
100 100
101 EXPECT_FALSE(unobserve_entry.Execute(kRequestId)); 101 EXPECT_FALSE(remove_watcher.Execute(kRequestId));
102 } 102 }
103 103
104 TEST_F(FileSystemProviderOperationsUnobserveEntryTest, OnSuccess) { 104 TEST_F(FileSystemProviderOperationsRemoveWatcherTest, OnSuccess) {
105 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 105 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
106 util::StatusCallbackLog callback_log; 106 util::StatusCallbackLog callback_log;
107 107
108 UnobserveEntry unobserve_entry( 108 RemoveWatcher remove_watcher(
109 NULL, 109 NULL,
110 file_system_info_, 110 file_system_info_,
111 base::FilePath::FromUTF8Unsafe(kEntryPath), 111 base::FilePath::FromUTF8Unsafe(kEntryPath),
112 true /* recursive */, 112 true /* recursive */,
113 base::Bind(&util::LogStatusCallback, &callback_log)); 113 base::Bind(&util::LogStatusCallback, &callback_log));
114 unobserve_entry.SetDispatchEventImplForTesting( 114 remove_watcher.SetDispatchEventImplForTesting(
115 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 115 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
116 base::Unretained(&dispatcher))); 116 base::Unretained(&dispatcher)));
117 117
118 EXPECT_TRUE(unobserve_entry.Execute(kRequestId)); 118 EXPECT_TRUE(remove_watcher.Execute(kRequestId));
119 119
120 unobserve_entry.OnSuccess(kRequestId, 120 remove_watcher.OnSuccess(kRequestId,
121 scoped_ptr<RequestValue>(new RequestValue()), 121 scoped_ptr<RequestValue>(new RequestValue()),
122 false /* has_more */); 122 false /* has_more */);
123 ASSERT_EQ(1u, callback_log.size()); 123 ASSERT_EQ(1u, callback_log.size());
124 EXPECT_EQ(base::File::FILE_OK, callback_log[0]); 124 EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
125 } 125 }
126 126
127 TEST_F(FileSystemProviderOperationsUnobserveEntryTest, OnError) { 127 TEST_F(FileSystemProviderOperationsRemoveWatcherTest, OnError) {
128 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 128 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
129 util::StatusCallbackLog callback_log; 129 util::StatusCallbackLog callback_log;
130 130
131 UnobserveEntry unobserve_entry( 131 RemoveWatcher remove_watcher(
132 NULL, 132 NULL,
133 file_system_info_, 133 file_system_info_,
134 base::FilePath::FromUTF8Unsafe(kEntryPath), 134 base::FilePath::FromUTF8Unsafe(kEntryPath),
135 true /* recursive */, 135 true /* recursive */,
136 base::Bind(&util::LogStatusCallback, &callback_log)); 136 base::Bind(&util::LogStatusCallback, &callback_log));
137 unobserve_entry.SetDispatchEventImplForTesting( 137 remove_watcher.SetDispatchEventImplForTesting(
138 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 138 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
139 base::Unretained(&dispatcher))); 139 base::Unretained(&dispatcher)));
140 140
141 EXPECT_TRUE(unobserve_entry.Execute(kRequestId)); 141 EXPECT_TRUE(remove_watcher.Execute(kRequestId));
142 142
143 unobserve_entry.OnError(kRequestId, 143 remove_watcher.OnError(kRequestId,
144 scoped_ptr<RequestValue>(new RequestValue()), 144 scoped_ptr<RequestValue>(new RequestValue()),
145 base::File::FILE_ERROR_TOO_MANY_OPENED); 145 base::File::FILE_ERROR_TOO_MANY_OPENED);
146 ASSERT_EQ(1u, callback_log.size()); 146 ASSERT_EQ(1u, callback_log.size());
147 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); 147 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
148 } 148 }
149 149
150 } // namespace operations 150 } // namespace operations
151 } // namespace file_system_provider 151 } // namespace file_system_provider
152 } // namespace chromeos 152 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698