| 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 "chrome/browser/chromeos/file_system_provider/operations/truncate.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/truncate.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" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 kFileSystemId, | 43 kFileSystemId, |
| 44 "" /* file_system_name */, | 44 "" /* file_system_name */, |
| 45 true /* writable */, | 45 true /* writable */, |
| 46 base::FilePath() /* mount_path */); | 46 base::FilePath() /* mount_path */); |
| 47 } | 47 } |
| 48 | 48 |
| 49 ProvidedFileSystemInfo file_system_info_; | 49 ProvidedFileSystemInfo file_system_info_; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 TEST_F(FileSystemProviderOperationsTruncateTest, Execute) { | 52 TEST_F(FileSystemProviderOperationsTruncateTest, Execute) { |
| 53 using extensions::api::file_system_provider::TruncateRequestedOptions; |
| 54 |
| 53 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 55 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 54 util::StatusCallbackLog callback_log; | 56 util::StatusCallbackLog callback_log; |
| 55 | 57 |
| 56 Truncate truncate(NULL, | 58 Truncate truncate(NULL, |
| 57 file_system_info_, | 59 file_system_info_, |
| 58 base::FilePath::FromUTF8Unsafe(kFilePath), | 60 base::FilePath::FromUTF8Unsafe(kFilePath), |
| 59 kTruncateLength, | 61 kTruncateLength, |
| 60 base::Bind(&util::LogStatusCallback, &callback_log)); | 62 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 61 truncate.SetDispatchEventImplForTesting( | 63 truncate.SetDispatchEventImplForTesting( |
| 62 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 64 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 63 base::Unretained(&dispatcher))); | 65 base::Unretained(&dispatcher))); |
| 64 | 66 |
| 65 EXPECT_TRUE(truncate.Execute(kRequestId)); | 67 EXPECT_TRUE(truncate.Execute(kRequestId)); |
| 66 | 68 |
| 67 ASSERT_EQ(1u, dispatcher.events().size()); | 69 ASSERT_EQ(1u, dispatcher.events().size()); |
| 68 extensions::Event* event = dispatcher.events()[0]; | 70 extensions::Event* event = dispatcher.events()[0]; |
| 69 EXPECT_EQ( | 71 EXPECT_EQ( |
| 70 extensions::api::file_system_provider::OnTruncateRequested::kEventName, | 72 extensions::api::file_system_provider::OnTruncateRequested::kEventName, |
| 71 event->event_name); | 73 event->event_name); |
| 72 base::ListValue* event_args = event->event_args.get(); | 74 base::ListValue* event_args = event->event_args.get(); |
| 73 ASSERT_EQ(1u, event_args->GetSize()); | 75 ASSERT_EQ(1u, event_args->GetSize()); |
| 74 | 76 |
| 75 base::DictionaryValue* options = NULL; | 77 const base::DictionaryValue* options_as_value = NULL; |
| 76 ASSERT_TRUE(event_args->GetDictionary(0, &options)); | 78 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); |
| 77 | 79 |
| 78 std::string event_file_system_id; | 80 TruncateRequestedOptions options; |
| 79 EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id)); | 81 ASSERT_TRUE(TruncateRequestedOptions::Populate(*options_as_value, &options)); |
| 80 EXPECT_EQ(kFileSystemId, event_file_system_id); | 82 EXPECT_EQ(kFileSystemId, options.file_system_id); |
| 81 | 83 EXPECT_EQ(kRequestId, options.request_id); |
| 82 int event_request_id = -1; | 84 EXPECT_EQ(kFilePath, options.file_path); |
| 83 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); | 85 EXPECT_EQ(kTruncateLength, static_cast<double>(options.length)); |
| 84 EXPECT_EQ(kRequestId, event_request_id); | |
| 85 | |
| 86 std::string event_file_path; | |
| 87 EXPECT_TRUE(options->GetString("filePath", &event_file_path)); | |
| 88 EXPECT_EQ(kFilePath, event_file_path); | |
| 89 | |
| 90 double event_length = -1; | |
| 91 EXPECT_TRUE(options->GetDouble("length", &event_length)); | |
| 92 EXPECT_EQ(kTruncateLength, static_cast<double>(event_length)); | |
| 93 } | 86 } |
| 94 | 87 |
| 95 TEST_F(FileSystemProviderOperationsTruncateTest, Execute_NoListener) { | 88 TEST_F(FileSystemProviderOperationsTruncateTest, Execute_NoListener) { |
| 96 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); | 89 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); |
| 97 util::StatusCallbackLog callback_log; | 90 util::StatusCallbackLog callback_log; |
| 98 | 91 |
| 99 Truncate truncate(NULL, | 92 Truncate truncate(NULL, |
| 100 file_system_info_, | 93 file_system_info_, |
| 101 base::FilePath::FromUTF8Unsafe(kFilePath), | 94 base::FilePath::FromUTF8Unsafe(kFilePath), |
| 102 kTruncateLength, | 95 kTruncateLength, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 truncate.OnError(kRequestId, | 164 truncate.OnError(kRequestId, |
| 172 scoped_ptr<RequestValue>(new RequestValue()), | 165 scoped_ptr<RequestValue>(new RequestValue()), |
| 173 base::File::FILE_ERROR_TOO_MANY_OPENED); | 166 base::File::FILE_ERROR_TOO_MANY_OPENED); |
| 174 ASSERT_EQ(1u, callback_log.size()); | 167 ASSERT_EQ(1u, callback_log.size()); |
| 175 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); | 168 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); |
| 176 } | 169 } |
| 177 | 170 |
| 178 } // namespace operations | 171 } // namespace operations |
| 179 } // namespace file_system_provider | 172 } // namespace file_system_provider |
| 180 } // namespace chromeos | 173 } // namespace chromeos |
| OLD | NEW |