#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
-#include "apps/app_window.h"
-#include "apps/app_window_registry.h"
-#include "apps/ui/native_app_window.h"
#include "ash/ash_switches.h"
#include "ash/display/display_controller.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_button.h"
+#include "ash/shelf/shelf_constants.h"
#include "ash/shelf/shelf_model.h"
#include "ash/shelf/shelf_util.h"
#include "ash/shelf/shelf_view.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/apps/app_browsertest_util.h"
-#include "chrome/browser/automation/automation_util.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_function_test_utils.h"
#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_service.h"
#include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/host_desktop.h"
+#include "chrome/browser/ui/settings_window_manager.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
+#include "extensions/browser/app_window/app_window.h"
+#include "extensions/browser/app_window/app_window_registry.h"
+#include "extensions/browser/app_window/native_app_window.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/constants.h"
#include "extensions/common/switches.h"
+#include "extensions/test/extension_test_message_listener.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/app_list/views/apps_grid_view.h"
#include "ui/aura/client/aura_constants.h"
-#include "ui/aura/test/event_generator.h"
#include "ui/aura/window.h"
#include "ui/events/event.h"
+#include "ui/events/test/event_generator.h"
-using apps::AppWindow;
+using extensions::AppWindow;
using extensions::Extension;
using content::WebContents;
DISALLOW_COPY_AND_ASSIGN(TestEvent);
};
-class TestAppWindowRegistryObserver : public apps::AppWindowRegistry::Observer {
+class TestAppWindowRegistryObserver
+ : public extensions::AppWindowRegistry::Observer {
public:
explicit TestAppWindowRegistryObserver(Profile* profile)
: profile_(profile), icon_updates_(0) {
- apps::AppWindowRegistry::Get(profile_)->AddObserver(this);
+ extensions::AppWindowRegistry::Get(profile_)->AddObserver(this);
}
virtual ~TestAppWindowRegistryObserver() {
- apps::AppWindowRegistry::Get(profile_)->RemoveObserver(this);
+ extensions::AppWindowRegistry::Get(profile_)->RemoveObserver(this);
}
// Overridden from AppWindowRegistry::Observer:
- virtual void OnAppWindowAdded(AppWindow* app_window) OVERRIDE {}
-
virtual void OnAppWindowIconChanged(AppWindow* app_window) OVERRIDE {
++icon_updates_;
}
- virtual void OnAppWindowRemoved(AppWindow* app_window) OVERRIDE {}
-
int icon_updates() { return icon_updates_; }
private:
// Try to rip off |item_index|.
void RipOffItemIndex(int index,
- aura::test::EventGenerator* generator,
+ ui::test::EventGenerator* generator,
ash::test::ShelfViewTestAPI* test,
RipOffCommand command) {
- ash::internal::ShelfButton* button = test->GetButton(index);
+ ash::ShelfButton* button = test->GetButton(index);
gfx::Point start_point = button->GetBoundsInScreen().CenterPoint();
gfx::Point rip_off_point(start_point.x(), 0);
generator->MoveMouseTo(start_point.x(), start_point.y());
// Test that we can launch a platform app and get a running item.
IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) {
int item_count = shelf_model()->item_count();
- const Extension* extension = LoadAndLaunchPlatformApp("launch");
+ const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched");
AppWindow* window = CreateAppWindow(extension);
++item_count;
ASSERT_EQ(item_count, shelf_model()->item_count());
int item_count = shelf_model()->item_count();
// First get app_id.
- const Extension* extension = LoadAndLaunchPlatformApp("launch");
+ const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched");
const std::string app_id = extension->id();
// Then create a shortcut.
IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, PinRunning) {
// Run.
int item_count = shelf_model()->item_count();
- const Extension* extension = LoadAndLaunchPlatformApp("launch");
+ const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched");
AppWindow* window = CreateAppWindow(extension);
++item_count;
ASSERT_EQ(item_count, shelf_model()->item_count());
int item_count = shelf_model()->item_count();
// First get app_id.
- const Extension* extension = LoadAndLaunchPlatformApp("launch");
+ const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched");
const std::string app_id = extension->id();
// Then create a shortcut.
int item_count = shelf_model()->item_count();
// First run app.
- const Extension* extension = LoadAndLaunchPlatformApp("launch");
+ const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched");
AppWindow* window1 = CreateAppWindow(extension);
++item_count;
ASSERT_EQ(item_count, shelf_model()->item_count());
int item_count = shelf_model()->item_count();
// First run app.
- const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
+ const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched");
AppWindow* window1 = CreateAppWindow(extension1);
++item_count;
ASSERT_EQ(item_count, shelf_model()->item_count());
EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
// Then run second app.
- const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2");
+ const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2",
+ "Launched");
AppWindow* window2 = CreateAppWindow(extension2);
++item_count;
ASSERT_EQ(item_count, shelf_model()->item_count());
int item_count = shelf_model()->item_count();
// First run app.
- const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
+ const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched");
AppWindow* window1 = CreateAppWindow(extension1);
++item_count;
ASSERT_EQ(item_count, shelf_model()->item_count());
EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
// Then run second app.
- const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2");
+ const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2",
+ "Launched");
AppWindow* window2 = CreateAppWindow(extension2);
++item_count;
ASSERT_EQ(item_count, shelf_model()->item_count());
EXPECT_EQ(item_count, shelf_model()->item_count());
}
+// Verify that ChromeLauncherController::CanInstall() returns true for ephemeral
+// apps and false when the app is promoted to a regular installed app.
+IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, InstallEphemeralApp) {
+ int item_count = shelf_model()->item_count();
+
+ // Sanity check to verify that ChromeLauncherController::CanInstall() returns
+ // false for apps that are fully installed.
+ const Extension* app = LoadAndLaunchPlatformApp("launch", "Launched");
+ ASSERT_TRUE(app);
+ CreateAppWindow(app);
+ ++item_count;
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ const ash::ShelfItem& app_item = GetLastLauncherItem();
+ ash::ShelfID app_id = app_item.id;
+ EXPECT_FALSE(controller_->CanInstall(app_id));
+
+ // Add an ephemeral app.
+ const Extension* ephemeral_app = InstallEphemeralAppWithSourceAndFlags(
+ test_data_dir_.AppendASCII("platform_apps").AppendASCII("launch_2"),
+ 1,
+ extensions::Manifest::INTERNAL,
+ Extension::NO_FLAGS);
+ ASSERT_TRUE(ephemeral_app);
+ CreateAppWindow(ephemeral_app);
+ ++item_count;
+ ASSERT_EQ(item_count, shelf_model()->item_count());
+ const ash::ShelfItem& ephemeral_item = GetLastLauncherItem();
+ ash::ShelfID ephemeral_id = ephemeral_item.id;
+
+ // Verify that the shelf item for the ephemeral app can be installed.
+ EXPECT_TRUE(controller_->CanInstall(ephemeral_id));
+
+ // Promote the ephemeral app to a regular installed app.
+ ExtensionService* service =
+ extensions::ExtensionSystem::Get(profile())->extension_service();
+ service->PromoteEphemeralApp(ephemeral_app, false);
+
+ // Verify that the shelf item for the app can no longer be installed.
+ EXPECT_FALSE(controller_->CanInstall(ephemeral_id));
+}
+
// Confirm that Click behavior for app windows is correnct.
IN_PROC_BROWSER_TEST_F(ShelfAppBrowserNoMinimizeOnClick, AppClickBehavior) {
// Launch a platform app and create a window for it.
- const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
+ const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched");
AppWindow* window1 = CreateAppWindow(extension1);
EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
IN_PROC_BROWSER_TEST_F(ShelfAppBrowserMinimizeOnClick,
PackagedAppClickBehaviorInMinimizeMode) {
// Launch one platform app and create a window for it.
- const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
+ const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched");
AppWindow* window1 = CreateAppWindow(extension1);
EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
CommandLine::ForCurrentProcess()->AppendSwitch(
extensions::switches::kEnableExperimentalExtensionApis);
// Launch a platform app and create a panel window for it.
- const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
+ const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched");
AppWindow::CreateParams params;
params.window_type = AppWindow::WINDOW_TYPE_PANEL;
params.focused = false;
int item_count = shelf_model()->item_count();
// First run app.
- const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
+ const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched");
CreateAppWindow(extension1);
++item_count;
ASSERT_EQ(item_count, shelf_model()->item_count());
extensions::switches::kEnableExperimentalExtensionApis);
int base_shelf_item_count = shelf_model()->item_count();
- ExtensionTestMessageListener launched_listener("Launched", false);
ExtensionTestMessageListener completed_listener("Completed", false);
- LoadAndLaunchPlatformApp("app_icon");
- ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
+ LoadAndLaunchPlatformApp("app_icon", "Launched");
ASSERT_TRUE(completed_listener.WaitUntilSatisfied());
// Now wait until the WebContent has decoded the icons and chrome has
EXPECT_TRUE(app_item_controller->image_set_by_controller());
EXPECT_TRUE(panel_item_controller->image_set_by_controller());
// Ensure icon heights are correct (see test.js in app_icon/ test directory)
- EXPECT_EQ(48, app_item.image.height());
+ EXPECT_EQ(ash::kShelfSize, app_item.image.height());
EXPECT_EQ(64, panel_item.image.height());
}
IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest,
AltNumberAppsTabbing) {
// First run app.
- const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
+ const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched");
ui::BaseWindow* window1 = CreateAppWindow(extension1)->GetBaseWindow();
const ash::ShelfItem& item1 = GetLastLauncherItem();
ash::ShelfID app_id = item1.id;
EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
- const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2");
+ const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2",
+ "Launched");
ui::BaseWindow* window2 = CreateAppWindow(extension2)->GetBaseWindow();
// By now the browser should be active. Issue Alt keystrokes several times to
// Test that we can launch a platform app panel and get a running item.
IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPanelWindow) {
int item_count = shelf_model()->item_count();
- const Extension* extension = LoadAndLaunchPlatformApp("launch");
+ const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched");
AppWindow::CreateParams params;
params.window_type = AppWindow::WINDOW_TYPE_PANEL;
params.focused = false;
EXPECT_EQ(item_count, shelf_model()->item_count());
}
-#if defined(OS_CHROMEOS)
// Test that we get correct shelf presence with hidden app windows.
IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, HiddenAppWindows) {
int item_count = shelf_model()->item_count();
- const Extension* extension = LoadAndLaunchPlatformApp("launch");
+ const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched");
AppWindow::CreateParams params;
// Create a hidden window.
--item_count;
EXPECT_EQ(item_count, shelf_model()->item_count());
}
-#endif
// Test attention states of windows.
IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowAttentionStatus) {
- const Extension* extension = LoadAndLaunchPlatformApp("launch");
+ const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched");
AppWindow::CreateParams params;
params.window_type = AppWindow::WINDOW_TYPE_PANEL;
params.focused = false;
controller_->GetLauncherItemController(shortcut_id);
item_controller->ItemSelected(ui::KeyEvent(ui::ET_KEY_RELEASED,
ui::VKEY_RETURN,
- 0,
- false));
+ ui::EF_NONE));
// Check that we have set focus on the existing application and nothing new
// was created.
// TODO(skuhne): Test is flaky with a real compositor: crbug.com/331924
IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, DISABLED_DragAndDrop) {
// Get a number of interfaces we need.
- aura::test::EventGenerator generator(
- ash::Shell::GetPrimaryRootWindow(), gfx::Point());
+ ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow(),
+ gfx::Point());
ash::test::ShelfViewTestAPI test(
ash::test::ShelfTestAPI(shelf_).shelf_view());
AppListService* service = AppListService::Get(chrome::GetActiveDesktop());
aura::Window* secondary_root_window = ash::Shell::GetAllRootWindows()[1];
ash::Shelf* secondary_shelf = ash::Shelf::ForWindow(secondary_root_window);
- aura::test::EventGenerator generator(secondary_root_window, gfx::Point());
+ ui::test::EventGenerator generator(secondary_root_window, gfx::Point());
ash::test::ShelfViewTestAPI test(
ash::test::ShelfTestAPI(secondary_shelf).shelf_view());
AppListService* service = AppListService::Get(chrome::GetActiveDesktop());
// Do tests for removal of items from the shelf by dragging.
IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, DragOffShelf) {
- aura::test::EventGenerator generator(
- ash::Shell::GetPrimaryRootWindow(), gfx::Point());
+ ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow(),
+ gfx::Point());
ash::test::ShelfViewTestAPI test(
ash::test::ShelfTestAPI(shelf_).shelf_view());
test.SetAnimationDuration(1); // Speed up animations for test.
GetIndexOfShelfItemType(ash::TYPE_BROWSER_SHORTCUT));
// Make sure that the hide state has been unset after the snap back animation
// finished.
- ash::internal::ShelfButton* button = test.GetButton(browser_index);
- EXPECT_FALSE(button->state() & ash::internal::ShelfButton::STATE_HIDDEN);
+ ash::ShelfButton* button = test.GetButton(browser_index);
+ EXPECT_FALSE(button->state() & ash::ShelfButton::STATE_HIDDEN);
// Test #2: Ripping out the application and canceling the operation should
// not change anything.
// Check that clicking on an app shelf item launches a new browser.
IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, ClickItem) {
// Get a number of interfaces we need.
- aura::test::EventGenerator generator(
- ash::Shell::GetPrimaryRootWindow(), gfx::Point());
+ ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow(),
+ gfx::Point());
ash::test::ShelfViewTestAPI test(
ash::test::ShelfTestAPI(shelf_).shelf_view());
AppListService* service = AppListService::Get(chrome::GetActiveDesktop());
// still gets detected properly.
IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, V1AppNavigation) {
// We assume that the web store is always there (which it apparently is).
- controller_->PinAppWithID(extension_misc::kWebStoreAppId);
+ controller_->PinAppWithID(extensions::kWebStoreAppId);
ash::ShelfID id = controller_->GetShelfIDForAppID(
- extension_misc::kWebStoreAppId);
+ extensions::kWebStoreAppId);
ASSERT_NE(0, id);
EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(id)->status);
// Create a windowed application.
AppLaunchParams params(
profile(),
- controller_->GetExtensionForAppID(extension_misc::kWebStoreAppId),
+ controller_->GetExtensionForAppID(extensions::kWebStoreAppId),
0,
chrome::HOST_DESKTOP_TYPE_ASH);
params.container = extensions::LAUNCH_CONTAINER_WINDOW;
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(id)->status);
}
+
+// Checks that a opening a settings window creates a new launcher item.
+IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, SettingsWindow) {
+ chrome::SettingsWindowManager* settings_manager =
+ chrome::SettingsWindowManager::GetInstance();
+ ash::ShelfModel* shelf_model = ash::Shell::GetInstance()->shelf_model();
+
+ // Get the number of items in the shelf and browser menu.
+ int item_count = shelf_model->item_count();
+ size_t browser_count = NumberOfDetectedLauncherBrowsers(false);
+
+ // Open a settings window. Number of browser items should remain unchanged,
+ // number of shelf items should increase.
+ settings_manager->ShowChromePageForProfile(
+ browser()->profile(),
+ chrome::GetSettingsUrl(std::string()));
+ Browser* settings_browser =
+ settings_manager->FindBrowserForProfile(browser()->profile());
+ ASSERT_TRUE(settings_browser);
+ EXPECT_EQ(browser_count, NumberOfDetectedLauncherBrowsers(false));
+ EXPECT_EQ(item_count + 1, shelf_model->item_count());
+
+ // TODO(stevenjb): Test multiprofile on Chrome OS when test support is addded.
+ // crbug.com/230464.
+}