Index: chrome/browser/chromeos/file_system_provider/operations/truncate_unittest.cc |
diff --git a/chrome/browser/chromeos/file_system_provider/operations/create_file_unittest.cc b/chrome/browser/chromeos/file_system_provider/operations/truncate_unittest.cc |
similarity index 60% |
copy from chrome/browser/chromeos/file_system_provider/operations/create_file_unittest.cc |
copy to chrome/browser/chromeos/file_system_provider/operations/truncate_unittest.cc |
index 1dbce12445c432556e2944630a9adf849a067cf9..66e2adcbede4aaa307cd7550bdedaaf83f223650 100644 |
--- a/chrome/browser/chromeos/file_system_provider/operations/create_file_unittest.cc |
+++ b/chrome/browser/chromeos/file_system_provider/operations/truncate_unittest.cc |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/chromeos/file_system_provider/operations/create_file.h" |
+#include "chrome/browser/chromeos/file_system_provider/operations/truncate.h" |
#include <string> |
#include <vector> |
@@ -28,13 +28,14 @@ const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; |
const char kFileSystemId[] = "testing-file-system"; |
const int kRequestId = 2; |
const base::FilePath::CharType kFilePath[] = "/kitty/and/puppy/happy"; |
+const int64 kTruncateLength = 64; |
} // namespace |
-class FileSystemProviderOperationsCreateFileTest : public testing::Test { |
+class FileSystemProviderOperationsTruncateTest : public testing::Test { |
protected: |
- FileSystemProviderOperationsCreateFileTest() {} |
- virtual ~FileSystemProviderOperationsCreateFileTest() {} |
+ FileSystemProviderOperationsTruncateTest() {} |
+ virtual ~FileSystemProviderOperationsTruncateTest() {} |
virtual void SetUp() OVERRIDE { |
file_system_info_ = |
@@ -48,24 +49,25 @@ class FileSystemProviderOperationsCreateFileTest : public testing::Test { |
ProvidedFileSystemInfo file_system_info_; |
}; |
-TEST_F(FileSystemProviderOperationsCreateFileTest, Execute) { |
+TEST_F(FileSystemProviderOperationsTruncateTest, Execute) { |
util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
util::StatusCallbackLog callback_log; |
- CreateFile create_file(NULL, |
- file_system_info_, |
- base::FilePath::FromUTF8Unsafe(kFilePath), |
- base::Bind(&util::LogStatusCallback, &callback_log)); |
- create_file.SetDispatchEventImplForTesting( |
+ Truncate truncate(NULL, |
+ file_system_info_, |
+ base::FilePath::FromUTF8Unsafe(kFilePath), |
+ kTruncateLength, |
+ base::Bind(&util::LogStatusCallback, &callback_log)); |
+ truncate.SetDispatchEventImplForTesting( |
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
base::Unretained(&dispatcher))); |
- EXPECT_TRUE(create_file.Execute(kRequestId)); |
+ EXPECT_TRUE(truncate.Execute(kRequestId)); |
ASSERT_EQ(1u, dispatcher.events().size()); |
extensions::Event* event = dispatcher.events()[0]; |
EXPECT_EQ( |
- extensions::api::file_system_provider::OnCreateFileRequested::kEventName, |
+ extensions::api::file_system_provider::OnTruncateRequested::kEventName, |
event->event_name); |
base::ListValue* event_args = event->event_args.get(); |
ASSERT_EQ(1u, event_args->GetSize()); |
@@ -84,61 +86,68 @@ TEST_F(FileSystemProviderOperationsCreateFileTest, Execute) { |
std::string event_file_path; |
EXPECT_TRUE(options->GetString("filePath", &event_file_path)); |
EXPECT_EQ(kFilePath, event_file_path); |
+ |
+ double event_length = -1; |
+ EXPECT_TRUE(options->GetDouble("length", &event_length)); |
+ EXPECT_EQ(kTruncateLength, static_cast<double>(event_length)); |
} |
-TEST_F(FileSystemProviderOperationsCreateFileTest, Execute_NoListener) { |
+TEST_F(FileSystemProviderOperationsTruncateTest, Execute_NoListener) { |
util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); |
util::StatusCallbackLog callback_log; |
- CreateFile create_file(NULL, |
- file_system_info_, |
- base::FilePath::FromUTF8Unsafe(kFilePath), |
- base::Bind(&util::LogStatusCallback, &callback_log)); |
- create_file.SetDispatchEventImplForTesting( |
+ Truncate truncate(NULL, |
+ file_system_info_, |
+ base::FilePath::FromUTF8Unsafe(kFilePath), |
+ kTruncateLength, |
+ base::Bind(&util::LogStatusCallback, &callback_log)); |
+ truncate.SetDispatchEventImplForTesting( |
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
base::Unretained(&dispatcher))); |
- EXPECT_FALSE(create_file.Execute(kRequestId)); |
+ EXPECT_FALSE(truncate.Execute(kRequestId)); |
} |
-TEST_F(FileSystemProviderOperationsCreateFileTest, OnSuccess) { |
+TEST_F(FileSystemProviderOperationsTruncateTest, OnSuccess) { |
util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
util::StatusCallbackLog callback_log; |
- CreateFile create_file(NULL, |
- file_system_info_, |
- base::FilePath::FromUTF8Unsafe(kFilePath), |
- base::Bind(&util::LogStatusCallback, &callback_log)); |
- create_file.SetDispatchEventImplForTesting( |
+ Truncate truncate(NULL, |
+ file_system_info_, |
+ base::FilePath::FromUTF8Unsafe(kFilePath), |
+ kTruncateLength, |
+ base::Bind(&util::LogStatusCallback, &callback_log)); |
+ truncate.SetDispatchEventImplForTesting( |
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
base::Unretained(&dispatcher))); |
- EXPECT_TRUE(create_file.Execute(kRequestId)); |
+ EXPECT_TRUE(truncate.Execute(kRequestId)); |
- create_file.OnSuccess(kRequestId, |
- scoped_ptr<RequestValue>(new RequestValue()), |
- false /* has_more */); |
+ truncate.OnSuccess(kRequestId, |
+ scoped_ptr<RequestValue>(new RequestValue()), |
+ false /* has_more */); |
ASSERT_EQ(1u, callback_log.size()); |
EXPECT_EQ(base::File::FILE_OK, callback_log[0]); |
} |
-TEST_F(FileSystemProviderOperationsCreateFileTest, OnError) { |
+TEST_F(FileSystemProviderOperationsTruncateTest, OnError) { |
util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
util::StatusCallbackLog callback_log; |
- CreateFile create_file(NULL, |
- file_system_info_, |
- base::FilePath::FromUTF8Unsafe(kFilePath), |
- base::Bind(&util::LogStatusCallback, &callback_log)); |
- create_file.SetDispatchEventImplForTesting( |
+ Truncate truncate(NULL, |
+ file_system_info_, |
+ base::FilePath::FromUTF8Unsafe(kFilePath), |
+ kTruncateLength, |
+ base::Bind(&util::LogStatusCallback, &callback_log)); |
+ truncate.SetDispatchEventImplForTesting( |
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
base::Unretained(&dispatcher))); |
- EXPECT_TRUE(create_file.Execute(kRequestId)); |
+ EXPECT_TRUE(truncate.Execute(kRequestId)); |
- create_file.OnError(kRequestId, |
- scoped_ptr<RequestValue>(new RequestValue()), |
- base::File::FILE_ERROR_TOO_MANY_OPENED); |
+ truncate.OnError(kRequestId, |
+ scoped_ptr<RequestValue>(new RequestValue()), |
+ base::File::FILE_ERROR_TOO_MANY_OPENED); |
ASSERT_EQ(1u, callback_log.size()); |
EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); |
} |