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

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

Issue 547313002: [fsp] Use auto generated methods for generating dictionaries. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 6 years, 3 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
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/read_file.h" 5 #include "chrome/browser/chromeos/file_system_provider/operations/read_file.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 false /* writable */, 84 false /* writable */,
85 base::FilePath() /* mount_path */); 85 base::FilePath() /* mount_path */);
86 io_buffer_ = make_scoped_refptr(new net::IOBuffer(kOffset + kLength)); 86 io_buffer_ = make_scoped_refptr(new net::IOBuffer(kOffset + kLength));
87 } 87 }
88 88
89 ProvidedFileSystemInfo file_system_info_; 89 ProvidedFileSystemInfo file_system_info_;
90 scoped_refptr<net::IOBuffer> io_buffer_; 90 scoped_refptr<net::IOBuffer> io_buffer_;
91 }; 91 };
92 92
93 TEST_F(FileSystemProviderOperationsReadFileTest, Execute) { 93 TEST_F(FileSystemProviderOperationsReadFileTest, Execute) {
94 using extensions::api::file_system_provider::ReadFileRequestedOptions;
95
94 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 96 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
95 CallbackLogger callback_logger; 97 CallbackLogger callback_logger;
96 98
97 ReadFile read_file(NULL, 99 ReadFile read_file(NULL,
98 file_system_info_, 100 file_system_info_,
99 kFileHandle, 101 kFileHandle,
100 io_buffer_.get(), 102 io_buffer_.get(),
101 kOffset, 103 kOffset,
102 kLength, 104 kLength,
103 base::Bind(&CallbackLogger::OnReadFile, 105 base::Bind(&CallbackLogger::OnReadFile,
104 base::Unretained(&callback_logger))); 106 base::Unretained(&callback_logger)));
105 read_file.SetDispatchEventImplForTesting( 107 read_file.SetDispatchEventImplForTesting(
106 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 108 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
107 base::Unretained(&dispatcher))); 109 base::Unretained(&dispatcher)));
108 110
109 EXPECT_TRUE(read_file.Execute(kRequestId)); 111 EXPECT_TRUE(read_file.Execute(kRequestId));
110 112
111 ASSERT_EQ(1u, dispatcher.events().size()); 113 ASSERT_EQ(1u, dispatcher.events().size());
112 extensions::Event* event = dispatcher.events()[0]; 114 extensions::Event* event = dispatcher.events()[0];
113 EXPECT_EQ( 115 EXPECT_EQ(
114 extensions::api::file_system_provider::OnReadFileRequested::kEventName, 116 extensions::api::file_system_provider::OnReadFileRequested::kEventName,
115 event->event_name); 117 event->event_name);
116 base::ListValue* event_args = event->event_args.get(); 118 base::ListValue* event_args = event->event_args.get();
117 ASSERT_EQ(1u, event_args->GetSize()); 119 ASSERT_EQ(1u, event_args->GetSize());
118 120
119 base::DictionaryValue* options = NULL; 121 const base::DictionaryValue* options_as_value = NULL;
120 ASSERT_TRUE(event_args->GetDictionary(0, &options)); 122 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
121 123
122 std::string event_file_system_id; 124 ReadFileRequestedOptions options;
123 EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id)); 125 ASSERT_TRUE(ReadFileRequestedOptions::Populate(*options_as_value, &options));
124 EXPECT_EQ(kFileSystemId, event_file_system_id); 126 EXPECT_EQ(kFileSystemId, options.file_system_id);
125 127 EXPECT_EQ(kRequestId, options.request_id);
126 int event_request_id = -1; 128 EXPECT_EQ(kFileHandle, options.open_request_id);
127 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); 129 EXPECT_EQ(kOffset, static_cast<double>(options.offset));
128 EXPECT_EQ(kRequestId, event_request_id); 130 EXPECT_EQ(kLength, options.length);
129
130 int event_file_handle = -1;
131 EXPECT_TRUE(options->GetInteger("openRequestId", &event_file_handle));
132 EXPECT_EQ(kFileHandle, event_file_handle);
133
134 double event_offset = -1;
135 EXPECT_TRUE(options->GetDouble("offset", &event_offset));
136 EXPECT_EQ(kOffset, static_cast<double>(event_offset));
137
138 int event_length = -1;
139 EXPECT_TRUE(options->GetInteger("length", &event_length));
140 EXPECT_EQ(kLength, event_length);
141 } 131 }
142 132
143 TEST_F(FileSystemProviderOperationsReadFileTest, Execute_NoListener) { 133 TEST_F(FileSystemProviderOperationsReadFileTest, Execute_NoListener) {
144 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); 134 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
145 CallbackLogger callback_logger; 135 CallbackLogger callback_logger;
146 136
147 ReadFile read_file(NULL, 137 ReadFile read_file(NULL,
148 file_system_info_, 138 file_system_info_,
149 kFileHandle, 139 kFileHandle,
150 io_buffer_.get(), 140 io_buffer_.get(),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 base::File::FILE_ERROR_TOO_MANY_OPENED); 221 base::File::FILE_ERROR_TOO_MANY_OPENED);
232 222
233 ASSERT_EQ(1u, callback_logger.events().size()); 223 ASSERT_EQ(1u, callback_logger.events().size());
234 CallbackLogger::Event* event = callback_logger.events()[0]; 224 CallbackLogger::Event* event = callback_logger.events()[0];
235 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); 225 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result());
236 } 226 }
237 227
238 } // namespace operations 228 } // namespace operations
239 } // namespace file_system_provider 229 } // namespace file_system_provider
240 } // namespace chromeos 230 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698