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

Unified Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_browsertest.cc

Issue 12022002: Fixing activation states from the new launcher. Also adding a whole bunch of unit tests for the new… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed problem with ASAN unittest Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_browsertest.cc
diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_browsertest.cc
similarity index 85%
copy from chrome/browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc
copy to chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_browsertest.cc
index 6f6bf4d01895433fae7b245bb82562adfce6c4fd..db55cb52aaff3f50091b366d16706e1f19eb1461 100644
--- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc
+++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_browsertest.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
+#include "ash/ash_switches.h"
#include "ash/launcher/launcher.h"
#include "ash/launcher/launcher_model.h"
#include "ash/shell.h"
@@ -40,15 +41,22 @@
using extensions::Extension;
using content::WebContents;
-class LauncherPlatformAppBrowserTest
+// TODO(skuhne): Change name back to LauncherPlatformAppBrowserTest when the
+// old launcher gets ripped out.
+class LauncherPlatformPerAppAppBrowserTest
: public extensions::PlatformAppBrowserTest {
protected:
- LauncherPlatformAppBrowserTest()
+ LauncherPlatformPerAppAppBrowserTest()
: launcher_(NULL),
controller_(NULL) {
}
- virtual ~LauncherPlatformAppBrowserTest() {}
+ virtual ~LauncherPlatformPerAppAppBrowserTest() {}
+ // TODO(skuhne): Remove when the old launcher gets removed.
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ PlatformAppBrowserTest::SetUpCommandLine(command_line);
+ command_line->AppendSwitch(ash::switches::kAshEnablePerAppLauncher);
+ }
ash::LauncherModel* launcher_model() {
return ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model();
@@ -69,14 +77,22 @@ class LauncherPlatformAppBrowserTest
ChromeLauncherController* controller_;
};
-class LauncherAppBrowserTest : public ExtensionBrowserTest {
+// TODO(skuhne): Change name back to LauncherAppBrowserTest when the
+// old launcher gets ripped out.
+class LauncherPerAppAppBrowserTest : public ExtensionBrowserTest {
protected:
- LauncherAppBrowserTest()
+ LauncherPerAppAppBrowserTest()
: launcher_(NULL),
model_(NULL) {
}
- virtual ~LauncherAppBrowserTest() {}
+ virtual ~LauncherPerAppAppBrowserTest() {}
+
+ // TODO(skuhne): Remove when the old launcher gets removed.
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ ExtensionBrowserTest::SetUpCommandLine(command_line);
+ command_line->AppendSwitch(ash::switches::kAshEnablePerAppLauncher);
+ }
virtual void RunTestOnMainThreadLoop() {
launcher_ = ash::Launcher::ForPrimaryDisplay();
@@ -130,7 +146,7 @@ class LauncherAppBrowserTest : public ExtensionBrowserTest {
};
// Test that we can launch a platform app and get a running item.
-IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) {
+IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, LaunchUnpinned) {
int item_count = launcher_model()->item_count();
const Extension* extension = LoadAndLaunchPlatformApp("launch");
ShellWindow* window = CreateShellWindow(extension);
@@ -146,7 +162,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) {
}
// Test that we can launch a platform app that already has a shortcut.
-IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) {
+IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, LaunchPinned) {
int item_count = launcher_model()->item_count();
// First get app_id.
@@ -177,7 +193,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) {
EXPECT_EQ(ash::STATUS_CLOSED, item.status);
}
-IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, PinRunning) {
+IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, PinRunning) {
// Run.
int item_count = launcher_model()->item_count();
const Extension* extension = LoadAndLaunchPlatformApp("launch");
@@ -216,7 +232,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, PinRunning) {
ASSERT_EQ(item_count, launcher_model()->item_count());
}
-IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) {
+IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, UnpinRunning) {
int item_count = launcher_model()->item_count();
// First get app_id.
@@ -264,7 +280,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) {
}
// Test that we can launch a platform app with more than one window.
-IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) {
+IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, MultipleWindows) {
int item_count = launcher_model()->item_count();
// First run app.
@@ -299,7 +315,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) {
ASSERT_EQ(item_count, launcher_model()->item_count());
}
-IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) {
+IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, MultipleApps) {
int item_count = launcher_model()->item_count();
// First run app.
@@ -345,7 +361,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) {
// Confirm that app windows can be reactivated by clicking their icons and that
// the correct activation order is maintained.
-IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowActivation) {
+IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, WindowActivation) {
int item_count = launcher_model()->item_count();
// First run app.
@@ -431,7 +447,8 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowActivation) {
EXPECT_EQ(item_count, launcher_model()->item_count());
}
-IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, BrowserActivation) {
+IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest,
+ BrowserActivation) {
int item_count = launcher_model()->item_count();
// First run app.
@@ -451,7 +468,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, BrowserActivation) {
}
// Test that we can launch an app with a shortcut.
-IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchPinned) {
+IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchPinned) {
TabStripModel* tab_strip = browser()->tab_strip_model();
int tab_count = tab_strip->count();
ash::LauncherID shortcut_id = CreateShortcut("app1");
@@ -470,7 +487,7 @@ IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchPinned) {
}
// Launch the app first and then create the shortcut.
-IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchUnpinned) {
+IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchUnpinned) {
TabStripModel* tab_strip = browser()->tab_strip_model();
int tab_count = tab_strip->count();
LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB,
@@ -490,7 +507,7 @@ IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchUnpinned) {
// Launches an app in the background and then tries to open it. This is test for
// a crash we had.
-IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchInBackground) {
+IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchInBackground) {
TabStripModel* tab_strip = browser()->tab_strip_model();
int tab_count = tab_strip->count();
LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB,
@@ -501,7 +518,7 @@ IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchInBackground) {
// Confirm that clicking a icon for an app running in one of 2 maxmized windows
// activates the right window.
-IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchMaximized) {
+IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchMaximized) {
aura::Window* window1 = browser()->window()->GetNativeWindow();
ash::wm::MaximizeWindow(window1);
content::WindowedNotificationObserver open_observer(
@@ -529,7 +546,7 @@ IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchMaximized) {
}
// Activating the same app multiple times should launch only a single copy.
-IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivateApp) {
+IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, ActivateApp) {
TabStripModel* tab_strip = browser()->tab_strip_model();
int tab_count = tab_strip->count();
const Extension* extension =
@@ -542,7 +559,7 @@ IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivateApp) {
}
// Launching the same app multiple times should launch a copy for each call.
-IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchApp) {
+IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchApp) {
TabStripModel* tab_strip = browser()->tab_strip_model();
int tab_count = tab_strip->count();
const Extension* extension =
@@ -555,7 +572,7 @@ IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchApp) {
}
// Launch 2 apps and toggle which is active.
-IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleApps) {
+IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, MultipleApps) {
int item_count = model_->item_count();
TabStripModel* tab_strip = browser()->tab_strip_model();
int tab_count = tab_strip->count();
@@ -592,7 +609,6 @@ IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleApps) {
NEW_FOREGROUND_TAB,
0);
EXPECT_EQ(++tab_count, tab_strip->count());
- WebContents* tab3 = tab_strip->GetActiveWebContents();
EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status);
EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status);
@@ -606,14 +622,14 @@ IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleApps) {
// And second again. This time the second tab should become active.
launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut2));
EXPECT_EQ(tab_count, tab_strip->count());
- EXPECT_EQ(tab_strip->GetActiveWebContents(), tab3);
+ EXPECT_EQ(tab_strip->GetActiveWebContents(), tab2);
EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status);
EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status);
}
// Confirm that a page can be navigated from and to while maintaining the
// correct running state.
-IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, Navigation) {
+IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, Navigation) {
ash::LauncherID shortcut_id = CreateShortcut("app1");
EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
@@ -630,13 +646,14 @@ IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, Navigation) {
EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
}
-IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleOwnedTabs) {
+IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, MultipleOwnedTabs) {
TabStripModel* tab_strip = browser()->tab_strip_model();
int tab_count = tab_strip->count();
ash::LauncherID shortcut_id = CreateShortcut("app1");
launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
EXPECT_EQ(++tab_count, tab_strip->count());
EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
+ WebContents* first_tab = tab_strip->GetActiveWebContents();
// Create new tab owned by app.
ui_test_utils::NavigateToURLWithDisposition(
@@ -647,7 +664,6 @@ IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleOwnedTabs) {
EXPECT_EQ(++tab_count, tab_strip->count());
// Confirm app is still active.
EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
- WebContents* second_tab = tab_strip->GetActiveWebContents();
// Create new tab not owned by app.
ui_test_utils::NavigateToURLWithDisposition(
@@ -659,13 +675,13 @@ IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleOwnedTabs) {
// No longer active.
EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status);
- // Activating app makes second tab active again.
+ // Activating app makes first tab active again.
launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
- EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab);
+ EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab);
}
-IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilter) {
+IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, RefocusFilter) {
ChromeLauncherController* controller =
static_cast<ChromeLauncherController*>(launcher_->delegate());
TabStripModel* tab_strip = browser()->tab_strip_model();
@@ -705,7 +721,7 @@ IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilter) {
EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab);
}
-IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilterLaunch) {
+IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, RefocusFilterLaunch) {
ChromeLauncherController* controller =
static_cast<ChromeLauncherController*>(launcher_->delegate());
TabStripModel* tab_strip = browser()->tab_strip_model();
@@ -734,3 +750,51 @@ IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilterLaunch) {
EXPECT_NE(first_tab, second_tab);
EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab);
}
+
+// Check the launcher activation state for applications and browser.
+IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, ActivationStateCheck) {
+ ChromeLauncherController* controller =
+ static_cast<ChromeLauncherController*>(launcher_->delegate());
+ TabStripModel* tab_strip = browser()->tab_strip_model();
+ // Get the browser item index
+ int browser_index = -1;
+ for (size_t index = 0; index < model_->items().size() && browser_index == -1;
+ index++) {
+ if (model_->items()[index].type == ash::TYPE_BROWSER_SHORTCUT)
+ browser_index = index;
+ }
+ EXPECT_TRUE(browser_index >= 0);
+
+ // Even though we are just comming up, the browser should be active.
+ EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
+
+ ash::LauncherID shortcut_id = CreateShortcut("app1");
+ controller->SetRefocusURLPatternForTest(
+ shortcut_id, GURL("http://www.example.com/path1/*"));
+
+ EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status);
+ EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
+
+ // Create new tab which would be the running app.
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(),
+ GURL("http://www.example.com/path1/bar.html"),
+ NEW_FOREGROUND_TAB,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
+
+ EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
+ EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
+
+ tab_strip->ActivateTabAt(0, false);
+ EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status);
+ EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
+
+ tab_strip->CloseWebContentsAt(1, TabStripModel::CLOSE_NONE);
+ EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status);
+ EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
+
+ ash::wm::DeactivateWindow(browser()->window()->GetNativeWindow());
+ EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status);
+ EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[browser_index].status);
+}
+

Powered by Google App Engine
This is Rietveld 408576698