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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/operations/add_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/observe_direct ory.h" 5 #include "chrome/browser/chromeos/file_system_provider/operations/add_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 kDirectoryPath[] = "/kitty/and/puppy/happy"; 30 const base::FilePath::CharType kEntryPath[] = "/kitty/and/puppy/happy";
31 31
32 } // namespace 32 } // namespace
33 33
34 class FileSystemProviderOperationsObserveDirectoryTest : public testing::Test { 34 class FileSystemProviderOperationsAddWatcherTest : public testing::Test {
35 protected: 35 protected:
36 FileSystemProviderOperationsObserveDirectoryTest() {} 36 FileSystemProviderOperationsAddWatcherTest() {}
37 virtual ~FileSystemProviderOperationsObserveDirectoryTest() {} 37 virtual ~FileSystemProviderOperationsAddWatcherTest() {}
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(FileSystemProviderOperationsObserveDirectoryTest, Execute) { 49 TEST_F(FileSystemProviderOperationsAddWatcherTest, Execute) {
50 using extensions::api::file_system_provider::ObserveDirectoryRequestedOptions; 50 using extensions::api::file_system_provider::AddWatcherRequestedOptions;
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 ObserveDirectory observe_directory( 55 AddWatcher add_watcher(NULL,
56 NULL, 56 file_system_info_,
57 file_system_info_, 57 base::FilePath::FromUTF8Unsafe(kEntryPath),
58 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 58 true /* recursive */,
59 true /* recursive */, 59 base::Bind(&util::LogStatusCallback, &callback_log));
60 base::Bind(&util::LogStatusCallback, &callback_log)); 60 add_watcher.SetDispatchEventImplForTesting(
61 observe_directory.SetDispatchEventImplForTesting(
62 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 61 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
63 base::Unretained(&dispatcher))); 62 base::Unretained(&dispatcher)));
64 63
65 EXPECT_TRUE(observe_directory.Execute(kRequestId)); 64 EXPECT_TRUE(add_watcher.Execute(kRequestId));
66 65
67 ASSERT_EQ(1u, dispatcher.events().size()); 66 ASSERT_EQ(1u, dispatcher.events().size());
68 extensions::Event* event = dispatcher.events()[0]; 67 extensions::Event* event = dispatcher.events()[0];
69 EXPECT_EQ(extensions::api::file_system_provider::OnObserveDirectoryRequested:: 68 EXPECT_EQ(
70 kEventName, 69 extensions::api::file_system_provider::OnAddWatcherRequested::kEventName,
71 event->event_name); 70 event->event_name);
72 base::ListValue* event_args = event->event_args.get(); 71 base::ListValue* event_args = event->event_args.get();
73 ASSERT_EQ(1u, event_args->GetSize()); 72 ASSERT_EQ(1u, event_args->GetSize());
74 73
75 const base::DictionaryValue* options_as_value = NULL; 74 const base::DictionaryValue* options_as_value = NULL;
76 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); 75 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
77 76
78 ObserveDirectoryRequestedOptions options; 77 AddWatcherRequestedOptions options;
79 ASSERT_TRUE( 78 ASSERT_TRUE(
80 ObserveDirectoryRequestedOptions::Populate(*options_as_value, &options)); 79 AddWatcherRequestedOptions::Populate(*options_as_value, &options));
81 EXPECT_EQ(kFileSystemId, options.file_system_id); 80 EXPECT_EQ(kFileSystemId, options.file_system_id);
82 EXPECT_EQ(kRequestId, options.request_id); 81 EXPECT_EQ(kRequestId, options.request_id);
83 EXPECT_EQ(kDirectoryPath, options.directory_path); 82 EXPECT_EQ(kEntryPath, options.entry_path);
84 EXPECT_TRUE(options.recursive); 83 EXPECT_TRUE(options.recursive);
85 } 84 }
86 85
87 TEST_F(FileSystemProviderOperationsObserveDirectoryTest, Execute_NoListener) { 86 TEST_F(FileSystemProviderOperationsAddWatcherTest, Execute_NoListener) {
88 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); 87 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
89 util::StatusCallbackLog callback_log; 88 util::StatusCallbackLog callback_log;
90 89
91 ObserveDirectory observe_directory( 90 AddWatcher add_watcher(NULL,
92 NULL, 91 file_system_info_,
93 file_system_info_, 92 base::FilePath::FromUTF8Unsafe(kEntryPath),
94 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 93 true /* recursive */,
95 true /* recursive */, 94 base::Bind(&util::LogStatusCallback, &callback_log));
96 base::Bind(&util::LogStatusCallback, &callback_log)); 95 add_watcher.SetDispatchEventImplForTesting(
97 observe_directory.SetDispatchEventImplForTesting(
98 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 96 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
99 base::Unretained(&dispatcher))); 97 base::Unretained(&dispatcher)));
100 98
101 EXPECT_FALSE(observe_directory.Execute(kRequestId)); 99 EXPECT_FALSE(add_watcher.Execute(kRequestId));
102 } 100 }
103 101
104 TEST_F(FileSystemProviderOperationsObserveDirectoryTest, OnSuccess) { 102 TEST_F(FileSystemProviderOperationsAddWatcherTest, OnSuccess) {
105 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 103 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
106 util::StatusCallbackLog callback_log; 104 util::StatusCallbackLog callback_log;
107 105
108 ObserveDirectory observe_directory( 106 AddWatcher add_watcher(NULL,
109 NULL, 107 file_system_info_,
110 file_system_info_, 108 base::FilePath::FromUTF8Unsafe(kEntryPath),
111 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 109 true /* recursive */,
112 true /* recursive */, 110 base::Bind(&util::LogStatusCallback, &callback_log));
113 base::Bind(&util::LogStatusCallback, &callback_log)); 111 add_watcher.SetDispatchEventImplForTesting(
114 observe_directory.SetDispatchEventImplForTesting(
115 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 112 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
116 base::Unretained(&dispatcher))); 113 base::Unretained(&dispatcher)));
117 114
118 EXPECT_TRUE(observe_directory.Execute(kRequestId)); 115 EXPECT_TRUE(add_watcher.Execute(kRequestId));
119 116
120 observe_directory.OnSuccess(kRequestId, 117 add_watcher.OnSuccess(kRequestId,
121 scoped_ptr<RequestValue>(new RequestValue()), 118 scoped_ptr<RequestValue>(new RequestValue()),
122 false /* has_more */); 119 false /* has_more */);
123 ASSERT_EQ(1u, callback_log.size()); 120 ASSERT_EQ(1u, callback_log.size());
124 EXPECT_EQ(base::File::FILE_OK, callback_log[0]); 121 EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
125 } 122 }
126 123
127 TEST_F(FileSystemProviderOperationsObserveDirectoryTest, OnError) { 124 TEST_F(FileSystemProviderOperationsAddWatcherTest, OnError) {
128 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 125 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
129 util::StatusCallbackLog callback_log; 126 util::StatusCallbackLog callback_log;
130 127
131 ObserveDirectory observe_directory( 128 AddWatcher add_watcher(NULL,
132 NULL, 129 file_system_info_,
133 file_system_info_, 130 base::FilePath::FromUTF8Unsafe(kEntryPath),
134 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 131 true /* recursive */,
135 true /* recursive */, 132 base::Bind(&util::LogStatusCallback, &callback_log));
136 base::Bind(&util::LogStatusCallback, &callback_log)); 133 add_watcher.SetDispatchEventImplForTesting(
137 observe_directory.SetDispatchEventImplForTesting(
138 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 134 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
139 base::Unretained(&dispatcher))); 135 base::Unretained(&dispatcher)));
140 136
141 EXPECT_TRUE(observe_directory.Execute(kRequestId)); 137 EXPECT_TRUE(add_watcher.Execute(kRequestId));
142 138
143 observe_directory.OnError(kRequestId, 139 add_watcher.OnError(kRequestId,
144 scoped_ptr<RequestValue>(new RequestValue()), 140 scoped_ptr<RequestValue>(new RequestValue()),
145 base::File::FILE_ERROR_TOO_MANY_OPENED); 141 base::File::FILE_ERROR_TOO_MANY_OPENED);
146 ASSERT_EQ(1u, callback_log.size()); 142 ASSERT_EQ(1u, callback_log.size());
147 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); 143 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
148 } 144 }
149 145
150 } // namespace operations 146 } // namespace operations
151 } // namespace file_system_provider 147 } // namespace file_system_provider
152 } // namespace chromeos 148 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698