1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "ash/shell.h"
#include "base/command_line.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/apps/app_browsertest_util.h"
#include "chrome/browser/ui/app_list/app_list_service.h"
#include "chrome/browser/ui/app_list/app_list_service_views.h"
#include "chrome/browser/ui/app_list/app_list_shower_views.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "extensions/common/extension.h"
#include "extensions/common/switches.h"
#include "extensions/test/extension_test_message_listener.h"
#include "ui/app_list/app_list_switches.h"
#include "ui/app_list/views/app_list_main_view.h"
#include "ui/app_list/views/app_list_view.h"
#include "ui/app_list/views/contents_view.h"
#include "ui/app_list/views/search_box_view.h"
#include "ui/events/test/event_generator.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/focus/focus_manager.h"
namespace {
// The path of the test application within the "platform_apps" directory.
const char kCustomLauncherPagePath[] = "custom_launcher_page";
// The app ID of the test application.
const char kCustomLauncherPageID[] = "lmadimbbgapmngbiclpjjngmdickadpl";
} // namespace
// Browser tests for custom launcher pages, platform apps that run as a page in
// the app launcher. Within this test class, LoadAndLaunchPlatformApp runs the
// app inside the launcher, not as a standalone background page.
// the app launcher.
class CustomLauncherPageBrowserTest
: public extensions::PlatformAppBrowserTest {
public:
CustomLauncherPageBrowserTest() {}
void SetUpCommandLine(base::CommandLine* command_line) override {
PlatformAppBrowserTest::SetUpCommandLine(command_line);
// Custom launcher pages only work in the experimental app list.
command_line->AppendSwitch(app_list::switches::kEnableExperimentalAppList);
// Ensure the app list does not close during the test.
command_line->AppendSwitch(
app_list::switches::kDisableAppListDismissOnBlur);
// The test app must be whitelisted to use launcher_page.
command_line->AppendSwitchASCII(
extensions::switches::kWhitelistedExtensionID, kCustomLauncherPageID);
}
// Open the launcher. Ignores the Extension argument (this will simply
// activate any loaded launcher pages).
void LaunchPlatformApp(const extensions::Extension* /*unused*/) override {
AppListService* service =
AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE);
DCHECK(service);
service->ShowForProfile(browser()->profile());
}
app_list::AppListView* GetAppListView() {
app_list::AppListView* app_list_view = nullptr;
#if defined(OS_CHROMEOS)
ash::Shell* shell = ash::Shell::GetInstance();
app_list_view = shell->GetAppListView();
EXPECT_TRUE(shell->GetAppListTargetVisibility());
#else
AppListServiceViews* service = static_cast<AppListServiceViews*>(
AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE));
// The app list should have loaded instantly since the profile is already
// loaded.
EXPECT_TRUE(service->IsAppListVisible());
app_list_view = service->shower().app_list();
#endif
return app_list_view;
}
// Set the active page on the app list, according to |state|. Does not wait
// for any animation or custom page to complete.
void SetActivePageAndVerify(app_list::AppListModel::State state) {
app_list::ContentsView* contents_view =
GetAppListView()->app_list_main_view()->contents_view();
contents_view->SetActivePage(contents_view->GetPageIndexForState(state));
EXPECT_TRUE(contents_view->IsStateActive(state));
}
void SetCustomLauncherPageEnabled(bool enabled) {
const base::string16 kLauncherPageDisableScript =
base::ASCIIToUTF16("disableCustomLauncherPage();");
const base::string16 kLauncherPageEnableScript =
base::ASCIIToUTF16("enableCustomLauncherPage();");
app_list::ContentsView* contents_view =
GetAppListView()->app_list_main_view()->contents_view();
views::WebView* custom_page_view =
static_cast<views::WebView*>(contents_view->custom_page_view());
content::RenderFrameHost* custom_page_frame =
custom_page_view->GetWebContents()->GetMainFrame();
const char* test_message =
enabled ? "launcherPageEnabled" : "launcherPageDisabled";
ExtensionTestMessageListener listener(test_message, false);
custom_page_frame->ExecuteJavaScript(enabled ? kLauncherPageEnableScript
: kLauncherPageDisableScript);
listener.WaitUntilSatisfied();
}
private:
DISALLOW_COPY_AND_ASSIGN(CustomLauncherPageBrowserTest);
};
IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest,
OpenLauncherAndSwitchToCustomPage) {
LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched");
app_list::AppListView* app_list_view = GetAppListView();
app_list::ContentsView* contents_view =
app_list_view->app_list_main_view()->contents_view();
ASSERT_TRUE(
contents_view->IsStateActive(app_list::AppListModel::STATE_START));
{
ExtensionTestMessageListener listener("onPageProgressAt1", false);
contents_view->SetActivePage(contents_view->GetPageIndexForState(
app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
listener.WaitUntilSatisfied();
}
{
ExtensionTestMessageListener listener("onPageProgressAt0", false);
contents_view->SetActivePage(contents_view->GetPageIndexForState(
app_list::AppListModel::STATE_START));
listener.WaitUntilSatisfied();
}
}
// Test that the app list will switch to the custom launcher page by sending a
// click inside the clickzone, or a mouse scroll event.
IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest,
EventsActivateSwitchToCustomPage) {
LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched");
// Use an event generator to ensure targeting is correct.
app_list::AppListView* app_list_view = GetAppListView();
app_list::ContentsView* contents_view =
app_list_view->app_list_main_view()->contents_view();
gfx::NativeWindow window = app_list_view->GetWidget()->GetNativeWindow();
ui::test::EventGenerator event_generator(window->GetRootWindow(), window);
EXPECT_TRUE(
contents_view->IsStateActive(app_list::AppListModel::STATE_START));
// Find the clickzone.
gfx::Rect bounds = contents_view->GetCustomPageCollapsedBounds();
bounds.Intersect(contents_view->bounds());
gfx::Point point_in_clickzone = bounds.CenterPoint();
views::View::ConvertPointToWidget(contents_view, &point_in_clickzone);
// First try clicking 10px above the clickzone.
gfx::Point point_above_clickzone = point_in_clickzone;
point_above_clickzone.set_y(bounds.y() - 10);
views::View::ConvertPointToWidget(contents_view, &point_above_clickzone);
event_generator.MoveMouseRelativeTo(window, point_above_clickzone);
event_generator.ClickLeftButton();
// Should stay on the start page.
EXPECT_TRUE(
contents_view->IsStateActive(app_list::AppListModel::STATE_START));
// Now click in the clickzone.
event_generator.MoveMouseRelativeTo(window, point_in_clickzone);
// First, try disabling the custom page view. Click should do nothing.
SetCustomLauncherPageEnabled(false);
event_generator.ClickLeftButton();
EXPECT_TRUE(
contents_view->IsStateActive(app_list::AppListModel::STATE_START));
// Click again with it enabled. The active state should update immediately.
SetCustomLauncherPageEnabled(true);
event_generator.ClickLeftButton();
EXPECT_TRUE(contents_view->IsStateActive(
app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
// Back to the start page. And send a mouse wheel event.
SetActivePageAndVerify(app_list::AppListModel::STATE_START);
// Generate wheel events above the clickzone.
event_generator.MoveMouseRelativeTo(window, point_above_clickzone);
// Scrolling left, right or up should do nothing.
event_generator.MoveMouseWheel(-5, 0);
event_generator.MoveMouseWheel(5, 0);
event_generator.MoveMouseWheel(0, 5);
EXPECT_TRUE(
contents_view->IsStateActive(app_list::AppListModel::STATE_START));
// Scroll down to open launcher page.
event_generator.MoveMouseWheel(0, -5);
EXPECT_TRUE(contents_view->IsStateActive(
app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
// Constants for gesture/trackpad events.
const base::TimeDelta step_delay = base::TimeDelta::FromMilliseconds(300);
const int num_steps = 5;
const int num_fingers = 2;
#if defined(OS_CHROMEOS)
// Gesture events need to be in host coordinates. On Desktop platforms, the
// Widget is the host, so nothing needs to be done. On ChromeOS, the points
// need to be put into screen coordinates. This works because the root window
// assumes it fills the screen.
point_in_clickzone = bounds.CenterPoint();
point_above_clickzone.SetPoint(point_in_clickzone.x(), bounds.y() - 10);
views::View::ConvertPointToScreen(contents_view, &point_above_clickzone);
views::View::ConvertPointToScreen(contents_view, &point_in_clickzone);
#endif
// Back to the start page. And send a scroll gesture.
SetActivePageAndVerify(app_list::AppListModel::STATE_START);
// Going down should do nothing.
event_generator.GestureScrollSequence(
point_above_clickzone, point_in_clickzone, step_delay, num_steps);
EXPECT_TRUE(
contents_view->IsStateActive(app_list::AppListModel::STATE_START));
// Now go up - should change state.
event_generator.GestureScrollSequence(
point_in_clickzone, point_above_clickzone, step_delay, num_steps);
EXPECT_TRUE(contents_view->IsStateActive(
app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
// Back to the start page. And send a trackpad scroll event.
SetActivePageAndVerify(app_list::AppListModel::STATE_START);
// Going down left, right or up should do nothing.
event_generator.ScrollSequence(point_in_clickzone, step_delay, -5, 0,
num_steps, num_fingers);
event_generator.ScrollSequence(point_in_clickzone, step_delay, 5, 0,
num_steps, num_fingers);
event_generator.ScrollSequence(point_in_clickzone, step_delay, 0, 5,
num_steps, num_fingers);
EXPECT_TRUE(
contents_view->IsStateActive(app_list::AppListModel::STATE_START));
// Scroll up to open launcher page.
event_generator.ScrollSequence(point_in_clickzone, step_delay, 0, -5,
num_steps, num_fingers);
EXPECT_TRUE(contents_view->IsStateActive(
app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
// Back to the start page. And send a tap gesture.
SetActivePageAndVerify(app_list::AppListModel::STATE_START);
// Tapping outside the clickzone should do nothing.
event_generator.GestureTapAt(point_above_clickzone);
EXPECT_TRUE(
contents_view->IsStateActive(app_list::AppListModel::STATE_START));
// Now tap in the clickzone.
event_generator.GestureTapAt(point_in_clickzone);
EXPECT_TRUE(contents_view->IsStateActive(
app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
}
IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageSubpages) {
LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched");
app_list::AppListView* app_list_view = GetAppListView();
app_list::AppListModel* model = app_list_view->app_list_main_view()->model();
app_list::ContentsView* contents_view =
app_list_view->app_list_main_view()->contents_view();
ASSERT_TRUE(
contents_view->IsStateActive(app_list::AppListModel::STATE_START));
{
ExtensionTestMessageListener listener("onPageProgressAt1", false);
contents_view->SetActivePage(contents_view->GetPageIndexForState(
app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
listener.WaitUntilSatisfied();
EXPECT_TRUE(contents_view->IsStateActive(
app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
// The app pushes 2 subpages when the launcher page is shown.
EXPECT_EQ(2, model->custom_launcher_page_subpage_depth());
}
// Pop the subpages.
{
ExtensionTestMessageListener listener("onPopSubpage", false);
EXPECT_TRUE(contents_view->Back());
listener.WaitUntilSatisfied();
EXPECT_TRUE(contents_view->IsStateActive(
app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
EXPECT_EQ(1, model->custom_launcher_page_subpage_depth());
}
{
ExtensionTestMessageListener listener("onPopSubpage", false);
EXPECT_TRUE(contents_view->Back());
listener.WaitUntilSatisfied();
EXPECT_TRUE(contents_view->IsStateActive(
app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
EXPECT_EQ(0, model->custom_launcher_page_subpage_depth());
}
// Once all subpages are popped, the start page should show.
EXPECT_TRUE(contents_view->Back());
// Immediately finish the animation.
contents_view->Layout();
EXPECT_TRUE(
contents_view->IsStateActive(app_list::AppListModel::STATE_START));
}
IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest,
LauncherPageShow) {
const base::string16 kLauncherPageShowScript =
base::ASCIIToUTF16("chrome.launcherPage.show();");
LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched");
app_list::AppListView* app_list_view = GetAppListView();
app_list::ContentsView* contents_view =
app_list_view->app_list_main_view()->contents_view();
views::WebView* custom_page_view =
static_cast<views::WebView*>(contents_view->custom_page_view());
content::RenderFrameHost* custom_page_frame =
custom_page_view->GetWebContents()->GetMainFrame();
ASSERT_TRUE(
contents_view->IsStateActive(app_list::AppListModel::STATE_START));
// Ensure launcherPage.show() will switch the page to the custom launcher page
// if the app launcher is already showing.
{
ExtensionTestMessageListener listener("onPageProgressAt1", false);
custom_page_frame->ExecuteJavaScript(kLauncherPageShowScript);
listener.WaitUntilSatisfied();
EXPECT_TRUE(contents_view->IsStateActive(
app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
}
// Ensure launcherPage.show() will show the app list if it's hidden.
{
// Close the app list immediately.
app_list_view->Close();
app_list_view->GetWidget()->Close();
ExtensionTestMessageListener listener("onPageProgressAt1", false);
custom_page_frame->ExecuteJavaScript(kLauncherPageShowScript);
listener.WaitUntilSatisfied();
// The app list view will have changed on ChromeOS.
app_list_view = GetAppListView();
contents_view = app_list_view->app_list_main_view()->contents_view();
EXPECT_TRUE(contents_view->IsStateActive(
app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
}
}
IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageSetEnabled) {
LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched");
app_list::AppListView* app_list_view = GetAppListView();
app_list::AppListModel* model = app_list_view->app_list_main_view()->model();
app_list::ContentsView* contents_view =
app_list_view->app_list_main_view()->contents_view();
views::WebView* custom_page_view =
static_cast<views::WebView*>(contents_view->custom_page_view());
ASSERT_TRUE(
contents_view->IsStateActive(app_list::AppListModel::STATE_START));
EXPECT_TRUE(model->custom_launcher_page_enabled());
EXPECT_TRUE(custom_page_view->visible());
SetCustomLauncherPageEnabled(false);
EXPECT_FALSE(model->custom_launcher_page_enabled());
EXPECT_FALSE(custom_page_view->visible());
SetCustomLauncherPageEnabled(true);
EXPECT_TRUE(model->custom_launcher_page_enabled());
EXPECT_TRUE(custom_page_view->visible());
}
// Currently this fails on ChromeOS
// Disabled test http://crbug.com/463456
#if defined(OS_CHROMEOS)
#define MAYBE_LauncherPageFocusTraversal DISABLED_LauncherPageFocusTraversal
#else
#define MAYBE_LauncherPageFocusTraversal LauncherPageFocusTraversal
#endif
IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest,
MAYBE_LauncherPageFocusTraversal) {
LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched");
app_list::AppListView* app_list_view = GetAppListView();
app_list::ContentsView* contents_view =
app_list_view->app_list_main_view()->contents_view();
app_list::SearchBoxView* search_box_view =
app_list_view->app_list_main_view()->search_box_view();
ASSERT_TRUE(
contents_view->IsStateActive(app_list::AppListModel::STATE_START));
EXPECT_EQ(app_list_view->GetFocusManager()->GetFocusedView(),
search_box_view->search_box());
{
ExtensionTestMessageListener listener("onPageProgressAt1", false);
contents_view->SetActivePage(contents_view->GetPageIndexForState(
app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
listener.WaitUntilSatisfied();
EXPECT_TRUE(contents_view->IsStateActive(
app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
EXPECT_EQ(app_list_view->GetFocusManager()->GetFocusedView(),
search_box_view->search_box());
}
{
ExtensionTestMessageListener listener("textfieldFocused", false);
app_list_view->GetFocusManager()->AdvanceFocus(false);
listener.WaitUntilSatisfied();
EXPECT_NE(app_list_view->GetFocusManager()->GetFocusedView(),
search_box_view->search_box());
}
{
ExtensionTestMessageListener listener("textfieldBlurred", false);
app_list_view->GetFocusManager()->AdvanceFocus(false);
listener.WaitUntilSatisfied();
EXPECT_EQ(app_list_view->GetFocusManager()->GetFocusedView(),
search_box_view->search_box());
}
}
|