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

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

Issue 294073007: [fsp] Let extensions decide about the file system id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 7 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 | Annotate | Revision Log
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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/files/file.h" 8 #include "base/files/file.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
12 #include "chrome/browser/chromeos/file_system_provider/operations/close_file.h" 12 #include "chrome/browser/chromeos/file_system_provider/operations/close_file.h"
13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h" 13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h"
14 #include "chrome/common/extensions/api/file_system_provider.h" 14 #include "chrome/common/extensions/api/file_system_provider.h"
15 #include "chrome/common/extensions/api/file_system_provider_internal.h" 15 #include "chrome/common/extensions/api/file_system_provider_internal.h"
16 #include "extensions/browser/event_router.h" 16 #include "extensions/browser/event_router.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "webkit/browser/fileapi/async_file_util.h" 18 #include "webkit/browser/fileapi/async_file_util.h"
19 19
20 namespace chromeos { 20 namespace chromeos {
21 namespace file_system_provider { 21 namespace file_system_provider {
22 namespace operations { 22 namespace operations {
23 namespace { 23 namespace {
24 24
25 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; 25 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
26 const int kFileSystemId = 1; 26 const char kFileSystemId[] = "testing-file-system";
27 const int kRequestId = 2; 27 const int kRequestId = 2;
28 const int kOpenRequestId = 3; 28 const int kOpenRequestId = 3;
29 29
30 // Fake event dispatcher implementation with extra logging capability. Acts as 30 // Fake event dispatcher implementation with extra logging capability. Acts as
31 // a providing extension end-point. 31 // a providing extension end-point.
32 class LoggingDispatchEventImpl { 32 class LoggingDispatchEventImpl {
33 public: 33 public:
34 explicit LoggingDispatchEventImpl(bool dispatch_reply) 34 explicit LoggingDispatchEventImpl(bool dispatch_reply)
35 : dispatch_reply_(dispatch_reply) {} 35 : dispatch_reply_(dispatch_reply) {}
36 virtual ~LoggingDispatchEventImpl() {} 36 virtual ~LoggingDispatchEventImpl() {}
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 EXPECT_TRUE(close_file.Execute(kRequestId)); 104 EXPECT_TRUE(close_file.Execute(kRequestId));
105 105
106 ASSERT_EQ(1u, dispatcher.events().size()); 106 ASSERT_EQ(1u, dispatcher.events().size());
107 extensions::Event* event = dispatcher.events()[0]; 107 extensions::Event* event = dispatcher.events()[0];
108 EXPECT_EQ( 108 EXPECT_EQ(
109 extensions::api::file_system_provider::OnCloseFileRequested::kEventName, 109 extensions::api::file_system_provider::OnCloseFileRequested::kEventName,
110 event->event_name); 110 event->event_name);
111 base::ListValue* event_args = event->event_args.get(); 111 base::ListValue* event_args = event->event_args.get();
112 ASSERT_EQ(3u, event_args->GetSize()); 112 ASSERT_EQ(3u, event_args->GetSize());
113 113
114 int event_file_system_id = -1; 114 std::string event_file_system_id;
115 EXPECT_TRUE(event_args->GetInteger(0, &event_file_system_id)); 115 EXPECT_TRUE(event_args->GetString(0, &event_file_system_id));
116 EXPECT_EQ(kFileSystemId, event_file_system_id); 116 EXPECT_EQ(kFileSystemId, event_file_system_id);
117 117
118 int event_request_id = -1; 118 int event_request_id = -1;
119 EXPECT_TRUE(event_args->GetInteger(1, &event_request_id)); 119 EXPECT_TRUE(event_args->GetInteger(1, &event_request_id));
120 EXPECT_EQ(kRequestId, event_request_id); 120 EXPECT_EQ(kRequestId, event_request_id);
121 121
122 int event_open_request_id = -1; 122 int event_open_request_id = -1;
123 EXPECT_TRUE(event_args->GetInteger(2, &event_open_request_id)); 123 EXPECT_TRUE(event_args->GetInteger(2, &event_open_request_id));
124 EXPECT_EQ(kOpenRequestId, event_open_request_id); 124 EXPECT_EQ(kOpenRequestId, event_open_request_id);
125 } 125 }
126 126
127 TEST_F(FileSystemProviderOperationsCloseFileTest, Execute_NoListener) { 127 TEST_F(FileSystemProviderOperationsCloseFileTest, Execute_NoListener) {
128 LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); 128 LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
129 CallbackLogger callback_logger; 129 CallbackLogger callback_logger;
130 130
131 CloseFile close_file( 131 CloseFile close_file(
132 NULL, 132 NULL,
133 file_system_info_, 133 file_system_info_,
134 kOpenRequestId, 134 kOpenRequestId,
135 base::Bind(&CallbackLogger::OnCloseFile, callback_logger.GetWeakPtr())); 135 base::Bind(&CallbackLogger::OnCloseFile, callback_logger.GetWeakPtr()));
136 close_file.SetDispatchEventImplForTesting( 136 close_file.SetDispatchEventImplForTesting(
137 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, 137 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl,
138 base::Unretained(&dispatcher))); 138 base::Unretained(&dispatcher)));
139 139
140 EXPECT_FALSE(close_file.Execute(kRequestId)); 140 EXPECT_FALSE(close_file.Execute(kRequestId));
141 } 141 }
142 142
143 TEST_F(FileSystemProviderOperationsCloseFileTest, OnSuccess) { 143 TEST_F(FileSystemProviderOperationsCloseFileTest, OnSuccess) {
144 using extensions::api::file_system_provider::EntryMetadata;
145 using extensions::api::file_system_provider_internal:: 144 using extensions::api::file_system_provider_internal::
146 CloseFileRequestedSuccess::Params; 145 CloseFileRequestedSuccess::Params;
147 146
148 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 147 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
149 CallbackLogger callback_logger; 148 CallbackLogger callback_logger;
150 149
151 CloseFile close_file( 150 CloseFile close_file(
152 NULL, 151 NULL,
153 file_system_info_, 152 file_system_info_,
154 kOpenRequestId, 153 kOpenRequestId,
155 base::Bind(&CallbackLogger::OnCloseFile, callback_logger.GetWeakPtr())); 154 base::Bind(&CallbackLogger::OnCloseFile, callback_logger.GetWeakPtr()));
156 close_file.SetDispatchEventImplForTesting( 155 close_file.SetDispatchEventImplForTesting(
157 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, 156 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl,
158 base::Unretained(&dispatcher))); 157 base::Unretained(&dispatcher)));
159 158
160 EXPECT_TRUE(close_file.Execute(kRequestId)); 159 EXPECT_TRUE(close_file.Execute(kRequestId));
161 160
162 close_file.OnSuccess(kRequestId, 161 close_file.OnSuccess(kRequestId,
163 scoped_ptr<RequestValue>(new RequestValue()), 162 scoped_ptr<RequestValue>(new RequestValue()),
164 false /* has_next */); 163 false /* has_next */);
165 ASSERT_EQ(1u, callback_logger.events().size()); 164 ASSERT_EQ(1u, callback_logger.events().size());
166 EXPECT_EQ(base::File::FILE_OK, callback_logger.events()[0]); 165 EXPECT_EQ(base::File::FILE_OK, callback_logger.events()[0]);
167 } 166 }
168 167
169 TEST_F(FileSystemProviderOperationsCloseFileTest, OnError) { 168 TEST_F(FileSystemProviderOperationsCloseFileTest, OnError) {
170 using extensions::api::file_system_provider::EntryMetadata;
171 using extensions::api::file_system_provider_internal:: 169 using extensions::api::file_system_provider_internal::
172 CloseFileRequestedError::Params; 170 CloseFileRequestedError::Params;
173 171
174 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 172 LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
175 CallbackLogger callback_logger; 173 CallbackLogger callback_logger;
176 174
177 CloseFile close_file( 175 CloseFile close_file(
178 NULL, 176 NULL,
179 file_system_info_, 177 file_system_info_,
180 kOpenRequestId, 178 kOpenRequestId,
181 base::Bind(&CallbackLogger::OnCloseFile, callback_logger.GetWeakPtr())); 179 base::Bind(&CallbackLogger::OnCloseFile, callback_logger.GetWeakPtr()));
182 close_file.SetDispatchEventImplForTesting( 180 close_file.SetDispatchEventImplForTesting(
183 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, 181 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl,
184 base::Unretained(&dispatcher))); 182 base::Unretained(&dispatcher)));
185 183
186 EXPECT_TRUE(close_file.Execute(kRequestId)); 184 EXPECT_TRUE(close_file.Execute(kRequestId));
187 185
188 close_file.OnError(kRequestId, base::File::FILE_ERROR_TOO_MANY_OPENED); 186 close_file.OnError(kRequestId, base::File::FILE_ERROR_TOO_MANY_OPENED);
189 ASSERT_EQ(1u, callback_logger.events().size()); 187 ASSERT_EQ(1u, callback_logger.events().size());
190 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, 188 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED,
191 callback_logger.events()[0]); 189 callback_logger.events()[0]);
192 } 190 }
193 191
194 } // namespace operations 192 } // namespace operations
195 } // namespace file_system_provider 193 } // namespace file_system_provider
196 } // namespace chromeos 194 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698