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

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

Issue 625463002: [fsp] Add support for observing entries and notifying about changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months 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/create_directo ry.h" 5 #include "chrome/browser/chromeos/file_system_provider/operations/unobserve_entr y.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 FileSystemProviderOperationsCreateDirectoryTest : public testing::Test { 34 class FileSystemProviderOperationsUnobserveEntryTest : public testing::Test {
35 protected: 35 protected:
36 FileSystemProviderOperationsCreateDirectoryTest() {} 36 FileSystemProviderOperationsUnobserveEntryTest() {}
37 virtual ~FileSystemProviderOperationsCreateDirectoryTest() {} 37 virtual ~FileSystemProviderOperationsUnobserveEntryTest() {}
38 38
39 virtual void SetUp() OVERRIDE { 39 virtual void SetUp() OVERRIDE {
40 file_system_info_ = 40 file_system_info_ =
41 ProvidedFileSystemInfo(kExtensionId, 41 ProvidedFileSystemInfo(kExtensionId,
42 kFileSystemId, 42 kFileSystemId,
43 "" /* file_system_name */, 43 "" /* file_system_name */,
44 true /* writable */, 44 false /* writable */,
45 base::FilePath() /* mount_path */); 45 base::FilePath() /* mount_path */);
46 } 46 }
47 47
48 ProvidedFileSystemInfo file_system_info_; 48 ProvidedFileSystemInfo file_system_info_;
49 }; 49 };
50 50
51 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute) { 51 TEST_F(FileSystemProviderOperationsUnobserveEntryTest, Execute) {
52 using extensions::api::file_system_provider::CreateDirectoryRequestedOptions; 52 using extensions::api::file_system_provider::UnobserveEntryRequestedOptions;
53 53
54 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 54 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
55 util::StatusCallbackLog callback_log; 55 util::StatusCallbackLog callback_log;
56 56
57 CreateDirectory create_directory( 57 UnobserveEntry unobserve_entry(
58 NULL, 58 NULL,
59 file_system_info_, 59 file_system_info_,
60 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 60 base::FilePath::FromUTF8Unsafe(kEntryPath),
61 true /* recursive */, 61 true /* recursive */,
62 base::Bind(&util::LogStatusCallback, &callback_log)); 62 base::Bind(&util::LogStatusCallback, &callback_log));
63 create_directory.SetDispatchEventImplForTesting( 63 unobserve_entry.SetDispatchEventImplForTesting(
64 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 64 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
65 base::Unretained(&dispatcher))); 65 base::Unretained(&dispatcher)));
66 66
67 EXPECT_TRUE(create_directory.Execute(kRequestId)); 67 EXPECT_TRUE(unobserve_entry.Execute(kRequestId));
68 68
69 ASSERT_EQ(1u, dispatcher.events().size()); 69 ASSERT_EQ(1u, dispatcher.events().size());
70 extensions::Event* event = dispatcher.events()[0]; 70 extensions::Event* event = dispatcher.events()[0];
71 EXPECT_EQ(extensions::api::file_system_provider::OnCreateDirectoryRequested:: 71 EXPECT_EQ(extensions::api::file_system_provider::OnUnobserveEntryRequested::
72 kEventName, 72 kEventName,
73 event->event_name); 73 event->event_name);
74 base::ListValue* event_args = event->event_args.get(); 74 base::ListValue* event_args = event->event_args.get();
75 ASSERT_EQ(1u, event_args->GetSize()); 75 ASSERT_EQ(1u, event_args->GetSize());
76 76
77 const base::DictionaryValue* options_as_value = NULL; 77 const base::DictionaryValue* options_as_value = NULL;
78 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); 78 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
79 79
80 CreateDirectoryRequestedOptions options; 80 UnobserveEntryRequestedOptions options;
81 ASSERT_TRUE( 81 ASSERT_TRUE(
82 CreateDirectoryRequestedOptions::Populate(*options_as_value, &options)); 82 UnobserveEntryRequestedOptions::Populate(*options_as_value, &options));
83 EXPECT_EQ(kFileSystemId, options.file_system_id); 83 EXPECT_EQ(kFileSystemId, options.file_system_id);
84 EXPECT_EQ(kRequestId, options.request_id); 84 EXPECT_EQ(kRequestId, options.request_id);
85 EXPECT_EQ(kDirectoryPath, options.directory_path); 85 EXPECT_EQ(kEntryPath, options.entry_path);
86 EXPECT_TRUE(options.recursive); 86 EXPECT_TRUE(options.recursive);
87 } 87 }
88 88
89 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute_NoListener) { 89 TEST_F(FileSystemProviderOperationsUnobserveEntryTest, Execute_NoListener) {
90 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); 90 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
91 util::StatusCallbackLog callback_log; 91 util::StatusCallbackLog callback_log;
92 92
93 CreateDirectory create_directory( 93 UnobserveEntry unobserve_entry(
94 NULL, 94 NULL,
95 file_system_info_, 95 file_system_info_,
96 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 96 base::FilePath::FromUTF8Unsafe(kEntryPath),
97 true /* recursive */, 97 true /* recursive */,
98 base::Bind(&util::LogStatusCallback, &callback_log)); 98 base::Bind(&util::LogStatusCallback, &callback_log));
99 create_directory.SetDispatchEventImplForTesting( 99 unobserve_entry.SetDispatchEventImplForTesting(
100 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 100 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
101 base::Unretained(&dispatcher))); 101 base::Unretained(&dispatcher)));
102 102
103 EXPECT_FALSE(create_directory.Execute(kRequestId)); 103 EXPECT_FALSE(unobserve_entry.Execute(kRequestId));
104 } 104 }
105 105
106 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute_ReadOnly) { 106 TEST_F(FileSystemProviderOperationsUnobserveEntryTest, Execute_ReadOnly) {
107 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 107 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
108 util::StatusCallbackLog callback_log; 108 util::StatusCallbackLog callback_log;
109 109
110 const ProvidedFileSystemInfo read_only_file_system_info( 110 const ProvidedFileSystemInfo read_only_file_system_info(
111 kExtensionId, 111 kExtensionId,
112 kFileSystemId, 112 kFileSystemId,
113 "" /* file_system_name */, 113 "" /* file_system_name */,
114 false /* writable */, 114 false /* writable */,
115 base::FilePath() /* mount_path */); 115 base::FilePath() /* mount_path */);
116 116
117 CreateDirectory create_directory( 117 UnobserveEntry unobserve_entry(
118 NULL, 118 NULL,
119 read_only_file_system_info, 119 read_only_file_system_info,
120 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 120 base::FilePath::FromUTF8Unsafe(kEntryPath),
121 true /* recursive */, 121 true /* recursive */,
122 base::Bind(&util::LogStatusCallback, &callback_log)); 122 base::Bind(&util::LogStatusCallback, &callback_log));
123 create_directory.SetDispatchEventImplForTesting( 123 unobserve_entry.SetDispatchEventImplForTesting(
124 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 124 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
125 base::Unretained(&dispatcher))); 125 base::Unretained(&dispatcher)));
126 126
127 EXPECT_FALSE(create_directory.Execute(kRequestId)); 127 EXPECT_FALSE(unobserve_entry.Execute(kRequestId));
128 } 128 }
129 129
130 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, OnSuccess) { 130 TEST_F(FileSystemProviderOperationsUnobserveEntryTest, OnSuccess) {
131 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 131 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
132 util::StatusCallbackLog callback_log; 132 util::StatusCallbackLog callback_log;
133 133
134 CreateDirectory create_directory( 134 UnobserveEntry unobserve_entry(
135 NULL, 135 NULL,
136 file_system_info_, 136 file_system_info_,
137 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 137 base::FilePath::FromUTF8Unsafe(kEntryPath),
138 true /* recursive */, 138 true /* recursive */,
139 base::Bind(&util::LogStatusCallback, &callback_log)); 139 base::Bind(&util::LogStatusCallback, &callback_log));
140 create_directory.SetDispatchEventImplForTesting( 140 unobserve_entry.SetDispatchEventImplForTesting(
141 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 141 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
142 base::Unretained(&dispatcher))); 142 base::Unretained(&dispatcher)));
143 143
144 EXPECT_TRUE(create_directory.Execute(kRequestId)); 144 EXPECT_TRUE(unobserve_entry.Execute(kRequestId));
145 145
146 create_directory.OnSuccess(kRequestId, 146 unobserve_entry.OnSuccess(kRequestId,
147 scoped_ptr<RequestValue>(new RequestValue()), 147 scoped_ptr<RequestValue>(new RequestValue()),
148 false /* has_more */); 148 false /* has_more */);
149 ASSERT_EQ(1u, callback_log.size()); 149 ASSERT_EQ(1u, callback_log.size());
150 EXPECT_EQ(base::File::FILE_OK, callback_log[0]); 150 EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
151 } 151 }
152 152
153 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, OnError) { 153 TEST_F(FileSystemProviderOperationsUnobserveEntryTest, OnError) {
154 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 154 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
155 util::StatusCallbackLog callback_log; 155 util::StatusCallbackLog callback_log;
156 156
157 CreateDirectory create_directory( 157 UnobserveEntry unobserve_entry(
158 NULL, 158 NULL,
159 file_system_info_, 159 file_system_info_,
160 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 160 base::FilePath::FromUTF8Unsafe(kEntryPath),
161 true /* recursive */, 161 true /* recursive */,
162 base::Bind(&util::LogStatusCallback, &callback_log)); 162 base::Bind(&util::LogStatusCallback, &callback_log));
163 create_directory.SetDispatchEventImplForTesting( 163 unobserve_entry.SetDispatchEventImplForTesting(
164 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 164 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
165 base::Unretained(&dispatcher))); 165 base::Unretained(&dispatcher)));
166 166
167 EXPECT_TRUE(create_directory.Execute(kRequestId)); 167 EXPECT_TRUE(unobserve_entry.Execute(kRequestId));
168 168
169 create_directory.OnError(kRequestId, 169 unobserve_entry.OnError(kRequestId,
170 scoped_ptr<RequestValue>(new RequestValue()), 170 scoped_ptr<RequestValue>(new RequestValue()),
171 base::File::FILE_ERROR_TOO_MANY_OPENED); 171 base::File::FILE_ERROR_TOO_MANY_OPENED);
172 ASSERT_EQ(1u, callback_log.size()); 172 ASSERT_EQ(1u, callback_log.size());
173 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); 173 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
174 } 174 }
175 175
176 } // namespace operations 176 } // namespace operations
177 } // namespace file_system_provider 177 } // namespace file_system_provider
178 } // namespace chromeos 178 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698