1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 #include "base/command_line.h"
9 #include "chrome/browser/apps/app_browsertest_util.h"
10 #include "chrome/browser/ui/app_list/app_list_service.h"
11 #include "chrome/browser/ui/app_list/app_list_service_views.h"
12 #include "chrome/browser/ui/app_list/app_list_shower_views.h"
13 #include "extensions/common/extension.h"
14 #include "extensions/common/switches.h"
15 #include "extensions/test/extension_test_message_listener.h"
16 #include "ui/app_list/app_list_switches.h"
17 #include "ui/app_list/views/app_list_main_view.h"
18 #include "ui/app_list/views/app_list_view.h"
19 #include "ui/app_list/views/contents_view.h"
23 // The path of the test application within the "platform_apps" directory.
24 const char kCustomLauncherPagePath
[] = "custom_launcher_page";
26 // The app ID of the test application.
27 const char kCustomLauncherPageID
[] = "lmadimbbgapmngbiclpjjngmdickadpl";
31 // Browser tests for custom launcher pages, platform apps that run as a page in
32 // the app launcher. Within this test class, LoadAndLaunchPlatformApp runs the
33 // app inside the launcher, not as a standalone background page.
35 class CustomLauncherPageBrowserTest
36 : public extensions::PlatformAppBrowserTest
{
38 CustomLauncherPageBrowserTest() {}
40 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
41 PlatformAppBrowserTest::SetUpCommandLine(command_line
);
43 // Custom launcher pages only work in the experimental app list.
44 command_line
->AppendSwitch(app_list::switches::kEnableExperimentalAppList
);
46 // Ensure the app list does not close during the test.
47 command_line
->AppendSwitch(
48 app_list::switches::kDisableAppListDismissOnBlur
);
50 // The test app must be whitelisted to use launcher_page.
51 command_line
->AppendSwitchASCII(
52 extensions::switches::kWhitelistedExtensionID
, kCustomLauncherPageID
);
55 // Open the launcher. Ignores the Extension argument (this will simply
56 // activate any loaded launcher pages).
57 void LaunchPlatformApp(const extensions::Extension
* /*unused*/) override
{
58 AppListService
* service
=
59 AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE
);
61 service
->ShowForProfile(browser()->profile());
64 app_list::AppListView
* GetAppListView() {
65 app_list::AppListView
* app_list_view
= nullptr;
66 #if defined(OS_CHROMEOS)
67 ash::Shell
* shell
= ash::Shell::GetInstance();
68 app_list_view
= shell
->GetAppListView();
69 EXPECT_TRUE(shell
->GetAppListTargetVisibility());
71 AppListServiceViews
* service
= static_cast<AppListServiceViews
*>(
72 AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE
));
73 // The app list should have loaded instantly since the profile is already
75 EXPECT_TRUE(service
->IsAppListVisible());
76 app_list_view
= service
->shower().app_list();
82 DISALLOW_COPY_AND_ASSIGN(CustomLauncherPageBrowserTest
);
85 IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest
,
86 OpenLauncherAndSwitchToCustomPage
) {
87 LoadAndLaunchPlatformApp(kCustomLauncherPagePath
, "Launched");
88 app_list::AppListView
* app_list_view
= GetAppListView();
89 app_list::ContentsView
* contents_view
=
90 app_list_view
->app_list_main_view()->contents_view();
93 contents_view
->IsStateActive(app_list::AppListModel::STATE_START
));
96 ExtensionTestMessageListener
listener("onPageProgressAt1", false);
97 contents_view
->SetActivePage(contents_view
->GetPageIndexForState(
98 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE
));
100 listener
.WaitUntilSatisfied();
103 ExtensionTestMessageListener
listener("onPageProgressAt0", false);
104 contents_view
->SetActivePage(contents_view
->GetPageIndexForState(
105 app_list::AppListModel::STATE_START
));
107 listener
.WaitUntilSatisfied();
111 IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest
, LauncherPageSubpages
) {
112 LoadAndLaunchPlatformApp(kCustomLauncherPagePath
, "Launched");
114 app_list::AppListView
* app_list_view
= GetAppListView();
115 app_list::AppListModel
* model
= app_list_view
->app_list_main_view()->model();
116 app_list::ContentsView
* contents_view
=
117 app_list_view
->app_list_main_view()->contents_view();
120 contents_view
->IsStateActive(app_list::AppListModel::STATE_START
));
123 ExtensionTestMessageListener
listener("onPageProgressAt1", false);
124 contents_view
->SetActivePage(contents_view
->GetPageIndexForState(
125 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE
));
126 listener
.WaitUntilSatisfied();
127 EXPECT_TRUE(contents_view
->IsStateActive(
128 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE
));
129 // The app pushes 2 subpages when the launcher page is shown.
130 EXPECT_EQ(2, model
->custom_launcher_page_subpage_depth());
135 ExtensionTestMessageListener
listener("onPopSubpage", false);
136 EXPECT_TRUE(contents_view
->Back());
137 listener
.WaitUntilSatisfied();
138 EXPECT_TRUE(contents_view
->IsStateActive(
139 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE
));
140 EXPECT_EQ(1, model
->custom_launcher_page_subpage_depth());
143 ExtensionTestMessageListener
listener("onPopSubpage", false);
144 EXPECT_TRUE(contents_view
->Back());
145 listener
.WaitUntilSatisfied();
146 EXPECT_TRUE(contents_view
->IsStateActive(
147 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE
));
148 EXPECT_EQ(0, model
->custom_launcher_page_subpage_depth());
151 // Once all subpages are popped, the start page should show.
152 EXPECT_TRUE(contents_view
->Back());
154 // Immediately finish the animation.
155 contents_view
->Layout();
157 contents_view
->IsStateActive(app_list::AppListModel::STATE_START
));