| 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/json/json_reader.h" | 9 #include "base/json/json_reader.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 "chrome/browser/chromeos/file_system_provider/operations/read_directory
.h" | 13 #include "chrome/browser/chromeos/file_system_provider/operations/read_directory
.h" |
| 13 #include "chrome/common/extensions/api/file_system_provider.h" | 14 #include "chrome/common/extensions/api/file_system_provider.h" |
| 14 #include "chrome/common/extensions/api/file_system_provider_internal.h" | 15 #include "chrome/common/extensions/api/file_system_provider_internal.h" |
| 15 #include "extensions/browser/event_router.h" | 16 #include "extensions/browser/event_router.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "webkit/browser/fileapi/async_file_util.h" | 18 #include "webkit/browser/fileapi/async_file_util.h" |
| 18 | 19 |
| 19 namespace chromeos { | 20 namespace chromeos { |
| 20 namespace file_system_provider { | 21 namespace file_system_provider { |
| 21 namespace operations { | 22 namespace operations { |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; | 25 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; |
| 25 const int kFileSystemId = 1; | 26 const char kFileSystemId[] = "testing-file-system"; |
| 26 const int kRequestId = 2; | 27 const int kRequestId = 2; |
| 27 const base::FilePath::CharType kDirectoryPath[] = "/directory"; | 28 const base::FilePath::CharType kDirectoryPath[] = "/directory"; |
| 28 | 29 |
| 29 // Fake event dispatcher implementation with extra logging capability. Acts as | 30 // Fake event dispatcher implementation with extra logging capability. Acts as |
| 30 // a providing extension end-point. | 31 // a providing extension end-point. |
| 31 class LoggingDispatchEventImpl { | 32 class LoggingDispatchEventImpl { |
| 32 public: | 33 public: |
| 33 explicit LoggingDispatchEventImpl(bool dispatch_reply) | 34 explicit LoggingDispatchEventImpl(bool dispatch_reply) |
| 34 : dispatch_reply_(dispatch_reply) {} | 35 : dispatch_reply_(dispatch_reply) {} |
| 35 virtual ~LoggingDispatchEventImpl() {} | 36 virtual ~LoggingDispatchEventImpl() {} |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 EXPECT_TRUE(read_directory.Execute(kRequestId)); | 131 EXPECT_TRUE(read_directory.Execute(kRequestId)); |
| 131 | 132 |
| 132 ASSERT_EQ(1u, dispatcher.events().size()); | 133 ASSERT_EQ(1u, dispatcher.events().size()); |
| 133 extensions::Event* event = dispatcher.events()[0]; | 134 extensions::Event* event = dispatcher.events()[0]; |
| 134 EXPECT_EQ(extensions::api::file_system_provider::OnReadDirectoryRequested:: | 135 EXPECT_EQ(extensions::api::file_system_provider::OnReadDirectoryRequested:: |
| 135 kEventName, | 136 kEventName, |
| 136 event->event_name); | 137 event->event_name); |
| 137 base::ListValue* event_args = event->event_args.get(); | 138 base::ListValue* event_args = event->event_args.get(); |
| 138 ASSERT_EQ(3u, event_args->GetSize()); | 139 ASSERT_EQ(3u, event_args->GetSize()); |
| 139 | 140 |
| 140 int event_file_system_id = -1; | 141 std::string event_file_system_id; |
| 141 EXPECT_TRUE(event_args->GetInteger(0, &event_file_system_id)); | 142 EXPECT_TRUE(event_args->GetString(0, &event_file_system_id)); |
| 142 EXPECT_EQ(kFileSystemId, event_file_system_id); | 143 EXPECT_EQ(kFileSystemId, event_file_system_id); |
| 143 | 144 |
| 144 int event_request_id = -1; | 145 int event_request_id = -1; |
| 145 EXPECT_TRUE(event_args->GetInteger(1, &event_request_id)); | 146 EXPECT_TRUE(event_args->GetInteger(1, &event_request_id)); |
| 146 EXPECT_EQ(kRequestId, event_request_id); | 147 EXPECT_EQ(kRequestId, event_request_id); |
| 147 | 148 |
| 148 std::string event_directory_path; | 149 std::string event_directory_path; |
| 149 EXPECT_TRUE(event_args->GetString(2, &event_directory_path)); | 150 EXPECT_TRUE(event_args->GetString(2, &event_directory_path)); |
| 150 EXPECT_EQ(kDirectoryPath, event_directory_path); | 151 EXPECT_EQ(kDirectoryPath, event_directory_path); |
| 151 } | 152 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, | 184 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 184 base::Unretained(&dispatcher))); | 185 base::Unretained(&dispatcher))); |
| 185 | 186 |
| 186 EXPECT_TRUE(read_directory.Execute(kRequestId)); | 187 EXPECT_TRUE(read_directory.Execute(kRequestId)); |
| 187 | 188 |
| 188 // Sample input as JSON. Keep in sync with file_system_provider_api.idl. | 189 // Sample input as JSON. Keep in sync with file_system_provider_api.idl. |
| 189 // As for now, it is impossible to create *::Params class directly, not from | 190 // As for now, it is impossible to create *::Params class directly, not from |
| 190 // base::Value. | 191 // base::Value. |
| 191 const std::string input = | 192 const std::string input = |
| 192 "[\n" | 193 "[\n" |
| 193 " 1,\n" // kFileSystemId | 194 " \"testing-file-system\",\n" // kFileSystemId |
| 194 " 2,\n" // kRequestId | 195 " 2,\n" // kRequestId |
| 195 " [\n" | 196 " [\n" |
| 196 " {\n" | 197 " {\n" |
| 197 " \"isDirectory\": false,\n" | 198 " \"isDirectory\": false,\n" |
| 198 " \"name\": \"blueberries.txt\",\n" | 199 " \"name\": \"blueberries.txt\",\n" |
| 199 " \"size\": 4096,\n" | 200 " \"size\": 4096,\n" |
| 200 " \"modificationTime\": {\n" | 201 " \"modificationTime\": {\n" |
| 201 " \"value\": \"Thu Apr 24 00:46:52 UTC 2014\"\n" | 202 " \"value\": \"Thu Apr 24 00:46:52 UTC 2014\"\n" |
| 202 " }\n" | 203 " }\n" |
| 203 " }\n" | 204 " }\n" |
| 204 " ],\n" | 205 " ],\n" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 261 |
| 261 ASSERT_EQ(1u, callback_logger.events().size()); | 262 ASSERT_EQ(1u, callback_logger.events().size()); |
| 262 CallbackLogger::Event* event = callback_logger.events()[0]; | 263 CallbackLogger::Event* event = callback_logger.events()[0]; |
| 263 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); | 264 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); |
| 264 ASSERT_EQ(0u, event->entry_list().size()); | 265 ASSERT_EQ(0u, event->entry_list().size()); |
| 265 } | 266 } |
| 266 | 267 |
| 267 } // namespace operations | 268 } // namespace operations |
| 268 } // namespace file_system_provider | 269 } // namespace file_system_provider |
| 269 } // namespace chromeos | 270 } // namespace chromeos |
| OLD | NEW |