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

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc

Issue 22429004: Refactor LauncherDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add some comments Created 7 years, 4 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
OLDNEW
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 "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
6 6
7 #include "apps/native_app_window.h" 7 #include "apps/native_app_window.h"
8 #include "apps/shell_window.h" 8 #include "apps/shell_window.h"
9 #include "apps/shell_window_registry.h" 9 #include "apps/shell_window_registry.h"
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } 56 }
57 57
58 virtual ~LauncherPlatformAppBrowserTest() {} 58 virtual ~LauncherPlatformAppBrowserTest() {}
59 59
60 ash::LauncherModel* launcher_model() { 60 ash::LauncherModel* launcher_model() {
61 return ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); 61 return ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model();
62 } 62 }
63 63
64 virtual void RunTestOnMainThreadLoop() OVERRIDE { 64 virtual void RunTestOnMainThreadLoop() OVERRIDE {
65 launcher_ = ash::Launcher::ForPrimaryDisplay(); 65 launcher_ = ash::Launcher::ForPrimaryDisplay();
66 controller_ = static_cast<ChromeLauncherController*>(launcher_->delegate()); 66 controller_ = ChromeLauncherController::instance();
67 DCHECK(controller_);
67 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop(); 68 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop();
68 } 69 }
69 70
70 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 71 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
71 PlatformAppBrowserTest::SetUpCommandLine(command_line); 72 PlatformAppBrowserTest::SetUpCommandLine(command_line);
72 command_line->AppendSwitch(ash::switches::kAshDisablePerAppLauncher); 73 command_line->AppendSwitch(ash::switches::kAshDisablePerAppLauncher);
73 } 74 }
74 75
75 ash::LauncherID CreateAppShortcutLauncherItem(const std::string& name) { 76 ash::LauncherID CreateAppShortcutLauncherItem(const std::string& name) {
76 return controller_->CreateAppShortcutLauncherItem( 77 return controller_->CreateAppShortcutLauncherItem(
(...skipping 22 matching lines...) Expand all
99 : launcher_(NULL), 100 : launcher_(NULL),
100 model_(NULL) { 101 model_(NULL) {
101 } 102 }
102 103
103 virtual ~LauncherAppBrowserTest() {} 104 virtual ~LauncherAppBrowserTest() {}
104 105
105 virtual void RunTestOnMainThreadLoop() OVERRIDE { 106 virtual void RunTestOnMainThreadLoop() OVERRIDE {
106 launcher_ = ash::Launcher::ForPrimaryDisplay(); 107 launcher_ = ash::Launcher::ForPrimaryDisplay();
107 model_ = 108 model_ =
108 ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); 109 ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model();
110 controller_ = ChromeLauncherController::instance();
111 DCHECK(controller_);
Mr4D (OOO till 08-26) 2013/08/13 18:18:24 Isn't there a DCHECK already in the instance funct
simonhong_ 2013/08/13 19:54:56 Yes, it is already checked. Removed.
109 return ExtensionBrowserTest::RunTestOnMainThreadLoop(); 112 return ExtensionBrowserTest::RunTestOnMainThreadLoop();
110 } 113 }
111 114
112 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 115 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
113 ExtensionBrowserTest::SetUpCommandLine(command_line); 116 ExtensionBrowserTest::SetUpCommandLine(command_line);
114 command_line->AppendSwitch(ash::switches::kAshDisablePerAppLauncher); 117 command_line->AppendSwitch(ash::switches::kAshDisablePerAppLauncher);
115 } 118 }
116 119
117 const Extension* LoadAndLaunchExtension( 120 const Extension* LoadAndLaunchExtension(
118 const char* name, 121 const char* name,
(...skipping 16 matching lines...) Expand all
135 ExtensionService* service = extensions::ExtensionSystem::Get( 138 ExtensionService* service = extensions::ExtensionSystem::Get(
136 browser()->profile())->extension_service(); 139 browser()->profile())->extension_service();
137 LoadExtension(test_data_dir_.AppendASCII(name)); 140 LoadExtension(test_data_dir_.AppendASCII(name));
138 141
139 // First get app_id. 142 // First get app_id.
140 const Extension* extension = 143 const Extension* extension =
141 service->GetExtensionById(last_loaded_extension_id_, false); 144 service->GetExtensionById(last_loaded_extension_id_, false);
142 const std::string app_id = extension->id(); 145 const std::string app_id = extension->id();
143 146
144 // Then create a shortcut. 147 // Then create a shortcut.
145 ChromeLauncherController* controller =
146 static_cast<ChromeLauncherController*>(launcher_->delegate());
147 int item_count = model_->item_count(); 148 int item_count = model_->item_count();
148 ash::LauncherID shortcut_id = controller->CreateAppShortcutLauncherItem( 149 ash::LauncherID shortcut_id = controller_->CreateAppShortcutLauncherItem(
149 app_id, item_count); 150 app_id, item_count);
150 controller->PersistPinnedState(); 151 controller_->PersistPinnedState();
151 EXPECT_EQ(++item_count, model_->item_count()); 152 EXPECT_EQ(++item_count, model_->item_count());
152 ash::LauncherItem item = *model_->ItemByID(shortcut_id); 153 ash::LauncherItem item = *model_->ItemByID(shortcut_id);
153 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); 154 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type);
154 return item.id; 155 return item.id;
155 } 156 }
156 157
157 ash::LauncherID PinFakeApp(const std::string& name) { 158 ash::LauncherID PinFakeApp(const std::string& name) {
158 ChromeLauncherController* controller = 159 return controller_->CreateAppShortcutLauncherItem(
159 static_cast<ChromeLauncherController*>(launcher_->delegate());
160 return controller->CreateAppShortcutLauncherItem(
161 name, model_->item_count()); 160 name, model_->item_count());
162 } 161 }
163 162
164 ash::Launcher* launcher_; 163 ash::Launcher* launcher_;
165 ash::LauncherModel* model_; 164 ash::LauncherModel* model_;
165 ChromeLauncherController* controller_;
166 }; 166 };
167 167
168 // Test that we can launch a platform app and get a running item. 168 // Test that we can launch a platform app and get a running item.
169 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) { 169 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) {
170 int item_count = launcher_model()->item_count(); 170 int item_count = launcher_model()->item_count();
171 const Extension* extension = LoadAndLaunchPlatformApp("launch"); 171 const Extension* extension = LoadAndLaunchPlatformApp("launch");
172 ShellWindow* window = CreateShellWindow(extension); 172 ShellWindow* window = CreateShellWindow(extension);
173 ++item_count; 173 ++item_count;
174 ASSERT_EQ(item_count, launcher_model()->item_count()); 174 ASSERT_EQ(item_count, launcher_model()->item_count());
175 const ash::LauncherItem& item = GetLastLauncherItem(); 175 const ash::LauncherItem& item = GetLastLauncherItem();
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 } 559 }
560 560
561 // Launches an app in the background and then tries to open it. This is test for 561 // Launches an app in the background and then tries to open it. This is test for
562 // a crash we had. 562 // a crash we had.
563 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchInBackground) { 563 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchInBackground) {
564 TabStripModel* tab_strip = browser()->tab_strip_model(); 564 TabStripModel* tab_strip = browser()->tab_strip_model();
565 int tab_count = tab_strip->count(); 565 int tab_count = tab_strip->count();
566 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, 566 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB,
567 NEW_BACKGROUND_TAB); 567 NEW_BACKGROUND_TAB);
568 EXPECT_EQ(++tab_count, tab_strip->count()); 568 EXPECT_EQ(++tab_count, tab_strip->count());
569 ChromeLauncherController::instance()->LaunchApp(last_loaded_extension_id_, 0); 569 controller_->LaunchApp(last_loaded_extension_id_, 0);
570 } 570 }
571 571
572 // Confirm that clicking a icon for an app running in one of 2 maxmized windows 572 // Confirm that clicking a icon for an app running in one of 2 maxmized windows
573 // activates the right window. 573 // activates the right window.
574 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchMaximized) { 574 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchMaximized) {
575 aura::Window* window1 = browser()->window()->GetNativeWindow(); 575 aura::Window* window1 = browser()->window()->GetNativeWindow();
576 ash::wm::MaximizeWindow(window1); 576 ash::wm::MaximizeWindow(window1);
577 content::WindowedNotificationObserver open_observer( 577 content::WindowedNotificationObserver open_observer(
578 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 578 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
579 content::NotificationService::AllSources()); 579 content::NotificationService::AllSources());
(...skipping 18 matching lines...) Expand all
598 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 598 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
599 } 599 }
600 600
601 // Activating the same app multiple times should launch only a single copy. 601 // Activating the same app multiple times should launch only a single copy.
602 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivateApp) { 602 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivateApp) {
603 TabStripModel* tab_strip = browser()->tab_strip_model(); 603 TabStripModel* tab_strip = browser()->tab_strip_model();
604 int tab_count = tab_strip->count(); 604 int tab_count = tab_strip->count();
605 const Extension* extension = 605 const Extension* extension =
606 LoadExtension(test_data_dir_.AppendASCII("app1")); 606 LoadExtension(test_data_dir_.AppendASCII("app1"));
607 607
608 ChromeLauncherController::instance()->ActivateApp(extension->id(), 0); 608 controller_->ActivateApp(extension->id(), 0);
609 EXPECT_EQ(++tab_count, tab_strip->count()); 609 EXPECT_EQ(++tab_count, tab_strip->count());
610 ChromeLauncherController::instance()->ActivateApp(extension->id(), 0); 610 controller_->ActivateApp(extension->id(), 0);
611 EXPECT_EQ(tab_count, tab_strip->count()); 611 EXPECT_EQ(tab_count, tab_strip->count());
612 } 612 }
613 613
614 // Launching the same app multiple times should launch a copy for each call. 614 // Launching the same app multiple times should launch a copy for each call.
615 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchApp) { 615 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchApp) {
616 TabStripModel* tab_strip = browser()->tab_strip_model(); 616 TabStripModel* tab_strip = browser()->tab_strip_model();
617 int tab_count = tab_strip->count(); 617 int tab_count = tab_strip->count();
618 const Extension* extension = 618 const Extension* extension =
619 LoadExtension(test_data_dir_.AppendASCII("app1")); 619 LoadExtension(test_data_dir_.AppendASCII("app1"));
620 620
621 ChromeLauncherController::instance()->LaunchApp(extension->id(), 0); 621 controller_->LaunchApp(extension->id(), 0);
622 EXPECT_EQ(++tab_count, tab_strip->count()); 622 EXPECT_EQ(++tab_count, tab_strip->count());
623 ChromeLauncherController::instance()->LaunchApp(extension->id(), 0); 623 controller_->LaunchApp(extension->id(), 0);
624 EXPECT_EQ(++tab_count, tab_strip->count()); 624 EXPECT_EQ(++tab_count, tab_strip->count());
625 } 625 }
626 626
627 // Launch 2 apps and toggle which is active. 627 // Launch 2 apps and toggle which is active.
628 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleApps) { 628 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleApps) {
629 int item_count = model_->item_count(); 629 int item_count = model_->item_count();
630 TabStripModel* tab_strip = browser()->tab_strip_model(); 630 TabStripModel* tab_strip = browser()->tab_strip_model();
631 int tab_count = tab_strip->count(); 631 int tab_count = tab_strip->count();
632 ash::LauncherID shortcut1 = CreateShortcut("app1"); 632 ash::LauncherID shortcut1 = CreateShortcut("app1");
633 EXPECT_EQ(++item_count, model_->item_count()); 633 EXPECT_EQ(++item_count, model_->item_count());
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 // No longer active. 729 // No longer active.
730 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); 730 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status);
731 731
732 // Activating app makes second tab active again. 732 // Activating app makes second tab active again.
733 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 733 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
734 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 734 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
735 EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab); 735 EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab);
736 } 736 }
737 737
738 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilter) { 738 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilter) {
739 ChromeLauncherController* controller =
740 static_cast<ChromeLauncherController*>(launcher_->delegate());
741 TabStripModel* tab_strip = browser()->tab_strip_model(); 739 TabStripModel* tab_strip = browser()->tab_strip_model();
742 int tab_count = tab_strip->count(); 740 int tab_count = tab_strip->count();
743 ash::LauncherID shortcut_id = CreateShortcut("app1"); 741 ash::LauncherID shortcut_id = CreateShortcut("app1");
744 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 742 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
745 EXPECT_EQ(++tab_count, tab_strip->count()); 743 EXPECT_EQ(++tab_count, tab_strip->count());
746 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 744 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
747 WebContents* first_tab = tab_strip->GetActiveWebContents(); 745 WebContents* first_tab = tab_strip->GetActiveWebContents();
748 746
749 controller->SetRefocusURLPatternForTest( 747 controller_->SetRefocusURLPatternForTest(
750 shortcut_id, GURL("http://www.example.com/path1/*")); 748 shortcut_id, GURL("http://www.example.com/path1/*"));
751 // Create new tab owned by app. 749 // Create new tab owned by app.
752 ui_test_utils::NavigateToURLWithDisposition( 750 ui_test_utils::NavigateToURLWithDisposition(
753 browser(), 751 browser(),
754 GURL("http://www.example.com/path2/bar.html"), 752 GURL("http://www.example.com/path2/bar.html"),
755 NEW_FOREGROUND_TAB, 753 NEW_FOREGROUND_TAB,
756 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 754 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
757 EXPECT_EQ(++tab_count, tab_strip->count()); 755 EXPECT_EQ(++tab_count, tab_strip->count());
758 // Confirm app is still active. 756 // Confirm app is still active.
759 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 757 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
760 758
761 // Create new tab not owned by app. 759 // Create new tab not owned by app.
762 ui_test_utils::NavigateToURLWithDisposition( 760 ui_test_utils::NavigateToURLWithDisposition(
763 browser(), 761 browser(),
764 GURL("http://www.example.com/path3/foo.html"), 762 GURL("http://www.example.com/path3/foo.html"),
765 NEW_FOREGROUND_TAB, 763 NEW_FOREGROUND_TAB,
766 0); 764 0);
767 EXPECT_EQ(++tab_count, tab_strip->count()); 765 EXPECT_EQ(++tab_count, tab_strip->count());
768 // No longer active. 766 // No longer active.
769 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); 767 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status);
770 768
771 // Activating app makes first tab active again, because second tab isn't 769 // Activating app makes first tab active again, because second tab isn't
772 // in its refocus url path. 770 // in its refocus url path.
773 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 771 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
774 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 772 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
775 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab); 773 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab);
776 } 774 }
777 775
778 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilterLaunch) { 776 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilterLaunch) {
779 ChromeLauncherController* controller =
780 static_cast<ChromeLauncherController*>(launcher_->delegate());
781 TabStripModel* tab_strip = browser()->tab_strip_model(); 777 TabStripModel* tab_strip = browser()->tab_strip_model();
782 int tab_count = tab_strip->count(); 778 int tab_count = tab_strip->count();
783 ash::LauncherID shortcut_id = CreateShortcut("app1"); 779 ash::LauncherID shortcut_id = CreateShortcut("app1");
784 controller->SetRefocusURLPatternForTest( 780 controller_->SetRefocusURLPatternForTest(
785 shortcut_id, GURL("http://www.example.com/path1/*")); 781 shortcut_id, GURL("http://www.example.com/path1/*"));
786 782
787 // Create new tab owned by app. 783 // Create new tab owned by app.
788 ui_test_utils::NavigateToURLWithDisposition( 784 ui_test_utils::NavigateToURLWithDisposition(
789 browser(), 785 browser(),
790 GURL("http://www.example.com/path2/bar.html"), 786 GURL("http://www.example.com/path2/bar.html"),
791 NEW_FOREGROUND_TAB, 787 NEW_FOREGROUND_TAB,
792 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 788 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
793 EXPECT_EQ(++tab_count, tab_strip->count()); 789 EXPECT_EQ(++tab_count, tab_strip->count());
794 WebContents* first_tab = tab_strip->GetActiveWebContents(); 790 WebContents* first_tab = tab_strip->GetActiveWebContents();
(...skipping 26 matching lines...) Expand all
821 817
822 ++items_added; 818 ++items_added;
823 ASSERT_LT(items_added, 10000); 819 ASSERT_LT(items_added, 10000);
824 } 820 }
825 821
826 // Now show overflow bubble. 822 // Now show overflow bubble.
827 test.ShowOverflowBubble(); 823 test.ShowOverflowBubble();
828 EXPECT_TRUE(launcher_->IsShowingOverflowBubble()); 824 EXPECT_TRUE(launcher_->IsShowingOverflowBubble());
829 825
830 // Unpin first pinned app and there should be no crash. 826 // Unpin first pinned app and there should be no crash.
831 ChromeLauncherController* controller = 827 controller_->UnpinAppsWithID(std::string("fake_app_0"));
832 static_cast<ChromeLauncherController*>(launcher_->delegate());
833 controller->UnpinAppsWithID(std::string("fake_app_0"));
834 828
835 test.RunMessageLoopUntilAnimationsDone(); 829 test.RunMessageLoopUntilAnimationsDone();
836 EXPECT_FALSE(launcher_->IsShowingOverflowBubble()); 830 EXPECT_FALSE(launcher_->IsShowingOverflowBubble());
837 } 831 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698