OLD | NEW |
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 | 6 |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.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 "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/chromeos/file_system_provider/operations/read_file.h" | 13 #include "chrome/browser/chromeos/file_system_provider/operations/read_file.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 "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "webkit/browser/fileapi/async_file_util.h" | 19 #include "webkit/browser/fileapi/async_file_util.h" |
20 | 20 |
21 namespace chromeos { | 21 namespace chromeos { |
22 namespace file_system_provider { | 22 namespace file_system_provider { |
23 namespace operations { | 23 namespace operations { |
24 namespace { | 24 namespace { |
25 | 25 |
26 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; | 26 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; |
27 const int kFileSystemId = 1; | 27 const char kFileSystemId[] = "testing-file-system"; |
28 const int kRequestId = 2; | 28 const int kRequestId = 2; |
29 const int kFileHandle = 3; | 29 const int kFileHandle = 3; |
30 const int kOffset = 10; | 30 const int kOffset = 10; |
31 const int kLength = 5; | 31 const int kLength = 5; |
32 | 32 |
33 // Fake event dispatcher implementation with extra logging capability. Acts as | 33 // Fake event dispatcher implementation with extra logging capability. Acts as |
34 // a providing extension end-point. | 34 // a providing extension end-point. |
35 class LoggingDispatchEventImpl { | 35 class LoggingDispatchEventImpl { |
36 public: | 36 public: |
37 explicit LoggingDispatchEventImpl(bool dispatch_reply) | 37 explicit LoggingDispatchEventImpl(bool dispatch_reply) |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 EXPECT_TRUE(read_file.Execute(kRequestId)); | 133 EXPECT_TRUE(read_file.Execute(kRequestId)); |
134 | 134 |
135 ASSERT_EQ(1u, dispatcher.events().size()); | 135 ASSERT_EQ(1u, dispatcher.events().size()); |
136 extensions::Event* event = dispatcher.events()[0]; | 136 extensions::Event* event = dispatcher.events()[0]; |
137 EXPECT_EQ( | 137 EXPECT_EQ( |
138 extensions::api::file_system_provider::OnReadFileRequested::kEventName, | 138 extensions::api::file_system_provider::OnReadFileRequested::kEventName, |
139 event->event_name); | 139 event->event_name); |
140 base::ListValue* event_args = event->event_args.get(); | 140 base::ListValue* event_args = event->event_args.get(); |
141 ASSERT_EQ(5u, event_args->GetSize()); | 141 ASSERT_EQ(5u, event_args->GetSize()); |
142 | 142 |
143 int event_file_system_id = -1; | 143 std::string event_file_system_id; |
144 EXPECT_TRUE(event_args->GetInteger(0, &event_file_system_id)); | 144 EXPECT_TRUE(event_args->GetString(0, &event_file_system_id)); |
145 EXPECT_EQ(kFileSystemId, event_file_system_id); | 145 EXPECT_EQ(kFileSystemId, event_file_system_id); |
146 | 146 |
147 int event_request_id = -1; | 147 int event_request_id = -1; |
148 EXPECT_TRUE(event_args->GetInteger(1, &event_request_id)); | 148 EXPECT_TRUE(event_args->GetInteger(1, &event_request_id)); |
149 EXPECT_EQ(kRequestId, event_request_id); | 149 EXPECT_EQ(kRequestId, event_request_id); |
150 | 150 |
151 int event_file_handle = -1; | 151 int event_file_handle = -1; |
152 EXPECT_TRUE(event_args->GetInteger(2, &event_file_handle)); | 152 EXPECT_TRUE(event_args->GetInteger(2, &event_file_handle)); |
153 EXPECT_EQ(kFileHandle, event_file_handle); | 153 EXPECT_EQ(kFileHandle, event_file_handle); |
154 | 154 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 read_file.SetDispatchEventImplForTesting( | 198 read_file.SetDispatchEventImplForTesting( |
199 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, | 199 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, |
200 base::Unretained(&dispatcher))); | 200 base::Unretained(&dispatcher))); |
201 | 201 |
202 EXPECT_TRUE(read_file.Execute(kRequestId)); | 202 EXPECT_TRUE(read_file.Execute(kRequestId)); |
203 | 203 |
204 const std::string data = "ABCDE"; | 204 const std::string data = "ABCDE"; |
205 const bool has_next = false; | 205 const bool has_next = false; |
206 | 206 |
207 base::ListValue value_as_list; | 207 base::ListValue value_as_list; |
208 value_as_list.Set(0, new base::FundamentalValue(kFileSystemId)); | 208 value_as_list.Set(0, new base::StringValue(kFileSystemId)); |
209 value_as_list.Set(1, new base::FundamentalValue(kRequestId)); | 209 value_as_list.Set(1, new base::FundamentalValue(kRequestId)); |
210 value_as_list.Set( | 210 value_as_list.Set( |
211 2, base::BinaryValue::CreateWithCopiedBuffer(data.c_str(), data.size())); | 211 2, base::BinaryValue::CreateWithCopiedBuffer(data.c_str(), data.size())); |
212 value_as_list.Set(3, new base::FundamentalValue(has_next)); | 212 value_as_list.Set(3, new base::FundamentalValue(has_next)); |
213 | 213 |
214 scoped_ptr<Params> params(Params::Create(value_as_list)); | 214 scoped_ptr<Params> params(Params::Create(value_as_list)); |
215 ASSERT_TRUE(params.get()); | 215 ASSERT_TRUE(params.get()); |
216 scoped_ptr<RequestValue> request_value( | 216 scoped_ptr<RequestValue> request_value( |
217 RequestValue::CreateForReadFileSuccess(params.Pass())); | 217 RequestValue::CreateForReadFileSuccess(params.Pass())); |
218 ASSERT_TRUE(request_value.get()); | 218 ASSERT_TRUE(request_value.get()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 read_file.OnError(kRequestId, base::File::FILE_ERROR_TOO_MANY_OPENED); | 251 read_file.OnError(kRequestId, base::File::FILE_ERROR_TOO_MANY_OPENED); |
252 | 252 |
253 ASSERT_EQ(1u, callback_logger.events().size()); | 253 ASSERT_EQ(1u, callback_logger.events().size()); |
254 CallbackLogger::Event* event = callback_logger.events()[0]; | 254 CallbackLogger::Event* event = callback_logger.events()[0]; |
255 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); | 255 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); |
256 } | 256 } |
257 | 257 |
258 } // namespace operations | 258 } // namespace operations |
259 } // namespace file_system_provider | 259 } // namespace file_system_provider |
260 } // namespace chromeos | 260 } // namespace chromeos |
OLD | NEW |