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

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

Issue 667843005: Files.app: Refactoring for the onMessage function of FIleManagerBrowserTest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/copy_between_windows.js » ('j') | 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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 // test. 538 // test.
539 virtual void StartTest(); 539 virtual void StartTest();
540 void RunTestMessageLoop(); 540 void RunTestMessageLoop();
541 541
542 // Overriding point for test configurations. 542 // Overriding point for test configurations.
543 virtual const char* GetTestManifestName() const { 543 virtual const char* GetTestManifestName() const {
544 return "file_manager_test_manifest.json"; 544 return "file_manager_test_manifest.json";
545 } 545 }
546 virtual GuestMode GetGuestModeParam() const = 0; 546 virtual GuestMode GetGuestModeParam() const = 0;
547 virtual const char* GetTestCaseNameParam() const = 0; 547 virtual const char* GetTestCaseNameParam() const = 0;
548 virtual std::string OnMessage(const std::string& name, 548 virtual void OnMessage(const std::string& name,
549 const base::Value* value); 549 const base::Value& value,
550 std::string* output);
550 551
551 scoped_ptr<LocalTestVolume> local_volume_; 552 scoped_ptr<LocalTestVolume> local_volume_;
552 linked_ptr<DriveTestVolume> drive_volume_; 553 linked_ptr<DriveTestVolume> drive_volume_;
553 std::map<Profile*, linked_ptr<DriveTestVolume> > drive_volumes_; 554 std::map<Profile*, linked_ptr<DriveTestVolume> > drive_volumes_;
554 scoped_ptr<FakeTestVolume> usb_volume_; 555 scoped_ptr<FakeTestVolume> usb_volume_;
555 scoped_ptr<FakeTestVolume> mtp_volume_; 556 scoped_ptr<FakeTestVolume> mtp_volume_;
556 557
557 private: 558 private:
558 drive::DriveIntegrationService* CreateDriveIntegrationService( 559 drive::DriveIntegrationService* CreateDriveIntegrationService(
559 Profile* profile); 560 Profile* profile);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 const scoped_ptr<const base::Value> value( 636 const scoped_ptr<const base::Value> value(
636 base::JSONReader::Read(entry.message)); 637 base::JSONReader::Read(entry.message));
637 638
638 // If the message is not the expected format, just ignore it. 639 // If the message is not the expected format, just ignore it.
639 const base::DictionaryValue* message_dictionary = NULL; 640 const base::DictionaryValue* message_dictionary = NULL;
640 std::string name; 641 std::string name;
641 if (!value || !value->GetAsDictionary(&message_dictionary) || 642 if (!value || !value->GetAsDictionary(&message_dictionary) ||
642 !message_dictionary->GetString("name", &name)) 643 !message_dictionary->GetString("name", &name))
643 continue; 644 continue;
644 645
645 entry.function->Reply(OnMessage(name, value.get())); 646 std::string output;
647 OnMessage(name, *value.get(), &output);
648 if (HasFatalFailure())
649 break;
650 entry.function->Reply(output);
646 } 651 }
647 } 652 }
648 653
649 std::string FileManagerBrowserTestBase::OnMessage(const std::string& name, 654 void FileManagerBrowserTestBase::OnMessage(const std::string& name,
650 const base::Value* value) { 655 const base::Value& value,
656 std::string* output) {
651 if (name == "getTestName") { 657 if (name == "getTestName") {
652 // Pass the test case name. 658 // Pass the test case name.
653 return GetTestCaseNameParam(); 659 *output = GetTestCaseNameParam();
654 } else if (name == "getRootPaths") { 660 return;
661 }
662
663 if (name == "getRootPaths") {
655 // Pass the root paths. 664 // Pass the root paths.
656 const scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); 665 const scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
657 res->SetString("downloads", 666 res->SetString("downloads",
658 "/" + util::GetDownloadsMountPointName(profile())); 667 "/" + util::GetDownloadsMountPointName(profile()));
659 res->SetString("drive", 668 res->SetString("drive",
660 "/" + drive::util::GetDriveMountPointPath(profile() 669 "/" + drive::util::GetDriveMountPointPath(profile()
661 ).BaseName().AsUTF8Unsafe() + "/root"); 670 ).BaseName().AsUTF8Unsafe() + "/root");
662 std::string jsonString; 671 base::JSONWriter::Write(res.get(), output);
663 base::JSONWriter::Write(res.get(), &jsonString); 672 return;
664 return jsonString; 673 }
665 } else if (name == "isInGuestMode") { 674
675 if (name == "isInGuestMode") {
666 // Obtain whether the test is in guest mode or not. 676 // Obtain whether the test is in guest mode or not.
667 return GetGuestModeParam() != NOT_IN_GUEST_MODE ? "true" : "false"; 677 *output = GetGuestModeParam() != NOT_IN_GUEST_MODE ? "true" : "false";
668 } else if (name == "getCwsWidgetContainerMockUrl") { 678 return;
679 }
680
681 if (name == "getCwsWidgetContainerMockUrl") {
669 // Obtain whether the test is in guest mode or not. 682 // Obtain whether the test is in guest mode or not.
670 const GURL url = embedded_test_server()->GetURL( 683 const GURL url = embedded_test_server()->GetURL(
671 "/chromeos/file_manager/cws_container_mock/index.html"); 684 "/chromeos/file_manager/cws_container_mock/index.html");
672 std::string origin = url.GetOrigin().spec(); 685 std::string origin = url.GetOrigin().spec();
673 686
674 // Removes trailing a slash. 687 // Removes trailing a slash.
675 if (*origin.rbegin() == '/') 688 if (*origin.rbegin() == '/')
676 origin.resize(origin.length() - 1); 689 origin.resize(origin.length() - 1);
677 690
678 const scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); 691 const scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
679 res->SetString("url", url.spec()); 692 res->SetString("url", url.spec());
680 res->SetString("origin", origin); 693 res->SetString("origin", origin);
681 std::string jsonString; 694 base::JSONWriter::Write(res.get(), output);
682 base::JSONWriter::Write(res.get(), &jsonString); 695 return;
683 return jsonString; 696 }
684 } else if (name == "addEntries") { 697
698 if (name == "addEntries") {
685 // Add entries to the specified volume. 699 // Add entries to the specified volume.
686 base::JSONValueConverter<AddEntriesMessage> add_entries_message_converter; 700 base::JSONValueConverter<AddEntriesMessage> add_entries_message_converter;
687 AddEntriesMessage message; 701 AddEntriesMessage message;
688 if (!add_entries_message_converter.Convert(*value, &message)) 702 ASSERT_TRUE(add_entries_message_converter.Convert(value, &message));
689 return "onError"; 703
690 for (size_t i = 0; i < message.entries.size(); ++i) { 704 for (size_t i = 0; i < message.entries.size(); ++i) {
691 switch (message.volume) { 705 switch (message.volume) {
692 case LOCAL_VOLUME: 706 case LOCAL_VOLUME:
693 local_volume_->CreateEntry(*message.entries[i]); 707 local_volume_->CreateEntry(*message.entries[i]);
694 break; 708 break;
695 case DRIVE_VOLUME: 709 case DRIVE_VOLUME:
696 if (drive_volume_.get()) 710 if (drive_volume_.get())
697 drive_volume_->CreateEntry(*message.entries[i]); 711 drive_volume_->CreateEntry(*message.entries[i]);
698 break; 712 break;
699 case USB_VOLUME: 713 case USB_VOLUME:
700 if (usb_volume_) 714 if (usb_volume_)
701 usb_volume_->CreateEntry(*message.entries[i]); 715 usb_volume_->CreateEntry(*message.entries[i]);
702 break; 716 break;
703 default: 717 default:
704 NOTREACHED(); 718 NOTREACHED();
705 break; 719 break;
706 } 720 }
707 } 721 }
708 return "onEntryAdded"; 722
709 } else if (name == "mountFakeUsb") { 723 return;
724 }
725
726 if (name == "mountFakeUsb") {
710 usb_volume_.reset(new FakeTestVolume("fake-usb", 727 usb_volume_.reset(new FakeTestVolume("fake-usb",
711 VOLUME_TYPE_REMOVABLE_DISK_PARTITION, 728 VOLUME_TYPE_REMOVABLE_DISK_PARTITION,
712 chromeos::DEVICE_TYPE_USB)); 729 chromeos::DEVICE_TYPE_USB));
713 usb_volume_->Mount(profile()); 730 usb_volume_->Mount(profile());
714 return "true"; 731 return;
715 } else if (name == "mountFakeMtp") { 732 }
733
734 if (name == "mountFakeMtp") {
716 mtp_volume_.reset(new FakeTestVolume("fake-mtp", 735 mtp_volume_.reset(new FakeTestVolume("fake-mtp",
717 VOLUME_TYPE_MTP, 736 VOLUME_TYPE_MTP,
718 chromeos::DEVICE_TYPE_UNKNOWN)); 737 chromeos::DEVICE_TYPE_UNKNOWN));
719 if (!mtp_volume_->PrepareTestEntries(profile())) 738 ASSERT_TRUE(mtp_volume_->PrepareTestEntries(profile()));
720 return "false"; 739
721 mtp_volume_->Mount(profile()); 740 mtp_volume_->Mount(profile());
722 return "true"; 741 return;
723 } 742 }
724 return "unknownMessage"; 743
744 FAIL() << "Unknown test message: " << name;
725 } 745 }
726 746
727 drive::DriveIntegrationService* 747 drive::DriveIntegrationService*
728 FileManagerBrowserTestBase::CreateDriveIntegrationService(Profile* profile) { 748 FileManagerBrowserTestBase::CreateDriveIntegrationService(Profile* profile) {
729 drive_volumes_[profile->GetOriginalProfile()].reset(new DriveTestVolume()); 749 drive_volumes_[profile->GetOriginalProfile()].reset(new DriveTestVolume());
730 return drive_volumes_[profile->GetOriginalProfile()]-> 750 return drive_volumes_[profile->GetOriginalProfile()]->
731 CreateDriveIntegrationService(profile); 751 CreateDriveIntegrationService(profile);
732 } 752 }
733 753
734 // Parameter of FileManagerBrowserTest. 754 // Parameter of FileManagerBrowserTest.
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 1158
1139 private: 1159 private:
1140 virtual GuestMode GetGuestModeParam() const override { 1160 virtual GuestMode GetGuestModeParam() const override {
1141 return NOT_IN_GUEST_MODE; 1161 return NOT_IN_GUEST_MODE;
1142 } 1162 }
1143 1163
1144 virtual const char* GetTestCaseNameParam() const override { 1164 virtual const char* GetTestCaseNameParam() const override {
1145 return test_case_name_.c_str(); 1165 return test_case_name_.c_str();
1146 } 1166 }
1147 1167
1148 virtual std::string OnMessage(const std::string& name,
1149 const base::Value* value) override {
1150 if (name == "addAllUsers") {
1151 AddAllUsers();
1152 return "true";
1153 } else if (name == "getWindowOwnerId") {
1154 chrome::MultiUserWindowManager* const window_manager =
1155 chrome::MultiUserWindowManager::GetInstance();
1156 extensions::AppWindowRegistry* const app_window_registry =
1157 extensions::AppWindowRegistry::Get(profile());
1158 DCHECK(window_manager);
1159 DCHECK(app_window_registry);
1160
1161 const extensions::AppWindowRegistry::AppWindowList& list =
1162 app_window_registry->GetAppWindowsForApp(
1163 file_manager::kFileManagerAppId);
1164 return list.size() == 1u ?
1165 window_manager->GetUserPresentingWindow(
1166 list.front()->GetNativeWindow()) : "";
1167 }
1168 return FileManagerBrowserTestBase::OnMessage(name, value);
1169 }
1170
1171 std::string test_case_name_; 1168 std::string test_case_name_;
1172 }; 1169 };
1173 1170
1174 // Slow tests are disabled on debug build. http://crbug.com/327719 1171 // Slow tests are disabled on debug build. http://crbug.com/327719
1175 #if !defined(NDEBUG) 1172 #if !defined(NDEBUG)
1176 #define MAYBE_PRE_BasicDownloads DISABLED_PRE_BasicDownloads 1173 #define MAYBE_PRE_BasicDownloads DISABLED_PRE_BasicDownloads
1177 #define MAYBE_BasicDownloads DISABLED_BasicDownloads 1174 #define MAYBE_BasicDownloads DISABLED_BasicDownloads
1178 #else 1175 #else
1179 #define MAYBE_PRE_BasicDownloads PRE_BasicDownloads 1176 #define MAYBE_PRE_BasicDownloads PRE_BasicDownloads
1180 #define MAYBE_BasicDownloads BasicDownloads 1177 #define MAYBE_BasicDownloads BasicDownloads
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 return test_case_name_.c_str(); 1219 return test_case_name_.c_str();
1223 } 1220 }
1224 1221
1225 protected: 1222 protected:
1226 virtual void SetUp() override { 1223 virtual void SetUp() override {
1227 AddScript("common/test_util_common.js"); 1224 AddScript("common/test_util_common.js");
1228 AddScript("gallery/test_util.js"); 1225 AddScript("gallery/test_util.js");
1229 FileManagerBrowserTestBase::SetUp(); 1226 FileManagerBrowserTestBase::SetUp();
1230 } 1227 }
1231 1228
1232 virtual std::string OnMessage(const std::string& name, 1229 virtual void OnMessage(const std::string& name,
1233 const base::Value* value) override; 1230 const base::Value& value,
1231 std::string* output) override;
1234 1232
1235 virtual const char* GetTestManifestName() const override { 1233 virtual const char* GetTestManifestName() const override {
1236 return "gallery_test_manifest.json"; 1234 return "gallery_test_manifest.json";
1237 } 1235 }
1238 1236
1239 void AddScript(const std::string& name) { 1237 void AddScript(const std::string& name) {
1240 scripts_.AppendString( 1238 scripts_.AppendString(
1241 "chrome-extension://ejhcmmdhhpdhhgmifplfmjobgegbibkn/" + name); 1239 "chrome-extension://ejhcmmdhhpdhhgmifplfmjobgegbibkn/" + name);
1242 } 1240 }
1243 1241
1244 void set_test_case_name(const std::string& name) { 1242 void set_test_case_name(const std::string& name) {
1245 test_case_name_ = name; 1243 test_case_name_ = name;
1246 } 1244 }
1247 1245
1248 private: 1246 private:
1249 base::ListValue scripts_; 1247 base::ListValue scripts_;
1250 std::string test_case_name_; 1248 std::string test_case_name_;
1251 }; 1249 };
1252 1250
1253 template<GuestMode M> 1251 template <GuestMode M>
1254 std::string GalleryBrowserTestBase<M>::OnMessage(const std::string& name, 1252 void GalleryBrowserTestBase<M>::OnMessage(const std::string& name,
1255 const base::Value* value) { 1253 const base::Value& value,
1254 std::string* output) {
1256 if (name == "getScripts") { 1255 if (name == "getScripts") {
1257 std::string jsonString; 1256 std::string jsonString;
1258 base::JSONWriter::Write(&scripts_, &jsonString); 1257 base::JSONWriter::Write(&scripts_, output);
1259 return jsonString; 1258 return;
1260 } 1259 }
1261 return FileManagerBrowserTestBase::OnMessage(name, value); 1260
1261 FileManagerBrowserTestBase::OnMessage(name, value, output);
1262 } 1262 }
1263 1263
1264 typedef GalleryBrowserTestBase<NOT_IN_GUEST_MODE> GalleryBrowserTest; 1264 typedef GalleryBrowserTestBase<NOT_IN_GUEST_MODE> GalleryBrowserTest;
1265 typedef GalleryBrowserTestBase<IN_GUEST_MODE> GalleryBrowserTestInGuestMode; 1265 typedef GalleryBrowserTestBase<IN_GUEST_MODE> GalleryBrowserTestInGuestMode;
1266 1266
1267 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, OpenSingleImageOnDownloads) { 1267 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, OpenSingleImageOnDownloads) {
1268 AddScript("gallery/open_image_files.js"); 1268 AddScript("gallery/open_image_files.js");
1269 set_test_case_name("openSingleImageOnDownloads"); 1269 set_test_case_name("openSingleImageOnDownloads");
1270 StartTest(); 1270 StartTest();
1271 } 1271 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 AddScript("video_player/test_util.js"); 1430 AddScript("video_player/test_util.js");
1431 FileManagerBrowserTestBase::SetUp(); 1431 FileManagerBrowserTestBase::SetUp();
1432 } 1432 }
1433 1433
1434 virtual void SetUpCommandLine(CommandLine* command_line) override { 1434 virtual void SetUpCommandLine(CommandLine* command_line) override {
1435 command_line->AppendSwitch( 1435 command_line->AppendSwitch(
1436 chromeos::switches::kEnableVideoPlayerChromecastSupport); 1436 chromeos::switches::kEnableVideoPlayerChromecastSupport);
1437 FileManagerBrowserTestBase::SetUpCommandLine(command_line); 1437 FileManagerBrowserTestBase::SetUpCommandLine(command_line);
1438 } 1438 }
1439 1439
1440 virtual std::string OnMessage(const std::string& name, 1440 virtual void OnMessage(const std::string& name,
1441 const base::Value* value) override; 1441 const base::Value& value,
1442 std::string* output) override;
1442 1443
1443 virtual const char* GetTestManifestName() const override { 1444 virtual const char* GetTestManifestName() const override {
1444 return "video_player_test_manifest.json"; 1445 return "video_player_test_manifest.json";
1445 } 1446 }
1446 1447
1447 void AddScript(const std::string& name) { 1448 void AddScript(const std::string& name) {
1448 scripts_.AppendString( 1449 scripts_.AppendString(
1449 "chrome-extension://ljoplibgfehghmibaoaepfagnmbbfiga/" + name); 1450 "chrome-extension://ljoplibgfehghmibaoaepfagnmbbfiga/" + name);
1450 } 1451 }
1451 1452
1452 void set_test_case_name(const std::string& name) { 1453 void set_test_case_name(const std::string& name) {
1453 test_case_name_ = name; 1454 test_case_name_ = name;
1454 } 1455 }
1455 1456
1456 private: 1457 private:
1457 base::ListValue scripts_; 1458 base::ListValue scripts_;
1458 std::string test_case_name_; 1459 std::string test_case_name_;
1459 }; 1460 };
1460 1461
1461 template<GuestMode M> 1462 template <GuestMode M>
1462 std::string VideoPlayerBrowserTestBase<M>::OnMessage(const std::string& name, 1463 void VideoPlayerBrowserTestBase<M>::OnMessage(const std::string& name,
1463 const base::Value* value) { 1464 const base::Value& value,
1465 std::string* output) {
1464 if (name == "getScripts") { 1466 if (name == "getScripts") {
1465 std::string jsonString; 1467 std::string jsonString;
1466 base::JSONWriter::Write(&scripts_, &jsonString); 1468 base::JSONWriter::Write(&scripts_, output);
1467 return jsonString; 1469 return;
1468 } 1470 }
1469 return FileManagerBrowserTestBase::OnMessage(name, value); 1471
1472 FileManagerBrowserTestBase::OnMessage(name, value, output);
1470 } 1473 }
1471 1474
1472 typedef VideoPlayerBrowserTestBase<NOT_IN_GUEST_MODE> VideoPlayerBrowserTest; 1475 typedef VideoPlayerBrowserTestBase<NOT_IN_GUEST_MODE> VideoPlayerBrowserTest;
1473 typedef VideoPlayerBrowserTestBase<IN_GUEST_MODE> 1476 typedef VideoPlayerBrowserTestBase<IN_GUEST_MODE>
1474 VideoPlayerBrowserTestInGuestMode; 1477 VideoPlayerBrowserTestInGuestMode;
1475 1478
1476 IN_PROC_BROWSER_TEST_F(VideoPlayerBrowserTest, OpenSingleVideoOnDownloads) { 1479 IN_PROC_BROWSER_TEST_F(VideoPlayerBrowserTest, OpenSingleVideoOnDownloads) {
1477 AddScript("video_player/open_video_files.js"); 1480 AddScript("video_player/open_video_files.js");
1478 set_test_case_name("openSingleVideoOnDownloads"); 1481 set_test_case_name("openSingleVideoOnDownloads");
1479 StartTest(); 1482 StartTest();
1480 } 1483 }
1481 1484
1482 IN_PROC_BROWSER_TEST_F(VideoPlayerBrowserTest, OpenSingleVideoOnDrive) { 1485 IN_PROC_BROWSER_TEST_F(VideoPlayerBrowserTest, OpenSingleVideoOnDrive) {
1483 AddScript("video_player/open_video_files.js"); 1486 AddScript("video_player/open_video_files.js");
1484 set_test_case_name("openSingleVideoOnDrive"); 1487 set_test_case_name("openSingleVideoOnDrive");
1485 StartTest(); 1488 StartTest();
1486 } 1489 }
1487 1490
1488 } // namespace 1491 } // namespace
1489 } // namespace file_manager 1492 } // namespace file_manager
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/copy_between_windows.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698