diff options
author | tbarzic@chromium.org <tbarzic@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-28 23:26:21 +0000 |
---|---|---|
committer | tbarzic@chromium.org <tbarzic@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-28 23:26:21 +0000 |
commit | 5bfe52255baf07910a03d48b686675741a15cb9b (patch) | |
tree | ffe692da6f121bcc00901bcb11ffb373d1bd80bc /chrome/browser/extensions | |
parent | 427636ffcfdbcb4d77aae58225208ff601809fae (diff) | |
download | chromium_src-5bfe52255baf07910a03d48b686675741a15cb9b.zip chromium_src-5bfe52255baf07910a03d48b686675741a15cb9b.tar.gz chromium_src-5bfe52255baf07910a03d48b686675741a15cb9b.tar.bz2 |
Making fileBrowserPrivate.removeMount translate argument from fileUrl to its fileSystem path before calling MountLibrary
BUG=chromium-os:18325
TEST=ran ExtensionFileBrowserPrivateApiTest.*
Review URL: http://codereview.chromium.org/7493060
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94578 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
3 files changed, 49 insertions, 5 deletions
diff --git a/chrome/browser/extensions/extension_file_browser_private_api.cc b/chrome/browser/extensions/extension_file_browser_private_api.cc index 7ef2d1b..abd7fd0 100644 --- a/chrome/browser/extensions/extension_file_browser_private_api.cc +++ b/chrome/browser/extensions/extension_file_browser_private_api.cc @@ -1215,13 +1215,33 @@ bool RemoveMountFunction::RunImpl() { return false; } + UrlList file_paths; + file_paths.push_back(GURL(mount_path)); + + BrowserThread::PostTask( + BrowserThread::FILE, FROM_HERE, + NewRunnableMethod(this, + &RemoveMountFunction::GetLocalPathsOnFileThread, + file_paths, reinterpret_cast<void*>(NULL))); + return true; +} + +void RemoveMountFunction::GetLocalPathsResponseOnUIThread( + const FilePathList& files, void* context) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK(!context); + + if (files.size() != 1) { + SendResponse(false); + return; + } + #ifdef OS_CHROMEOS chromeos::CrosLibrary::Get()->GetMountLibrary()->UnmountPath( - mount_path.c_str()); + files[0].value().c_str()); #endif SendResponse(true); - return true; } GetMountPointsFunction::GetMountPointsFunction() { diff --git a/chrome/browser/extensions/extension_file_browser_private_api.h b/chrome/browser/extensions/extension_file_browser_private_api.h index cec9f70..2df3e9f 100644 --- a/chrome/browser/extensions/extension_file_browser_private_api.h +++ b/chrome/browser/extensions/extension_file_browser_private_api.h @@ -247,14 +247,17 @@ class AddMountFunction // Unmounts selected device. Expects mount point path as an argument. class RemoveMountFunction - : public SyncExtensionFunction { + : public FileBrowserFunction { public: RemoveMountFunction(); protected: virtual ~RemoveMountFunction(); + // FileBrowserFunction overrides. virtual bool RunImpl() OVERRIDE; + virtual void GetLocalPathsResponseOnUIThread(const FilePathList& files, + void* context) OVERRIDE; private: DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.removeMount"); diff --git a/chrome/browser/extensions/extension_file_browser_private_apitest.cc b/chrome/browser/extensions/extension_file_browser_private_apitest.cc index 58d41c9..f381104 100644 --- a/chrome/browser/extensions/extension_file_browser_private_apitest.cc +++ b/chrome/browser/extensions/extension_file_browser_private_apitest.cc @@ -2,9 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <stdio.h> + #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/mock_mount_library.h" #include "chrome/browser/extensions/extension_apitest.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" +#include "webkit/fileapi/file_system_context.h" +#include "webkit/fileapi/file_system_mount_point_provider.h" +#include "webkit/fileapi/file_system_path_manager.h" using ::testing::_; using ::testing::ReturnRef; @@ -12,7 +19,7 @@ using ::testing::StrEq; class ExtensionFileBrowserPrivateApiTest : public ExtensionApiTest { public: - ExtensionFileBrowserPrivateApiTest() { + ExtensionFileBrowserPrivateApiTest() : test_mount_point_("/tmp") { mount_library_mock_.SetupDefaultReplies(); chromeos::CrosLibrary::Get()->GetTestApi()->SetMountLibrary( @@ -27,6 +34,14 @@ class ExtensionFileBrowserPrivateApiTest : public ExtensionApiTest { chromeos::CrosLibrary::Get()->GetTestApi()->SetMountLibrary(NULL, true); } + void AddTmpMountPoint() { + fileapi::FileSystemPathManager* path_manager = + browser()->profile()->GetFileSystemContext()->path_manager(); + fileapi::ExternalFileSystemMountPointProvider* provider = + path_manager->external_provider(); + provider->AddMountPoint(test_mount_point_); + } + private: void CreateVolumeMap() { // These have to be sync'd with values in filebrowser_mount extension. @@ -92,12 +107,18 @@ class ExtensionFileBrowserPrivateApiTest : public ExtensionApiTest { protected: chromeos::MockMountLibrary mount_library_mock_; chromeos::MountLibrary::DiskMap volumes_; + + private: + FilePath test_mount_point_; }; IN_PROC_BROWSER_TEST_F(ExtensionFileBrowserPrivateApiTest, FileBrowserMount) { // We will call fileBrowserPrivate.unmountVolume once. To test that method, we // check that UnmountPath is really called with the same value. - EXPECT_CALL(mount_library_mock_, UnmountPath(StrEq("devicePath1"))) + AddTmpMountPoint(); + EXPECT_CALL(mount_library_mock_, UnmountPath(_)) + .Times(0); + EXPECT_CALL(mount_library_mock_, UnmountPath(StrEq("/tmp/test_file.zip"))) .Times(1); EXPECT_CALL(mount_library_mock_, disks()) |