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

Side by Side Diff: chrome/browser/chromeos/extensions/external_filesystem_apitest.cc

Issue 10993066: Add oem mount point to cros_mount_provider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: forgot one file Created 8 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/file_path.h" 6 #include "base/file_path.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/json/json_file_value_serializer.h" 8 #include "base/json/json_file_value_serializer.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
(...skipping 25 matching lines...) Expand all
36 #include "webkit/fileapi/file_system_mount_point_provider.h" 36 #include "webkit/fileapi/file_system_mount_point_provider.h"
37 37
38 using ::testing::_; 38 using ::testing::_;
39 using ::testing::Return; 39 using ::testing::Return;
40 using content::BrowserContext; 40 using content::BrowserContext;
41 41
42 namespace { 42 namespace {
43 43
44 // These should match the counterparts in remote.js. 44 // These should match the counterparts in remote.js.
45 // Also, the size of the file in |kTestRootFeed| has to be set to 45 // Also, the size of the file in |kTestRootFeed| has to be set to
46 // |size(kTestFileContents)|. 46 // length of kTestFileContent string.
47 const char kTestFileContents[] = "hello, world"; 47 const char kTestFileContent[] = "hello, world!";
48 48
49 // Contains a folder entry for the folder 'Folder' that will be 'created'. 49 // Contains a folder entry for the folder 'Folder' that will be 'created'.
50 const char kTestDirectory[] = "new_folder_entry.json"; 50 const char kTestDirectory[] = "new_folder_entry.json";
51 51
52 // Contains a folder named Folder that has a file File.aBc inside of it. 52 // Contains a folder named Folder that has a file File.aBc inside of it.
53 const char kTestRootFeed[] = "remote_file_system_apitest_root_feed.json"; 53 const char kTestRootFeed[] = "remote_file_system_apitest_root_feed.json";
54 54
55 // Contains metadata of the document that will be "downloaded" in test. 55 // Contains metadata of the document that will be "downloaded" in test.
56 const char kTestDocumentToDownloadEntry[] = 56 const char kTestDocumentToDownloadEntry[] =
57 "remote_file_system_apitest_document_to_download.json"; 57 "remote_file_system_apitest_document_to_download.json";
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 base::Bind(arg4, status, base::Passed(value))); 129 base::Bind(arg4, status, base::Passed(value)));
130 } 130 }
131 131
132 // Action used to mock expectations fo GetDocumentEntry. 132 // Action used to mock expectations fo GetDocumentEntry.
133 ACTION_P2(MockGetDocumentEntryCallback, status, value) { 133 ACTION_P2(MockGetDocumentEntryCallback, status, value) {
134 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 134 base::MessageLoopProxy::current()->PostTask(FROM_HERE,
135 base::Bind(arg1, status, base::Passed(value))); 135 base::Bind(arg1, status, base::Passed(value)));
136 } 136 }
137 137
138 // Creates a cache representation of the test file with predetermined content. 138 // Creates a cache representation of the test file with predetermined content.
139 void CreateDownloadFile(const FilePath& path) { 139 void CreateFileWithContent(const FilePath& path, const std::string& content) {
140 int file_content_size = static_cast<int>(sizeof(kTestFileContents)); 140 int content_size = static_cast<int>(content.length());
141 ASSERT_EQ(file_content_size, 141 ASSERT_EQ(content_size,
142 file_util::WriteFile(path, kTestFileContents, file_content_size)); 142 file_util::WriteFile(path, content.c_str(), content_size));
143 } 143 }
144 144
145 // Action used to set mock expectations for DownloadFile(). 145 // Action used to set mock expectations for DownloadFile().
146 ACTION_P(MockDownloadFileCallback, status) { 146 ACTION_P(MockDownloadFileCallback, status) {
147 ASSERT_TRUE(content::BrowserThread::PostTaskAndReply( 147 ASSERT_TRUE(content::BrowserThread::PostTaskAndReply(
148 content::BrowserThread::FILE, 148 content::BrowserThread::FILE,
149 FROM_HERE, 149 FROM_HERE,
150 base::Bind(&CreateDownloadFile, arg1), 150 base::Bind(&CreateFileWithContent, arg1, kTestFileContent),
151 base::Bind(arg3, status, arg2, arg1))); 151 base::Bind(arg3, status, arg2, arg1)));
152 } 152 }
153 153
154 } // namespace 154 } // namespace
155 155
156 class FileSystemExtensionApiTest : public ExtensionApiTest { 156 class FileSystemExtensionApiTest : public ExtensionApiTest {
157 public: 157 public:
158 FileSystemExtensionApiTest() : test_mount_point_("/tmp") { 158 FileSystemExtensionApiTest() : test_mount_point_("/tmp") {
159 } 159 }
160 160
(...skipping 21 matching lines...) Expand all
182 const extensions::Extension* extension = LoadExtension(extdir); 182 const extensions::Extension* extension = LoadExtension(extdir);
183 if (extension) 183 if (extension)
184 page_complete.WaitUntilClosed(); 184 page_complete.WaitUntilClosed();
185 return extension; 185 return extension;
186 } 186 }
187 187
188 private: 188 private:
189 FilePath test_mount_point_; 189 FilePath test_mount_point_;
190 }; 190 };
191 191
192 class RestrictedFileSystemExtensionApiTest : public ExtensionApiTest {
193 public:
194 RestrictedFileSystemExtensionApiTest() {}
195
196 virtual ~RestrictedFileSystemExtensionApiTest() {}
197
198 virtual void SetUp() OVERRIDE {
199 FilePath tmp_path;
200 PathService::Get(base::DIR_TEMP, &tmp_path);
201 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDirUnderPath(tmp_path));
202 mount_point_dir_ = tmp_dir_.path().Append("mount");
203 // Create the mount point.
204 file_util::CreateDirectory(mount_point_dir_);
205
206 FilePath test_dir = mount_point_dir_.Append("test_dir");
207 file_util::CreateDirectory(test_dir);
208
209 FilePath test_file = test_dir.AppendASCII("test_file.foo");
210 CreateFileWithContent(test_file, kTestFileContent);
211
212 test_file = test_dir.AppendASCII("mutable_test_file.foo");
213 CreateFileWithContent(test_file, kTestFileContent);
214
215 test_file = test_dir.AppendASCII("test_file_to_delete.foo");
216 CreateFileWithContent(test_file, kTestFileContent);
217
218 test_file = test_dir.AppendASCII("test_file_to_move.foo");
219 CreateFileWithContent(test_file, kTestFileContent);
220
221 // Create test files.
222 ExtensionApiTest::SetUp();
223 }
224
225 virtual void TearDown() OVERRIDE {
226 ExtensionApiTest::TearDown();
227 }
228
229 void AddRestrictedMountPoint() {
230 fileapi::ExternalFileSystemMountPointProvider* provider =
231 BrowserContext::GetDefaultStoragePartition(
232 browser()->profile())->GetFileSystemContext()->external_provider();
233 provider->AddRestrictedLocalMountPoint(mount_point_dir_);
234 }
235
236 protected:
237 ScopedTempDir tmp_dir_;
238 FilePath mount_point_dir_;
239 };
240
241
192 class RemoteFileSystemExtensionApiTest : public ExtensionApiTest { 242 class RemoteFileSystemExtensionApiTest : public ExtensionApiTest {
193 public: 243 public:
194 RemoteFileSystemExtensionApiTest() {} 244 RemoteFileSystemExtensionApiTest() {}
195 245
196 virtual ~RemoteFileSystemExtensionApiTest() {} 246 virtual ~RemoteFileSystemExtensionApiTest() {}
197 247
198 virtual void SetUp() OVERRIDE { 248 virtual void SetUp() OVERRIDE {
199 // Set up cache root and documents service to be used when creating gdata 249 // Set up cache root and documents service to be used when creating gdata
200 // system service. This has to be done early on (before the browser is 250 // system service. This has to be done early on (before the browser is
201 // created) because the system service instance is initialized very early 251 // created) because the system service instance is initialized very early
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 299
250 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, FileBrowserWebIntentTest) { 300 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, FileBrowserWebIntentTest) {
251 AddTmpMountPoint(); 301 AddTmpMountPoint();
252 302
253 ResultCatcher catcher; 303 ResultCatcher catcher;
254 ScopedTempDir tmp_dir; 304 ScopedTempDir tmp_dir;
255 ASSERT_TRUE(tmp_dir.CreateUniqueTempDir()); 305 ASSERT_TRUE(tmp_dir.CreateUniqueTempDir());
256 306
257 // Create a test file inside the ScopedTempDir. 307 // Create a test file inside the ScopedTempDir.
258 FilePath test_file = tmp_dir.path().AppendASCII("text_file.xul"); 308 FilePath test_file = tmp_dir.path().AppendASCII("text_file.xul");
259 CreateDownloadFile(test_file); 309 CreateFileWithContent(test_file, kTestFileContent);
260 310
261 ASSERT_TRUE(LoadExtension( 311 ASSERT_TRUE(LoadExtension(
262 test_data_dir_.AppendASCII("webintent_handler"))) << message_; 312 test_data_dir_.AppendASCII("webintent_handler"))) << message_;
263 313
264 // Load the source component, with the fileUrl within the virtual mount 314 // Load the source component, with the fileUrl within the virtual mount
265 // point. 315 // point.
266 const extensions::Extension* extension = LoadExtensionAsComponent( 316 const extensions::Extension* extension = LoadExtensionAsComponent(
267 test_data_dir_.AppendASCII("filebrowser_component")); 317 test_data_dir_.AppendASCII("filebrowser_component"));
268 ASSERT_TRUE(extension) << message_; 318 ASSERT_TRUE(extension) << message_;
269 std::string path = "filesystem:chrome-extension://" + extension->id() + 319 std::string path = "filesystem:chrome-extension://" + extension->id() +
(...skipping 23 matching lines...) Expand all
293 343
294 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, 344 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest,
295 FileBrowserTestWriteComponent) { 345 FileBrowserTestWriteComponent) {
296 AddTmpMountPoint(); 346 AddTmpMountPoint();
297 ASSERT_TRUE(RunComponentExtensionTest("filesystem_handler_write")) 347 ASSERT_TRUE(RunComponentExtensionTest("filesystem_handler_write"))
298 << message_; 348 << message_;
299 ASSERT_TRUE(RunExtensionSubtest( 349 ASSERT_TRUE(RunExtensionSubtest(
300 "filebrowser_component", "write.html", kComponentFlags)) << message_; 350 "filebrowser_component", "write.html", kComponentFlags)) << message_;
301 } 351 }
302 352
353 IN_PROC_BROWSER_TEST_F(RestrictedFileSystemExtensionApiTest, Basic) {
354 AddRestrictedMountPoint();
355 ASSERT_TRUE(RunExtensionSubtest(
356 "filebrowser_component", "restricted.html", kComponentFlags)) << message_;
357 }
358
303 IN_PROC_BROWSER_TEST_F(RemoteFileSystemExtensionApiTest, 359 IN_PROC_BROWSER_TEST_F(RemoteFileSystemExtensionApiTest,
304 RemoteMountPoint) { 360 RemoteMountPoint) {
305 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1); 361 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1);
306 362
307 // First, file browser will try to create new directory. 363 // First, file browser will try to create new directory.
308 scoped_ptr<base::Value> dir_value(LoadJSONFile(kTestDirectory)); 364 scoped_ptr<base::Value> dir_value(LoadJSONFile(kTestDirectory));
309 EXPECT_CALL(*mock_drive_service_, 365 EXPECT_CALL(*mock_drive_service_,
310 CreateDirectory(_, _, _)) 366 CreateDirectory(_, _, _))
311 .WillOnce(MockCreateDirectoryCallback(gdata::HTTP_SUCCESS, &dir_value)); 367 .WillOnce(MockCreateDirectoryCallback(gdata::HTTP_SUCCESS, &dir_value));
312 368
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 _, _)) 436 _, _))
381 .WillOnce(MockDownloadFileCallback(gdata::HTTP_SUCCESS)); 437 .WillOnce(MockDownloadFileCallback(gdata::HTTP_SUCCESS));
382 438
383 // On exit, all operations in progress should be cancelled. 439 // On exit, all operations in progress should be cancelled.
384 EXPECT_CALL(*mock_drive_service_, CancelAll()); 440 EXPECT_CALL(*mock_drive_service_, CancelAll());
385 441
386 // All is set... RUN THE TEST. 442 // All is set... RUN THE TEST.
387 EXPECT_TRUE(RunExtensionSubtest("filebrowser_component", "remote_search.html", 443 EXPECT_TRUE(RunExtensionSubtest("filebrowser_component", "remote_search.html",
388 kComponentFlags)) << message_; 444 kComponentFlags)) << message_;
389 } 445 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698