Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/platform_file.h" | 6 #include "base/platform_file.h" |
| 7 #include "base/path_service.h" | |
| 8 #include "base/scoped_temp_dir.h" | |
| 7 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "chrome/browser/chromeos/gdata/gdata_file_system_proxy.h" | |
| 8 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "webkit/fileapi/file_system_context.h" | 15 #include "webkit/fileapi/file_system_context.h" |
| 13 #include "webkit/fileapi/file_system_mount_point_provider.h" | 16 #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 14 #if defined(OS_CHROMEOS) | |
| 15 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 17 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 16 #include "webkit/chromeos/fileapi/remote_file_system_proxy.h" | 18 #include "webkit/chromeos/fileapi/remote_file_system_proxy.h" |
| 17 #endif | |
| 18 | 19 |
| 19 using ::testing::_; | 20 using ::testing::_; |
| 20 using content::BrowserContext; | 21 using content::BrowserContext; |
| 21 | 22 |
| 22 #if defined(OS_CHROMEOS) | |
| 23 | |
| 24 // These should match the counterparts in remote.js. | 23 // These should match the counterparts in remote.js. |
| 25 const char kTestFileName[] = "hello.txt"; | 24 const char kTestDirPath[] = "/test_dir"; |
| 25 const char kTestFilePath[] = "/test_dir/hello.txt"; | |
| 26 const char kTestFileContents[] = "hello, world"; | 26 const char kTestFileContents[] = "hello, world"; |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // The ID of the file browser extension. | 30 // The ID of the file browser extension. |
| 31 const char kFileBrowserExtensionId[] = "ddammdhioacbehjngdmkjcjbnfginlla"; | 31 const char kFileBrowserExtensionId[] = "ddammdhioacbehjngdmkjcjbnfginlla"; |
| 32 | 32 |
| 33 // Returns the expected URL for the given path. | 33 // Returns the expected URL for the given path. |
| 34 GURL GetExpectedURL(const std::string& path) { | 34 GURL GetExpectedURL(const std::string& path) { |
| 35 return GURL( | 35 return GURL( |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 provider->AddLocalMountPoint(test_mount_point_); | 122 provider->AddLocalMountPoint(test_mount_point_); |
| 123 } | 123 } |
| 124 | 124 |
| 125 private: | 125 private: |
| 126 FilePath test_mount_point_; | 126 FilePath test_mount_point_; |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 class RemoteFileSystemExtensionApiTest : public ExtensionApiTest { | 129 class RemoteFileSystemExtensionApiTest : public ExtensionApiTest { |
| 130 public: | 130 public: |
| 131 RemoteFileSystemExtensionApiTest() | 131 RemoteFileSystemExtensionApiTest() |
| 132 : test_mount_point_("/tmp"), | 132 : mock_remote_file_system_proxy_(NULL) { |
| 133 mock_remote_file_system_proxy_(NULL) { | |
| 134 } | 133 } |
| 135 | 134 |
| 136 virtual ~RemoteFileSystemExtensionApiTest() {} | 135 virtual ~RemoteFileSystemExtensionApiTest() {} |
| 137 | 136 |
| 138 virtual void SetUp() OVERRIDE { | 137 virtual void SetUp() OVERRIDE { |
| 139 file_util::CreateTemporaryFile(&test_file_path_); | 138 FilePath tmp_dir_path; |
| 139 PathService::Get(base::DIR_TEMP, &tmp_dir_path); | |
| 140 | |
| 141 ASSERT_TRUE(test_mount_point_.CreateUniqueTempDirUnderPath(tmp_dir_path)); | |
|
tbarzic
2012/03/22 22:18:28
I randomized this to make sure the cache paths don
| |
| 142 | |
| 143 file_util::CreateTemporaryFileInDir(test_mount_point_.path(), | |
| 144 &test_file_path_); | |
| 140 file_util::WriteFile(test_file_path_, | 145 file_util::WriteFile(test_file_path_, |
| 141 kTestFileContents, | 146 kTestFileContents, |
| 142 sizeof(kTestFileContents) - 1); | 147 sizeof(kTestFileContents) - 1); |
| 143 file_util::GetFileInfo(test_file_path_, &test_file_info_); | 148 file_util::GetFileInfo(test_file_path_, &test_file_info_); |
| 144 | 149 |
| 145 // ExtensionApiTest::SetUp() should be called at the end. For some | 150 // ExtensionApiTest::SetUp() should be called at the end. For some |
| 146 // reason, ExtensionApiTest::SetUp() starts running tests, so any | 151 // reason, ExtensionApiTest::SetUp() starts running tests, so any |
| 147 // setup has to be done before calling this. | 152 // setup has to be done before calling this. |
| 148 ExtensionApiTest::SetUp(); | 153 ExtensionApiTest::SetUp(); |
| 149 } | 154 } |
| 150 | 155 |
| 151 virtual void TearDown() OVERRIDE { | |
| 152 file_util::Delete(test_file_path_, false); | |
| 153 | |
| 154 ExtensionApiTest::TearDown(); | |
| 155 } | |
| 156 | |
| 157 // Adds a remote mount point at at mount point /tmp. | 156 // Adds a remote mount point at at mount point /tmp. |
| 158 void AddTmpMountPoint() { | 157 void AddTmpMountPoint() { |
| 159 fileapi::ExternalFileSystemMountPointProvider* provider = | 158 fileapi::ExternalFileSystemMountPointProvider* provider = |
| 160 BrowserContext::GetFileSystemContext(browser()->profile())-> | 159 BrowserContext::GetFileSystemContext(browser()->profile())-> |
| 161 external_provider(); | 160 external_provider(); |
| 162 mock_remote_file_system_proxy_ = new MockRemoteFileSystemProxy; | 161 mock_remote_file_system_proxy_ = new MockRemoteFileSystemProxy; |
| 163 // Take the ownership of mock_remote_file_system_proxy_. | 162 // Take the ownership of mock_remote_file_system_proxy_. |
| 164 provider->AddRemoteMountPoint(test_mount_point_, | 163 provider->AddRemoteMountPoint(test_mount_point_.path(), |
| 165 mock_remote_file_system_proxy_); | 164 mock_remote_file_system_proxy_); |
| 165 } | |
| 166 | |
| 167 std::string GetPathOnMountPoint(const std::string& path) { | |
| 168 return test_mount_point_.path().BaseName().value() + path; | |
| 166 } | 169 } |
| 167 | 170 |
| 168 protected: | 171 protected: |
| 169 base::PlatformFileInfo test_file_info_; | 172 base::PlatformFileInfo test_file_info_; |
| 170 FilePath test_file_path_; | 173 FilePath test_file_path_; |
| 171 FilePath test_mount_point_; | 174 ScopedTempDir test_mount_point_; |
| 172 MockRemoteFileSystemProxy* mock_remote_file_system_proxy_; | 175 MockRemoteFileSystemProxy* mock_remote_file_system_proxy_; |
| 173 }; | 176 }; |
| 174 | 177 |
| 175 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, LocalFileSystem) { | 178 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, LocalFileSystem) { |
| 176 AddTmpMountPoint(); | 179 AddTmpMountPoint(); |
| 177 ASSERT_TRUE(RunComponentExtensionTest("local_filesystem")) << message_; | 180 ASSERT_TRUE(RunComponentExtensionTest("local_filesystem")) << message_; |
| 178 } | 181 } |
| 179 | 182 |
| 180 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, FileBrowserTest) { | 183 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, FileBrowserTest) { |
| 181 AddTmpMountPoint(); | 184 AddTmpMountPoint(); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 195 FileBrowserTestWriteComponent) { | 198 FileBrowserTestWriteComponent) { |
| 196 AddTmpMountPoint(); | 199 AddTmpMountPoint(); |
| 197 ASSERT_TRUE(RunComponentExtensionTest("filesystem_handler_write")) | 200 ASSERT_TRUE(RunComponentExtensionTest("filesystem_handler_write")) |
| 198 << message_; | 201 << message_; |
| 199 ASSERT_TRUE(RunComponentExtensionSubtest("filebrowser_component", | 202 ASSERT_TRUE(RunComponentExtensionSubtest("filebrowser_component", |
| 200 "write.html")) << message_; | 203 "write.html")) << message_; |
| 201 } | 204 } |
| 202 | 205 |
| 203 IN_PROC_BROWSER_TEST_F(RemoteFileSystemExtensionApiTest, RemoteMountPoint) { | 206 IN_PROC_BROWSER_TEST_F(RemoteFileSystemExtensionApiTest, RemoteMountPoint) { |
| 204 AddTmpMountPoint(); | 207 AddTmpMountPoint(); |
| 205 | |
| 206 // The test directory is created first. | 208 // The test directory is created first. |
| 207 const GURL test_dir_url = GetExpectedURL("tmp/test_dir"); | 209 const GURL test_dir_url = |
| 210 GetExpectedURL(GetPathOnMountPoint(kTestDirPath)); | |
| 208 EXPECT_CALL(*mock_remote_file_system_proxy_, | 211 EXPECT_CALL(*mock_remote_file_system_proxy_, |
| 209 CreateDirectory(test_dir_url, false, false, _)) | 212 CreateDirectory(test_dir_url, false, false, _)) |
| 210 .WillOnce(MockCreateDirectory(base::PLATFORM_FILE_OK)); | 213 .WillOnce(MockCreateDirectory(base::PLATFORM_FILE_OK)); |
| 211 | 214 |
| 212 // Then GetFileInfo() is called over "tmp/test_dir/hello.txt". | 215 // Then GetFileInfo() is called over "tmp/test_dir/hello.txt". |
| 213 const std::string expected_path = | 216 const std::string expected_path = GetPathOnMountPoint(kTestFilePath); |
| 214 std::string("tmp/test_dir/") + kTestFileName; | |
| 215 GURL expected_url = GetExpectedURL(expected_path); | 217 GURL expected_url = GetExpectedURL(expected_path); |
| 216 EXPECT_CALL(*mock_remote_file_system_proxy_, | 218 EXPECT_CALL(*mock_remote_file_system_proxy_, |
| 217 GetFileInfo(expected_url, _)) | 219 GetFileInfo(expected_url, _)) |
| 218 .WillOnce(MockGetFileInfo( | 220 .WillOnce(MockGetFileInfo( |
| 219 base::PLATFORM_FILE_OK, | 221 base::PLATFORM_FILE_OK, |
| 220 test_file_info_, | 222 test_file_info_, |
| 221 FilePath::FromUTF8Unsafe(expected_path))); | 223 FilePath::FromUTF8Unsafe(expected_path))); |
| 222 | 224 |
| 223 // Then CreateSnapshotFile() is called over "tmp/test_dir/hello.txt". | 225 // Then CreateSnapshotFile() is called over "tmp/test_dir/hello.txt". |
| 224 EXPECT_CALL(*mock_remote_file_system_proxy_, | 226 EXPECT_CALL(*mock_remote_file_system_proxy_, |
| 225 CreateSnapshotFile(expected_url, _)) | 227 CreateSnapshotFile(expected_url, _)) |
| 226 .WillOnce(MockCreateSnapshotFile( | 228 .WillOnce(MockCreateSnapshotFile( |
| 227 base::PLATFORM_FILE_OK, | 229 base::PLATFORM_FILE_OK, |
| 228 test_file_info_, | 230 test_file_info_, |
| 229 // Returns the path to the temporary file on the local drive. | 231 // Returns the path to the temporary file on the local drive. |
| 230 test_file_path_, | 232 test_file_path_, |
| 231 scoped_refptr<webkit_blob::ShareableFileReference>(NULL))); | 233 scoped_refptr<webkit_blob::ShareableFileReference>(NULL))); |
| 232 | 234 ASSERT_TRUE(RunComponentExtensionSubtest( |
| 233 ASSERT_TRUE(RunComponentExtensionSubtest("filebrowser_component", | 235 "filebrowser_component", |
| 234 "remote.html")) << message_; | 236 "remote.html#" + GetPathOnMountPoint(""))) << message_; |
| 235 } | 237 } |
| 236 | |
| 237 #endif | |
| OLD | NEW |