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

Side by Side Diff: chrome/browser/ui/views/ash/launcher/chrome_launcher_controller_browsertest.cc

Issue 10855094: launcher: Remove old files and update DEPS whitelist. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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.
4
5 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_controller.h"
6
7 #include "ash/launcher/launcher.h"
8 #include "ash/launcher/launcher_model.h"
9 #include "ash/shell.h"
10 #include "ash/wm/window_util.h"
11 #include "base/command_line.h"
12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/automation/automation_util.h"
14 #include "chrome/browser/extensions/extension_apitest.h"
15 #include "chrome/browser/extensions/extension_browsertest.h"
16 #include "chrome/browser/extensions/extension_function_test_utils.h"
17 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/extensions/extension_test_message_listener.h"
19 #include "chrome/browser/extensions/platform_app_browsertest_util.h"
20 #include "chrome/browser/extensions/shell_window_registry.h"
21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_commands.h"
24 #include "chrome/browser/ui/browser_window.h"
25 #include "chrome/browser/ui/extensions/application_launch.h"
26 #include "chrome/browser/ui/extensions/shell_window.h"
27 #include "chrome/browser/ui/tabs/tab_strip_model.h"
28 #include "chrome/common/chrome_notification_types.h"
29 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/extensions/extension_constants.h"
31 #include "chrome/test/base/ui_test_utils.h"
32 #include "content/public/browser/notification_service.h"
33 #include "content/public/browser/notification_source.h"
34 #include "content/public/browser/web_contents.h"
35 #include "testing/gtest/include/gtest/gtest.h"
36 #include "ui/aura/window.h"
37
38 using extensions::Extension;
39 using content::WebContents;
40
41 typedef PlatformAppBrowserTest LauncherPlatformAppBrowserTest;
42
43 class LauncherAppBrowserTest : public ExtensionBrowserTest {
44 protected:
45 LauncherAppBrowserTest()
46 : launcher_(NULL),
47 model_(NULL) {
48 }
49
50 virtual ~LauncherAppBrowserTest() {}
51
52 virtual void RunTestOnMainThreadLoop() {
53 launcher_ = ash::Shell::GetInstance()->launcher();
54 model_ = launcher_->model();
55 return ExtensionBrowserTest::RunTestOnMainThreadLoop();
56 }
57
58 const Extension* LoadAndLaunchExtension(
59 const char* name,
60 extension_misc::LaunchContainer container,
61 WindowOpenDisposition disposition) {
62 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII(name)));
63
64 ExtensionService* service = browser()->profile()->GetExtensionService();
65 const Extension* extension =
66 service->GetExtensionById(last_loaded_extension_id_, false);
67 EXPECT_TRUE(extension);
68
69 application_launch::OpenApplication(application_launch::LaunchParams(
70 browser()->profile(), extension, container, disposition));
71 return extension;
72 }
73
74 ash::LauncherID CreateShortcut(const char* name) {
75 ExtensionService* service = browser()->profile()->GetExtensionService();
76 LoadExtension(test_data_dir_.AppendASCII(name));
77
78 // First get app_id.
79 const Extension* extension =
80 service->GetExtensionById(last_loaded_extension_id_, false);
81 const std::string app_id = extension->id();
82
83 // Then create a shortcut.
84 ChromeLauncherController* controller =
85 static_cast<ChromeLauncherController*>(launcher_->delegate());
86 int item_count = model_->item_count();
87 ash::LauncherID shortcut_id =
88 controller->CreateAppLauncherItem(NULL, app_id, ash::STATUS_CLOSED);
89 controller->PersistPinnedState();
90 EXPECT_EQ(++item_count, model_->item_count());
91 ash::LauncherItem item = *model_->ItemByID(shortcut_id);
92 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type);
93 return item.id;
94 }
95
96 ash::Launcher* launcher_;
97 ash::LauncherModel* model_;
98 };
99
100 // Test that we can launch a platform app and get a running item.
101 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) {
102 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher();
103 int item_count = launcher->model()->item_count();
104 const Extension* extension = LoadAndLaunchPlatformApp("launch");
105 ShellWindow* window = CreateShellWindow(extension);
106 ++item_count;
107 ASSERT_EQ(item_count, launcher->model()->item_count());
108 ash::LauncherItem item =
109 launcher->model()->items()[launcher->model()->item_count() - 2];
110 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type);
111 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
112 CloseShellWindow(window);
113 --item_count;
114 EXPECT_EQ(item_count, launcher->model()->item_count());
115 }
116
117 // Test that we can launch a platform app that already has a shortcut.
118 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) {
119 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher();
120 int item_count = launcher->model()->item_count();
121
122 // First get app_id.
123 const Extension* extension = LoadAndLaunchPlatformApp("launch");
124 const std::string app_id = extension->id();
125
126 // Then create a shortcut.
127 ChromeLauncherController* controller =
128 static_cast<ChromeLauncherController*>(launcher->delegate());
129 ash::LauncherID shortcut_id =
130 controller->CreateAppLauncherItem(NULL, app_id, ash::STATUS_CLOSED);
131 ++item_count;
132 ASSERT_EQ(item_count, launcher->model()->item_count());
133 ash::LauncherItem item = *launcher->model()->ItemByID(shortcut_id);
134 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type);
135 EXPECT_EQ(ash::STATUS_CLOSED, item.status);
136
137 // Open a window. Confirm the item is now running.
138 ShellWindow* window = CreateShellWindow(extension);
139 ash::wm::ActivateWindow(window->GetNativeWindow());
140 ASSERT_EQ(item_count, launcher->model()->item_count());
141 item = *launcher->model()->ItemByID(shortcut_id);
142 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type);
143 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
144
145 // Then close it, make sure there's still an item.
146 CloseShellWindow(window);
147 ASSERT_EQ(item_count, launcher->model()->item_count());
148 item = *launcher->model()->ItemByID(shortcut_id);
149 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type);
150 EXPECT_EQ(ash::STATUS_CLOSED, item.status);
151 }
152
153 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, PinRunning) {
154 // Run.
155 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher();
156 ChromeLauncherController* controller =
157 static_cast<ChromeLauncherController*>(launcher->delegate());
158 int item_count = launcher->model()->item_count();
159 const Extension* extension = LoadAndLaunchPlatformApp("launch");
160 ShellWindow* window = CreateShellWindow(extension);
161 ++item_count;
162 ASSERT_EQ(item_count, launcher->model()->item_count());
163 ash::LauncherItem item =
164 launcher->model()->items()[launcher->model()->item_count() - 2];
165 ash::LauncherID id = item.id;
166 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type);
167 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
168
169 // Create a shortcut. The app item should be after it.
170 ash::LauncherID foo_id = controller->CreateAppLauncherItem(
171 NULL, std::string("foo"), ash::STATUS_CLOSED);
172 ++item_count;
173 ASSERT_EQ(item_count, launcher->model()->item_count());
174 EXPECT_LT(launcher->model()->ItemIndexByID(foo_id),
175 launcher->model()->ItemIndexByID(id));
176
177 // Pin the app. The item should remain.
178 controller->Pin(id);
179 ASSERT_EQ(item_count, launcher->model()->item_count());
180 item = *launcher->model()->ItemByID(id);
181 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type);
182 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
183
184 // New shortcuts should come after the item.
185 ash::LauncherID bar_id = controller->CreateAppLauncherItem(
186 NULL, std::string("bar"), ash::STATUS_CLOSED);
187 ++item_count;
188 ASSERT_EQ(item_count, launcher->model()->item_count());
189 EXPECT_LT(launcher->model()->ItemIndexByID(id),
190 launcher->model()->ItemIndexByID(bar_id));
191
192 // Then close it, make sure the item remains.
193 CloseShellWindow(window);
194 ASSERT_EQ(item_count, launcher->model()->item_count());
195 }
196
197 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) {
198 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher();
199 int item_count = launcher->model()->item_count();
200
201 // First get app_id.
202 const Extension* extension = LoadAndLaunchPlatformApp("launch");
203 const std::string app_id = extension->id();
204
205 // Then create a shortcut.
206 ChromeLauncherController* controller =
207 static_cast<ChromeLauncherController*>(launcher->delegate());
208 ash::LauncherID shortcut_id =
209 controller->CreateAppLauncherItem(NULL, app_id, ash::STATUS_CLOSED);
210 ++item_count;
211 ASSERT_EQ(item_count, launcher->model()->item_count());
212 ash::LauncherItem item = *launcher->model()->ItemByID(shortcut_id);
213 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type);
214 EXPECT_EQ(ash::STATUS_CLOSED, item.status);
215
216 // Create a second shortcut. This will be needed to force the first one to
217 // move once it gets unpinned.
218 ash::LauncherID foo_id = controller->CreateAppLauncherItem(
219 NULL, std::string("foo"), ash::STATUS_CLOSED);
220 ++item_count;
221 ASSERT_EQ(item_count, launcher->model()->item_count());
222 EXPECT_LT(launcher->model()->ItemIndexByID(shortcut_id),
223 launcher->model()->ItemIndexByID(foo_id));
224
225 // Open a window. Confirm the item is now running.
226 ShellWindow* window = CreateShellWindow(extension);
227 ash::wm::ActivateWindow(window->GetNativeWindow());
228 ASSERT_EQ(item_count, launcher->model()->item_count());
229 item = *launcher->model()->ItemByID(shortcut_id);
230 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type);
231 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
232
233 // Unpin the app. The item should remain.
234 controller->Unpin(shortcut_id);
235 ASSERT_EQ(item_count, launcher->model()->item_count());
236 item = *launcher->model()->ItemByID(shortcut_id);
237 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type);
238 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
239 // The item should have moved after the other shortcuts.
240 EXPECT_GT(launcher->model()->ItemIndexByID(shortcut_id),
241 launcher->model()->ItemIndexByID(foo_id));
242
243 // Then close it, make sure the item's gone.
244 CloseShellWindow(window);
245 --item_count;
246 ASSERT_EQ(item_count, launcher->model()->item_count());
247 }
248
249 // Test that we can launch a platform app with more than one window.
250 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) {
251 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher();
252 int item_count = launcher->model()->item_count();
253
254 // First run app.
255 const Extension* extension = LoadAndLaunchPlatformApp("launch");
256 ShellWindow* window1 = CreateShellWindow(extension);
257 ++item_count;
258 ASSERT_EQ(item_count, launcher->model()->item_count());
259 ash::LauncherItem item =
260 launcher->model()->items()[launcher->model()->item_count() - 2];
261 ash::LauncherID item_id = item.id;
262 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type);
263 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
264
265 // Add second window.
266 ShellWindow* window2 = CreateShellWindow(extension);
267 // Confirm item stays.
268 ASSERT_EQ(item_count, launcher->model()->item_count());
269 item = *launcher->model()->ItemByID(item_id);
270 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
271
272 // Close second window.
273 CloseShellWindow(window2);
274 // Confirm item stays.
275 ASSERT_EQ(item_count, launcher->model()->item_count());
276 item = *launcher->model()->ItemByID(item_id);
277 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
278
279 // Close first window.
280 CloseShellWindow(window1);
281 // Confirm item is removed.
282 --item_count;
283 ASSERT_EQ(item_count, launcher->model()->item_count());
284 }
285
286 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) {
287 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher();
288 int item_count = launcher->model()->item_count();
289
290 // First run app.
291 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
292 ShellWindow* window1 = CreateShellWindow(extension1);
293 ++item_count;
294 ASSERT_EQ(item_count, launcher->model()->item_count());
295 ash::LauncherItem item1 =
296 launcher->model()->items()[launcher->model()->item_count() - 2];
297 ash::LauncherID item_id1 = item1.id;
298 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
299 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
300
301 // Then run second app.
302 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2");
303 ShellWindow* window2 = CreateShellWindow(extension2);
304 ++item_count;
305 ASSERT_EQ(item_count, launcher->model()->item_count());
306 ash::LauncherItem item2 =
307 launcher->model()->items()[launcher->model()->item_count() - 2];
308 ash::LauncherID item_id2 = item2.id;
309 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item2.type);
310 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status);
311
312 EXPECT_NE(item_id1, item_id2);
313 EXPECT_EQ(ash::STATUS_RUNNING, launcher->model()->ItemByID(item_id1)->status);
314
315 // Close second app.
316 CloseShellWindow(window2);
317 --item_count;
318 ASSERT_EQ(item_count, launcher->model()->item_count());
319 // First app should be active again.
320 EXPECT_EQ(ash::STATUS_ACTIVE, launcher->model()->ItemByID(item_id1)->status);
321
322 // Close first app.
323 CloseShellWindow(window1);
324 --item_count;
325 ASSERT_EQ(item_count, launcher->model()->item_count());
326
327 }
328
329 // Confirm that app windows can be reactivated by clicking their icons and that
330 // the correct activation order is maintained.
331 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowActivation) {
332 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher();
333 int item_count = launcher->model()->item_count();
334
335 // First run app.
336 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
337 ShellWindow* window1 = CreateShellWindow(extension1);
338 ++item_count;
339 ASSERT_EQ(item_count, launcher->model()->item_count());
340 ash::LauncherItem item1 =
341 launcher->model()->items()[launcher->model()->item_count() - 2];
342 ash::LauncherID item_id1 = item1.id;
343 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
344 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
345
346 // Then run second app.
347 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2");
348 ShellWindow* window2 = CreateShellWindow(extension2);
349 ++item_count;
350 ASSERT_EQ(item_count, launcher->model()->item_count());
351 ash::LauncherItem item2 =
352 launcher->model()->items()[launcher->model()->item_count() - 2];
353 ash::LauncherID item_id2 = item2.id;
354 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item2.type);
355 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status);
356
357 EXPECT_NE(item_id1, item_id2);
358 EXPECT_EQ(ash::STATUS_RUNNING, launcher->model()->ItemByID(item_id1)->status);
359
360 // Activate first one.
361 launcher->ActivateLauncherItem(launcher->model()->ItemIndexByID(item_id1));
362 EXPECT_EQ(ash::STATUS_ACTIVE, launcher->model()->ItemByID(item_id1)->status);
363 EXPECT_EQ(ash::STATUS_RUNNING, launcher->model()->ItemByID(item_id2)->status);
364 EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow()));
365 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow()));
366
367 // Activate second one.
368 launcher->ActivateLauncherItem(launcher->model()->ItemIndexByID(item_id2));
369 EXPECT_EQ(ash::STATUS_RUNNING, launcher->model()->ItemByID(item_id1)->status);
370 EXPECT_EQ(ash::STATUS_ACTIVE, launcher->model()->ItemByID(item_id2)->status);
371 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow()));
372 EXPECT_TRUE(ash::wm::IsActiveWindow(window2->GetNativeWindow()));
373
374 // Add window for app1. This will activate it.
375 ShellWindow* window3 = CreateShellWindow(extension1);
376 ash::wm::ActivateWindow(window3->GetNativeWindow());
377 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow()));
378 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow()));
379 EXPECT_TRUE(ash::wm::IsActiveWindow(window3->GetNativeWindow()));
380
381 // Activate the second app again
382 launcher->ActivateLauncherItem(launcher->model()->ItemIndexByID(item_id2));
383 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow()));
384 EXPECT_TRUE(ash::wm::IsActiveWindow(window2->GetNativeWindow()));
385 EXPECT_FALSE(ash::wm::IsActiveWindow(window3->GetNativeWindow()));
386
387 // Activate the first app app
388 launcher->ActivateLauncherItem(launcher->model()->ItemIndexByID(item_id1));
389 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow()));
390 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow()));
391 EXPECT_TRUE(ash::wm::IsActiveWindow(window3->GetNativeWindow()));
392
393 // Close second app.
394 CloseShellWindow(window2);
395 --item_count;
396 EXPECT_EQ(item_count, launcher->model()->item_count());
397 // First app should be active again.
398 EXPECT_EQ(ash::STATUS_ACTIVE, launcher->model()->ItemByID(item_id1)->status);
399
400 // Close first app.
401 CloseShellWindow(window3);
402 CloseShellWindow(window1);
403 --item_count;
404 EXPECT_EQ(item_count, launcher->model()->item_count());
405
406 }
407
408 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, BrowserActivation) {
409 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher();
410 int item_count = launcher->model()->item_count();
411
412 // First run app.
413 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
414 CreateShellWindow(extension1);
415 ++item_count;
416 ASSERT_EQ(item_count, launcher->model()->item_count());
417 ash::LauncherItem item1 =
418 launcher->model()->items()[launcher->model()->item_count() - 2];
419 ash::LauncherID item_id1 = item1.id;
420 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
421 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
422
423 ash::wm::ActivateWindow(browser()->window()->GetNativeWindow());
424 EXPECT_EQ(ash::STATUS_RUNNING, launcher->model()->ItemByID(item_id1)->status);
425 }
426
427 // Test that we can launch an app with a shortcut.
428 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchPinned) {
429 TabStripModel* tab_strip = browser()->tab_strip_model();
430 int tab_count = tab_strip->count();
431 ash::LauncherID shortcut_id = CreateShortcut("app1");
432 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
433 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
434 EXPECT_EQ(++tab_count, tab_strip->count());
435 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
436 TabContents* tab = tab_strip->GetActiveTabContents();
437 content::WindowedNotificationObserver close_observer(
438 chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED,
439 content::Source<TabContents>(tab));
440 browser()->tab_strip_model()->CloseSelectedTabs();
441 close_observer.Wait();
442 EXPECT_EQ(--tab_count, tab_strip->count());
443 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
444 }
445
446 // Launch the app first and then create the shortcut.
447 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchUnpinned) {
448 TabStripModel* tab_strip = browser()->tab_strip_model();
449 int tab_count = tab_strip->count();
450 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB,
451 NEW_FOREGROUND_TAB);
452 EXPECT_EQ(++tab_count, tab_strip->count());
453 ash::LauncherID shortcut_id = CreateShortcut("app1");
454 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
455 TabContents* tab = tab_strip->GetActiveTabContents();
456 content::WindowedNotificationObserver close_observer(
457 chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED,
458 content::Source<TabContents>(tab));
459 browser()->tab_strip_model()->CloseSelectedTabs();
460 close_observer.Wait();
461 EXPECT_EQ(--tab_count, tab_strip->count());
462 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
463 }
464
465 // Launches an app in the background and then tries to open it. This is test for
466 // a crash we had.
467 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchInBackground) {
468 TabStripModel* tab_strip = browser()->tab_strip_model();
469 int tab_count = tab_strip->count();
470 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB,
471 NEW_BACKGROUND_TAB);
472 EXPECT_EQ(++tab_count, tab_strip->count());
473 ChromeLauncherController::instance()->OpenAppID(last_loaded_extension_id_, 0);
474 }
475
476 // Confirm that clicking a icon for an app running in one of 2 maxmized windows
477 // activates the right window.
478 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchMaximized) {
479 aura::Window* window1 = browser()->window()->GetNativeWindow();
480 ash::wm::MaximizeWindow(window1);
481 content::WindowedNotificationObserver open_observer(
482 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
483 content::NotificationService::AllSources());
484 chrome::NewEmptyWindow(browser()->profile());
485 open_observer.Wait();
486 Browser* browser2 = content::Source<Browser>(open_observer.source()).ptr();
487 aura::Window* window2 = browser2->window()->GetNativeWindow();
488 TabStripModel* tab_strip = browser2->tab_strip_model();
489 int tab_count = tab_strip->count();
490 ash::wm::MaximizeWindow(window2);
491
492 ash::LauncherID shortcut_id = CreateShortcut("app1");
493 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
494 EXPECT_EQ(++tab_count, tab_strip->count());
495 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
496
497 window1->Show();
498 ash::wm::ActivateWindow(window1);
499 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut_id)).status);
500
501 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
502 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
503 }
504
505 // Launches app multiple times through the api that the applist uses.
506 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, OpenAppID) {
507 TabStripModel* tab_strip = browser()->tab_strip_model();
508 int tab_count = tab_strip->count();
509 const Extension* extension =
510 LoadExtension(test_data_dir_.AppendASCII("app1"));
511
512 ChromeLauncherController::instance()->OpenAppID(extension->id(), 0);
513 EXPECT_EQ(++tab_count, tab_strip->count());
514 ChromeLauncherController::instance()->OpenAppID(extension->id(), 0);
515 EXPECT_EQ(tab_count, tab_strip->count());
516 }
517
518 // Launch 2 apps and toggle which is active.
519 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleApps) {
520 int item_count = model_->item_count();
521 TabStripModel* tab_strip = browser()->tab_strip_model();
522 int tab_count = tab_strip->count();
523 ash::LauncherID shortcut1 = CreateShortcut("app1");
524 EXPECT_EQ(++item_count, model_->item_count());
525 ash::LauncherID shortcut2 = CreateShortcut("app2");
526 EXPECT_EQ(++item_count, model_->item_count());
527
528 // Launch first app.
529 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut1));
530 EXPECT_EQ(++tab_count, tab_strip->count());
531 TabContents* tab1 = tab_strip->GetActiveTabContents();
532 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status);
533
534 // Launch second app.
535 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut2));
536 EXPECT_EQ(++tab_count, tab_strip->count());
537 TabContents* tab2 = tab_strip->GetActiveTabContents();
538 ASSERT_NE(tab1, tab2);
539 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status);
540 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status);
541
542 // Reactivate first app.
543 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut1));
544 EXPECT_EQ(tab_count, tab_strip->count());
545 EXPECT_EQ(tab_strip->GetActiveTabContents(), tab1);
546 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status);
547 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut2)).status);
548
549 // Open second tab for second app. This should activate it.
550 ui_test_utils::NavigateToURLWithDisposition(
551 browser(),
552 GURL("http://www.example.com/path3/foo.html"),
553 NEW_FOREGROUND_TAB,
554 0);
555 EXPECT_EQ(++tab_count, tab_strip->count());
556 TabContents* tab3 = tab_strip->GetActiveTabContents();
557 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status);
558 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status);
559
560 // Reactivate first app.
561 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut1));
562 EXPECT_EQ(tab_count, tab_strip->count());
563 EXPECT_EQ(tab_strip->GetActiveTabContents(), tab1);
564 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status);
565 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut2)).status);
566
567 // And second again. This time the second tab should become active.
568 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut2));
569 EXPECT_EQ(tab_count, tab_strip->count());
570 EXPECT_EQ(tab_strip->GetActiveTabContents(), tab3);
571 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status);
572 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status);
573 }
574
575 // Confirm that a page can be navigated from and to while maintaining the
576 // correct running state.
577 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, Navigation) {
578 ash::LauncherID shortcut_id = CreateShortcut("app1");
579 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
580 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
581 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
582
583 // Navigate away.
584 ui_test_utils::NavigateToURL(
585 browser(), GURL("http://www.example.com/path0/bar.html"));
586 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
587
588 // Navigate back.
589 ui_test_utils::NavigateToURL(
590 browser(), GURL("http://www.example.com/path1/foo.html"));
591 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
592 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698