OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // Browser test for basic Chrome OS file manager functionality: | 5 // Browser test for basic Chrome OS file manager functionality: |
6 // - The file list is updated when a file is added externally to the Downloads | 6 // - The file list is updated when a file is added externally to the Downloads |
7 // folder. | 7 // folder. |
8 // - Selecting a file and copy-pasting it with the keyboard copies the file. | 8 // - Selecting a file and copy-pasting it with the keyboard copies the file. |
9 // - Selecting a file and pressing delete deletes it. | 9 // - Selecting a file and pressing delete deletes it. |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #include "base/files/file_path_watcher.h" | |
18 #include "base/run_loop.h" | |
19 #include "base/time.h" | 17 #include "base/time.h" |
20 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 18 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
21 #include "chrome/browser/chromeos/drive/file_system_interface.h" | 19 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
22 #include "chrome/browser/chromeos/drive/file_system_observer.h" | |
23 #include "chrome/browser/chromeos/extensions/file_manager/drive_test_util.h" | 20 #include "chrome/browser/chromeos/extensions/file_manager/drive_test_util.h" |
24 #include "chrome/browser/extensions/component_loader.h" | 21 #include "chrome/browser/extensions/component_loader.h" |
25 #include "chrome/browser/extensions/extension_apitest.h" | 22 #include "chrome/browser/extensions/extension_apitest.h" |
26 #include "chrome/browser/extensions/extension_test_message_listener.h" | 23 #include "chrome/browser/extensions/extension_test_message_listener.h" |
27 #include "chrome/browser/google_apis/fake_drive_service.h" | 24 #include "chrome/browser/google_apis/fake_drive_service.h" |
28 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 25 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
29 #include "chrome/browser/google_apis/test_util.h" | 26 #include "chrome/browser/google_apis/test_util.h" |
30 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/extensions/extension.h" | 29 #include "chrome/common/extensions/extension.h" |
33 #include "chromeos/chromeos_switches.h" | 30 #include "chromeos/chromeos_switches.h" |
34 #include "content/public/browser/browser_context.h" | 31 #include "content/public/browser/browser_context.h" |
35 #include "webkit/browser/fileapi/external_mount_points.h" | 32 #include "webkit/browser/fileapi/external_mount_points.h" |
36 | 33 |
37 namespace { | 34 namespace { |
38 | 35 |
39 const char kKeyboardTestFileName[] = "world.ogv"; | |
40 const char kKeyboardTestFileCopyName[] = "world (1).ogv"; | |
41 | |
42 // Test suffixes appended to the Javascript tests' names. | 36 // Test suffixes appended to the Javascript tests' names. |
43 const char kDownloadsVolume[] = "Downloads"; | 37 const char kDownloadsVolume[] = "Downloads"; |
44 const char kDriveVolume[] = "Drive"; | 38 const char kDriveVolume[] = "Drive"; |
45 | 39 |
46 enum EntryType { | 40 enum EntryType { |
47 FILE, | 41 FILE, |
48 DIRECTORY, | 42 DIRECTORY, |
49 }; | 43 }; |
50 | 44 |
51 enum SharedOption { | 45 enum SharedOption { |
52 NONE, | 46 NONE, |
53 SHARED, | 47 SHARED, |
54 }; | 48 }; |
55 | 49 |
56 struct TestEntryInfo { | 50 struct TestEntryInfo { |
57 EntryType type; | 51 EntryType type; |
58 const char* source_file_name; // Source file name to be used as a prototype. | 52 const char* source_file_name; // Source file name to be used as a prototype. |
59 const char* target_name; // Target file or directory name. | 53 const char* target_name; // Target file or directory name. |
60 const char* mime_type; | 54 const char* mime_type; |
61 SharedOption shared_option; | 55 SharedOption shared_option; |
62 const char* last_modified_time_as_string; | 56 const char* last_modified_time_as_string; |
63 }; | 57 }; |
64 | 58 |
65 TestEntryInfo kTestEntrySetCommon[] = { | 59 TestEntryInfo kTestEntrySetCommon[] = { |
66 { FILE, "text.txt", "hello.txt", "text/plain", NONE, "4 Sep 1998 12:34:56" }, | 60 { FILE, "text.txt", "hello.txt", "text/plain", NONE, "4 Sep 1998 12:34:56" }, |
67 { FILE, "image.png", "My Desktop Background.png", "text/plain", NONE, | 61 { FILE, "image.png", "My Desktop Background.png", "text/plain", NONE, |
68 "18 Jan 2038 01:02:03" }, | 62 "18 Jan 2038 01:02:03" }, |
69 { FILE, "video.ogv", kKeyboardTestFileName, "text/plain", NONE, | 63 { FILE, "video.ogv", "world.ogv", "text/plain", NONE, |
70 "4 July 2012 10:35:00" }, | 64 "4 July 2012 10:35:00" }, |
71 { DIRECTORY, "", "photos", NULL, NONE, "1 Jan 1980 23:59:59" }, | 65 { DIRECTORY, "", "photos", NULL, NONE, "1 Jan 1980 23:59:59" }, |
72 { DIRECTORY, "", ".warez", NULL, NONE, "26 Oct 1985 13:39" } | 66 { DIRECTORY, "", ".warez", NULL, NONE, "26 Oct 1985 13:39" } |
73 }; | 67 }; |
74 | 68 |
75 TestEntryInfo kTestEntrySetDriveOnly[] = { | 69 TestEntryInfo kTestEntrySetDriveOnly[] = { |
76 { FILE, "", "Test Document", "application/vnd.google-apps.document", NONE, | 70 { FILE, "", "Test Document", "application/vnd.google-apps.document", NONE, |
77 "10 Apr 2013 16:20:00" }, | 71 "10 Apr 2013 16:20:00" }, |
78 { FILE, "", "Test Shared Document", "application/vnd.google-apps.document", | 72 { FILE, "", "Test Shared Document", "application/vnd.google-apps.document", |
79 SHARED, "20 Mar 2013 22:40:00" } | 73 SHARED, "20 Mar 2013 22:40:00" } |
80 }; | 74 }; |
81 | 75 |
82 // Monitors changes to a single file until the supplied condition callback | |
83 // returns true. Usage: | |
84 // TestFilePathWatcher watcher(path_to_file, MyConditionCallback); | |
85 // watcher.StartAndWaitUntilReady(); | |
86 // ... trigger filesystem modification ... | |
87 // watcher.RunMessageLoopUntilConditionSatisfied(); | |
88 class TestFilePathWatcher { | |
89 public: | |
90 typedef base::Callback<bool(const base::FilePath& file_path)> | |
91 ConditionCallback; | |
92 | |
93 // Stores the supplied |path| and |condition| for later use (no side effects). | |
94 TestFilePathWatcher(const base::FilePath& path, | |
95 const ConditionCallback& condition); | |
96 | |
97 // Waits (running a message pump) until the callback returns true or | |
98 // FilePathWatcher reports an error. Return true on success. | |
99 bool RunMessageLoopUntilConditionSatisfied(); | |
100 | |
101 private: | |
102 // Starts the FilePathWatcher to watch the target file. Also check if the | |
103 // condition is already met. | |
104 void StartWatching(); | |
105 | |
106 // FilePathWatcher callback (on the FILE thread). Posts Done() to the UI | |
107 // thread when the condition is satisfied or there is an error. | |
108 void FilePathWatcherCallback(const base::FilePath& path, bool error); | |
109 | |
110 const base::FilePath path_; | |
111 ConditionCallback condition_; | |
112 scoped_ptr<base::FilePathWatcher> watcher_; | |
113 base::RunLoop run_loop_; | |
114 base::Closure quit_closure_; | |
115 bool failed_; | |
116 }; | |
117 | |
118 TestFilePathWatcher::TestFilePathWatcher(const base::FilePath& path, | |
119 const ConditionCallback& condition) | |
120 : path_(path), | |
121 condition_(condition), | |
122 quit_closure_(run_loop_.QuitClosure()), | |
123 failed_(false) { | |
124 } | |
125 | |
126 void TestFilePathWatcher::StartWatching() { | |
127 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | |
128 | |
129 watcher_.reset(new base::FilePathWatcher); | |
130 failed_ = !watcher_->Watch( | |
131 path_, false /*recursive*/, | |
132 base::Bind(&TestFilePathWatcher::FilePathWatcherCallback, | |
133 base::Unretained(this))); | |
134 | |
135 // If failed to start the watcher, then quit the message loop immediately. | |
136 // Also, if the condition was already met before FilePathWatcher was launched, | |
137 // FilePathWatcher won't be able to detect a change, so check the condition | |
138 // here. | |
139 if (failed_ || condition_.Run(path_)) { | |
140 watcher_.reset(); | |
141 content::BrowserThread::PostTask(content::BrowserThread::UI, | |
142 FROM_HERE, | |
143 quit_closure_); | |
144 return; | |
145 } | |
146 } | |
147 | |
148 void TestFilePathWatcher::FilePathWatcherCallback(const base::FilePath& path, | |
149 bool failed) { | |
150 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | |
151 DCHECK_EQ(path_.value(), path.value()); | |
152 | |
153 if (failed || condition_.Run(path)) { | |
154 failed_ = failed; | |
155 watcher_.reset(); | |
156 content::BrowserThread::PostTask(content::BrowserThread::UI, | |
157 FROM_HERE, | |
158 quit_closure_); | |
159 } | |
160 } | |
161 | |
162 bool TestFilePathWatcher::RunMessageLoopUntilConditionSatisfied() { | |
163 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
164 | |
165 content::BrowserThread::PostTask( | |
166 content::BrowserThread::FILE, | |
167 FROM_HERE, | |
168 base::Bind(&TestFilePathWatcher::StartWatching, | |
169 base::Unretained(this))); | |
170 | |
171 // Wait until the condition is met. | |
172 run_loop_.Run(); | |
173 return !failed_; | |
174 } | |
175 | |
176 // Returns true if a file with the given size is present at |path|. | |
177 bool FilePresentWithSize(const int64 file_size, | |
178 const base::FilePath& path) { | |
179 int64 copy_size = 0; | |
180 // If the file doesn't exist yet this will fail and we'll keep waiting. | |
181 if (!file_util::GetFileSize(path, ©_size)) | |
182 return false; | |
183 return (copy_size == file_size); | |
184 } | |
185 | |
186 // Returns true if a file is not present at |path|. | |
187 bool FileNotPresent(const base::FilePath& path) { | |
188 return !file_util::PathExists(path); | |
189 }; | |
190 | |
191 // The base class of volumes for test. | 76 // The base class of volumes for test. |
192 // Sub-classes of this class are used by test cases and provide operations such | 77 // Sub-classes of this class are used by test cases and provide operations such |
193 // as creating files for each type of test volume. | 78 // as creating files for each type of test volume. |
194 class TestVolume { | 79 class TestVolume { |
195 public: | 80 public: |
196 virtual ~TestVolume() {} | 81 virtual ~TestVolume() {} |
197 | 82 |
198 // Creates an entry with given information. | 83 // Creates an entry with given information. |
199 virtual void CreateEntry(const TestEntryInfo& entry) = 0; | 84 virtual void CreateEntry(const TestEntryInfo& entry) = 0; |
200 | 85 |
201 // Returns the path of the root directory. | |
202 virtual base::FilePath GetRootPath() const = 0; | |
203 | |
204 // Returns true if |file_path| exists. | |
205 virtual bool PathExists(const base::FilePath& file_path) const = 0; | |
206 | |
207 // Returns the name of volume such as "Downloads" or "Drive". | 86 // Returns the name of volume such as "Downloads" or "Drive". |
208 virtual std::string GetName() const = 0; | 87 virtual std::string GetName() const = 0; |
209 | |
210 // Waits until a file with the given size is present at |path|. Returns | |
211 // true on success. | |
212 virtual bool WaitUntilFilePresentWithSize(const base::FilePath& file_path, | |
213 int64 file_size) = 0; | |
214 | |
215 // Waits until a file is not present at |path|. Returns true on success. | |
216 virtual bool WaitUntilFileNotPresent(const base::FilePath& file_path) = 0; | |
217 }; | 88 }; |
218 | 89 |
219 // The local volume class for test. | 90 // The local volume class for test. |
220 // This class provides the operations for a test volume that simulates local | 91 // This class provides the operations for a test volume that simulates local |
221 // drive. | 92 // drive. |
222 class LocalTestVolume : public TestVolume { | 93 class LocalTestVolume : public TestVolume { |
223 public: | 94 public: |
224 explicit LocalTestVolume(const std::string& mount_name) | 95 explicit LocalTestVolume(const std::string& mount_name) |
225 : mount_name_(mount_name) { | 96 : mount_name_(mount_name) { |
226 } | 97 } |
227 | 98 |
228 LocalTestVolume(const std::string& mount_name, | |
229 const base::FilePath& local_path) | |
230 : mount_name_(mount_name), | |
231 local_path_(local_path) { | |
232 } | |
233 | |
234 // Adds this volume to the file system as a local volume. Returns true on | 99 // Adds this volume to the file system as a local volume. Returns true on |
235 // success. | 100 // success. |
236 bool Mount(Profile* profile) { | 101 bool Mount(Profile* profile) { |
237 if (local_path_.empty()) { | 102 if (local_path_.empty()) { |
238 if (!tmp_dir_.CreateUniqueTempDir()) | 103 if (!tmp_dir_.CreateUniqueTempDir()) |
239 return false; | 104 return false; |
240 local_path_ = tmp_dir_.path().Append(mount_name_); | 105 local_path_ = tmp_dir_.path().Append(mount_name_); |
241 } | 106 } |
242 fileapi::ExternalMountPoints* const mount_points = | 107 fileapi::ExternalMountPoints* const mount_points = |
243 content::BrowserContext::GetMountPoints(profile); | 108 content::BrowserContext::GetMountPoints(profile); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 "Failed to create a directory: " << target_name; | 156 "Failed to create a directory: " << target_name; |
292 base::Time time; | 157 base::Time time; |
293 ASSERT_TRUE(base::Time::FromString(modification_time.c_str(), &time)); | 158 ASSERT_TRUE(base::Time::FromString(modification_time.c_str(), &time)); |
294 ASSERT_TRUE(file_util::SetLastModifiedTime(path, time)); | 159 ASSERT_TRUE(file_util::SetLastModifiedTime(path, time)); |
295 } | 160 } |
296 | 161 |
297 virtual std::string GetName() const OVERRIDE { | 162 virtual std::string GetName() const OVERRIDE { |
298 return mount_name_; | 163 return mount_name_; |
299 } | 164 } |
300 | 165 |
301 virtual base::FilePath GetRootPath() const OVERRIDE { | |
302 return local_path_; | |
303 } | |
304 | |
305 virtual bool PathExists(const base::FilePath& file_path) const OVERRIDE { | |
306 return file_util::PathExists(file_path); | |
307 } | |
308 | |
309 virtual bool WaitUntilFilePresentWithSize( | |
310 const base::FilePath& file_path, | |
311 int64 file_size) OVERRIDE { | |
312 TestFilePathWatcher watcher(file_path, base::Bind(FilePresentWithSize, | |
313 file_size)); | |
314 return watcher.RunMessageLoopUntilConditionSatisfied(); | |
315 } | |
316 | |
317 virtual bool WaitUntilFileNotPresent( | |
318 const base::FilePath& file_path) OVERRIDE { | |
319 TestFilePathWatcher watcher(file_path, base::Bind(FileNotPresent)); | |
320 return watcher.RunMessageLoopUntilConditionSatisfied(); | |
321 } | |
322 | |
323 private: | 166 private: |
324 std::string mount_name_; | 167 std::string mount_name_; |
325 base::FilePath local_path_; | 168 base::FilePath local_path_; |
326 base::ScopedTempDir tmp_dir_; | 169 base::ScopedTempDir tmp_dir_; |
327 }; | 170 }; |
328 | 171 |
329 // The drive volume class for test. | 172 // The drive volume class for test. |
330 // This class provides the operations for a test volume that simulates Google | 173 // This class provides the operations for a test volume that simulates Google |
331 // drive. | 174 // drive. |
332 class DriveTestVolume : public TestVolume, | 175 class DriveTestVolume : public TestVolume { |
333 public drive::FileSystemObserver { | |
334 public: | 176 public: |
335 DriveTestVolume() : fake_drive_service_(NULL), | 177 DriveTestVolume() : fake_drive_service_(NULL), |
336 integration_service_(NULL), | 178 integration_service_(NULL) { |
337 waiting_for_directory_change_(false) { | |
338 } | 179 } |
339 | 180 |
340 // Send request to add this volume to the file system as Google drive. | 181 // Send request to add this volume to the file system as Google drive. |
341 // This method must be calld at SetUp method of FileManagerBrowserTestBase. | 182 // This method must be calld at SetUp method of FileManagerBrowserTestBase. |
342 // Returns true on success. | 183 // Returns true on success. |
343 bool SetUp() { | 184 bool SetUp() { |
344 if (!test_cache_root_.CreateUniqueTempDir()) | 185 if (!test_cache_root_.CreateUniqueTempDir()) |
345 return false; | 186 return false; |
346 drive::DriveIntegrationServiceFactory::SetFactoryForTest( | 187 drive::DriveIntegrationServiceFactory::SetFactoryForTest( |
347 base::Bind(&DriveTestVolume::CreateDriveIntegrationService, | 188 base::Bind(&DriveTestVolume::CreateDriveIntegrationService, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 time, | 273 time, |
433 google_apis::test_util::CreateCopyResultCallback(&error, | 274 google_apis::test_util::CreateCopyResultCallback(&error, |
434 &resource_entry)); | 275 &resource_entry)); |
435 MessageLoop::current()->RunUntilIdle(); | 276 MessageLoop::current()->RunUntilIdle(); |
436 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 277 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
437 ASSERT_TRUE(resource_entry); | 278 ASSERT_TRUE(resource_entry); |
438 | 279 |
439 CheckForUpdates(); | 280 CheckForUpdates(); |
440 } | 281 } |
441 | 282 |
442 virtual base::FilePath GetRootPath() const OVERRIDE { | |
443 return base::FilePath(drive::util::kDriveMyDriveRootPath); | |
444 } | |
445 | |
446 virtual bool PathExists(const base::FilePath& file_path) const OVERRIDE { | |
447 DCHECK(integration_service_); | |
448 DCHECK(integration_service_->file_system()); | |
449 | |
450 drive::FileError error = drive::FILE_ERROR_FAILED; | |
451 scoped_ptr<drive::ResourceEntry> entry_proto; | |
452 integration_service_->file_system()->GetResourceEntryByPath( | |
453 file_path, | |
454 google_apis::test_util::CreateCopyResultCallback(&error, &entry_proto)); | |
455 google_apis::test_util::RunBlockingPoolTask(); | |
456 | |
457 return error == drive::FILE_ERROR_OK; | |
458 } | |
459 | |
460 virtual bool WaitUntilFilePresentWithSize( | |
461 const base::FilePath& file_path, | |
462 int64 file_size) OVERRIDE { | |
463 while (true) { | |
464 if (FileIsPresentWithSize(file_path, file_size)) | |
465 return true; | |
466 WaitUntilDirectoryChanged(); | |
467 } | |
468 NOTREACHED(); | |
469 return false; | |
470 } | |
471 | |
472 virtual bool WaitUntilFileNotPresent( | |
473 const base::FilePath& file_path) OVERRIDE { | |
474 while (true) { | |
475 if (FileIsNotPresent(file_path)) | |
476 return true; | |
477 WaitUntilDirectoryChanged(); | |
478 } | |
479 NOTREACHED(); | |
480 return false; | |
481 } | |
482 | |
483 virtual void OnDirectoryChanged( | |
484 const base::FilePath& directory_path) OVERRIDE { | |
485 if (waiting_for_directory_change_) | |
486 MessageLoop::current()->Quit(); | |
487 } | |
488 | |
489 // Notifies FileSystem that the contents in FakeDriveService are | 283 // Notifies FileSystem that the contents in FakeDriveService are |
490 // changed, hence the new contents should be fetched. | 284 // changed, hence the new contents should be fetched. |
491 void CheckForUpdates() { | 285 void CheckForUpdates() { |
492 if (integration_service_ && integration_service_->file_system()) { | 286 if (integration_service_ && integration_service_->file_system()) { |
493 integration_service_->file_system()->CheckForUpdates(); | 287 integration_service_->file_system()->CheckForUpdates(); |
494 } | 288 } |
495 } | 289 } |
496 | 290 |
497 // Waits until a notification for a directory change is received. | |
498 void WaitUntilDirectoryChanged() { | |
499 waiting_for_directory_change_ = true; | |
500 MessageLoop::current()->Run(); | |
501 waiting_for_directory_change_ = false; | |
502 } | |
503 | |
504 // Returns true if a file of the size |file_size| is present at |file_path|. | |
505 bool FileIsPresentWithSize( | |
506 const base::FilePath& file_path, | |
507 int64 file_size) { | |
508 DCHECK(integration_service_); | |
509 DCHECK(integration_service_->file_system()); | |
510 | |
511 drive::FileError error = drive::FILE_ERROR_FAILED; | |
512 scoped_ptr<drive::ResourceEntry> entry_proto; | |
513 integration_service_->file_system()->GetResourceEntryByPath( | |
514 file_path, | |
515 google_apis::test_util::CreateCopyResultCallback(&error, &entry_proto)); | |
516 google_apis::test_util::RunBlockingPoolTask(); | |
517 | |
518 return (error == drive::FILE_ERROR_OK && | |
519 entry_proto->file_info().size() == file_size); | |
520 } | |
521 | |
522 // Returns true if a file is not present at |file_path|. | |
523 bool FileIsNotPresent( | |
524 const base::FilePath& file_path) { | |
525 DCHECK(integration_service_); | |
526 DCHECK(integration_service_->file_system()); | |
527 | |
528 drive::FileError error = drive::FILE_ERROR_FAILED; | |
529 scoped_ptr<drive::ResourceEntry> entry_proto; | |
530 integration_service_->file_system()->GetResourceEntryByPath( | |
531 file_path, | |
532 google_apis::test_util::CreateCopyResultCallback(&error, &entry_proto)); | |
533 google_apis::test_util::RunBlockingPoolTask(); | |
534 | |
535 return error == drive::FILE_ERROR_NOT_FOUND; | |
536 } | |
537 | |
538 drive::DriveIntegrationService* CreateDriveIntegrationService( | 291 drive::DriveIntegrationService* CreateDriveIntegrationService( |
539 Profile* profile) { | 292 Profile* profile) { |
540 fake_drive_service_ = new google_apis::FakeDriveService; | 293 fake_drive_service_ = new google_apis::FakeDriveService; |
541 fake_drive_service_->LoadResourceListForWapi( | 294 fake_drive_service_->LoadResourceListForWapi( |
542 "chromeos/gdata/empty_feed.json"); | 295 "chromeos/gdata/empty_feed.json"); |
543 fake_drive_service_->LoadAccountMetadataForWapi( | 296 fake_drive_service_->LoadAccountMetadataForWapi( |
544 "chromeos/gdata/account_metadata.json"); | 297 "chromeos/gdata/account_metadata.json"); |
545 fake_drive_service_->LoadAppListForDriveApi("chromeos/drive/applist.json"); | 298 fake_drive_service_->LoadAppListForDriveApi("chromeos/drive/applist.json"); |
546 integration_service_ = new drive::DriveIntegrationService( | 299 integration_service_ = new drive::DriveIntegrationService( |
547 profile, | 300 profile, |
548 fake_drive_service_, | 301 fake_drive_service_, |
549 test_cache_root_.path(), | 302 test_cache_root_.path(), |
550 NULL); | 303 NULL); |
551 integration_service_->file_system()->AddObserver(this); | |
552 return integration_service_; | 304 return integration_service_; |
553 } | 305 } |
554 | 306 |
555 private: | 307 private: |
556 base::ScopedTempDir test_cache_root_; | 308 base::ScopedTempDir test_cache_root_; |
557 google_apis::FakeDriveService* fake_drive_service_; | 309 google_apis::FakeDriveService* fake_drive_service_; |
558 drive::DriveIntegrationService* integration_service_; | 310 drive::DriveIntegrationService* integration_service_; |
559 bool waiting_for_directory_change_; | |
560 }; | 311 }; |
561 | 312 |
562 // The base test class. Used by FileManagerBrowserLocalTest, | 313 // The base test class. Used by FileManagerBrowserLocalTest, |
563 // FileManagerBrowserDriveTest, and FileManagerBrowserTransferTest. | 314 // FileManagerBrowserDriveTest, and FileManagerBrowserTransferTest. |
564 // The boolean parameter, retrieved by GetParam(), is true if testing in the | 315 // The boolean parameter, retrieved by GetParam(), is true if testing in the |
565 // guest mode. See SetUpCommandLine() below for details. | 316 // guest mode. See SetUpCommandLine() below for details. |
566 class FileManagerBrowserTestBase : public ExtensionApiTest, | 317 class FileManagerBrowserTestBase : public ExtensionApiTest, |
567 public ::testing::WithParamInterface<bool> { | 318 public ::testing::WithParamInterface<bool> { |
568 protected: | 319 protected: |
569 // Adds an incognito and guest-mode flags for tests in the guest mode. | 320 // Adds an incognito and guest-mode flags for tests in the guest mode. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 "audio/ogg", | 383 "audio/ogg", |
633 NONE, | 384 NONE, |
634 "4 Sep 1998 00:00:00" | 385 "4 Sep 1998 00:00:00" |
635 }; | 386 }; |
636 volume->CreateEntry(entry); | 387 volume->CreateEntry(entry); |
637 listener.Reply("file added"); | 388 listener.Reply("file added"); |
638 | 389 |
639 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 390 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
640 } | 391 } |
641 | 392 |
642 void FileManagerBrowserTestBase::DoTestGalleryOpen(TestVolume* volume) { | |
643 ResultCatcher catcher; | |
644 StartTest("galleryOpen" + volume->GetName()); | |
645 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | |
646 } | |
647 | |
648 void FileManagerBrowserTestBase::DoTestKeyboardCopy(TestVolume* volume) { | |
649 base::FilePath copy_path = | |
650 volume->GetRootPath().AppendASCII(kKeyboardTestFileCopyName); | |
651 ASSERT_FALSE(volume->PathExists(copy_path)); | |
652 | |
653 ResultCatcher catcher; | |
654 ASSERT_NO_FATAL_FAILURE(StartTest("keyboardCopy" + volume->GetName())); | |
655 | |
656 const int64 kKeyboardTestFileSize = 59943; | |
657 | |
658 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | |
659 ASSERT_TRUE(volume->WaitUntilFilePresentWithSize( | |
660 copy_path, kKeyboardTestFileSize)); | |
661 | |
662 // Check that it was a copy, not a move. | |
663 base::FilePath source_path = | |
664 volume->GetRootPath().AppendASCII(kKeyboardTestFileName); | |
665 ASSERT_TRUE(volume->PathExists(source_path)); | |
666 } | |
667 | |
668 void FileManagerBrowserTestBase::DoTestKeyboardDelete(TestVolume* volume) { | |
669 base::FilePath delete_path = | |
670 volume->GetRootPath().AppendASCII(kKeyboardTestFileName); | |
671 ASSERT_TRUE(volume->PathExists(delete_path)); | |
672 | |
673 ResultCatcher catcher; | |
674 ASSERT_NO_FATAL_FAILURE(StartTest("keyboardDelete" + volume->GetName())); | |
675 | |
676 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | |
677 ASSERT_TRUE(volume->WaitUntilFileNotPresent(delete_path)); | |
678 } | |
679 | |
680 // A class to test local volumes. | 393 // A class to test local volumes. |
681 class FileManagerBrowserLocalTest : public FileManagerBrowserTestBase { | 394 class FileManagerBrowserLocalTest : public FileManagerBrowserTestBase { |
682 public: | 395 public: |
683 FileManagerBrowserLocalTest() : volume_("Downloads") {} | 396 FileManagerBrowserLocalTest() : volume_("Downloads") {} |
684 | 397 |
685 protected: | 398 protected: |
686 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 399 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
687 FileManagerBrowserTestBase::SetUpInProcessBrowserTestFixture(); | 400 FileManagerBrowserTestBase::SetUpInProcessBrowserTestFixture(); |
688 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting(); | 401 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting(); |
689 } | 402 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 // the guest mode. | 479 // the guest mode. |
767 INSTANTIATE_TEST_CASE_P(InNonGuestMode, | 480 INSTANTIATE_TEST_CASE_P(InNonGuestMode, |
768 FileManagerBrowserTransferTest, | 481 FileManagerBrowserTransferTest, |
769 ::testing::Values(false)); | 482 ::testing::Values(false)); |
770 | 483 |
771 IN_PROC_BROWSER_TEST_P(FileManagerBrowserLocalTest, TestFileDisplay) { | 484 IN_PROC_BROWSER_TEST_P(FileManagerBrowserLocalTest, TestFileDisplay) { |
772 DoTestFileDisplay(&volume_); | 485 DoTestFileDisplay(&volume_); |
773 } | 486 } |
774 | 487 |
775 IN_PROC_BROWSER_TEST_P(FileManagerBrowserLocalTest, TestGalleryOpen) { | 488 IN_PROC_BROWSER_TEST_P(FileManagerBrowserLocalTest, TestGalleryOpen) { |
776 DoTestGalleryOpen(&volume_); | 489 ResultCatcher catcher; |
| 490 ASSERT_NO_FATAL_FAILURE(StartTest("galleryOpenDownloads")); |
| 491 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
777 } | 492 } |
778 | 493 |
779 IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, TestGalleryOpen) { | 494 // Disabled temporarily since fails on Linux Chromium OS ASAN Tests (2). |
780 DoTestGalleryOpen(&volume_); | 495 // TODO(mtomasz): crbug.com/243611. |
| 496 IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, DISABLED_TestGalleryOpen) { |
| 497 ResultCatcher catcher; |
| 498 ASSERT_NO_FATAL_FAILURE(StartTest("galleryOpenDrive")); |
| 499 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
781 } | 500 } |
782 | 501 |
783 IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, TestKeyboardCopy) { | 502 IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, TestKeyboardCopy) { |
784 DoTestKeyboardCopy(&volume_); | 503 ResultCatcher catcher; |
| 504 ASSERT_NO_FATAL_FAILURE(StartTest("keyboardCopyDrive")); |
| 505 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
785 } | 506 } |
786 | 507 |
787 IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, TestKeyboardDelete) { | 508 IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, TestKeyboardDelete) { |
788 DoTestKeyboardDelete(&volume_); | 509 ResultCatcher catcher; |
| 510 ASSERT_NO_FATAL_FAILURE(StartTest("keyboardDeleteDrive")); |
| 511 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
789 } | 512 } |
790 | 513 |
791 IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, TestOpenRecent) { | 514 IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, TestOpenRecent) { |
792 ResultCatcher catcher; | 515 ResultCatcher catcher; |
793 ASSERT_NO_FATAL_FAILURE(StartTest("openSidebarRecent")); | 516 ASSERT_NO_FATAL_FAILURE(StartTest("openSidebarRecent")); |
794 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 517 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
795 } | 518 } |
796 | 519 |
797 IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, TestOpenOffline) { | 520 IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, TestOpenOffline) { |
798 ResultCatcher catcher; | 521 ResultCatcher catcher; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 } | 585 } |
863 | 586 |
864 IN_PROC_BROWSER_TEST_P(FileManagerBrowserTransferTest, | 587 IN_PROC_BROWSER_TEST_P(FileManagerBrowserTransferTest, |
865 TransferFromOfflineToDrive) { | 588 TransferFromOfflineToDrive) { |
866 ResultCatcher catcher; | 589 ResultCatcher catcher; |
867 ASSERT_NO_FATAL_FAILURE(StartTest("transferFromOfflineToDrive")); | 590 ASSERT_NO_FATAL_FAILURE(StartTest("transferFromOfflineToDrive")); |
868 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 591 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
869 } | 592 } |
870 | 593 |
871 } // namespace | 594 } // namespace |
OLD | NEW |