| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/unmount.h" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/configure.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" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" | 13 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" |
| 14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" | 14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" |
| 15 #include "chrome/common/extensions/api/file_system_provider.h" | 15 #include "chrome/common/extensions/api/file_system_provider.h" |
| 16 #include "chrome/common/extensions/api/file_system_provider_internal.h" | 16 #include "chrome/common/extensions/api/file_system_provider_internal.h" |
| 17 #include "extensions/browser/event_router.h" | 17 #include "extensions/browser/event_router.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 namespace chromeos { | 20 namespace chromeos { |
| 21 namespace file_system_provider { | 21 namespace file_system_provider { |
| 22 namespace operations { | 22 namespace operations { |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; | 25 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; |
| 26 const char kFileSystemId[] = "testing-file-system"; | 26 const char kFileSystemId[] = "testing-file-system"; |
| 27 const int kRequestId = 2; | 27 const int kRequestId = 2; |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 class FileSystemProviderOperationsUnmountTest : public testing::Test { | 31 class FileSystemProviderOperationsConfigureTest : public testing::Test { |
| 32 protected: | 32 protected: |
| 33 FileSystemProviderOperationsUnmountTest() {} | 33 FileSystemProviderOperationsConfigureTest() {} |
| 34 ~FileSystemProviderOperationsUnmountTest() override {} | 34 ~FileSystemProviderOperationsConfigureTest() override {} |
| 35 | 35 |
| 36 void SetUp() override { | 36 void SetUp() override { |
| 37 file_system_info_ = ProvidedFileSystemInfo( | 37 file_system_info_ = ProvidedFileSystemInfo( |
| 38 kExtensionId, | 38 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */), |
| 39 MountOptions(kFileSystemId, "" /* display_name */), | |
| 40 base::FilePath()); | 39 base::FilePath()); |
| 41 } | 40 } |
| 42 | 41 |
| 43 ProvidedFileSystemInfo file_system_info_; | 42 ProvidedFileSystemInfo file_system_info_; |
| 44 }; | 43 }; |
| 45 | 44 |
| 46 TEST_F(FileSystemProviderOperationsUnmountTest, Execute) { | 45 TEST_F(FileSystemProviderOperationsConfigureTest, Execute) { |
| 47 using extensions::api::file_system_provider::UnmountRequestedOptions; | 46 using extensions::api::file_system_provider::ConfigureRequestedOptions; |
| 48 | 47 |
| 49 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 48 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 50 util::StatusCallbackLog callback_log; | 49 util::StatusCallbackLog callback_log; |
| 51 | 50 |
| 52 Unmount unmount(NULL, | 51 Configure configure(NULL, file_system_info_, |
| 53 file_system_info_, | 52 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 54 base::Bind(&util::LogStatusCallback, &callback_log)); | 53 configure.SetDispatchEventImplForTesting( |
| 55 unmount.SetDispatchEventImplForTesting( | |
| 56 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 54 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 57 base::Unretained(&dispatcher))); | 55 base::Unretained(&dispatcher))); |
| 58 | 56 |
| 59 EXPECT_TRUE(unmount.Execute(kRequestId)); | 57 EXPECT_TRUE(configure.Execute(kRequestId)); |
| 60 | 58 |
| 61 ASSERT_EQ(1u, dispatcher.events().size()); | 59 ASSERT_EQ(1u, dispatcher.events().size()); |
| 62 extensions::Event* event = dispatcher.events()[0]; | 60 extensions::Event* event = dispatcher.events()[0]; |
| 63 EXPECT_EQ( | 61 EXPECT_EQ( |
| 64 extensions::api::file_system_provider::OnUnmountRequested::kEventName, | 62 extensions::api::file_system_provider::OnConfigureRequested::kEventName, |
| 65 event->event_name); | 63 event->event_name); |
| 66 base::ListValue* event_args = event->event_args.get(); | 64 base::ListValue* event_args = event->event_args.get(); |
| 67 ASSERT_EQ(1u, event_args->GetSize()); | 65 ASSERT_EQ(1u, event_args->GetSize()); |
| 68 | 66 |
| 69 const base::DictionaryValue* options_as_value = NULL; | 67 const base::DictionaryValue* options_as_value = NULL; |
| 70 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); | 68 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); |
| 71 | 69 |
| 72 UnmountRequestedOptions options; | 70 ConfigureRequestedOptions options; |
| 73 ASSERT_TRUE(UnmountRequestedOptions::Populate(*options_as_value, &options)); | 71 ASSERT_TRUE(ConfigureRequestedOptions::Populate(*options_as_value, &options)); |
| 74 EXPECT_EQ(kFileSystemId, options.file_system_id); | 72 EXPECT_EQ(kFileSystemId, options.file_system_id); |
| 75 EXPECT_EQ(kRequestId, options.request_id); | 73 EXPECT_EQ(kRequestId, options.request_id); |
| 76 } | 74 } |
| 77 | 75 |
| 78 TEST_F(FileSystemProviderOperationsUnmountTest, Execute_NoListener) { | 76 TEST_F(FileSystemProviderOperationsConfigureTest, Execute_NoListener) { |
| 79 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); | 77 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); |
| 80 util::StatusCallbackLog callback_log; | 78 util::StatusCallbackLog callback_log; |
| 81 | 79 |
| 82 Unmount unmount(NULL, | 80 Configure configure(NULL, file_system_info_, |
| 83 file_system_info_, | 81 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 84 base::Bind(&util::LogStatusCallback, &callback_log)); | 82 configure.SetDispatchEventImplForTesting( |
| 85 unmount.SetDispatchEventImplForTesting( | |
| 86 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 83 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 87 base::Unretained(&dispatcher))); | 84 base::Unretained(&dispatcher))); |
| 88 | 85 |
| 89 EXPECT_FALSE(unmount.Execute(kRequestId)); | 86 EXPECT_FALSE(configure.Execute(kRequestId)); |
| 90 } | 87 } |
| 91 | 88 |
| 92 TEST_F(FileSystemProviderOperationsUnmountTest, OnSuccess) { | 89 TEST_F(FileSystemProviderOperationsConfigureTest, OnSuccess) { |
| 93 using extensions::api::file_system_provider_internal:: | |
| 94 UnmountRequestedSuccess::Params; | |
| 95 | |
| 96 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 90 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 97 util::StatusCallbackLog callback_log; | 91 util::StatusCallbackLog callback_log; |
| 98 | 92 |
| 99 Unmount unmount(NULL, | 93 Configure configure(NULL, file_system_info_, |
| 100 file_system_info_, | 94 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 101 base::Bind(&util::LogStatusCallback, &callback_log)); | 95 configure.SetDispatchEventImplForTesting( |
| 102 unmount.SetDispatchEventImplForTesting( | |
| 103 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 96 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 104 base::Unretained(&dispatcher))); | 97 base::Unretained(&dispatcher))); |
| 105 | 98 |
| 106 EXPECT_TRUE(unmount.Execute(kRequestId)); | 99 EXPECT_TRUE(configure.Execute(kRequestId)); |
| 107 | 100 |
| 108 unmount.OnSuccess(kRequestId, | 101 configure.OnSuccess(kRequestId, scoped_ptr<RequestValue>(new RequestValue()), |
| 109 scoped_ptr<RequestValue>(new RequestValue()), | 102 false /* has_more */); |
| 110 false /* has_more */); | |
| 111 ASSERT_EQ(1u, callback_log.size()); | 103 ASSERT_EQ(1u, callback_log.size()); |
| 112 base::File::Error event_result = callback_log[0]; | 104 base::File::Error event_result = callback_log[0]; |
| 113 EXPECT_EQ(base::File::FILE_OK, event_result); | 105 EXPECT_EQ(base::File::FILE_OK, event_result); |
| 114 } | 106 } |
| 115 | 107 |
| 116 TEST_F(FileSystemProviderOperationsUnmountTest, OnError) { | 108 TEST_F(FileSystemProviderOperationsConfigureTest, OnError) { |
| 117 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 109 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| 118 util::StatusCallbackLog callback_log; | 110 util::StatusCallbackLog callback_log; |
| 119 | 111 |
| 120 Unmount unmount(NULL, | 112 Configure configure(NULL, file_system_info_, |
| 121 file_system_info_, | 113 base::Bind(&util::LogStatusCallback, &callback_log)); |
| 122 base::Bind(&util::LogStatusCallback, &callback_log)); | 114 configure.SetDispatchEventImplForTesting( |
| 123 unmount.SetDispatchEventImplForTesting( | |
| 124 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, | 115 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, |
| 125 base::Unretained(&dispatcher))); | 116 base::Unretained(&dispatcher))); |
| 126 | 117 |
| 127 EXPECT_TRUE(unmount.Execute(kRequestId)); | 118 EXPECT_TRUE(configure.Execute(kRequestId)); |
| 128 | 119 |
| 129 unmount.OnError(kRequestId, | 120 configure.OnError(kRequestId, scoped_ptr<RequestValue>(new RequestValue()), |
| 130 scoped_ptr<RequestValue>(new RequestValue()), | 121 base::File::FILE_ERROR_NOT_FOUND); |
| 131 base::File::FILE_ERROR_NOT_FOUND); | |
| 132 ASSERT_EQ(1u, callback_log.size()); | 122 ASSERT_EQ(1u, callback_log.size()); |
| 133 base::File::Error event_result = callback_log[0]; | 123 base::File::Error event_result = callback_log[0]; |
| 134 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, event_result); | 124 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, event_result); |
| 135 } | 125 } |
| 136 | 126 |
| 137 } // namespace operations | 127 } // namespace operations |
| 138 } // namespace file_system_provider | 128 } // namespace file_system_provider |
| 139 } // namespace chromeos | 129 } // namespace chromeos |
| OLD | NEW |