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 |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 protected: | 517 protected: |
518 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; | 518 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; |
519 | 519 |
520 virtual void SetUpOnMainThread() OVERRIDE; | 520 virtual void SetUpOnMainThread() OVERRIDE; |
521 | 521 |
522 // Adds an incognito and guest-mode flags for tests in the guest mode. | 522 // Adds an incognito and guest-mode flags for tests in the guest mode. |
523 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; | 523 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; |
524 | 524 |
525 // Loads our testing extension and sends it a string identifying the current | 525 // Loads our testing extension and sends it a string identifying the current |
526 // test. | 526 // test. |
527 void StartTest(); | 527 virtual void StartTest(); |
| 528 void RunTestMessageLoop(); |
528 | 529 |
529 // Overriding point for test configurations. | 530 // Overriding point for test configurations. |
| 531 virtual const char* GetTestManifestName() const { |
| 532 return "file_manager_test_manifest.json"; |
| 533 } |
530 virtual GuestMode GetGuestModeParam() const = 0; | 534 virtual GuestMode GetGuestModeParam() const = 0; |
531 virtual const char* GetTestCaseNameParam() const = 0; | 535 virtual const char* GetTestCaseNameParam() const = 0; |
532 virtual std::string OnMessage(const std::string& name, | 536 virtual std::string OnMessage(const std::string& name, |
533 const base::Value* value); | 537 const base::Value* value); |
534 | 538 |
535 scoped_ptr<LocalTestVolume> local_volume_; | 539 scoped_ptr<LocalTestVolume> local_volume_; |
536 linked_ptr<DriveTestVolume> drive_volume_; | 540 linked_ptr<DriveTestVolume> drive_volume_; |
537 std::map<Profile*, linked_ptr<DriveTestVolume> > drive_volumes_; | 541 std::map<Profile*, linked_ptr<DriveTestVolume> > drive_volumes_; |
538 scoped_ptr<LocalTestVolume> usb_volume_; | 542 scoped_ptr<LocalTestVolume> usb_volume_; |
539 | 543 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 if (GetGuestModeParam() == IN_GUEST_MODE) { | 584 if (GetGuestModeParam() == IN_GUEST_MODE) { |
581 command_line->AppendSwitch(chromeos::switches::kGuestSession); | 585 command_line->AppendSwitch(chromeos::switches::kGuestSession); |
582 command_line->AppendSwitchNative(chromeos::switches::kLoginUser, ""); | 586 command_line->AppendSwitchNative(chromeos::switches::kLoginUser, ""); |
583 command_line->AppendSwitch(switches::kIncognito); | 587 command_line->AppendSwitch(switches::kIncognito); |
584 } | 588 } |
585 ExtensionApiTest::SetUpCommandLine(command_line); | 589 ExtensionApiTest::SetUpCommandLine(command_line); |
586 } | 590 } |
587 | 591 |
588 void FileManagerBrowserTestBase::StartTest() { | 592 void FileManagerBrowserTestBase::StartTest() { |
589 // Launch the extension. | 593 // Launch the extension. |
590 base::FilePath path = test_data_dir_.AppendASCII("file_manager_browsertest"); | 594 const base::FilePath path = |
591 const extensions::Extension* extension = LoadExtensionAsComponent(path); | 595 test_data_dir_.AppendASCII("file_manager_browsertest"); |
| 596 const extensions::Extension* const extension = |
| 597 LoadExtensionAsComponentWithManifest(path, GetTestManifestName()); |
592 ASSERT_TRUE(extension); | 598 ASSERT_TRUE(extension); |
593 | 599 |
| 600 RunTestMessageLoop(); |
| 601 } |
| 602 |
| 603 void FileManagerBrowserTestBase::RunTestMessageLoop() { |
594 // Handle the messages from JavaScript. | 604 // Handle the messages from JavaScript. |
595 // The while loop is break when the test is passed or failed. | 605 // The while loop is break when the test is passed or failed. |
596 FileManagerTestListener listener; | 606 FileManagerTestListener listener; |
597 while (true) { | 607 while (true) { |
598 FileManagerTestListener::Message entry = listener.GetNextMessage(); | 608 FileManagerTestListener::Message entry = listener.GetNextMessage(); |
599 if (entry.type == chrome::NOTIFICATION_EXTENSION_TEST_PASSED) { | 609 if (entry.type == chrome::NOTIFICATION_EXTENSION_TEST_PASSED) { |
600 // Test succeed. | 610 // Test succeed. |
601 break; | 611 break; |
602 } else if (entry.type == chrome::NOTIFICATION_EXTENSION_TEST_FAILED) { | 612 } else if (entry.type == chrome::NOTIFICATION_EXTENSION_TEST_FAILED) { |
603 // Test failed. | 613 // Test failed. |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 // in and checks that nothing goes wrong. Here, the primary user (alice) logs | 1071 // in and checks that nothing goes wrong. Here, the primary user (alice) logs |
1062 // in first, then the "extra" users follow, and then lastly the other users | 1072 // in first, then the "extra" users follow, and then lastly the other users |
1063 // (bob and charlie) are added in the test. Thus the existing test verifies | 1073 // (bob and charlie) are added in the test. Thus the existing test verifies |
1064 // that the feature is effectively working with lastly logged in users. | 1074 // that the feature is effectively working with lastly logged in users. |
1065 AddExtraUsersForStressTesting(); | 1075 AddExtraUsersForStressTesting(); |
1066 | 1076 |
1067 set_test_case_name("multiProfileVisitDesktopMenu"); | 1077 set_test_case_name("multiProfileVisitDesktopMenu"); |
1068 StartTest(); | 1078 StartTest(); |
1069 } | 1079 } |
1070 | 1080 |
| 1081 template<GuestMode M> |
| 1082 class GalleryBrowserTestBase : public FileManagerBrowserTestBase { |
| 1083 public: |
| 1084 virtual GuestMode GetGuestModeParam() const OVERRIDE { return M; } |
| 1085 virtual const char* GetTestCaseNameParam() const OVERRIDE { |
| 1086 return test_case_name_.c_str(); |
| 1087 } |
| 1088 |
| 1089 protected: |
| 1090 virtual std::string OnMessage(const std::string& name, |
| 1091 const base::Value* value) OVERRIDE; |
| 1092 |
| 1093 virtual const char* GetTestManifestName() const OVERRIDE { |
| 1094 return "gallery_test_manifest.json"; |
| 1095 } |
| 1096 |
| 1097 void AddScript(const std::string& name) { |
| 1098 scripts_.AppendString( |
| 1099 "chrome-extension://ejhcmmdhhpdhhgmifplfmjobgegbibkn/" + name); |
| 1100 } |
| 1101 |
| 1102 void set_test_case_name(const std::string& name) { |
| 1103 test_case_name_ = name; |
| 1104 } |
| 1105 |
| 1106 private: |
| 1107 base::ListValue scripts_; |
| 1108 std::string test_case_name_; |
| 1109 }; |
| 1110 |
| 1111 template<GuestMode M> |
| 1112 std::string GalleryBrowserTestBase<M>::OnMessage(const std::string& name, |
| 1113 const base::Value* value) { |
| 1114 if (name == "getScripts") { |
| 1115 std::string jsonString; |
| 1116 base::JSONWriter::Write(&scripts_, &jsonString); |
| 1117 return jsonString; |
| 1118 } |
| 1119 return FileManagerBrowserTestBase::OnMessage(name, value); |
| 1120 } |
| 1121 |
| 1122 typedef GalleryBrowserTestBase<NOT_IN_GUEST_MODE> GalleryBrowserTest; |
| 1123 typedef GalleryBrowserTestBase<IN_GUEST_MODE> GalleryBrowserTestInGuestMode; |
| 1124 |
| 1125 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, OpenSingleImageOnDownloads) { |
| 1126 AddScript("gallery/open_image_files.js"); |
| 1127 set_test_case_name("openSingleImageOnDownloads"); |
| 1128 StartTest(); |
| 1129 } |
| 1130 |
| 1131 IN_PROC_BROWSER_TEST_F(GalleryBrowserTestInGuestMode, |
| 1132 OpenSingleImageOnDownloads) { |
| 1133 AddScript("gallery/open_image_files.js"); |
| 1134 set_test_case_name("openSingleImageOnDownloads"); |
| 1135 StartTest(); |
| 1136 } |
| 1137 |
| 1138 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, OpenSingleImageOnDrive) { |
| 1139 AddScript("gallery/open_image_files.js"); |
| 1140 set_test_case_name("openSingleImageOnDrive"); |
| 1141 StartTest(); |
| 1142 } |
| 1143 |
1071 } // namespace | 1144 } // namespace |
1072 } // namespace file_manager | 1145 } // namespace file_manager |
OLD | NEW |