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" | 7 #include "base/path_service.h" |
8 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "chrome/browser/chromeos/gdata/gdata_file_system_proxy.h" | 10 #include "chrome/browser/chromeos/gdata/gdata_file_system_proxy.h" |
| 11 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
11 #include "chrome/browser/extensions/extension_apitest.h" | 12 #include "chrome/browser/extensions/extension_apitest.h" |
| 13 #include "chrome/browser/extensions/extension_test_message_listener.h" |
12 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" |
| 19 #include "content/public/browser/notification_service.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "webkit/fileapi/file_system_context.h" | 21 #include "webkit/fileapi/file_system_context.h" |
16 #include "webkit/fileapi/file_system_mount_point_provider.h" | 22 #include "webkit/fileapi/file_system_mount_point_provider.h" |
17 #include "chrome/browser/chromeos/gdata/gdata_util.h" | |
18 #include "webkit/chromeos/fileapi/remote_file_system_proxy.h" | 23 #include "webkit/chromeos/fileapi/remote_file_system_proxy.h" |
19 | 24 |
20 using ::testing::_; | 25 using ::testing::_; |
21 using content::BrowserContext; | 26 using content::BrowserContext; |
22 | 27 |
23 // These should match the counterparts in remote.js. | 28 // These should match the counterparts in remote.js. |
24 const char kTestDirPath[] = "/test_dir"; | 29 const char kTestDirPath[] = "/test_dir"; |
25 const char kTestFilePath[] = "/test_dir/hello.txt"; | 30 const char kTestFilePath[] = "/test_dir/hello.txt"; |
26 const char kTestFileContents[] = "hello, world"; | 31 const char kTestFileContents[] = "hello, world"; |
27 | 32 |
28 namespace { | 33 namespace { |
29 | 34 |
30 // The ID of the file browser extension. | 35 // The ID of the file browser extension. |
31 const char kFileBrowserExtensionId[] = "ddammdhioacbehjngdmkjcjbnfginlla"; | 36 const char kFileBrowserExtensionId[] = "ddammdhioacbehjngdmkjcjbnfginlla"; |
32 | 37 |
33 // Flags used to run the tests with a COMPONENT extension. | 38 // Flags used to run the tests with a COMPONENT extension. |
34 const int kComponentFlags = ExtensionApiTest::kFlagEnableFileAccess | | 39 const int kComponentFlags = ExtensionApiTest::kFlagEnableFileAccess | |
35 ExtensionApiTest::kFlagLoadAsComponent; | 40 ExtensionApiTest::kFlagLoadAsComponent; |
36 | 41 |
| 42 // Helper class to wait for a background page to load or close again. |
| 43 // TODO(tbarzic): We can probably share this with e.g. |
| 44 // lazy_background_page_apitest. |
| 45 class BackgroundObserver { |
| 46 public: |
| 47 BackgroundObserver() |
| 48 : page_created_(chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, |
| 49 content::NotificationService::AllSources()), |
| 50 page_closed_(chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 51 content::NotificationService::AllSources()) { |
| 52 } |
| 53 |
| 54 // TODO(tbarzic): Use this for file handlers in the rest of the tests |
| 55 // (instead of calling chrome.test.succeed in js). |
| 56 void WaitUntilLoaded() { |
| 57 page_created_.Wait(); |
| 58 } |
| 59 |
| 60 void WaitUntilClosed() { |
| 61 page_closed_.Wait(); |
| 62 } |
| 63 |
| 64 private: |
| 65 ui_test_utils::WindowedNotificationObserver page_created_; |
| 66 ui_test_utils::WindowedNotificationObserver page_closed_; |
| 67 }; |
| 68 |
37 // Returns the expected URL for the given path. | 69 // Returns the expected URL for the given path. |
38 GURL GetExpectedURL(const std::string& path) { | 70 GURL GetExpectedURL(const std::string& path) { |
39 return GURL( | 71 return GURL( |
40 base::StringPrintf( | 72 base::StringPrintf( |
41 "filesystem:chrome-extension://%s/external/%s", | 73 "filesystem:chrome-extension://%s/external/%s", |
42 kFileBrowserExtensionId, | 74 kFileBrowserExtensionId, |
43 path.c_str())); | 75 path.c_str())); |
44 } | 76 } |
45 | 77 |
46 // Action used to set mock expectations for CreateDirectory(). | 78 // Action used to set mock expectations for CreateDirectory(). |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 "Got unexpected error: File handler error: SECURITY_ERR"; | 143 "Got unexpected error: File handler error: SECURITY_ERR"; |
112 } | 144 } |
113 | 145 |
114 class FileSystemExtensionApiTest : public ExtensionApiTest { | 146 class FileSystemExtensionApiTest : public ExtensionApiTest { |
115 public: | 147 public: |
116 FileSystemExtensionApiTest() : test_mount_point_("/tmp") { | 148 FileSystemExtensionApiTest() : test_mount_point_("/tmp") { |
117 } | 149 } |
118 | 150 |
119 virtual ~FileSystemExtensionApiTest() {} | 151 virtual ~FileSystemExtensionApiTest() {} |
120 | 152 |
| 153 void SetUpCommandLine(CommandLine* command_line) { |
| 154 ExtensionApiTest::SetUpCommandLine(command_line); |
| 155 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
| 156 } |
| 157 |
121 // Adds a local mount point at at mount point /tmp. | 158 // Adds a local mount point at at mount point /tmp. |
122 void AddTmpMountPoint() { | 159 void AddTmpMountPoint() { |
123 fileapi::ExternalFileSystemMountPointProvider* provider = | 160 fileapi::ExternalFileSystemMountPointProvider* provider = |
124 BrowserContext::GetFileSystemContext(browser()->profile())-> | 161 BrowserContext::GetFileSystemContext(browser()->profile())-> |
125 external_provider(); | 162 external_provider(); |
126 provider->AddLocalMountPoint(test_mount_point_); | 163 provider->AddLocalMountPoint(test_mount_point_); |
127 } | 164 } |
128 | 165 |
| 166 // Loads the extension, which temporarily starts the lazy background page |
| 167 // to dispatch the onInstalled event. We wait until it shuts down again. |
| 168 const Extension* LoadExtensionAndWait(const std::string& test_name) { |
| 169 BackgroundObserver page_complete; |
| 170 FilePath extdir = test_data_dir_.AppendASCII(test_name); |
| 171 const Extension* extension = LoadExtension(extdir); |
| 172 if (extension) |
| 173 page_complete.WaitUntilClosed(); |
| 174 return extension; |
| 175 } |
| 176 |
129 private: | 177 private: |
130 FilePath test_mount_point_; | 178 FilePath test_mount_point_; |
131 }; | 179 }; |
132 | 180 |
133 class RemoteFileSystemExtensionApiTest : public ExtensionApiTest { | 181 class RemoteFileSystemExtensionApiTest : public ExtensionApiTest { |
134 public: | 182 public: |
135 RemoteFileSystemExtensionApiTest() | 183 RemoteFileSystemExtensionApiTest() |
136 : mock_remote_file_system_proxy_(NULL) { | 184 : mock_remote_file_system_proxy_(NULL) { |
137 } | 185 } |
138 | 186 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 ASSERT_TRUE(RunComponentExtensionTest("local_filesystem")) << message_; | 232 ASSERT_TRUE(RunComponentExtensionTest("local_filesystem")) << message_; |
185 } | 233 } |
186 | 234 |
187 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, FileBrowserTest) { | 235 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, FileBrowserTest) { |
188 AddTmpMountPoint(); | 236 AddTmpMountPoint(); |
189 ASSERT_TRUE(RunExtensionTest("filesystem_handler")) << message_; | 237 ASSERT_TRUE(RunExtensionTest("filesystem_handler")) << message_; |
190 ASSERT_TRUE(RunExtensionSubtest( | 238 ASSERT_TRUE(RunExtensionSubtest( |
191 "filebrowser_component", "read.html", kComponentFlags)) << message_; | 239 "filebrowser_component", "read.html", kComponentFlags)) << message_; |
192 } | 240 } |
193 | 241 |
| 242 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, FileBrowserTestLazy) { |
| 243 AddTmpMountPoint(); |
| 244 ASSERT_TRUE(LoadExtensionAndWait("filesystem_handler_lazy_background")) |
| 245 << message_; |
| 246 ASSERT_TRUE(RunExtensionSubtest( |
| 247 "filebrowser_component", "read.html", kComponentFlags)) << message_; |
| 248 } |
| 249 |
194 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, FileBrowserTestWrite) { | 250 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, FileBrowserTestWrite) { |
195 AddTmpMountPoint(); | 251 AddTmpMountPoint(); |
196 ASSERT_TRUE(RunExtensionTest("filesystem_handler_write")) << message_; | 252 ASSERT_TRUE(RunExtensionTest("filesystem_handler_write")) << message_; |
197 ASSERT_TRUE(RunExtensionSubtest( | 253 ASSERT_TRUE(RunExtensionSubtest( |
198 "filebrowser_component", "write.html", kComponentFlags)) << message_; | 254 "filebrowser_component", "write.html", kComponentFlags)) << message_; |
199 } | 255 } |
200 | 256 |
201 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, | 257 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, |
202 FileBrowserTestWriteReadOnly) { | 258 FileBrowserTestWriteReadOnly) { |
203 AddTmpMountPoint(); | 259 AddTmpMountPoint(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 .WillOnce(MockCreateSnapshotFile( | 296 .WillOnce(MockCreateSnapshotFile( |
241 base::PLATFORM_FILE_OK, | 297 base::PLATFORM_FILE_OK, |
242 test_file_info_, | 298 test_file_info_, |
243 // Returns the path to the temporary file on the local drive. | 299 // Returns the path to the temporary file on the local drive. |
244 test_file_path_, | 300 test_file_path_, |
245 scoped_refptr<webkit_blob::ShareableFileReference>(NULL))); | 301 scoped_refptr<webkit_blob::ShareableFileReference>(NULL))); |
246 ASSERT_TRUE(RunExtensionSubtest( | 302 ASSERT_TRUE(RunExtensionSubtest( |
247 "filebrowser_component", "remote.html#" + GetPathOnMountPoint(""), | 303 "filebrowser_component", "remote.html#" + GetPathOnMountPoint(""), |
248 kComponentFlags)) << message_; | 304 kComponentFlags)) << message_; |
249 } | 305 } |
OLD | NEW |