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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/file_manager_browsertest.cc

Issue 16016002: Parameterize FileManagerBrowserTransferTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 29 matching lines...) Expand all
40 enum EntryType { 40 enum EntryType {
41 FILE, 41 FILE,
42 DIRECTORY, 42 DIRECTORY,
43 }; 43 };
44 44
45 enum SharedOption { 45 enum SharedOption {
46 NONE, 46 NONE,
47 SHARED, 47 SHARED,
48 }; 48 };
49 49
50 enum GestModeOption {
hashimoto 2013/05/31 09:16:21 s/Gest/Guest/?
hirono 2013/06/03 01:45:53 Done.
51 NOT_IN_GEST_MODE,
52 IN_GEST_MODE
53 };
54
55 std::ostream& operator<<(std::ostream& os, const GestModeOption& option) {
hashimoto 2013/05/31 09:16:21 Please add a comment to describe why we need this.
hirono 2013/06/03 01:45:53 Done.
56 return os << (option == NOT_IN_GEST_MODE ?
57 "Not in guest mode" : "In gest mode");
58 }
59
50 struct TestEntryInfo { 60 struct TestEntryInfo {
51 EntryType type; 61 EntryType type;
52 const char* source_file_name; // Source file name to be used as a prototype. 62 const char* source_file_name; // Source file name to be used as a prototype.
53 const char* target_name; // Target file or directory name. 63 const char* target_name; // Target file or directory name.
54 const char* mime_type; 64 const char* mime_type;
55 SharedOption shared_option; 65 SharedOption shared_option;
56 const char* last_modified_time_as_string; 66 const char* last_modified_time_as_string;
57 }; 67 };
58 68
59 TestEntryInfo kTestEntrySetCommon[] = { 69 TestEntryInfo kTestEntrySetCommon[] = {
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 } 317 }
308 318
309 private: 319 private:
310 base::ScopedTempDir test_cache_root_; 320 base::ScopedTempDir test_cache_root_;
311 google_apis::FakeDriveService* fake_drive_service_; 321 google_apis::FakeDriveService* fake_drive_service_;
312 drive::DriveIntegrationService* integration_service_; 322 drive::DriveIntegrationService* integration_service_;
313 }; 323 };
314 324
315 // The base test class. Used by FileManagerBrowserLocalTest, 325 // The base test class. Used by FileManagerBrowserLocalTest,
316 // FileManagerBrowserDriveTest, and FileManagerBrowserTransferTest. 326 // FileManagerBrowserDriveTest, and FileManagerBrowserTransferTest.
317 // The boolean parameter, retrieved by GetParam(), is true if testing in the 327 class FileManagerBrowserTestBase : public ExtensionApiTest {
318 // guest mode. See SetUpCommandLine() below for details.
319 class FileManagerBrowserTestBase : public ExtensionApiTest,
320 public ::testing::WithParamInterface<bool> {
321 protected: 328 protected:
329 // gest_mode is true if testing in the guest mode. See SetUpCommandLine()
hashimoto 2013/05/31 09:16:21 nit: I think this comment is useless or at least w
hirono 2013/06/03 01:45:53 Done.
330 // below for details.
331 explicit FileManagerBrowserTestBase(GestModeOption gest_mode) :
332 gest_mode_(gest_mode_) {}
333
322 // Adds an incognito and guest-mode flags for tests in the guest mode. 334 // Adds an incognito and guest-mode flags for tests in the guest mode.
323 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; 335 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
324 336
325 // Loads our testing extension and sends it a string identifying the current 337 // Loads our testing extension and sends it a string identifying the current
326 // test. 338 // test.
327 void StartTest(const std::string& test_name); 339 void StartTest(const std::string& test_name);
328 340
329 // Creates test files and directories. 341 // Creates test files and directories.
330 void CreateTestEntries(TestVolume* volume, const TestEntryInfo* entries, 342 void CreateTestEntries(TestVolume* volume, const TestEntryInfo* entries,
331 size_t num_entries); 343 size_t num_entries);
332 344
333 // Runs the file display test on the passed |volume|, shared by subclasses. 345 // Runs the file display test on the passed |volume|, shared by subclasses.
334 void DoTestFileDisplay(TestVolume* volume); 346 void DoTestFileDisplay(TestVolume* volume);
347
348 private:
349 GestModeOption gest_mode_;
335 }; 350 };
336 351
337 void FileManagerBrowserTestBase::SetUpCommandLine(CommandLine* command_line) { 352 void FileManagerBrowserTestBase::SetUpCommandLine(CommandLine* command_line) {
338 bool in_guest_mode = GetParam(); 353 if (gest_mode_ == IN_GEST_MODE) {
339 if (in_guest_mode) {
340 command_line->AppendSwitch(chromeos::switches::kGuestSession); 354 command_line->AppendSwitch(chromeos::switches::kGuestSession);
341 command_line->AppendSwitchNative(chromeos::switches::kLoginUser, ""); 355 command_line->AppendSwitchNative(chromeos::switches::kLoginUser, "");
342 command_line->AppendSwitch(switches::kIncognito); 356 command_line->AppendSwitch(switches::kIncognito);
343 } 357 }
344 ExtensionApiTest::SetUpCommandLine(command_line); 358 ExtensionApiTest::SetUpCommandLine(command_line);
345 } 359 }
346 360
347 void FileManagerBrowserTestBase::StartTest(const std::string& test_name) { 361 void FileManagerBrowserTestBase::StartTest(const std::string& test_name) {
348 base::FilePath path = test_data_dir_.AppendASCII("file_manager_browsertest"); 362 base::FilePath path = test_data_dir_.AppendASCII("file_manager_browsertest");
349 const extensions::Extension* extension = LoadExtensionAsComponent(path); 363 const extensions::Extension* extension = LoadExtensionAsComponent(path);
350 ASSERT_TRUE(extension); 364 ASSERT_TRUE(extension);
351 365
352 bool in_guest_mode = GetParam(); 366 bool in_guest_mode = gest_mode_ == IN_GEST_MODE;
353 ExtensionTestMessageListener listener( 367 ExtensionTestMessageListener listener(
354 in_guest_mode ? "which test guest" : "which test non-guest", true); 368 in_guest_mode ? "which test guest" : "which test non-guest", true);
355 ASSERT_TRUE(listener.WaitUntilSatisfied()); 369 ASSERT_TRUE(listener.WaitUntilSatisfied());
356 listener.Reply(test_name); 370 listener.Reply(test_name);
357 } 371 }
358 372
359 void FileManagerBrowserTestBase::CreateTestEntries( 373 void FileManagerBrowserTestBase::CreateTestEntries(
360 TestVolume* volume, const TestEntryInfo* entries, size_t num_entries) { 374 TestVolume* volume, const TestEntryInfo* entries, size_t num_entries) {
361 for (size_t i = 0; i < num_entries; ++i) { 375 for (size_t i = 0; i < num_entries; ++i) {
362 volume->CreateEntry(entries[i]); 376 volume->CreateEntry(entries[i]);
(...skipping 14 matching lines...) Expand all
377 NONE, 391 NONE,
378 "4 Sep 1998 00:00:00" 392 "4 Sep 1998 00:00:00"
379 }; 393 };
380 volume->CreateEntry(entry); 394 volume->CreateEntry(entry);
381 listener.Reply("file added"); 395 listener.Reply("file added");
382 396
383 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 397 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
384 } 398 }
385 399
386 // A class to test local volumes. 400 // A class to test local volumes.
387 class FileManagerBrowserLocalTest : public FileManagerBrowserTestBase { 401 class FileManagerBrowserLocalTest :
402 public FileManagerBrowserTestBase,
403 public ::testing::WithParamInterface<GestModeOption> {
388 public: 404 public:
389 FileManagerBrowserLocalTest() : volume_("Downloads") {} 405 FileManagerBrowserLocalTest() : FileManagerBrowserTestBase(GetParam()),
406 volume_("Downloads") {}
390 407
391 protected: 408 protected:
392 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 409 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
393 FileManagerBrowserTestBase::SetUpInProcessBrowserTestFixture(); 410 FileManagerBrowserTestBase::SetUpInProcessBrowserTestFixture();
394 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting(); 411 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting();
395 } 412 }
396 413
397 virtual void SetUpOnMainThread() OVERRIDE { 414 virtual void SetUpOnMainThread() OVERRIDE {
398 FileManagerBrowserTestBase::SetUpOnMainThread(); 415 FileManagerBrowserTestBase::SetUpOnMainThread();
399 ASSERT_TRUE(volume_.Mount(browser()->profile())); 416 ASSERT_TRUE(volume_.Mount(browser()->profile()));
400 CreateTestEntries(&volume_, kTestEntrySetCommon, 417 CreateTestEntries(&volume_, kTestEntrySetCommon,
401 arraysize(kTestEntrySetCommon)); 418 arraysize(kTestEntrySetCommon));
402 } 419 }
403 420
404 LocalTestVolume volume_; 421 LocalTestVolume volume_;
405 }; 422 };
406 423
407 INSTANTIATE_TEST_CASE_P(InGuestMode, 424 INSTANTIATE_TEST_CASE_P(BothGuestMode,
408 FileManagerBrowserLocalTest, 425 FileManagerBrowserLocalTest,
409 ::testing::Values(true)); 426 ::testing::Values(IN_GEST_MODE, NOT_IN_GEST_MODE));
410
411 INSTANTIATE_TEST_CASE_P(InNonGuestMode,
412 FileManagerBrowserLocalTest,
413 ::testing::Values(false));
414 427
415 // A class to test Drive's volumes 428 // A class to test Drive's volumes
416 class FileManagerBrowserDriveTest : public FileManagerBrowserTestBase { 429 class FileManagerBrowserDriveTest :
430 public FileManagerBrowserTestBase,
431 public ::testing::WithParamInterface<GestModeOption> {
hashimoto 2013/05/31 09:16:21 Can't we just pass NOT_IN_GUEST_MODE to the ctor o
hirono 2013/06/03 01:45:53 Done.
432 public:
433 FileManagerBrowserDriveTest() : FileManagerBrowserTestBase(GetParam()) {}
434
417 protected: 435 protected:
418 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 436 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
419 FileManagerBrowserTestBase::SetUpInProcessBrowserTestFixture(); 437 FileManagerBrowserTestBase::SetUpInProcessBrowserTestFixture();
420 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting(); 438 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting();
421 ASSERT_TRUE(volume_.SetUp()); 439 ASSERT_TRUE(volume_.SetUp());
422 } 440 }
423 441
424 virtual void SetUpOnMainThread() OVERRIDE { 442 virtual void SetUpOnMainThread() OVERRIDE {
425 FileManagerBrowserTestBase::SetUpOnMainThread(); 443 FileManagerBrowserTestBase::SetUpOnMainThread();
426 CreateTestEntries(&volume_, kTestEntrySetCommon, 444 CreateTestEntries(&volume_, kTestEntrySetCommon,
427 arraysize(kTestEntrySetCommon)); 445 arraysize(kTestEntrySetCommon));
428 // For testing Drive, create more entries with Drive specific attributes. 446 // For testing Drive, create more entries with Drive specific attributes.
429 // TODO(haruki): Add a case for an entry cached by DriveCache. 447 // TODO(haruki): Add a case for an entry cached by DriveCache.
430 CreateTestEntries(&volume_, kTestEntrySetDriveOnly, 448 CreateTestEntries(&volume_, kTestEntrySetDriveOnly,
431 arraysize(kTestEntrySetDriveOnly)); 449 arraysize(kTestEntrySetDriveOnly));
432 drive_test_util::WaitUntilDriveMountPointIsAdded(browser()->profile()); 450 drive_test_util::WaitUntilDriveMountPointIsAdded(browser()->profile());
433 } 451 }
434 452
435 DriveTestVolume volume_; 453 DriveTestVolume volume_;
436 }; 454 };
437 455
438 // Don't test Drive in the guest mode as it's not supported. 456 // Don't test Drive in the guest mode as it's not supported.
439 INSTANTIATE_TEST_CASE_P(InNonGuestMode, 457 INSTANTIATE_TEST_CASE_P(InNonGuestMode,
440 FileManagerBrowserDriveTest, 458 FileManagerBrowserDriveTest,
441 ::testing::Values(false)); 459 ::testing::Values(NOT_IN_GEST_MODE));
460
461 typedef std::tr1::tuple<GestModeOption, const char*> TransferTestParam;
442 462
443 // A class to test both local and Drive's volumes. 463 // A class to test both local and Drive's volumes.
444 class FileManagerBrowserTransferTest : public FileManagerBrowserTestBase { 464 class FileManagerBrowserJavaScriptTest :
hashimoto 2013/05/31 09:16:21 "JavaScriptTest" seems to be too generic. Why did
hirono 2013/06/03 01:45:53 To parameterize all the tests, I removed FileManag
465 public FileManagerBrowserTestBase,
466 public ::testing::WithParamInterface<TransferTestParam> {
445 public: 467 public:
446 FileManagerBrowserTransferTest() : local_volume_("Downloads") {} 468 FileManagerBrowserJavaScriptTest() :
469 // FileManagerBrowserJavaScriptTest depends on Drive, which is not
470 // supported in the guest mode.
471 FileManagerBrowserTestBase(std::tr1::get<0>(GetParam())),
472 local_volume_("Downloads") {}
447 473
448 protected: 474 protected:
449 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 475 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
450 FileManagerBrowserTestBase::SetUpInProcessBrowserTestFixture(); 476 FileManagerBrowserTestBase::SetUpInProcessBrowserTestFixture();
451 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting(); 477 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting();
452 ASSERT_TRUE(drive_volume_.SetUp()); 478 ASSERT_TRUE(drive_volume_.SetUp());
453 } 479 }
454 480
455 virtual void SetUpOnMainThread() OVERRIDE { 481 virtual void SetUpOnMainThread() OVERRIDE {
456 FileManagerBrowserTestBase::SetUpOnMainThread(); 482 FileManagerBrowserTestBase::SetUpOnMainThread();
457 ASSERT_TRUE(local_volume_.Mount(browser()->profile())); 483 ASSERT_TRUE(local_volume_.Mount(browser()->profile()));
458 CreateTestEntries(&local_volume_, kTestEntrySetCommon, 484 CreateTestEntries(&local_volume_, kTestEntrySetCommon,
459 arraysize(kTestEntrySetCommon)); 485 arraysize(kTestEntrySetCommon));
460 CreateTestEntries(&drive_volume_, kTestEntrySetCommon, 486 CreateTestEntries(&drive_volume_, kTestEntrySetCommon,
461 arraysize(kTestEntrySetCommon)); 487 arraysize(kTestEntrySetCommon));
462 CreateTestEntries(&drive_volume_, kTestEntrySetDriveOnly, 488 CreateTestEntries(&drive_volume_, kTestEntrySetDriveOnly,
463 arraysize(kTestEntrySetDriveOnly)); 489 arraysize(kTestEntrySetDriveOnly));
464 drive_test_util::WaitUntilDriveMountPointIsAdded(browser()->profile()); 490 drive_test_util::WaitUntilDriveMountPointIsAdded(browser()->profile());
465 } 491 }
466 492
467 LocalTestVolume local_volume_; 493 LocalTestVolume local_volume_;
468 DriveTestVolume drive_volume_; 494 DriveTestVolume drive_volume_;
469 }; 495 };
470 496
471 // FileManagerBrowserTransferTest depends on Drive and Drive is not supported in 497 INSTANTIATE_TEST_CASE_P(
hashimoto 2013/05/31 09:16:21 Can't we do the same thing for all tests except Fi
hirono 2013/06/03 01:45:53 Done.
472 // the guest mode. 498 TransferTest,
473 INSTANTIATE_TEST_CASE_P(InNonGuestMode, 499 FileManagerBrowserJavaScriptTest,
474 FileManagerBrowserTransferTest, 500 ::testing::Combine(
475 ::testing::Values(false)); 501 ::testing::Values(NOT_IN_GEST_MODE),
502 ::testing::Values(
503 "transferFromDriveToDownloads",
504 "transferFromDownloadsToDrive",
505 "transferFromSharedToDownloads",
506 "transferFromSharedToDrive",
507 "transferFromRecentToDownloads",
508 "transferFromRecentToDrive",
509 "transferFromOfflineToDownloads",
510 "transferFromOfflineToDrive")));
476 511
477 IN_PROC_BROWSER_TEST_P(FileManagerBrowserLocalTest, TestFileDisplay) { 512 IN_PROC_BROWSER_TEST_P(FileManagerBrowserLocalTest, TestFileDisplay) {
478 DoTestFileDisplay(&volume_); 513 DoTestFileDisplay(&volume_);
479 } 514 }
480 515
481 IN_PROC_BROWSER_TEST_P(FileManagerBrowserLocalTest, TestGalleryOpen) { 516 IN_PROC_BROWSER_TEST_P(FileManagerBrowserLocalTest, TestGalleryOpen) {
482 ResultCatcher catcher; 517 ResultCatcher catcher;
483 ASSERT_NO_FATAL_FAILURE(StartTest("galleryOpenDownloads")); 518 ASSERT_NO_FATAL_FAILURE(StartTest("galleryOpenDownloads"));
484 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 519 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
485 } 520 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 ASSERT_NO_FATAL_FAILURE(StartTest("openSidebarSharedWithMe")); 585 ASSERT_NO_FATAL_FAILURE(StartTest("openSidebarSharedWithMe"));
551 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 586 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
552 } 587 }
553 588
554 IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, TestAutocomplete) { 589 IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, TestAutocomplete) {
555 ResultCatcher catcher; 590 ResultCatcher catcher;
556 ASSERT_NO_FATAL_FAILURE(StartTest("autocomplete")); 591 ASSERT_NO_FATAL_FAILURE(StartTest("autocomplete"));
557 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 592 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
558 } 593 }
559 594
560 IN_PROC_BROWSER_TEST_P(FileManagerBrowserTransferTest, 595 IN_PROC_BROWSER_TEST_P(FileManagerBrowserJavaScriptTest,
561 TransferFromDriveToDownloads) { 596 ExecuteJavaScript) {
562 ResultCatcher catcher; 597 ResultCatcher catcher;
563 ASSERT_NO_FATAL_FAILURE(StartTest("transferFromDriveToDownloads")); 598 ASSERT_NO_FATAL_FAILURE(StartTest(std::tr1::get<1>(GetParam())));
564 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 599 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
565 } 600 }
566
567 IN_PROC_BROWSER_TEST_P(FileManagerBrowserTransferTest,
568 TransferFromDownloadsToDrive) {
569 ResultCatcher catcher;
570 ASSERT_NO_FATAL_FAILURE(StartTest("transferFromDownloadsToDrive"));
571 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
572 }
573
574 IN_PROC_BROWSER_TEST_P(FileManagerBrowserTransferTest,
575 TransferFromSharedToDownloads) {
576 ResultCatcher catcher;
577 ASSERT_NO_FATAL_FAILURE(StartTest("transferFromSharedToDownloads"));
578 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
579 }
580
581 IN_PROC_BROWSER_TEST_P(FileManagerBrowserTransferTest,
582 TransferFromSharedToDrive) {
583 ResultCatcher catcher;
584 ASSERT_NO_FATAL_FAILURE(StartTest("transferFromSharedToDrive"));
585 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
586 }
587
588 IN_PROC_BROWSER_TEST_P(FileManagerBrowserTransferTest,
589 TransferFromRecentToDownloads) {
590 ResultCatcher catcher;
591 ASSERT_NO_FATAL_FAILURE(StartTest("transferFromRecentToDownloads"));
592 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
593 }
594
595 IN_PROC_BROWSER_TEST_P(FileManagerBrowserTransferTest,
596 TransferFromRecentToDrive) {
597 ResultCatcher catcher;
598 ASSERT_NO_FATAL_FAILURE(StartTest("transferFromRecentToDrive"));
599 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
600 }
601
602 IN_PROC_BROWSER_TEST_P(FileManagerBrowserTransferTest,
603 TransferFromOfflineToDownloads) {
604 ResultCatcher catcher;
605 ASSERT_NO_FATAL_FAILURE(StartTest("transferFromOfflineToDownloads"));
606 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
607 }
608
609 IN_PROC_BROWSER_TEST_P(FileManagerBrowserTransferTest,
610 TransferFromOfflineToDrive) {
611 ResultCatcher catcher;
612 ASSERT_NO_FATAL_FAILURE(StartTest("transferFromOfflineToDrive"));
613 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
614 }
615
616 } // namespace 601 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698