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

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

Issue 12022002: Fixing activation states from the new launcher. Also adding a whole bunch of unit tests for the new… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed problem with ASAN unittest Created 7 years, 11 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
6 6
7 #include "ash/ash_switches.h"
7 #include "ash/launcher/launcher.h" 8 #include "ash/launcher/launcher.h"
8 #include "ash/launcher/launcher_model.h" 9 #include "ash/launcher/launcher_model.h"
9 #include "ash/shell.h" 10 #include "ash/shell.h"
10 #include "ash/test/shell_test_api.h" 11 #include "ash/test/shell_test_api.h"
11 #include "ash/wm/window_util.h" 12 #include "ash/wm/window_util.h"
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/automation/automation_util.h" 15 #include "chrome/browser/automation/automation_util.h"
15 #include "chrome/browser/extensions/extension_apitest.h" 16 #include "chrome/browser/extensions/extension_apitest.h"
16 #include "chrome/browser/extensions/extension_browsertest.h" 17 #include "chrome/browser/extensions/extension_browsertest.h"
(...skipping 16 matching lines...) Expand all
33 #include "chrome/test/base/ui_test_utils.h" 34 #include "chrome/test/base/ui_test_utils.h"
34 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
35 #include "content/public/browser/notification_source.h" 36 #include "content/public/browser/notification_source.h"
36 #include "content/public/browser/web_contents.h" 37 #include "content/public/browser/web_contents.h"
37 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
38 #include "ui/aura/window.h" 39 #include "ui/aura/window.h"
39 40
40 using extensions::Extension; 41 using extensions::Extension;
41 using content::WebContents; 42 using content::WebContents;
42 43
43 class LauncherPlatformAppBrowserTest 44 // TODO(skuhne): Change name back to LauncherPlatformAppBrowserTest when the
45 // old launcher gets ripped out.
46 class LauncherPlatformPerAppAppBrowserTest
44 : public extensions::PlatformAppBrowserTest { 47 : public extensions::PlatformAppBrowserTest {
45 protected: 48 protected:
46 LauncherPlatformAppBrowserTest() 49 LauncherPlatformPerAppAppBrowserTest()
47 : launcher_(NULL), 50 : launcher_(NULL),
48 controller_(NULL) { 51 controller_(NULL) {
49 } 52 }
50 53
51 virtual ~LauncherPlatformAppBrowserTest() {} 54 virtual ~LauncherPlatformPerAppAppBrowserTest() {}
55 // TODO(skuhne): Remove when the old launcher gets removed.
56 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
57 PlatformAppBrowserTest::SetUpCommandLine(command_line);
58 command_line->AppendSwitch(ash::switches::kAshEnablePerAppLauncher);
59 }
52 60
53 ash::LauncherModel* launcher_model() { 61 ash::LauncherModel* launcher_model() {
54 return ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); 62 return ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model();
55 } 63 }
56 64
57 virtual void RunTestOnMainThreadLoop() { 65 virtual void RunTestOnMainThreadLoop() {
58 launcher_ = ash::Launcher::ForPrimaryDisplay(); 66 launcher_ = ash::Launcher::ForPrimaryDisplay();
59 controller_ = static_cast<ChromeLauncherController*>(launcher_->delegate()); 67 controller_ = static_cast<ChromeLauncherController*>(launcher_->delegate());
60 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop(); 68 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop();
61 } 69 }
62 70
63 ash::LauncherID CreateAppShortcutLauncherItem(const std::string& name) { 71 ash::LauncherID CreateAppShortcutLauncherItem(const std::string& name) {
64 return controller_->CreateAppShortcutLauncherItem( 72 return controller_->CreateAppShortcutLauncherItem(
65 name, controller_->model()->item_count()); 73 name, controller_->model()->item_count());
66 } 74 }
67 75
68 ash::Launcher* launcher_; 76 ash::Launcher* launcher_;
69 ChromeLauncherController* controller_; 77 ChromeLauncherController* controller_;
70 }; 78 };
71 79
72 class LauncherAppBrowserTest : public ExtensionBrowserTest { 80 // TODO(skuhne): Change name back to LauncherAppBrowserTest when the
81 // old launcher gets ripped out.
82 class LauncherPerAppAppBrowserTest : public ExtensionBrowserTest {
73 protected: 83 protected:
74 LauncherAppBrowserTest() 84 LauncherPerAppAppBrowserTest()
75 : launcher_(NULL), 85 : launcher_(NULL),
76 model_(NULL) { 86 model_(NULL) {
77 } 87 }
78 88
79 virtual ~LauncherAppBrowserTest() {} 89 virtual ~LauncherPerAppAppBrowserTest() {}
90
91 // TODO(skuhne): Remove when the old launcher gets removed.
92 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
93 ExtensionBrowserTest::SetUpCommandLine(command_line);
94 command_line->AppendSwitch(ash::switches::kAshEnablePerAppLauncher);
95 }
80 96
81 virtual void RunTestOnMainThreadLoop() { 97 virtual void RunTestOnMainThreadLoop() {
82 launcher_ = ash::Launcher::ForPrimaryDisplay(); 98 launcher_ = ash::Launcher::ForPrimaryDisplay();
83 model_ = 99 model_ =
84 ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); 100 ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model();
85 return ExtensionBrowserTest::RunTestOnMainThreadLoop(); 101 return ExtensionBrowserTest::RunTestOnMainThreadLoop();
86 } 102 }
87 103
88 const Extension* LoadAndLaunchExtension( 104 const Extension* LoadAndLaunchExtension(
89 const char* name, 105 const char* name,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 ash::LauncherItem item = *model_->ItemByID(shortcut_id); 139 ash::LauncherItem item = *model_->ItemByID(shortcut_id);
124 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); 140 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type);
125 return item.id; 141 return item.id;
126 } 142 }
127 143
128 ash::Launcher* launcher_; 144 ash::Launcher* launcher_;
129 ash::LauncherModel* model_; 145 ash::LauncherModel* model_;
130 }; 146 };
131 147
132 // Test that we can launch a platform app and get a running item. 148 // Test that we can launch a platform app and get a running item.
133 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) { 149 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, LaunchUnpinned) {
134 int item_count = launcher_model()->item_count(); 150 int item_count = launcher_model()->item_count();
135 const Extension* extension = LoadAndLaunchPlatformApp("launch"); 151 const Extension* extension = LoadAndLaunchPlatformApp("launch");
136 ShellWindow* window = CreateShellWindow(extension); 152 ShellWindow* window = CreateShellWindow(extension);
137 ++item_count; 153 ++item_count;
138 ASSERT_EQ(item_count, launcher_model()->item_count()); 154 ASSERT_EQ(item_count, launcher_model()->item_count());
139 ash::LauncherItem item = 155 ash::LauncherItem item =
140 launcher_model()->items()[launcher_model()->item_count() - 2]; 156 launcher_model()->items()[launcher_model()->item_count() - 2];
141 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); 157 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type);
142 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); 158 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
143 CloseShellWindow(window); 159 CloseShellWindow(window);
144 --item_count; 160 --item_count;
145 EXPECT_EQ(item_count, launcher_model()->item_count()); 161 EXPECT_EQ(item_count, launcher_model()->item_count());
146 } 162 }
147 163
148 // Test that we can launch a platform app that already has a shortcut. 164 // Test that we can launch a platform app that already has a shortcut.
149 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) { 165 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, LaunchPinned) {
150 int item_count = launcher_model()->item_count(); 166 int item_count = launcher_model()->item_count();
151 167
152 // First get app_id. 168 // First get app_id.
153 const Extension* extension = LoadAndLaunchPlatformApp("launch"); 169 const Extension* extension = LoadAndLaunchPlatformApp("launch");
154 const std::string app_id = extension->id(); 170 const std::string app_id = extension->id();
155 171
156 // Then create a shortcut. 172 // Then create a shortcut.
157 ash::LauncherID shortcut_id = CreateAppShortcutLauncherItem(app_id); 173 ash::LauncherID shortcut_id = CreateAppShortcutLauncherItem(app_id);
158 ++item_count; 174 ++item_count;
159 ASSERT_EQ(item_count, launcher_model()->item_count()); 175 ASSERT_EQ(item_count, launcher_model()->item_count());
(...skipping 10 matching lines...) Expand all
170 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); 186 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
171 187
172 // Then close it, make sure there's still an item. 188 // Then close it, make sure there's still an item.
173 CloseShellWindow(window); 189 CloseShellWindow(window);
174 ASSERT_EQ(item_count, launcher_model()->item_count()); 190 ASSERT_EQ(item_count, launcher_model()->item_count());
175 item = *launcher_model()->ItemByID(shortcut_id); 191 item = *launcher_model()->ItemByID(shortcut_id);
176 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); 192 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type);
177 EXPECT_EQ(ash::STATUS_CLOSED, item.status); 193 EXPECT_EQ(ash::STATUS_CLOSED, item.status);
178 } 194 }
179 195
180 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, PinRunning) { 196 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, PinRunning) {
181 // Run. 197 // Run.
182 int item_count = launcher_model()->item_count(); 198 int item_count = launcher_model()->item_count();
183 const Extension* extension = LoadAndLaunchPlatformApp("launch"); 199 const Extension* extension = LoadAndLaunchPlatformApp("launch");
184 ShellWindow* window = CreateShellWindow(extension); 200 ShellWindow* window = CreateShellWindow(extension);
185 ++item_count; 201 ++item_count;
186 ASSERT_EQ(item_count, launcher_model()->item_count()); 202 ASSERT_EQ(item_count, launcher_model()->item_count());
187 ash::LauncherItem item = 203 ash::LauncherItem item =
188 launcher_model()->items()[launcher_model()->item_count() - 2]; 204 launcher_model()->items()[launcher_model()->item_count() - 2];
189 ash::LauncherID id = item.id; 205 ash::LauncherID id = item.id;
190 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); 206 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type);
(...skipping 18 matching lines...) Expand all
209 ++item_count; 225 ++item_count;
210 ASSERT_EQ(item_count, launcher_model()->item_count()); 226 ASSERT_EQ(item_count, launcher_model()->item_count());
211 EXPECT_LT(launcher_model()->ItemIndexByID(id), 227 EXPECT_LT(launcher_model()->ItemIndexByID(id),
212 launcher_model()->ItemIndexByID(bar_id)); 228 launcher_model()->ItemIndexByID(bar_id));
213 229
214 // Then close it, make sure the item remains. 230 // Then close it, make sure the item remains.
215 CloseShellWindow(window); 231 CloseShellWindow(window);
216 ASSERT_EQ(item_count, launcher_model()->item_count()); 232 ASSERT_EQ(item_count, launcher_model()->item_count());
217 } 233 }
218 234
219 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) { 235 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, UnpinRunning) {
220 int item_count = launcher_model()->item_count(); 236 int item_count = launcher_model()->item_count();
221 237
222 // First get app_id. 238 // First get app_id.
223 const Extension* extension = LoadAndLaunchPlatformApp("launch"); 239 const Extension* extension = LoadAndLaunchPlatformApp("launch");
224 const std::string app_id = extension->id(); 240 const std::string app_id = extension->id();
225 241
226 // Then create a shortcut. 242 // Then create a shortcut.
227 ash::LauncherID shortcut_id = CreateAppShortcutLauncherItem(app_id); 243 ash::LauncherID shortcut_id = CreateAppShortcutLauncherItem(app_id);
228 ++item_count; 244 ++item_count;
229 ASSERT_EQ(item_count, launcher_model()->item_count()); 245 ASSERT_EQ(item_count, launcher_model()->item_count());
(...skipping 27 matching lines...) Expand all
257 EXPECT_GT(launcher_model()->ItemIndexByID(shortcut_id), 273 EXPECT_GT(launcher_model()->ItemIndexByID(shortcut_id),
258 launcher_model()->ItemIndexByID(foo_id)); 274 launcher_model()->ItemIndexByID(foo_id));
259 275
260 // Then close it, make sure the item's gone. 276 // Then close it, make sure the item's gone.
261 CloseShellWindow(window); 277 CloseShellWindow(window);
262 --item_count; 278 --item_count;
263 ASSERT_EQ(item_count, launcher_model()->item_count()); 279 ASSERT_EQ(item_count, launcher_model()->item_count());
264 } 280 }
265 281
266 // Test that we can launch a platform app with more than one window. 282 // Test that we can launch a platform app with more than one window.
267 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) { 283 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, MultipleWindows) {
268 int item_count = launcher_model()->item_count(); 284 int item_count = launcher_model()->item_count();
269 285
270 // First run app. 286 // First run app.
271 const Extension* extension = LoadAndLaunchPlatformApp("launch"); 287 const Extension* extension = LoadAndLaunchPlatformApp("launch");
272 ShellWindow* window1 = CreateShellWindow(extension); 288 ShellWindow* window1 = CreateShellWindow(extension);
273 ++item_count; 289 ++item_count;
274 ASSERT_EQ(item_count, launcher_model()->item_count()); 290 ASSERT_EQ(item_count, launcher_model()->item_count());
275 ash::LauncherItem item = 291 ash::LauncherItem item =
276 launcher_model()->items()[launcher_model()->item_count() - 2]; 292 launcher_model()->items()[launcher_model()->item_count() - 2];
277 ash::LauncherID item_id = item.id; 293 ash::LauncherID item_id = item.id;
(...skipping 14 matching lines...) Expand all
292 item = *launcher_model()->ItemByID(item_id); 308 item = *launcher_model()->ItemByID(item_id);
293 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); 309 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
294 310
295 // Close first window. 311 // Close first window.
296 CloseShellWindow(window1); 312 CloseShellWindow(window1);
297 // Confirm item is removed. 313 // Confirm item is removed.
298 --item_count; 314 --item_count;
299 ASSERT_EQ(item_count, launcher_model()->item_count()); 315 ASSERT_EQ(item_count, launcher_model()->item_count());
300 } 316 }
301 317
302 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) { 318 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, MultipleApps) {
303 int item_count = launcher_model()->item_count(); 319 int item_count = launcher_model()->item_count();
304 320
305 // First run app. 321 // First run app.
306 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); 322 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
307 ShellWindow* window1 = CreateShellWindow(extension1); 323 ShellWindow* window1 = CreateShellWindow(extension1);
308 ++item_count; 324 ++item_count;
309 ASSERT_EQ(item_count, launcher_model()->item_count()); 325 ASSERT_EQ(item_count, launcher_model()->item_count());
310 ash::LauncherItem item1 = 326 ash::LauncherItem item1 =
311 launcher_model()->items()[launcher_model()->item_count() - 2]; 327 launcher_model()->items()[launcher_model()->item_count() - 2];
312 ash::LauncherID item_id1 = item1.id; 328 ash::LauncherID item_id1 = item1.id;
(...skipping 25 matching lines...) Expand all
338 354
339 // Close first app. 355 // Close first app.
340 CloseShellWindow(window1); 356 CloseShellWindow(window1);
341 --item_count; 357 --item_count;
342 ASSERT_EQ(item_count, launcher_model()->item_count()); 358 ASSERT_EQ(item_count, launcher_model()->item_count());
343 359
344 } 360 }
345 361
346 // Confirm that app windows can be reactivated by clicking their icons and that 362 // Confirm that app windows can be reactivated by clicking their icons and that
347 // the correct activation order is maintained. 363 // the correct activation order is maintained.
348 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowActivation) { 364 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, WindowActivation) {
349 int item_count = launcher_model()->item_count(); 365 int item_count = launcher_model()->item_count();
350 366
351 // First run app. 367 // First run app.
352 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); 368 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
353 ShellWindow* window1 = CreateShellWindow(extension1); 369 ShellWindow* window1 = CreateShellWindow(extension1);
354 ++item_count; 370 ++item_count;
355 ASSERT_EQ(item_count, launcher_model()->item_count()); 371 ASSERT_EQ(item_count, launcher_model()->item_count());
356 ash::LauncherItem item1 = 372 ash::LauncherItem item1 =
357 launcher_model()->items()[launcher_model()->item_count() - 2]; 373 launcher_model()->items()[launcher_model()->item_count() - 2];
358 ash::LauncherID item_id1 = item1.id; 374 ash::LauncherID item_id1 = item1.id;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 // First app should be active again. 440 // First app should be active again.
425 EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id1)->status); 441 EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id1)->status);
426 442
427 // Close first app. 443 // Close first app.
428 CloseShellWindow(window1b); 444 CloseShellWindow(window1b);
429 CloseShellWindow(window1); 445 CloseShellWindow(window1);
430 --item_count; 446 --item_count;
431 EXPECT_EQ(item_count, launcher_model()->item_count()); 447 EXPECT_EQ(item_count, launcher_model()->item_count());
432 } 448 }
433 449
434 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, BrowserActivation) { 450 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest,
451 BrowserActivation) {
435 int item_count = launcher_model()->item_count(); 452 int item_count = launcher_model()->item_count();
436 453
437 // First run app. 454 // First run app.
438 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); 455 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
439 CreateShellWindow(extension1); 456 CreateShellWindow(extension1);
440 ++item_count; 457 ++item_count;
441 ASSERT_EQ(item_count, launcher_model()->item_count()); 458 ASSERT_EQ(item_count, launcher_model()->item_count());
442 ash::LauncherItem item1 = 459 ash::LauncherItem item1 =
443 launcher_model()->items()[launcher_model()->item_count() - 2]; 460 launcher_model()->items()[launcher_model()->item_count() - 2];
444 ash::LauncherID item_id1 = item1.id; 461 ash::LauncherID item_id1 = item1.id;
445 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); 462 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
446 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); 463 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
447 464
448 ash::wm::ActivateWindow(browser()->window()->GetNativeWindow()); 465 ash::wm::ActivateWindow(browser()->window()->GetNativeWindow());
449 EXPECT_EQ(ash::STATUS_RUNNING, 466 EXPECT_EQ(ash::STATUS_RUNNING,
450 launcher_model()->ItemByID(item_id1)->status); 467 launcher_model()->ItemByID(item_id1)->status);
451 } 468 }
452 469
453 // Test that we can launch an app with a shortcut. 470 // Test that we can launch an app with a shortcut.
454 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchPinned) { 471 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchPinned) {
455 TabStripModel* tab_strip = browser()->tab_strip_model(); 472 TabStripModel* tab_strip = browser()->tab_strip_model();
456 int tab_count = tab_strip->count(); 473 int tab_count = tab_strip->count();
457 ash::LauncherID shortcut_id = CreateShortcut("app1"); 474 ash::LauncherID shortcut_id = CreateShortcut("app1");
458 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 475 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
459 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 476 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
460 EXPECT_EQ(++tab_count, tab_strip->count()); 477 EXPECT_EQ(++tab_count, tab_strip->count());
461 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 478 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
462 WebContents* tab = tab_strip->GetActiveWebContents(); 479 WebContents* tab = tab_strip->GetActiveWebContents();
463 content::WindowedNotificationObserver close_observer( 480 content::WindowedNotificationObserver close_observer(
464 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 481 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
465 content::Source<WebContents>(tab)); 482 content::Source<WebContents>(tab));
466 browser()->tab_strip_model()->CloseSelectedTabs(); 483 browser()->tab_strip_model()->CloseSelectedTabs();
467 close_observer.Wait(); 484 close_observer.Wait();
468 EXPECT_EQ(--tab_count, tab_strip->count()); 485 EXPECT_EQ(--tab_count, tab_strip->count());
469 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 486 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
470 } 487 }
471 488
472 // Launch the app first and then create the shortcut. 489 // Launch the app first and then create the shortcut.
473 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchUnpinned) { 490 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchUnpinned) {
474 TabStripModel* tab_strip = browser()->tab_strip_model(); 491 TabStripModel* tab_strip = browser()->tab_strip_model();
475 int tab_count = tab_strip->count(); 492 int tab_count = tab_strip->count();
476 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, 493 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB,
477 NEW_FOREGROUND_TAB); 494 NEW_FOREGROUND_TAB);
478 EXPECT_EQ(++tab_count, tab_strip->count()); 495 EXPECT_EQ(++tab_count, tab_strip->count());
479 ash::LauncherID shortcut_id = CreateShortcut("app1"); 496 ash::LauncherID shortcut_id = CreateShortcut("app1");
480 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 497 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
481 WebContents* tab = tab_strip->GetActiveWebContents(); 498 WebContents* tab = tab_strip->GetActiveWebContents();
482 content::WindowedNotificationObserver close_observer( 499 content::WindowedNotificationObserver close_observer(
483 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 500 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
484 content::Source<WebContents>(tab)); 501 content::Source<WebContents>(tab));
485 browser()->tab_strip_model()->CloseSelectedTabs(); 502 browser()->tab_strip_model()->CloseSelectedTabs();
486 close_observer.Wait(); 503 close_observer.Wait();
487 EXPECT_EQ(--tab_count, tab_strip->count()); 504 EXPECT_EQ(--tab_count, tab_strip->count());
488 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 505 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
489 } 506 }
490 507
491 // Launches an app in the background and then tries to open it. This is test for 508 // Launches an app in the background and then tries to open it. This is test for
492 // a crash we had. 509 // a crash we had.
493 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchInBackground) { 510 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchInBackground) {
494 TabStripModel* tab_strip = browser()->tab_strip_model(); 511 TabStripModel* tab_strip = browser()->tab_strip_model();
495 int tab_count = tab_strip->count(); 512 int tab_count = tab_strip->count();
496 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, 513 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB,
497 NEW_BACKGROUND_TAB); 514 NEW_BACKGROUND_TAB);
498 EXPECT_EQ(++tab_count, tab_strip->count()); 515 EXPECT_EQ(++tab_count, tab_strip->count());
499 ChromeLauncherController::instance()->LaunchApp(last_loaded_extension_id_, 0); 516 ChromeLauncherController::instance()->LaunchApp(last_loaded_extension_id_, 0);
500 } 517 }
501 518
502 // Confirm that clicking a icon for an app running in one of 2 maxmized windows 519 // Confirm that clicking a icon for an app running in one of 2 maxmized windows
503 // activates the right window. 520 // activates the right window.
504 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchMaximized) { 521 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchMaximized) {
505 aura::Window* window1 = browser()->window()->GetNativeWindow(); 522 aura::Window* window1 = browser()->window()->GetNativeWindow();
506 ash::wm::MaximizeWindow(window1); 523 ash::wm::MaximizeWindow(window1);
507 content::WindowedNotificationObserver open_observer( 524 content::WindowedNotificationObserver open_observer(
508 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 525 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
509 content::NotificationService::AllSources()); 526 content::NotificationService::AllSources());
510 chrome::NewEmptyWindow(browser()->profile()); 527 chrome::NewEmptyWindow(browser()->profile());
511 open_observer.Wait(); 528 open_observer.Wait();
512 Browser* browser2 = content::Source<Browser>(open_observer.source()).ptr(); 529 Browser* browser2 = content::Source<Browser>(open_observer.source()).ptr();
513 aura::Window* window2 = browser2->window()->GetNativeWindow(); 530 aura::Window* window2 = browser2->window()->GetNativeWindow();
514 TabStripModel* tab_strip = browser2->tab_strip_model(); 531 TabStripModel* tab_strip = browser2->tab_strip_model();
515 int tab_count = tab_strip->count(); 532 int tab_count = tab_strip->count();
516 ash::wm::MaximizeWindow(window2); 533 ash::wm::MaximizeWindow(window2);
517 534
518 ash::LauncherID shortcut_id = CreateShortcut("app1"); 535 ash::LauncherID shortcut_id = CreateShortcut("app1");
519 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 536 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
520 EXPECT_EQ(++tab_count, tab_strip->count()); 537 EXPECT_EQ(++tab_count, tab_strip->count());
521 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 538 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
522 539
523 window1->Show(); 540 window1->Show();
524 ash::wm::ActivateWindow(window1); 541 ash::wm::ActivateWindow(window1);
525 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut_id)).status); 542 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut_id)).status);
526 543
527 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 544 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
528 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 545 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
529 } 546 }
530 547
531 // Activating the same app multiple times should launch only a single copy. 548 // Activating the same app multiple times should launch only a single copy.
532 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivateApp) { 549 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, ActivateApp) {
533 TabStripModel* tab_strip = browser()->tab_strip_model(); 550 TabStripModel* tab_strip = browser()->tab_strip_model();
534 int tab_count = tab_strip->count(); 551 int tab_count = tab_strip->count();
535 const Extension* extension = 552 const Extension* extension =
536 LoadExtension(test_data_dir_.AppendASCII("app1")); 553 LoadExtension(test_data_dir_.AppendASCII("app1"));
537 554
538 ChromeLauncherController::instance()->ActivateApp(extension->id(), 0); 555 ChromeLauncherController::instance()->ActivateApp(extension->id(), 0);
539 EXPECT_EQ(++tab_count, tab_strip->count()); 556 EXPECT_EQ(++tab_count, tab_strip->count());
540 ChromeLauncherController::instance()->ActivateApp(extension->id(), 0); 557 ChromeLauncherController::instance()->ActivateApp(extension->id(), 0);
541 EXPECT_EQ(tab_count, tab_strip->count()); 558 EXPECT_EQ(tab_count, tab_strip->count());
542 } 559 }
543 560
544 // Launching the same app multiple times should launch a copy for each call. 561 // Launching the same app multiple times should launch a copy for each call.
545 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchApp) { 562 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchApp) {
546 TabStripModel* tab_strip = browser()->tab_strip_model(); 563 TabStripModel* tab_strip = browser()->tab_strip_model();
547 int tab_count = tab_strip->count(); 564 int tab_count = tab_strip->count();
548 const Extension* extension = 565 const Extension* extension =
549 LoadExtension(test_data_dir_.AppendASCII("app1")); 566 LoadExtension(test_data_dir_.AppendASCII("app1"));
550 567
551 ChromeLauncherController::instance()->LaunchApp(extension->id(), 0); 568 ChromeLauncherController::instance()->LaunchApp(extension->id(), 0);
552 EXPECT_EQ(++tab_count, tab_strip->count()); 569 EXPECT_EQ(++tab_count, tab_strip->count());
553 ChromeLauncherController::instance()->LaunchApp(extension->id(), 0); 570 ChromeLauncherController::instance()->LaunchApp(extension->id(), 0);
554 EXPECT_EQ(++tab_count, tab_strip->count()); 571 EXPECT_EQ(++tab_count, tab_strip->count());
555 } 572 }
556 573
557 // Launch 2 apps and toggle which is active. 574 // Launch 2 apps and toggle which is active.
558 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleApps) { 575 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, MultipleApps) {
559 int item_count = model_->item_count(); 576 int item_count = model_->item_count();
560 TabStripModel* tab_strip = browser()->tab_strip_model(); 577 TabStripModel* tab_strip = browser()->tab_strip_model();
561 int tab_count = tab_strip->count(); 578 int tab_count = tab_strip->count();
562 ash::LauncherID shortcut1 = CreateShortcut("app1"); 579 ash::LauncherID shortcut1 = CreateShortcut("app1");
563 EXPECT_EQ(++item_count, model_->item_count()); 580 EXPECT_EQ(++item_count, model_->item_count());
564 ash::LauncherID shortcut2 = CreateShortcut("app2"); 581 ash::LauncherID shortcut2 = CreateShortcut("app2");
565 EXPECT_EQ(++item_count, model_->item_count()); 582 EXPECT_EQ(++item_count, model_->item_count());
566 583
567 // Launch first app. 584 // Launch first app.
568 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut1)); 585 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut1));
(...skipping 16 matching lines...) Expand all
585 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status); 602 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status);
586 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut2)).status); 603 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut2)).status);
587 604
588 // Open second tab for second app. This should activate it. 605 // Open second tab for second app. This should activate it.
589 ui_test_utils::NavigateToURLWithDisposition( 606 ui_test_utils::NavigateToURLWithDisposition(
590 browser(), 607 browser(),
591 GURL("http://www.example.com/path3/foo.html"), 608 GURL("http://www.example.com/path3/foo.html"),
592 NEW_FOREGROUND_TAB, 609 NEW_FOREGROUND_TAB,
593 0); 610 0);
594 EXPECT_EQ(++tab_count, tab_strip->count()); 611 EXPECT_EQ(++tab_count, tab_strip->count());
595 WebContents* tab3 = tab_strip->GetActiveWebContents();
596 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status); 612 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status);
597 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status); 613 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status);
598 614
599 // Reactivate first app. 615 // Reactivate first app.
600 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut1)); 616 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut1));
601 EXPECT_EQ(tab_count, tab_strip->count()); 617 EXPECT_EQ(tab_count, tab_strip->count());
602 EXPECT_EQ(tab_strip->GetActiveWebContents(), tab1); 618 EXPECT_EQ(tab_strip->GetActiveWebContents(), tab1);
603 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status); 619 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status);
604 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut2)).status); 620 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut2)).status);
605 621
606 // And second again. This time the second tab should become active. 622 // And second again. This time the second tab should become active.
607 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut2)); 623 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut2));
608 EXPECT_EQ(tab_count, tab_strip->count()); 624 EXPECT_EQ(tab_count, tab_strip->count());
609 EXPECT_EQ(tab_strip->GetActiveWebContents(), tab3); 625 EXPECT_EQ(tab_strip->GetActiveWebContents(), tab2);
610 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status); 626 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status);
611 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status); 627 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status);
612 } 628 }
613 629
614 // Confirm that a page can be navigated from and to while maintaining the 630 // Confirm that a page can be navigated from and to while maintaining the
615 // correct running state. 631 // correct running state.
616 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, Navigation) { 632 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, Navigation) {
617 ash::LauncherID shortcut_id = CreateShortcut("app1"); 633 ash::LauncherID shortcut_id = CreateShortcut("app1");
618 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 634 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
619 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 635 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
620 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 636 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
621 637
622 // Navigate away. 638 // Navigate away.
623 ui_test_utils::NavigateToURL( 639 ui_test_utils::NavigateToURL(
624 browser(), GURL("http://www.example.com/path0/bar.html")); 640 browser(), GURL("http://www.example.com/path0/bar.html"));
625 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 641 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
626 642
627 // Navigate back. 643 // Navigate back.
628 ui_test_utils::NavigateToURL( 644 ui_test_utils::NavigateToURL(
629 browser(), GURL("http://www.example.com/path1/foo.html")); 645 browser(), GURL("http://www.example.com/path1/foo.html"));
630 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 646 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
631 } 647 }
632 648
633 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleOwnedTabs) { 649 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, MultipleOwnedTabs) {
634 TabStripModel* tab_strip = browser()->tab_strip_model(); 650 TabStripModel* tab_strip = browser()->tab_strip_model();
635 int tab_count = tab_strip->count(); 651 int tab_count = tab_strip->count();
636 ash::LauncherID shortcut_id = CreateShortcut("app1"); 652 ash::LauncherID shortcut_id = CreateShortcut("app1");
637 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 653 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
638 EXPECT_EQ(++tab_count, tab_strip->count()); 654 EXPECT_EQ(++tab_count, tab_strip->count());
639 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 655 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
656 WebContents* first_tab = tab_strip->GetActiveWebContents();
640 657
641 // Create new tab owned by app. 658 // Create new tab owned by app.
642 ui_test_utils::NavigateToURLWithDisposition( 659 ui_test_utils::NavigateToURLWithDisposition(
643 browser(), 660 browser(),
644 GURL("http://www.example.com/path2/bar.html"), 661 GURL("http://www.example.com/path2/bar.html"),
645 NEW_FOREGROUND_TAB, 662 NEW_FOREGROUND_TAB,
646 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 663 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
647 EXPECT_EQ(++tab_count, tab_strip->count()); 664 EXPECT_EQ(++tab_count, tab_strip->count());
648 // Confirm app is still active. 665 // Confirm app is still active.
649 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 666 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
650 WebContents* second_tab = tab_strip->GetActiveWebContents();
651 667
652 // Create new tab not owned by app. 668 // Create new tab not owned by app.
653 ui_test_utils::NavigateToURLWithDisposition( 669 ui_test_utils::NavigateToURLWithDisposition(
654 browser(), 670 browser(),
655 GURL("http://www.example.com/path3/foo.html"), 671 GURL("http://www.example.com/path3/foo.html"),
656 NEW_FOREGROUND_TAB, 672 NEW_FOREGROUND_TAB,
657 0); 673 0);
658 EXPECT_EQ(++tab_count, tab_strip->count()); 674 EXPECT_EQ(++tab_count, tab_strip->count());
659 // No longer active. 675 // No longer active.
660 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); 676 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status);
661 677
662 // Activating app makes second tab active again. 678 // Activating app makes first tab active again.
663 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 679 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
664 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 680 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
665 EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab); 681 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab);
666 } 682 }
667 683
668 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilter) { 684 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, RefocusFilter) {
669 ChromeLauncherController* controller = 685 ChromeLauncherController* controller =
670 static_cast<ChromeLauncherController*>(launcher_->delegate()); 686 static_cast<ChromeLauncherController*>(launcher_->delegate());
671 TabStripModel* tab_strip = browser()->tab_strip_model(); 687 TabStripModel* tab_strip = browser()->tab_strip_model();
672 int tab_count = tab_strip->count(); 688 int tab_count = tab_strip->count();
673 ash::LauncherID shortcut_id = CreateShortcut("app1"); 689 ash::LauncherID shortcut_id = CreateShortcut("app1");
674 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 690 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
675 EXPECT_EQ(++tab_count, tab_strip->count()); 691 EXPECT_EQ(++tab_count, tab_strip->count());
676 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 692 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
677 WebContents* first_tab = tab_strip->GetActiveWebContents(); 693 WebContents* first_tab = tab_strip->GetActiveWebContents();
678 694
(...skipping 19 matching lines...) Expand all
698 // No longer active. 714 // No longer active.
699 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); 715 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status);
700 716
701 // Activating app makes first tab active again, because second tab isn't 717 // Activating app makes first tab active again, because second tab isn't
702 // in its refocus url path. 718 // in its refocus url path.
703 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 719 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
704 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 720 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
705 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab); 721 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab);
706 } 722 }
707 723
708 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilterLaunch) { 724 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, RefocusFilterLaunch) {
709 ChromeLauncherController* controller = 725 ChromeLauncherController* controller =
710 static_cast<ChromeLauncherController*>(launcher_->delegate()); 726 static_cast<ChromeLauncherController*>(launcher_->delegate());
711 TabStripModel* tab_strip = browser()->tab_strip_model(); 727 TabStripModel* tab_strip = browser()->tab_strip_model();
712 int tab_count = tab_strip->count(); 728 int tab_count = tab_strip->count();
713 ash::LauncherID shortcut_id = CreateShortcut("app1"); 729 ash::LauncherID shortcut_id = CreateShortcut("app1");
714 controller->SetRefocusURLPatternForTest( 730 controller->SetRefocusURLPatternForTest(
715 shortcut_id, GURL("http://www.example.com/path1/*")); 731 shortcut_id, GURL("http://www.example.com/path1/*"));
716 732
717 // Create new tab owned by app. 733 // Create new tab owned by app.
718 ui_test_utils::NavigateToURLWithDisposition( 734 ui_test_utils::NavigateToURLWithDisposition(
719 browser(), 735 browser(),
720 GURL("http://www.example.com/path2/bar.html"), 736 GURL("http://www.example.com/path2/bar.html"),
721 NEW_FOREGROUND_TAB, 737 NEW_FOREGROUND_TAB,
722 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 738 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
723 EXPECT_EQ(++tab_count, tab_strip->count()); 739 EXPECT_EQ(++tab_count, tab_strip->count());
724 WebContents* first_tab = tab_strip->GetActiveWebContents(); 740 WebContents* first_tab = tab_strip->GetActiveWebContents();
725 // Confirm app is active. 741 // Confirm app is active.
726 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 742 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
727 743
728 // Activating app should launch new tab, because second tab isn't 744 // Activating app should launch new tab, because second tab isn't
729 // in its refocus url path. 745 // in its refocus url path.
730 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 746 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
731 EXPECT_EQ(++tab_count, tab_strip->count()); 747 EXPECT_EQ(++tab_count, tab_strip->count());
732 WebContents* second_tab = tab_strip->GetActiveWebContents(); 748 WebContents* second_tab = tab_strip->GetActiveWebContents();
733 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 749 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
734 EXPECT_NE(first_tab, second_tab); 750 EXPECT_NE(first_tab, second_tab);
735 EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab); 751 EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab);
736 } 752 }
753
754 // Check the launcher activation state for applications and browser.
755 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, ActivationStateCheck) {
756 ChromeLauncherController* controller =
757 static_cast<ChromeLauncherController*>(launcher_->delegate());
758 TabStripModel* tab_strip = browser()->tab_strip_model();
759 // Get the browser item index
760 int browser_index = -1;
761 for (size_t index = 0; index < model_->items().size() && browser_index == -1;
762 index++) {
763 if (model_->items()[index].type == ash::TYPE_BROWSER_SHORTCUT)
764 browser_index = index;
765 }
766 EXPECT_TRUE(browser_index >= 0);
767
768 // Even though we are just comming up, the browser should be active.
769 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
770
771 ash::LauncherID shortcut_id = CreateShortcut("app1");
772 controller->SetRefocusURLPatternForTest(
773 shortcut_id, GURL("http://www.example.com/path1/*"));
774
775 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status);
776 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
777
778 // Create new tab which would be the running app.
779 ui_test_utils::NavigateToURLWithDisposition(
780 browser(),
781 GURL("http://www.example.com/path1/bar.html"),
782 NEW_FOREGROUND_TAB,
783 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
784
785 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
786 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
787
788 tab_strip->ActivateTabAt(0, false);
789 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status);
790 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
791
792 tab_strip->CloseWebContentsAt(1, TabStripModel::CLOSE_NONE);
793 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status);
794 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
795
796 ash::wm::DeactivateWindow(browser()->window()->GetNativeWindow());
797 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status);
798 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[browser_index].status);
799 }
800
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698