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

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

Issue 2297633002: Add chrome.app.window API tests for items shown in shelf Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pin and Restore Unit Test Created 4 years 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_impl_browsertest.cc
diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl_browsertest.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl_browsertest.cc
index be80e2d21ce205896f2e12f12e0467365c6b57cc..3c28d4019ee2c4e5fd7ae8aa2490464b1e5f7eb8 100644
--- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl_browsertest.cc
+++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl_browsertest.cc
@@ -415,6 +415,27 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) {
EXPECT_EQ(item_count, shelf_model()->item_count());
}
+IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest,
+ LaunchUnpinnedShowInShelfWindow) {
+ int item_count = shelf_model()->item_count();
+ const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched");
+ AppWindow::CreateParams params;
+
+ // Open a window shown in shelf.
+ params.show_in_shelf = true;
+ params.window_key = "window";
+ AppWindow* window =
+ CreateAppWindowFromParams(browser()->profile(), extension, params);
+ ++item_count;
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ const ash::ShelfItem& item = GetLastLauncherItem();
+ EXPECT_EQ(ash::TYPE_APP, item.type);
+ EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
+ CloseAppWindow(window);
+ --item_count;
+ EXPECT_EQ(item_count, shelf_model()->item_count());
+}
+
// Test that we can launch a platform app that already has a shortcut.
IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) {
int item_count = shelf_model()->item_count();
@@ -448,6 +469,43 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) {
EXPECT_EQ(ash::STATUS_CLOSED, item.status);
}
+IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest,
+ LaunchPinnedShowInShelfWindow) {
+ int item_count = shelf_model()->item_count();
+
+ // First get app_id.
+ const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched");
+ const std::string app_id = extension->id();
+ AppWindow::CreateParams params;
+
+ // Then create a shortcut.
+ ash::ShelfID shortcut_id = CreateAppShortcutLauncherItem(
+ ash::launcher::AppLauncherId(app_id, "window"));
+ ++item_count;
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ ash::ShelfItem item = *shelf_model()->ItemByID(shortcut_id);
+ EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type);
+ EXPECT_EQ(ash::STATUS_CLOSED, item.status);
+
+ // Open a window shown in shelf. Confirm the item is now running.
+ params.show_in_shelf = true;
+ params.window_key = "window";
+ AppWindow* window =
+ CreateAppWindowFromParams(browser()->profile(), extension, params);
+ ash::wm::ActivateWindow(window->GetNativeWindow());
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ item = *shelf_model()->ItemByID(shortcut_id);
+ EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type);
+ EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
+
+ // Then close it, make sure there's still an item.
+ CloseAppWindow(window);
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ item = *shelf_model()->ItemByID(shortcut_id);
+ EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type);
+ EXPECT_EQ(ash::STATUS_CLOSED, item.status);
+}
+
IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, PinRunning) {
// Run.
int item_count = shelf_model()->item_count();
@@ -488,6 +546,69 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, PinRunning) {
ASSERT_EQ(item_count, shelf_model()->item_count());
}
+IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest,
+ PinRunningShowInShelfWindow) {
+ // Run.
+ int item_count = shelf_model()->item_count();
+ const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched");
+ AppWindow::CreateParams params;
+
+ AppWindow* window1 = CreateAppWindow(browser()->profile(), extension);
+ ++item_count;
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ const ash::ShelfItem& item_window1 = GetLastLauncherItem();
+ ash::ShelfID id_window1 = item_window1.id;
+ EXPECT_EQ(ash::TYPE_APP, item_window1.type);
+ EXPECT_EQ(ash::STATUS_ACTIVE, item_window1.status);
+
+ // Open a window shown in shelf.
+ params.show_in_shelf = true;
+ params.window_key = "window2";
+ AppWindow* window2 =
+ CreateAppWindowFromParams(browser()->profile(), extension, params);
+ ++item_count;
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ const ash::ShelfItem& item_window2 = GetLastLauncherItem();
+ ash::ShelfID id_window2 = item_window2.id;
+ EXPECT_EQ(ash::TYPE_APP, item_window2.type);
+ EXPECT_EQ(ash::STATUS_ACTIVE, item_window2.status);
+
+ // Create a shortcut. The app window1 and window2 should be after it.
+ ash::ShelfID foo_id =
+ CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId("foo"));
+ ++item_count;
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ EXPECT_LT(shelf_model()->ItemIndexByID(foo_id),
+ shelf_model()->ItemIndexByID(id_window1));
+ EXPECT_LT(shelf_model()->ItemIndexByID(foo_id),
+ shelf_model()->ItemIndexByID(id_window2));
+
+ // Pin the app window1. The item should remain.
+ controller_->Pin(id_window1);
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ const ash::ShelfItem& item_window = *shelf_model()->ItemByID(id_window1);
+ EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item_window.type);
+ EXPECT_EQ(ash::STATUS_RUNNING, item_window.status);
+
+ // New shortcuts should come after the app window1 and before window2.
+ ash::ShelfID bar_id =
+ CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId("bar"));
+ ++item_count;
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ EXPECT_LT(shelf_model()->ItemIndexByID(id_window1),
+ shelf_model()->ItemIndexByID(bar_id));
+ EXPECT_LT(shelf_model()->ItemIndexByID(bar_id),
+ shelf_model()->ItemIndexByID(id_window2));
+
+ // Then close the app window1, make sure the item remains.
+ CloseAppWindow(window1);
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ // Then close the app window2.
+ CloseAppWindow(window2);
+ --item_count;
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+}
+
IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) {
int item_count = shelf_model()->item_count();
@@ -537,6 +658,74 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) {
ASSERT_EQ(item_count, shelf_model()->item_count());
}
+IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest,
+ UnpinRunningShowInShelfWindow) {
+ int item_count = shelf_model()->item_count();
+
+ // First get app_id.
+ const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched");
+ const std::string app_id = extension->id();
+ AppWindow::CreateParams params;
+
+ // Then create a shortcut window1.
+ ash::ShelfID shortcut_id_window1 =
+ CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId(app_id));
+ ++item_count;
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ ash::ShelfItem item_window1 = *shelf_model()->ItemByID(shortcut_id_window1);
+ EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item_window1.type);
+ EXPECT_EQ(ash::STATUS_CLOSED, item_window1.status);
+
+ // Create a second shortcut. This will be needed to force the first one to
+ // move once it gets unpinned.
+ ash::ShelfID foo_id =
+ CreateAppShortcutLauncherItem(ash::launcher::AppLauncherId("foo"));
+ ++item_count;
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ EXPECT_LT(shelf_model()->ItemIndexByID(shortcut_id_window1),
+ shelf_model()->ItemIndexByID(foo_id));
+
+ // Open app window1. Confirm the item is now running.
+ AppWindow* window1 = CreateAppWindow(browser()->profile(), extension);
+ ash::wm::ActivateWindow(window1->GetNativeWindow());
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ item_window1 = *shelf_model()->ItemByID(shortcut_id_window1);
+ EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item_window1.type);
+ EXPECT_EQ(ash::STATUS_ACTIVE, item_window1.status);
+
+ // Open the app window2 shown in shelf.
+ params.show_in_shelf = true;
+ params.window_key = "window2";
+ AppWindow* window2 =
+ CreateAppWindowFromParams(browser()->profile(), extension, params);
+ ++item_count;
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ const ash::ShelfItem& item_window2 = GetLastLauncherItem();
+ ash::ShelfID id_window2 = item_window2.id;
+ EXPECT_EQ(ash::TYPE_APP, item_window2.type);
+ EXPECT_EQ(ash::STATUS_ACTIVE, item_window2.status);
+ EXPECT_GT(shelf_model()->ItemIndexByID(id_window2),
+ shelf_model()->ItemIndexByID(foo_id));
+
+ // Unpin the app window1. The item should remain.
+ controller_->Unpin(shortcut_id_window1);
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ item_window1 = *shelf_model()->ItemByID(shortcut_id_window1);
+ EXPECT_EQ(ash::TYPE_APP, item_window1.type);
+ EXPECT_EQ(ash::STATUS_RUNNING, item_window1.status);
+ // The app window1 should have moved after the other shortcuts.
+ EXPECT_GT(shelf_model()->ItemIndexByID(shortcut_id_window1),
+ shelf_model()->ItemIndexByID(foo_id));
+
+ // Then close app window1 and window2, make sure the item's gone.
+ CloseAppWindow(window1);
+ --item_count;
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ CloseAppWindow(window2);
+ --item_count;
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+}
+
// Test that we can launch a platform app with more than one window.
IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) {
int item_count = shelf_model()->item_count();
@@ -2424,3 +2613,80 @@ IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest,
ASSERT_FALSE(
IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE));
}
+
+IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest,
+ PinAndRestoreShowInShelfWindow) {
+ // Run.
+ int item_count = shelf_model()->item_count();
+ const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched");
+ AppWindow::CreateParams params;
+
+ AppWindow* window1 = CreateAppWindow(browser()->profile(), extension);
+ ++item_count;
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ const ash::ShelfItem& item_window1 = GetLastLauncherItem();
+ EXPECT_EQ(ash::TYPE_APP, item_window1.type);
+ EXPECT_EQ(ash::STATUS_ACTIVE, item_window1.status);
+
+ // Open a window shown in shelf.
+ params.show_in_shelf = true;
+ params.window_key = "window2";
+ AppWindow* window2 =
+ CreateAppWindowFromParams(browser()->profile(), extension, params);
+ ++item_count;
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ const ash::ShelfItem& item_window2 = GetLastLauncherItem();
+ ash::ShelfID id_window2 = item_window2.id;
+ EXPECT_EQ(ash::TYPE_APP, item_window2.type);
+ EXPECT_EQ(ash::STATUS_ACTIVE, item_window2.status);
+
+ // Open the second window shown in shelf.
+ params.show_in_shelf = true;
+ params.window_key = "window3";
+ AppWindow* window3 =
+ CreateAppWindowFromParams(browser()->profile(), extension, params);
+ ++item_count;
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ const ash::ShelfItem& item_window3 = GetLastLauncherItem();
+ ash::ShelfID id_window3 = item_window3.id;
+ EXPECT_EQ(ash::TYPE_APP, item_window3.type);
+ EXPECT_EQ(ash::STATUS_ACTIVE, item_window3.status);
+
+ // Pin the app window2. The item should remain.
+ controller_->Pin(id_window2);
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ const ash::ShelfItem& item_window_p2 = *shelf_model()->ItemByID(id_window2);
+ EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item_window_p2.type);
+ EXPECT_EQ(ash::STATUS_RUNNING, item_window_p2.status);
+
+ // Pin the app window3. The item should remain.
+ controller_->Pin(id_window3);
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ const ash::ShelfItem& item_window_p3 = *shelf_model()->ItemByID(id_window3);
+ EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item_window_p3.type);
+ EXPECT_EQ(ash::STATUS_ACTIVE, item_window_p3.status);
+
+ // Then close the app window2, make sure the item remains.
+ CloseAppWindow(window2);
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ // Then close the app window1.
+ CloseAppWindow(window1);
+ --item_count;
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ // Then close the app window3, make sure the item remains.
+ CloseAppWindow(window3);
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+
+ // Open app window2. Confirm the item is now running.
+ EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item_window_p2.type);
+ EXPECT_EQ(ash::STATUS_CLOSED, item_window_p2.status);
+ params.show_in_shelf = true;
+ params.window_key = "window2";
+ AppWindow* window_p2 =
+ CreateAppWindowFromParams(browser()->profile(), extension, params);
+ ash::wm::ActivateWindow(window_p2->GetNativeWindow());
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ const ash::ShelfItem& item_window_r2 = *shelf_model()->ItemByID(id_window2);
+ EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item_window_r2.type);
+ EXPECT_EQ(ash::STATUS_ACTIVE, item_window_r2.status);
+}
« no previous file with comments | « chrome/browser/apps/app_browsertest_util.cc ('k') | chrome/test/data/extensions/platform_apps/app_window/generic/icon_128.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698