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

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

Issue 366263002: [fsp] Add support for creating directories. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. 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/close_file.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"
11 #include "base/memory/scoped_vector.h"
12 #include "chrome/browser/chromeos/file_system_provider/operations/create_directo ry.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 int kOpenRequestId = 3; 29 const base::FilePath::CharType kDirectoryPath[] = "/kitty/and/puppy/happy";
30 30
31 } // namespace 31 } // namespace
32 32
33 class FileSystemProviderOperationsCloseFileTest : public testing::Test { 33 class FileSystemProviderOperationsCreateDirectoryTest : public testing::Test {
34 protected: 34 protected:
35 FileSystemProviderOperationsCloseFileTest() {} 35 FileSystemProviderOperationsCreateDirectoryTest() {}
36 virtual ~FileSystemProviderOperationsCloseFileTest() {} 36 virtual ~FileSystemProviderOperationsCreateDirectoryTest() {}
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 "" /* display_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(FileSystemProviderOperationsCloseFileTest, Execute) { 49 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, 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 CloseFile close_file(NULL, 53 CreateDirectory create_directory(
54 file_system_info_, 54 NULL,
55 kOpenRequestId, 55 file_system_info_,
56 base::Bind(&util::LogStatusCallback, &callback_log)); 56 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
57 close_file.SetDispatchEventImplForTesting( 57 false /* exclusive */,
58 true /* recursive */,
59 base::Bind(&util::LogStatusCallback, &callback_log));
60 create_directory.SetDispatchEventImplForTesting(
58 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 61 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
59 base::Unretained(&dispatcher))); 62 base::Unretained(&dispatcher)));
60 63
61 EXPECT_TRUE(close_file.Execute(kRequestId)); 64 EXPECT_TRUE(create_directory.Execute(kRequestId));
62 65
63 ASSERT_EQ(1u, dispatcher.events().size()); 66 ASSERT_EQ(1u, dispatcher.events().size());
64 extensions::Event* event = dispatcher.events()[0]; 67 extensions::Event* event = dispatcher.events()[0];
65 EXPECT_EQ( 68 EXPECT_EQ(extensions::api::file_system_provider::OnCreateDirectoryRequested::
66 extensions::api::file_system_provider::OnCloseFileRequested::kEventName, 69 kEventName,
67 event->event_name); 70 event->event_name);
68 base::ListValue* event_args = event->event_args.get(); 71 base::ListValue* event_args = event->event_args.get();
69 ASSERT_EQ(1u, event_args->GetSize()); 72 ASSERT_EQ(1u, event_args->GetSize());
70 73
71 base::DictionaryValue* options = NULL; 74 base::DictionaryValue* options = NULL;
72 ASSERT_TRUE(event_args->GetDictionary(0, &options)); 75 ASSERT_TRUE(event_args->GetDictionary(0, &options));
73 76
74 std::string event_file_system_id; 77 std::string event_file_system_id;
75 EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id)); 78 EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id));
76 EXPECT_EQ(kFileSystemId, event_file_system_id); 79 EXPECT_EQ(kFileSystemId, event_file_system_id);
77 80
78 int event_request_id = -1; 81 int event_request_id = -1;
79 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); 82 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id));
80 EXPECT_EQ(kRequestId, event_request_id); 83 EXPECT_EQ(kRequestId, event_request_id);
81 84
82 int event_open_request_id = -1; 85 std::string event_directory_path;
83 EXPECT_TRUE(options->GetInteger("openRequestId", &event_open_request_id)); 86 EXPECT_TRUE(options->GetString("directoryPath", &event_directory_path));
84 EXPECT_EQ(kOpenRequestId, event_open_request_id); 87 EXPECT_EQ(kDirectoryPath, event_directory_path);
88
89 bool event_exclusive;
90 EXPECT_TRUE(options->GetBoolean("exclusive", &event_exclusive));
91 EXPECT_FALSE(event_exclusive);
92
93 bool event_recursive;
94 EXPECT_TRUE(options->GetBoolean("recursive", &event_recursive));
95 EXPECT_TRUE(event_recursive);
85 } 96 }
86 97
87 TEST_F(FileSystemProviderOperationsCloseFileTest, Execute_NoListener) { 98 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute_NoListener) {
88 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); 99 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
89 util::StatusCallbackLog callback_log; 100 util::StatusCallbackLog callback_log;
90 101
91 CloseFile close_file(NULL, 102 CreateDirectory create_directory(
92 file_system_info_, 103 NULL,
93 kOpenRequestId, 104 file_system_info_,
94 base::Bind(&util::LogStatusCallback, &callback_log)); 105 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
95 close_file.SetDispatchEventImplForTesting( 106 false /* exclusive */,
107 true /* recursive */,
108 base::Bind(&util::LogStatusCallback, &callback_log));
109 create_directory.SetDispatchEventImplForTesting(
96 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 110 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
97 base::Unretained(&dispatcher))); 111 base::Unretained(&dispatcher)));
98 112
99 EXPECT_FALSE(close_file.Execute(kRequestId)); 113 EXPECT_FALSE(create_directory.Execute(kRequestId));
100 } 114 }
101 115
102 TEST_F(FileSystemProviderOperationsCloseFileTest, OnSuccess) { 116 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, OnSuccess) {
103 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 117 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
104 util::StatusCallbackLog callback_log; 118 util::StatusCallbackLog callback_log;
105 119
106 CloseFile close_file(NULL, 120 CreateDirectory create_directory(
107 file_system_info_, 121 NULL,
108 kOpenRequestId, 122 file_system_info_,
109 base::Bind(&util::LogStatusCallback, &callback_log)); 123 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
110 close_file.SetDispatchEventImplForTesting( 124 false /* exclusive */,
125 true /* recursive */,
126 base::Bind(&util::LogStatusCallback, &callback_log));
127 create_directory.SetDispatchEventImplForTesting(
111 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 128 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
112 base::Unretained(&dispatcher))); 129 base::Unretained(&dispatcher)));
113 130
114 EXPECT_TRUE(close_file.Execute(kRequestId)); 131 EXPECT_TRUE(create_directory.Execute(kRequestId));
115 132
116 close_file.OnSuccess(kRequestId, 133 create_directory.OnSuccess(kRequestId,
117 scoped_ptr<RequestValue>(new RequestValue()), 134 scoped_ptr<RequestValue>(new RequestValue()),
118 false /* has_more */); 135 false /* has_more */);
119 ASSERT_EQ(1u, callback_log.size()); 136 ASSERT_EQ(1u, callback_log.size());
120 EXPECT_EQ(base::File::FILE_OK, callback_log[0]); 137 EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
121 } 138 }
122 139
123 TEST_F(FileSystemProviderOperationsCloseFileTest, OnError) { 140 TEST_F(FileSystemProviderOperationsCreateDirectoryTest, OnError) {
124 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 141 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
125 util::StatusCallbackLog callback_log; 142 util::StatusCallbackLog callback_log;
126 143
127 CloseFile close_file(NULL, 144 CreateDirectory create_directory(
128 file_system_info_, 145 NULL,
129 kOpenRequestId, 146 file_system_info_,
130 base::Bind(&util::LogStatusCallback, &callback_log)); 147 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
131 close_file.SetDispatchEventImplForTesting( 148 false /* exclusive */,
149 true /* recursive */,
150 base::Bind(&util::LogStatusCallback, &callback_log));
151 create_directory.SetDispatchEventImplForTesting(
132 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 152 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
133 base::Unretained(&dispatcher))); 153 base::Unretained(&dispatcher)));
134 154
135 EXPECT_TRUE(close_file.Execute(kRequestId)); 155 EXPECT_TRUE(create_directory.Execute(kRequestId));
136 156
137 close_file.OnError(kRequestId, 157 create_directory.OnError(kRequestId,
138 scoped_ptr<RequestValue>(new RequestValue()), 158 scoped_ptr<RequestValue>(new RequestValue()),
139 base::File::FILE_ERROR_TOO_MANY_OPENED); 159 base::File::FILE_ERROR_TOO_MANY_OPENED);
140 ASSERT_EQ(1u, callback_log.size()); 160 ASSERT_EQ(1u, callback_log.size());
141 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); 161 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
142 } 162 }
143 163
144 } // namespace operations 164 } // namespace operations
145 } // namespace file_system_provider 165 } // namespace file_system_provider
146 } // namespace chromeos 166 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698