Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Side by Side Diff: chrome/browser/chromeos/file_system_provider/operations/move_entry_unittest.cc

Issue 389973002: [fsp] Add support for moving files within a provided file system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/copy_entry.h"
6
7 #include <string> 5 #include <string>
8 #include <vector> 6 #include <vector>
9 7
10 #include "base/files/file.h" 8 #include "base/files/file.h"
11 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
12 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
12 #include "chrome/browser/chromeos/file_system_provider/operations/move_entry.h"
kinaba 2014/07/15 07:12:54 You can move this line to the top of the #includes
mtomasz 2014/07/16 07:36:12 Done.
14 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h" 13 #include "chrome/browser/chromeos/file_system_provider/operations/test_util.h"
15 #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"
16 #include "chrome/common/extensions/api/file_system_provider.h" 15 #include "chrome/common/extensions/api/file_system_provider.h"
17 #include "chrome/common/extensions/api/file_system_provider_internal.h" 16 #include "chrome/common/extensions/api/file_system_provider_internal.h"
18 #include "extensions/browser/event_router.h" 17 #include "extensions/browser/event_router.h"
19 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
20 #include "webkit/browser/fileapi/async_file_util.h" 19 #include "webkit/browser/fileapi/async_file_util.h"
21 20
22 namespace chromeos { 21 namespace chromeos {
23 namespace file_system_provider { 22 namespace file_system_provider {
24 namespace operations { 23 namespace operations {
25 namespace { 24 namespace {
26 25
27 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; 26 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
28 const char kFileSystemId[] = "testing-file-system"; 27 const char kFileSystemId[] = "testing-file-system";
29 const int kRequestId = 2; 28 const int kRequestId = 2;
30 const base::FilePath::CharType kSourcePath[] = "/bunny/and/bear/happy"; 29 const base::FilePath::CharType kSourcePath[] = "/bunny/and/bear/happy";
31 const base::FilePath::CharType kTargetPath[] = "/kitty/and/puppy/happy"; 30 const base::FilePath::CharType kTargetPath[] = "/kitty/and/puppy/happy";
32 31
33 } // namespace 32 } // namespace
34 33
35 class FileSystemProviderOperationsCopyEntryTest : public testing::Test { 34 class FileSystemProviderOperationsMoveEntryTest : public testing::Test {
36 protected: 35 protected:
37 FileSystemProviderOperationsCopyEntryTest() {} 36 FileSystemProviderOperationsMoveEntryTest() {}
38 virtual ~FileSystemProviderOperationsCopyEntryTest() {} 37 virtual ~FileSystemProviderOperationsMoveEntryTest() {}
39 38
40 virtual void SetUp() OVERRIDE { 39 virtual void SetUp() OVERRIDE {
41 file_system_info_ = 40 file_system_info_ =
42 ProvidedFileSystemInfo(kExtensionId, 41 ProvidedFileSystemInfo(kExtensionId,
43 kFileSystemId, 42 kFileSystemId,
44 "" /* file_system_name */, 43 "" /* file_system_name */,
45 true /* writable */, 44 true /* writable */,
46 base::FilePath() /* mount_path */); 45 base::FilePath() /* mount_path */);
47 } 46 }
48 47
49 ProvidedFileSystemInfo file_system_info_; 48 ProvidedFileSystemInfo file_system_info_;
50 }; 49 };
51 50
52 TEST_F(FileSystemProviderOperationsCopyEntryTest, Execute) { 51 TEST_F(FileSystemProviderOperationsMoveEntryTest, Execute) {
53 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 52 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
54 util::StatusCallbackLog callback_log; 53 util::StatusCallbackLog callback_log;
55 54
56 CopyEntry copy_entry(NULL, 55 MoveEntry move_entry(NULL,
57 file_system_info_, 56 file_system_info_,
58 base::FilePath::FromUTF8Unsafe(kSourcePath), 57 base::FilePath::FromUTF8Unsafe(kSourcePath),
59 base::FilePath::FromUTF8Unsafe(kTargetPath), 58 base::FilePath::FromUTF8Unsafe(kTargetPath),
60 base::Bind(&util::LogStatusCallback, &callback_log)); 59 base::Bind(&util::LogStatusCallback, &callback_log));
61 copy_entry.SetDispatchEventImplForTesting( 60 move_entry.SetDispatchEventImplForTesting(
62 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 61 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
63 base::Unretained(&dispatcher))); 62 base::Unretained(&dispatcher)));
64 63
65 EXPECT_TRUE(copy_entry.Execute(kRequestId)); 64 EXPECT_TRUE(move_entry.Execute(kRequestId));
66 65
67 ASSERT_EQ(1u, dispatcher.events().size()); 66 ASSERT_EQ(1u, dispatcher.events().size());
68 extensions::Event* event = dispatcher.events()[0]; 67 extensions::Event* event = dispatcher.events()[0];
69 EXPECT_EQ( 68 EXPECT_EQ(
70 extensions::api::file_system_provider::OnCopyEntryRequested::kEventName, 69 extensions::api::file_system_provider::OnMoveEntryRequested::kEventName,
71 event->event_name); 70 event->event_name);
72 base::ListValue* event_args = event->event_args.get(); 71 base::ListValue* event_args = event->event_args.get();
73 ASSERT_EQ(1u, event_args->GetSize()); 72 ASSERT_EQ(1u, event_args->GetSize());
74 73
75 base::DictionaryValue* options = NULL; 74 base::DictionaryValue* options = NULL;
76 ASSERT_TRUE(event_args->GetDictionary(0, &options)); 75 ASSERT_TRUE(event_args->GetDictionary(0, &options));
77 76
78 std::string event_file_system_id; 77 std::string event_file_system_id;
79 EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id)); 78 EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id));
80 EXPECT_EQ(kFileSystemId, event_file_system_id); 79 EXPECT_EQ(kFileSystemId, event_file_system_id);
81 80
82 int event_request_id = -1; 81 int event_request_id = -1;
83 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); 82 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id));
84 EXPECT_EQ(kRequestId, event_request_id); 83 EXPECT_EQ(kRequestId, event_request_id);
85 84
86 std::string event_source_path; 85 std::string event_source_path;
87 EXPECT_TRUE(options->GetString("sourcePath", &event_source_path)); 86 EXPECT_TRUE(options->GetString("sourcePath", &event_source_path));
88 EXPECT_EQ(kSourcePath, event_source_path); 87 EXPECT_EQ(kSourcePath, event_source_path);
89 88
90 std::string event_target_path; 89 std::string event_target_path;
91 EXPECT_TRUE(options->GetString("targetPath", &event_target_path)); 90 EXPECT_TRUE(options->GetString("targetPath", &event_target_path));
92 EXPECT_EQ(kTargetPath, event_target_path); 91 EXPECT_EQ(kTargetPath, event_target_path);
93 } 92 }
94 93
95 TEST_F(FileSystemProviderOperationsCopyEntryTest, Execute_NoListener) { 94 TEST_F(FileSystemProviderOperationsMoveEntryTest, Execute_NoListener) {
96 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); 95 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
97 util::StatusCallbackLog callback_log; 96 util::StatusCallbackLog callback_log;
98 97
99 CopyEntry copy_entry(NULL, 98 MoveEntry move_entry(NULL,
100 file_system_info_, 99 file_system_info_,
101 base::FilePath::FromUTF8Unsafe(kSourcePath), 100 base::FilePath::FromUTF8Unsafe(kSourcePath),
102 base::FilePath::FromUTF8Unsafe(kTargetPath), 101 base::FilePath::FromUTF8Unsafe(kTargetPath),
103 base::Bind(&util::LogStatusCallback, &callback_log)); 102 base::Bind(&util::LogStatusCallback, &callback_log));
104 copy_entry.SetDispatchEventImplForTesting( 103 move_entry.SetDispatchEventImplForTesting(
105 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 104 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
106 base::Unretained(&dispatcher))); 105 base::Unretained(&dispatcher)));
107 106
108 EXPECT_FALSE(copy_entry.Execute(kRequestId)); 107 EXPECT_FALSE(move_entry.Execute(kRequestId));
109 } 108 }
110 109
111 TEST_F(FileSystemProviderOperationsCopyEntryTest, OnSuccess) { 110 TEST_F(FileSystemProviderOperationsMoveEntryTest, OnSuccess) {
112 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 111 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
113 util::StatusCallbackLog callback_log; 112 util::StatusCallbackLog callback_log;
114 113
115 CopyEntry copy_entry(NULL, 114 MoveEntry move_entry(NULL,
116 file_system_info_, 115 file_system_info_,
117 base::FilePath::FromUTF8Unsafe(kSourcePath), 116 base::FilePath::FromUTF8Unsafe(kSourcePath),
118 base::FilePath::FromUTF8Unsafe(kTargetPath), 117 base::FilePath::FromUTF8Unsafe(kTargetPath),
119 base::Bind(&util::LogStatusCallback, &callback_log)); 118 base::Bind(&util::LogStatusCallback, &callback_log));
120 copy_entry.SetDispatchEventImplForTesting( 119 move_entry.SetDispatchEventImplForTesting(
121 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 120 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
122 base::Unretained(&dispatcher))); 121 base::Unretained(&dispatcher)));
123 122
124 EXPECT_TRUE(copy_entry.Execute(kRequestId)); 123 EXPECT_TRUE(move_entry.Execute(kRequestId));
125 124
126 copy_entry.OnSuccess(kRequestId, 125 move_entry.OnSuccess(kRequestId,
127 scoped_ptr<RequestValue>(new RequestValue()), 126 scoped_ptr<RequestValue>(new RequestValue()),
128 false /* has_more */); 127 false /* has_more */);
129 ASSERT_EQ(1u, callback_log.size()); 128 ASSERT_EQ(1u, callback_log.size());
130 EXPECT_EQ(base::File::FILE_OK, callback_log[0]); 129 EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
131 } 130 }
132 131
133 TEST_F(FileSystemProviderOperationsCopyEntryTest, OnError) { 132 TEST_F(FileSystemProviderOperationsMoveEntryTest, OnError) {
134 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 133 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
135 util::StatusCallbackLog callback_log; 134 util::StatusCallbackLog callback_log;
136 135
137 CopyEntry copy_entry(NULL, 136 MoveEntry move_entry(NULL,
138 file_system_info_, 137 file_system_info_,
139 base::FilePath::FromUTF8Unsafe(kSourcePath), 138 base::FilePath::FromUTF8Unsafe(kSourcePath),
140 base::FilePath::FromUTF8Unsafe(kTargetPath), 139 base::FilePath::FromUTF8Unsafe(kTargetPath),
141 base::Bind(&util::LogStatusCallback, &callback_log)); 140 base::Bind(&util::LogStatusCallback, &callback_log));
142 copy_entry.SetDispatchEventImplForTesting( 141 move_entry.SetDispatchEventImplForTesting(
143 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 142 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
144 base::Unretained(&dispatcher))); 143 base::Unretained(&dispatcher)));
145 144
146 EXPECT_TRUE(copy_entry.Execute(kRequestId)); 145 EXPECT_TRUE(move_entry.Execute(kRequestId));
147 146
148 copy_entry.OnError(kRequestId, 147 move_entry.OnError(kRequestId,
149 scoped_ptr<RequestValue>(new RequestValue()), 148 scoped_ptr<RequestValue>(new RequestValue()),
150 base::File::FILE_ERROR_TOO_MANY_OPENED); 149 base::File::FILE_ERROR_TOO_MANY_OPENED);
151 ASSERT_EQ(1u, callback_log.size()); 150 ASSERT_EQ(1u, callback_log.size());
152 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); 151 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
153 } 152 }
154 153
155 } // namespace operations 154 } // namespace operations
156 } // namespace file_system_provider 155 } // namespace file_system_provider
157 } // namespace chromeos 156 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698