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

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

Issue 375543002: [fsp] Add support for deleting entries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased + cleaned up. 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/files/file.h" 8 #include "base/files/file.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.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 "chrome/browser/chromeos/file_system_provider/operations/create_directo ry.h" 12 #include "chrome/browser/chromeos/file_system_provider/operations/delete_entry.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 #include "webkit/browser/fileapi/async_file_util.h" 19 #include "webkit/browser/fileapi/async_file_util.h"
20 20
21 namespace chromeos { 21 namespace chromeos {
22 namespace file_system_provider { 22 namespace file_system_provider {
23 namespace operations { 23 namespace operations {
24 namespace { 24 namespace {
25 25
26 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; 26 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
27 const char kFileSystemId[] = "testing-file-system"; 27 const char kFileSystemId[] = "testing-file-system";
28 const int kRequestId = 2; 28 const int kRequestId = 2;
29 const base::FilePath::CharType kDirectoryPath[] = "/kitty/and/puppy/happy"; 29 const base::FilePath::CharType kEntryPath[] = "/kitty/and/puppy/happy";
30 30
31 } // namespace 31 } // namespace
32 32
33 class FileSystemProviderOperationsCreateDirectoryTest : public testing::Test { 33 class FileSystemProviderOperationsDeleteEntryTest : public testing::Test {
34 protected: 34 protected:
35 FileSystemProviderOperationsCreateDirectoryTest() {} 35 FileSystemProviderOperationsDeleteEntryTest() {}
36 virtual ~FileSystemProviderOperationsCreateDirectoryTest() {} 36 virtual ~FileSystemProviderOperationsDeleteEntryTest() {}
37 37
38 virtual void SetUp() OVERRIDE { 38 virtual void SetUp() OVERRIDE {
39 file_system_info_ = 39 file_system_info_ =
40 ProvidedFileSystemInfo(kExtensionId, 40 ProvidedFileSystemInfo(kExtensionId,
41 kFileSystemId, 41 kFileSystemId,
42 "" /* file_system_name */, 42 "" /* file_system_name */,
43 base::FilePath() /* mount_path */); 43 base::FilePath() /* mount_path */);
44 } 44 }
45 45
46 ProvidedFileSystemInfo file_system_info_; 46 ProvidedFileSystemInfo file_system_info_;
47 }; 47 };
48 48
49 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute) { 49 TEST_F(FileSystemProviderOperationsDeleteEntryTest, Execute) {
50 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 50 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
51 util::StatusCallbackLog callback_log; 51 util::StatusCallbackLog callback_log;
52 52
53 CreateDirectory create_directory( 53 DeleteEntry delete_entry(NULL,
54 NULL, 54 file_system_info_,
55 file_system_info_, 55 base::FilePath::FromUTF8Unsafe(kEntryPath),
56 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 56 true /* recursive */,
57 false /* exclusive */, 57 base::Bind(&util::LogStatusCallback, &callback_log));
58 true /* recursive */, 58 delete_entry.SetDispatchEventImplForTesting(
59 base::Bind(&util::LogStatusCallback, &callback_log));
60 create_directory.SetDispatchEventImplForTesting(
61 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 59 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
62 base::Unretained(&dispatcher))); 60 base::Unretained(&dispatcher)));
63 61
64 EXPECT_TRUE(create_directory.Execute(kRequestId)); 62 EXPECT_TRUE(delete_entry.Execute(kRequestId));
65 63
66 ASSERT_EQ(1u, dispatcher.events().size()); 64 ASSERT_EQ(1u, dispatcher.events().size());
67 extensions::Event* event = dispatcher.events()[0]; 65 extensions::Event* event = dispatcher.events()[0];
68 EXPECT_EQ(extensions::api::file_system_provider::OnCreateDirectoryRequested:: 66 EXPECT_EQ(
69 kEventName, 67 extensions::api::file_system_provider::OnDeleteEntryRequested::kEventName,
70 event->event_name); 68 event->event_name);
71 base::ListValue* event_args = event->event_args.get(); 69 base::ListValue* event_args = event->event_args.get();
72 ASSERT_EQ(1u, event_args->GetSize()); 70 ASSERT_EQ(1u, event_args->GetSize());
73 71
74 base::DictionaryValue* options = NULL; 72 base::DictionaryValue* options = NULL;
75 ASSERT_TRUE(event_args->GetDictionary(0, &options)); 73 ASSERT_TRUE(event_args->GetDictionary(0, &options));
76 74
77 std::string event_file_system_id; 75 std::string event_file_system_id;
78 EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id)); 76 EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id));
79 EXPECT_EQ(kFileSystemId, event_file_system_id); 77 EXPECT_EQ(kFileSystemId, event_file_system_id);
80 78
81 int event_request_id = -1; 79 int event_request_id = -1;
82 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); 80 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id));
83 EXPECT_EQ(kRequestId, event_request_id); 81 EXPECT_EQ(kRequestId, event_request_id);
84 82
85 std::string event_directory_path; 83 std::string event_entry_path;
86 EXPECT_TRUE(options->GetString("directoryPath", &event_directory_path)); 84 EXPECT_TRUE(options->GetString("entryPath", &event_entry_path));
87 EXPECT_EQ(kDirectoryPath, event_directory_path); 85 EXPECT_EQ(kEntryPath, event_entry_path);
88
89 bool event_exclusive;
90 EXPECT_TRUE(options->GetBoolean("exclusive", &event_exclusive));
91 EXPECT_FALSE(event_exclusive);
92 86
93 bool event_recursive; 87 bool event_recursive;
94 EXPECT_TRUE(options->GetBoolean("recursive", &event_recursive)); 88 EXPECT_TRUE(options->GetBoolean("recursive", &event_recursive));
95 EXPECT_TRUE(event_recursive); 89 EXPECT_TRUE(event_recursive);
96 } 90 }
97 91
98 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute_NoListener) { 92 TEST_F(FileSystemProviderOperationsDeleteEntryTest, Execute_NoListener) {
99 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); 93 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
100 util::StatusCallbackLog callback_log; 94 util::StatusCallbackLog callback_log;
101 95
102 CreateDirectory create_directory( 96 DeleteEntry delete_entry(NULL,
103 NULL, 97 file_system_info_,
104 file_system_info_, 98 base::FilePath::FromUTF8Unsafe(kEntryPath),
105 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 99 true /* recursive */,
106 false /* exclusive */, 100 base::Bind(&util::LogStatusCallback, &callback_log));
107 true /* recursive */, 101 delete_entry.SetDispatchEventImplForTesting(
108 base::Bind(&util::LogStatusCallback, &callback_log));
109 create_directory.SetDispatchEventImplForTesting(
110 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 102 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
111 base::Unretained(&dispatcher))); 103 base::Unretained(&dispatcher)));
112 104
113 EXPECT_FALSE(create_directory.Execute(kRequestId)); 105 EXPECT_FALSE(delete_entry.Execute(kRequestId));
114 } 106 }
115 107
116 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, OnSuccess) { 108 TEST_F(FileSystemProviderOperationsDeleteEntryTest, OnSuccess) {
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 CreateDirectory create_directory( 112 DeleteEntry delete_entry(NULL,
121 NULL, 113 file_system_info_,
122 file_system_info_, 114 base::FilePath::FromUTF8Unsafe(kEntryPath),
123 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 115 true /* recursive */,
124 false /* exclusive */, 116 base::Bind(&util::LogStatusCallback, &callback_log));
125 true /* recursive */, 117 delete_entry.SetDispatchEventImplForTesting(
126 base::Bind(&util::LogStatusCallback, &callback_log));
127 create_directory.SetDispatchEventImplForTesting(
128 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 118 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
129 base::Unretained(&dispatcher))); 119 base::Unretained(&dispatcher)));
130 120
131 EXPECT_TRUE(create_directory.Execute(kRequestId)); 121 EXPECT_TRUE(delete_entry.Execute(kRequestId));
132 122
133 create_directory.OnSuccess(kRequestId, 123 delete_entry.OnSuccess(kRequestId,
134 scoped_ptr<RequestValue>(new RequestValue()), 124 scoped_ptr<RequestValue>(new RequestValue()),
135 false /* has_more */); 125 false /* has_more */);
136 ASSERT_EQ(1u, callback_log.size()); 126 ASSERT_EQ(1u, callback_log.size());
137 EXPECT_EQ(base::File::FILE_OK, callback_log[0]); 127 EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
138 } 128 }
139 129
140 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, OnError) { 130 TEST_F(FileSystemProviderOperationsDeleteEntryTest, OnError) {
141 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 131 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
142 util::StatusCallbackLog callback_log; 132 util::StatusCallbackLog callback_log;
143 133
144 CreateDirectory create_directory( 134 DeleteEntry delete_entry(NULL,
145 NULL, 135 file_system_info_,
146 file_system_info_, 136 base::FilePath::FromUTF8Unsafe(kEntryPath),
147 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 137 true /* recursive */,
148 false /* exclusive */, 138 base::Bind(&util::LogStatusCallback, &callback_log));
149 true /* recursive */, 139 delete_entry.SetDispatchEventImplForTesting(
150 base::Bind(&util::LogStatusCallback, &callback_log));
151 create_directory.SetDispatchEventImplForTesting(
152 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 140 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
153 base::Unretained(&dispatcher))); 141 base::Unretained(&dispatcher)));
154 142
155 EXPECT_TRUE(create_directory.Execute(kRequestId)); 143 EXPECT_TRUE(delete_entry.Execute(kRequestId));
156 144
157 create_directory.OnError(kRequestId, 145 delete_entry.OnError(kRequestId,
158 scoped_ptr<RequestValue>(new RequestValue()), 146 scoped_ptr<RequestValue>(new RequestValue()),
159 base::File::FILE_ERROR_TOO_MANY_OPENED); 147 base::File::FILE_ERROR_TOO_MANY_OPENED);
160 ASSERT_EQ(1u, callback_log.size()); 148 ASSERT_EQ(1u, callback_log.size());
161 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); 149 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
162 } 150 }
163 151
164 } // namespace operations 152 } // namespace operations
165 } // namespace file_system_provider 153 } // namespace file_system_provider
166 } // namespace chromeos 154 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698