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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/operations/open_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/open_file.h" 5 #include "chrome/browser/chromeos/file_system_provider/operations/open_file.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"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 kFileSystemId, 77 kFileSystemId,
78 "" /* display_name */, 78 "" /* display_name */,
79 false /* writable */, 79 false /* writable */,
80 base::FilePath() /* mount_path */); 80 base::FilePath() /* mount_path */);
81 } 81 }
82 82
83 ProvidedFileSystemInfo file_system_info_; 83 ProvidedFileSystemInfo file_system_info_;
84 }; 84 };
85 85
86 TEST_F(FileSystemProviderOperationsOpenFileTest, Execute) { 86 TEST_F(FileSystemProviderOperationsOpenFileTest, Execute) {
87 using extensions::api::file_system_provider::OpenFileRequestedOptions;
88
87 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); 89 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
88 CallbackLogger callback_logger; 90 CallbackLogger callback_logger;
89 91
90 OpenFile open_file(NULL, 92 OpenFile open_file(NULL,
91 file_system_info_, 93 file_system_info_,
92 base::FilePath::FromUTF8Unsafe(kFilePath), 94 base::FilePath::FromUTF8Unsafe(kFilePath),
93 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, 95 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ,
94 base::Bind(&CallbackLogger::OnOpenFile, 96 base::Bind(&CallbackLogger::OnOpenFile,
95 base::Unretained(&callback_logger))); 97 base::Unretained(&callback_logger)));
96 open_file.SetDispatchEventImplForTesting( 98 open_file.SetDispatchEventImplForTesting(
97 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, 99 base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
98 base::Unretained(&dispatcher))); 100 base::Unretained(&dispatcher)));
99 101
100 EXPECT_TRUE(open_file.Execute(kRequestId)); 102 EXPECT_TRUE(open_file.Execute(kRequestId));
101 103
102 ASSERT_EQ(1u, dispatcher.events().size()); 104 ASSERT_EQ(1u, dispatcher.events().size());
103 extensions::Event* event = dispatcher.events()[0]; 105 extensions::Event* event = dispatcher.events()[0];
104 EXPECT_EQ( 106 EXPECT_EQ(
105 extensions::api::file_system_provider::OnOpenFileRequested::kEventName, 107 extensions::api::file_system_provider::OnOpenFileRequested::kEventName,
106 event->event_name); 108 event->event_name);
107 base::ListValue* event_args = event->event_args.get(); 109 base::ListValue* event_args = event->event_args.get();
108 ASSERT_EQ(1u, event_args->GetSize()); 110 ASSERT_EQ(1u, event_args->GetSize());
109 111
110 base::DictionaryValue* options = NULL; 112 const base::DictionaryValue* options_as_value = NULL;
111 ASSERT_TRUE(event_args->GetDictionary(0, &options)); 113 ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
112 114
113 std::string event_file_system_id; 115 OpenFileRequestedOptions options;
114 EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id)); 116 ASSERT_TRUE(OpenFileRequestedOptions::Populate(*options_as_value, &options));
115 EXPECT_EQ(kFileSystemId, event_file_system_id); 117 EXPECT_EQ(kFileSystemId, options.file_system_id);
116 118 EXPECT_EQ(kRequestId, options.request_id);
117 int event_request_id = -1; 119 EXPECT_EQ(kFilePath, options.file_path);
118 EXPECT_TRUE(options->GetInteger("requestId", &event_request_id)); 120 EXPECT_EQ(extensions::api::file_system_provider::OPEN_FILE_MODE_READ,
119 EXPECT_EQ(kRequestId, event_request_id); 121 options.mode);
120
121 std::string event_file_path;
122 EXPECT_TRUE(options->GetString("filePath", &event_file_path));
123 EXPECT_EQ(kFilePath, event_file_path);
124
125 std::string event_file_open_mode;
126 EXPECT_TRUE(options->GetString("mode", &event_file_open_mode));
127 const std::string expected_file_open_mode =
128 extensions::api::file_system_provider::ToString(
129 extensions::api::file_system_provider::OPEN_FILE_MODE_READ);
130 EXPECT_EQ(expected_file_open_mode, event_file_open_mode);
131 } 122 }
132 123
133 TEST_F(FileSystemProviderOperationsOpenFileTest, Execute_NoListener) { 124 TEST_F(FileSystemProviderOperationsOpenFileTest, Execute_NoListener) {
134 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); 125 util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
135 CallbackLogger callback_logger; 126 CallbackLogger callback_logger;
136 127
137 OpenFile open_file(NULL, 128 OpenFile open_file(NULL,
138 file_system_info_, 129 file_system_info_,
139 base::FilePath::FromUTF8Unsafe(kFilePath), 130 base::FilePath::FromUTF8Unsafe(kFilePath),
140 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ, 131 ProvidedFileSystemInterface::OPEN_FILE_MODE_READ,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 base::File::FILE_ERROR_TOO_MANY_OPENED); 226 base::File::FILE_ERROR_TOO_MANY_OPENED);
236 ASSERT_EQ(1u, callback_logger.events().size()); 227 ASSERT_EQ(1u, callback_logger.events().size());
237 CallbackLogger::Event* event = callback_logger.events()[0]; 228 CallbackLogger::Event* event = callback_logger.events()[0];
238 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); 229 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result());
239 ASSERT_EQ(0, event->file_handle()); 230 ASSERT_EQ(0, event->file_handle());
240 } 231 }
241 232
242 } // namespace operations 233 } // namespace operations
243 } // namespace file_system_provider 234 } // namespace file_system_provider
244 } // namespace chromeos 235 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698