| 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/get_metadata.h
" | 13 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 EXPECT_TRUE(get_metadata.Execute(kRequestId)); | 124 EXPECT_TRUE(get_metadata.Execute(kRequestId)); |
| 124 | 125 |
| 125 ASSERT_EQ(1u, dispatcher.events().size()); | 126 ASSERT_EQ(1u, dispatcher.events().size()); |
| 126 extensions::Event* event = dispatcher.events()[0]; | 127 extensions::Event* event = dispatcher.events()[0]; |
| 127 EXPECT_EQ( | 128 EXPECT_EQ( |
| 128 extensions::api::file_system_provider::OnGetMetadataRequested::kEventName, | 129 extensions::api::file_system_provider::OnGetMetadataRequested::kEventName, |
| 129 event->event_name); | 130 event->event_name); |
| 130 base::ListValue* event_args = event->event_args.get(); | 131 base::ListValue* event_args = event->event_args.get(); |
| 131 ASSERT_EQ(3u, event_args->GetSize()); | 132 ASSERT_EQ(3u, event_args->GetSize()); |
| 132 | 133 |
| 133 int event_file_system_id = -1; | 134 std::string event_file_system_id; |
| 134 EXPECT_TRUE(event_args->GetInteger(0, &event_file_system_id)); | 135 EXPECT_TRUE(event_args->GetString(0, &event_file_system_id)); |
| 135 EXPECT_EQ(kFileSystemId, event_file_system_id); | 136 EXPECT_EQ(kFileSystemId, event_file_system_id); |
| 136 | 137 |
| 137 int event_request_id = -1; | 138 int event_request_id = -1; |
| 138 EXPECT_TRUE(event_args->GetInteger(1, &event_request_id)); | 139 EXPECT_TRUE(event_args->GetInteger(1, &event_request_id)); |
| 139 EXPECT_EQ(kRequestId, event_request_id); | 140 EXPECT_EQ(kRequestId, event_request_id); |
| 140 | 141 |
| 141 std::string event_directory_path; | 142 std::string event_directory_path; |
| 142 EXPECT_TRUE(event_args->GetString(2, &event_directory_path)); | 143 EXPECT_TRUE(event_args->GetString(2, &event_directory_path)); |
| 143 EXPECT_EQ(kDirectoryPath, event_directory_path); | 144 EXPECT_EQ(kDirectoryPath, event_directory_path); |
| 144 } | 145 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, | 177 base::Bind(&LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 177 base::Unretained(&dispatcher))); | 178 base::Unretained(&dispatcher))); |
| 178 | 179 |
| 179 EXPECT_TRUE(get_metadata.Execute(kRequestId)); | 180 EXPECT_TRUE(get_metadata.Execute(kRequestId)); |
| 180 | 181 |
| 181 // Sample input as JSON. Keep in sync with file_system_provider_api.idl. | 182 // Sample input as JSON. Keep in sync with file_system_provider_api.idl. |
| 182 // As for now, it is impossible to create *::Params class directly, not from | 183 // As for now, it is impossible to create *::Params class directly, not from |
| 183 // base::Value. | 184 // base::Value. |
| 184 const std::string input = | 185 const std::string input = |
| 185 "[\n" | 186 "[\n" |
| 186 " 1,\n" // kFileSystemId | 187 " \"testing-file-system\",\n" // kFileSystemId |
| 187 " 2,\n" // kRequestId | 188 " 2,\n" // kRequestId |
| 188 " {\n" | 189 " {\n" |
| 189 " \"isDirectory\": false,\n" | 190 " \"isDirectory\": false,\n" |
| 190 " \"name\": \"blueberries.txt\",\n" | 191 " \"name\": \"blueberries.txt\",\n" |
| 191 " \"size\": 4096,\n" | 192 " \"size\": 4096,\n" |
| 192 " \"modificationTime\": {\n" | 193 " \"modificationTime\": {\n" |
| 193 " \"value\": \"Thu Apr 24 00:46:52 UTC 2014\"\n" | 194 " \"value\": \"Thu Apr 24 00:46:52 UTC 2014\"\n" |
| 194 " }\n" | 195 " }\n" |
| 195 " }\n" | 196 " }\n" |
| 196 "]\n"; | 197 "]\n"; |
| 197 | 198 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 get_metadata.OnError(kRequestId, base::File::FILE_ERROR_TOO_MANY_OPENED); | 248 get_metadata.OnError(kRequestId, base::File::FILE_ERROR_TOO_MANY_OPENED); |
| 248 | 249 |
| 249 ASSERT_EQ(1u, callback_logger.events().size()); | 250 ASSERT_EQ(1u, callback_logger.events().size()); |
| 250 CallbackLogger::Event* event = callback_logger.events()[0]; | 251 CallbackLogger::Event* event = callback_logger.events()[0]; |
| 251 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); | 252 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); |
| 252 } | 253 } |
| 253 | 254 |
| 254 } // namespace operations | 255 } // namespace operations |
| 255 } // namespace file_system_provider | 256 } // namespace file_system_provider |
| 256 } // namespace chromeos | 257 } // namespace chromeos |
| OLD | NEW |