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

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

Issue 22887015: Remove PerBrowser launcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nit Created 7 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
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 "apps/native_app_window.h" 7 #include "apps/native_app_window.h"
8 #include "apps/shell_window.h" 8 #include "apps/shell_window.h"
9 #include "apps/shell_window_registry.h" 9 #include "apps/shell_window_registry.h"
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
11 #include "ash/display/display_controller.h"
11 #include "ash/launcher/launcher.h" 12 #include "ash/launcher/launcher.h"
12 #include "ash/launcher/launcher_model.h" 13 #include "ash/launcher/launcher_model.h"
14 #include "ash/launcher/launcher_util.h"
15 #include "ash/launcher/launcher_view.h"
13 #include "ash/shell.h" 16 #include "ash/shell.h"
14 #include "ash/test/launcher_view_test_api.h" 17 #include "ash/test/launcher_view_test_api.h"
15 #include "ash/test/shell_test_api.h" 18 #include "ash/test/shell_test_api.h"
16 #include "ash/wm/window_util.h" 19 #include "ash/wm/window_util.h"
17 #include "base/command_line.h"
18 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
19 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
20 #include "chrome/browser/apps/app_browsertest_util.h" 22 #include "chrome/browser/apps/app_browsertest_util.h"
21 #include "chrome/browser/automation/automation_util.h" 23 #include "chrome/browser/automation/automation_util.h"
22 #include "chrome/browser/chrome_notification_types.h" 24 #include "chrome/browser/chrome_notification_types.h"
23 #include "chrome/browser/extensions/extension_apitest.h" 25 #include "chrome/browser/extensions/extension_apitest.h"
24 #include "chrome/browser/extensions/extension_browsertest.h" 26 #include "chrome/browser/extensions/extension_browsertest.h"
25 #include "chrome/browser/extensions/extension_function_test_utils.h" 27 #include "chrome/browser/extensions/extension_function_test_utils.h"
26 #include "chrome/browser/extensions/extension_service.h" 28 #include "chrome/browser/extensions/extension_service.h"
27 #include "chrome/browser/extensions/extension_system.h" 29 #include "chrome/browser/extensions/extension_system.h"
28 #include "chrome/browser/extensions/extension_test_message_listener.h" 30 #include "chrome/browser/extensions/extension_test_message_listener.h"
29 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
32 #include "chrome/browser/ui/app_list/app_list_service.h"
33 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h"
34 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
30 #include "chrome/browser/ui/browser.h" 35 #include "chrome/browser/ui/browser.h"
31 #include "chrome/browser/ui/browser_commands.h" 36 #include "chrome/browser/ui/browser_commands.h"
37 #include "chrome/browser/ui/browser_finder.h"
38 #include "chrome/browser/ui/browser_list.h"
32 #include "chrome/browser/ui/browser_window.h" 39 #include "chrome/browser/ui/browser_window.h"
33 #include "chrome/browser/ui/extensions/application_launch.h" 40 #include "chrome/browser/ui/extensions/application_launch.h"
34 #include "chrome/browser/ui/host_desktop.h" 41 #include "chrome/browser/ui/host_desktop.h"
35 #include "chrome/browser/ui/tabs/tab_strip_model.h" 42 #include "chrome/browser/ui/tabs/tab_strip_model.h"
36 #include "chrome/common/chrome_switches.h" 43 #include "chrome/common/chrome_switches.h"
37 #include "chrome/common/extensions/extension_constants.h" 44 #include "chrome/common/extensions/extension_constants.h"
38 #include "chrome/test/base/ui_test_utils.h" 45 #include "chrome/test/base/ui_test_utils.h"
39 #include "content/public/browser/notification_service.h" 46 #include "content/public/browser/notification_service.h"
40 #include "content/public/browser/notification_source.h" 47 #include "content/public/browser/notification_source.h"
41 #include "content/public/browser/web_contents.h" 48 #include "content/public/browser/web_contents.h"
49 #include "extensions/common/switches.h"
42 #include "testing/gtest/include/gtest/gtest.h" 50 #include "testing/gtest/include/gtest/gtest.h"
51 #include "ui/app_list/views/apps_grid_view.h"
43 #include "ui/aura/client/aura_constants.h" 52 #include "ui/aura/client/aura_constants.h"
53 #include "ui/aura/test/event_generator.h"
44 #include "ui/aura/window.h" 54 #include "ui/aura/window.h"
55 #include "ui/base/events/event.h"
45 56
46 using apps::ShellWindow; 57 using apps::ShellWindow;
47 using extensions::Extension; 58 using extensions::Extension;
48 using content::WebContents; 59 using content::WebContents;
49 60
61 namespace {
62
63 class TestEvent : public ui::Event {
64 public:
65 explicit TestEvent(ui::EventType type)
66 : ui::Event(type, base::TimeDelta(), 0) {
67 }
68 virtual ~TestEvent() {
69 }
70
71 private:
72 DISALLOW_COPY_AND_ASSIGN(TestEvent);
73 };
74
75 class TestShellWindowRegistryObserver
76 : public apps::ShellWindowRegistry::Observer {
77 public:
78 explicit TestShellWindowRegistryObserver(Profile* profile)
79 : profile_(profile),
80 icon_updates_(0) {
81 apps::ShellWindowRegistry::Get(profile_)->AddObserver(this);
82 }
83
84 virtual ~TestShellWindowRegistryObserver() {
85 apps::ShellWindowRegistry::Get(profile_)->RemoveObserver(this);
86 }
87
88 // Overridden from ShellWindowRegistry::Observer:
89 virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE {}
90
91 virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE {
92 ++icon_updates_;
93 }
94
95 virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE {}
96
97 int icon_updates() { return icon_updates_; }
98
99 private:
100 Profile* profile_;
101 int icon_updates_;
102
103 DISALLOW_COPY_AND_ASSIGN(TestShellWindowRegistryObserver);
104 };
105
106 } // namespace
107
50 class LauncherPlatformAppBrowserTest 108 class LauncherPlatformAppBrowserTest
51 : public extensions::PlatformAppBrowserTest { 109 : public extensions::PlatformAppBrowserTest {
52 protected: 110 protected:
53 LauncherPlatformAppBrowserTest() 111 LauncherPlatformAppBrowserTest() : launcher_(NULL), controller_(NULL) {
54 : launcher_(NULL),
55 controller_(NULL) {
56 } 112 }
57 113
58 virtual ~LauncherPlatformAppBrowserTest() {} 114 virtual ~LauncherPlatformAppBrowserTest() {}
59 115
116 virtual void RunTestOnMainThreadLoop() OVERRIDE {
117 launcher_ = ash::Launcher::ForPrimaryDisplay();
118 controller_ = ChromeLauncherController::instance();
119 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop();
120 }
121
60 ash::LauncherModel* launcher_model() { 122 ash::LauncherModel* launcher_model() {
61 return ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); 123 return ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model();
62 } 124 }
63 125
64 virtual void RunTestOnMainThreadLoop() OVERRIDE {
65 launcher_ = ash::Launcher::ForPrimaryDisplay();
66 controller_ = static_cast<ChromeLauncherController*>(launcher_->delegate());
67 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop();
68 }
69
70 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
71 PlatformAppBrowserTest::SetUpCommandLine(command_line);
72 command_line->AppendSwitch(ash::switches::kAshDisablePerAppLauncher);
73 }
74
75 ash::LauncherID CreateAppShortcutLauncherItem(const std::string& name) { 126 ash::LauncherID CreateAppShortcutLauncherItem(const std::string& name) {
76 return controller_->CreateAppShortcutLauncherItem( 127 return controller_->CreateAppShortcutLauncherItem(
77 name, controller_->model()->item_count()); 128 name, controller_->model()->item_count());
78 } 129 }
79 130
80 const ash::LauncherItem& GetLastLauncherItem() { 131 const ash::LauncherItem& GetLastLauncherItem() {
81 // Unless there are any panels, the item at index [count - 1] will be 132 // Unless there are any panels, the item at index [count - 1] will be
82 // the app list, and the item at [count - 2] will be the desited item. 133 // the app list, and the item at [count - 2] will be the desired item.
83 return launcher_model()->items()[launcher_model()->item_count() - 2]; 134 return launcher_model()->items()[launcher_model()->item_count() - 2];
84 } 135 }
85 136
86 const ash::LauncherItem& GetLastLauncherPanelItem() { 137 const ash::LauncherItem& GetLastLauncherPanelItem() {
87 // Panels show up on the right side of the launcher, so the desired item 138 // Panels show up on the right side of the launcher, so the desired item
88 // will be the last one. 139 // will be the last one.
89 return launcher_model()->items()[launcher_model()->item_count() - 1]; 140 return launcher_model()->items()[launcher_model()->item_count() - 1];
90 } 141 }
91 142
143 LauncherItemController* GetItemController(ash::LauncherID id) {
144 return controller_->id_to_item_controller_map_[id];
145 }
146
147 // Returns the number of menu items, ignoring separators.
148 int GetNumApplicationMenuItems(const ash::LauncherItem& item) {
149 const int event_flags = 0;
150 scoped_ptr<ash::LauncherMenuModel> menu(
151 controller_->CreateApplicationMenu(item, event_flags));
152 int num_items = 0;
153 for (int i = 0; i < menu->GetItemCount(); ++i) {
154 if (menu->GetTypeAt(i) != ui::MenuModel::TYPE_SEPARATOR)
155 ++num_items;
156 }
157 return num_items;
158 }
159
160 // Activate the launcher item with the given |id|.
161 void ActivateLauncherItem(int id) {
162 launcher_->ActivateLauncherItem(id);
163 }
164
92 ash::Launcher* launcher_; 165 ash::Launcher* launcher_;
93 ChromeLauncherController* controller_; 166 ChromeLauncherController* controller_;
167
168 private:
169
170 DISALLOW_COPY_AND_ASSIGN(LauncherPlatformAppBrowserTest);
94 }; 171 };
95 172
96 class LauncherAppBrowserTest : public ExtensionBrowserTest { 173 class LauncherAppBrowserTest : public ExtensionBrowserTest {
97 protected: 174 protected:
98 LauncherAppBrowserTest() 175 LauncherAppBrowserTest() : launcher_(NULL), model_(NULL), controller_(NULL) {
99 : launcher_(NULL),
100 model_(NULL) {
101 } 176 }
102 177
103 virtual ~LauncherAppBrowserTest() {} 178 virtual ~LauncherAppBrowserTest() {}
104 179
105 virtual void RunTestOnMainThreadLoop() OVERRIDE { 180 virtual void RunTestOnMainThreadLoop() OVERRIDE {
106 launcher_ = ash::Launcher::ForPrimaryDisplay(); 181 launcher_ = ash::Launcher::ForPrimaryDisplay();
107 model_ = 182 model_ =
108 ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); 183 ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model();
184 controller_ = ChromeLauncherController::instance();
109 return ExtensionBrowserTest::RunTestOnMainThreadLoop(); 185 return ExtensionBrowserTest::RunTestOnMainThreadLoop();
110 } 186 }
111 187
112 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 188 size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) {
113 ExtensionBrowserTest::SetUpCommandLine(command_line); 189 LauncherItemController* item_controller =
114 command_line->AppendSwitch(ash::switches::kAshDisablePerAppLauncher); 190 controller_->GetBrowserShortcutLauncherItemController();
191 int items = item_controller->GetApplicationList(
192 show_all_tabs ? ui::EF_SHIFT_DOWN : 0).size();
193 // If we have at least one item, we have also a title which we remove here.
194 return items ? (items - 1) : 0;
115 } 195 }
116 196
117 const Extension* LoadAndLaunchExtension( 197 const Extension* LoadAndLaunchExtension(
118 const char* name, 198 const char* name,
119 extension_misc::LaunchContainer container, 199 extension_misc::LaunchContainer container,
120 WindowOpenDisposition disposition) { 200 WindowOpenDisposition disposition) {
121 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII(name))); 201 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII(name)));
122 202
123 ExtensionService* service = extensions::ExtensionSystem::Get( 203 ExtensionService* service = extensions::ExtensionSystem::Get(
124 browser()->profile())->extension_service(); 204 profile())->extension_service();
125 const Extension* extension = 205 const Extension* extension =
126 service->GetExtensionById(last_loaded_extension_id_, false); 206 service->GetExtensionById(last_loaded_extension_id_, false);
127 EXPECT_TRUE(extension); 207 EXPECT_TRUE(extension);
128 208
129 chrome::OpenApplication(chrome::AppLaunchParams( 209 chrome::OpenApplication(chrome::AppLaunchParams(profile(),
130 browser()->profile(), extension, container, disposition)); 210 extension,
211 container,
212 disposition));
131 return extension; 213 return extension;
132 } 214 }
133 215
134 ash::LauncherID CreateShortcut(const char* name) { 216 ash::LauncherID CreateShortcut(const char* name) {
135 ExtensionService* service = extensions::ExtensionSystem::Get( 217 ExtensionService* service = extensions::ExtensionSystem::Get(
136 browser()->profile())->extension_service(); 218 profile())->extension_service();
137 LoadExtension(test_data_dir_.AppendASCII(name)); 219 LoadExtension(test_data_dir_.AppendASCII(name));
138 220
139 // First get app_id. 221 // First get app_id.
140 const Extension* extension = 222 const Extension* extension =
141 service->GetExtensionById(last_loaded_extension_id_, false); 223 service->GetExtensionById(last_loaded_extension_id_, false);
142 const std::string app_id = extension->id(); 224 const std::string app_id = extension->id();
143 225
144 // Then create a shortcut. 226 // Then create a shortcut.
145 ChromeLauncherController* controller =
146 static_cast<ChromeLauncherController*>(launcher_->delegate());
147 int item_count = model_->item_count(); 227 int item_count = model_->item_count();
148 ash::LauncherID shortcut_id = controller->CreateAppShortcutLauncherItem( 228 ash::LauncherID shortcut_id = controller_->CreateAppShortcutLauncherItem(
149 app_id, item_count); 229 app_id,
150 controller->PersistPinnedState(); 230 item_count);
231 controller_->PersistPinnedState();
151 EXPECT_EQ(++item_count, model_->item_count()); 232 EXPECT_EQ(++item_count, model_->item_count());
152 ash::LauncherItem item = *model_->ItemByID(shortcut_id); 233 const ash::LauncherItem& item = *model_->ItemByID(shortcut_id);
153 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); 234 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type);
154 return item.id; 235 return item.id;
155 } 236 }
156 237
238 // Activate the launcher item with the given |id|.
239 void ActivateLauncherItem(int id) {
240 launcher_->ActivateLauncherItem(id);
241 }
242
157 ash::LauncherID PinFakeApp(const std::string& name) { 243 ash::LauncherID PinFakeApp(const std::string& name) {
158 ChromeLauncherController* controller = 244 return controller_->CreateAppShortcutLauncherItem(
159 static_cast<ChromeLauncherController*>(launcher_->delegate());
160 return controller->CreateAppShortcutLauncherItem(
161 name, model_->item_count()); 245 name, model_->item_count());
162 } 246 }
163 247
164 ash::Launcher* launcher_; 248 ash::Launcher* launcher_;
165 ash::LauncherModel* model_; 249 ash::LauncherModel* model_;
250 ChromeLauncherController* controller_;
251
252 private:
253
254 DISALLOW_COPY_AND_ASSIGN(LauncherAppBrowserTest);
166 }; 255 };
167 256
257 class LauncherAppBrowserTestNoDefaultBrowser : public LauncherAppBrowserTest {
258 protected:
259 LauncherAppBrowserTestNoDefaultBrowser() {}
260 virtual ~LauncherAppBrowserTestNoDefaultBrowser() {}
261
262 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
263 LauncherAppBrowserTest::SetUpCommandLine(command_line);
264 command_line->AppendSwitch(switches::kNoStartupWindow);
265 }
266
267 private:
268
269 DISALLOW_COPY_AND_ASSIGN(LauncherAppBrowserTestNoDefaultBrowser);
270 };
271
272 // Since the default for minimizing on click might change, I added both classes
273 // to either get the minimize on click or not.
274 class LauncherAppBrowserNoMinimizeOnClick
275 : public LauncherPlatformAppBrowserTest {
276 protected:
277 LauncherAppBrowserNoMinimizeOnClick() {}
278 virtual ~LauncherAppBrowserNoMinimizeOnClick() {}
279
280 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
281 LauncherPlatformAppBrowserTest::SetUpCommandLine(command_line);
282 command_line->AppendSwitch(
283 switches::kDisableMinimizeOnSecondLauncherItemClick);
284 }
285
286 private:
287
288 DISALLOW_COPY_AND_ASSIGN(LauncherAppBrowserNoMinimizeOnClick);
289 };
290
291 typedef LauncherPlatformAppBrowserTest LauncherAppBrowserMinimizeOnClick;
292
168 // Test that we can launch a platform app and get a running item. 293 // Test that we can launch a platform app and get a running item.
169 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) { 294 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) {
170 int item_count = launcher_model()->item_count(); 295 int item_count = launcher_model()->item_count();
171 const Extension* extension = LoadAndLaunchPlatformApp("launch"); 296 const Extension* extension = LoadAndLaunchPlatformApp("launch");
172 ShellWindow* window = CreateShellWindow(extension); 297 ShellWindow* window = CreateShellWindow(extension);
173 ++item_count; 298 ++item_count;
174 ASSERT_EQ(item_count, launcher_model()->item_count()); 299 ASSERT_EQ(item_count, launcher_model()->item_count());
175 const ash::LauncherItem& item = GetLastLauncherItem(); 300 const ash::LauncherItem& item = GetLastLauncherItem();
176 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); 301 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type);
177 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); 302 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 428
304 // First run app. 429 // First run app.
305 const Extension* extension = LoadAndLaunchPlatformApp("launch"); 430 const Extension* extension = LoadAndLaunchPlatformApp("launch");
306 ShellWindow* window1 = CreateShellWindow(extension); 431 ShellWindow* window1 = CreateShellWindow(extension);
307 ++item_count; 432 ++item_count;
308 ASSERT_EQ(item_count, launcher_model()->item_count()); 433 ASSERT_EQ(item_count, launcher_model()->item_count());
309 const ash::LauncherItem& item1 = GetLastLauncherItem(); 434 const ash::LauncherItem& item1 = GetLastLauncherItem();
310 ash::LauncherID item_id = item1.id; 435 ash::LauncherID item_id = item1.id;
311 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); 436 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
312 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); 437 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
438 EXPECT_EQ(2, GetNumApplicationMenuItems(item1)); // Title + 1 window
313 439
314 // Add second window. 440 // Add second window.
315 ShellWindow* window2 = CreateShellWindow(extension); 441 ShellWindow* window2 = CreateShellWindow(extension);
316 // Confirm item stays. 442 // Confirm item stays.
317 ASSERT_EQ(item_count, launcher_model()->item_count()); 443 ASSERT_EQ(item_count, launcher_model()->item_count());
318 const ash::LauncherItem& item2 = *launcher_model()->ItemByID(item_id); 444 const ash::LauncherItem& item2 = *launcher_model()->ItemByID(item_id);
319 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); 445 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status);
446 EXPECT_EQ(3, GetNumApplicationMenuItems(item2)); // Title + 2 windows
320 447
321 // Close second window. 448 // Close second window.
322 CloseShellWindow(window2); 449 CloseShellWindow(window2);
323 // Confirm item stays. 450 // Confirm item stays.
324 ASSERT_EQ(item_count, launcher_model()->item_count()); 451 ASSERT_EQ(item_count, launcher_model()->item_count());
325 const ash::LauncherItem& item3 = *launcher_model()->ItemByID(item_id); 452 const ash::LauncherItem& item3 = *launcher_model()->ItemByID(item_id);
326 EXPECT_EQ(ash::STATUS_ACTIVE, item3.status); 453 EXPECT_EQ(ash::STATUS_ACTIVE, item3.status);
454 EXPECT_EQ(2, GetNumApplicationMenuItems(item3)); // Title + 1 window
327 455
328 // Close first window. 456 // Close first window.
329 CloseShellWindow(window1); 457 CloseShellWindow(window1);
330 // Confirm item is removed. 458 // Confirm item is removed.
331 --item_count; 459 --item_count;
332 ASSERT_EQ(item_count, launcher_model()->item_count()); 460 ASSERT_EQ(item_count, launcher_model()->item_count());
333 } 461 }
334 462
335 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) { 463 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) {
336 int item_count = launcher_model()->item_count(); 464 int item_count = launcher_model()->item_count();
(...skipping 29 matching lines...) Expand all
366 // First app should be active again. 494 // First app should be active again.
367 EXPECT_EQ(ash::STATUS_ACTIVE, 495 EXPECT_EQ(ash::STATUS_ACTIVE,
368 launcher_model()->ItemByID(item_id1)->status); 496 launcher_model()->ItemByID(item_id1)->status);
369 497
370 // Close first app. 498 // Close first app.
371 CloseShellWindow(window1); 499 CloseShellWindow(window1);
372 --item_count; 500 --item_count;
373 ASSERT_EQ(item_count, launcher_model()->item_count()); 501 ASSERT_EQ(item_count, launcher_model()->item_count());
374 } 502 }
375 503
376 // Test that we can launch a platform app panel and get a running item.
377 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPanelWindow) {
378 int item_count = launcher_model()->item_count();
379 const Extension* extension = LoadAndLaunchPlatformApp("launch");
380 ShellWindow::CreateParams params;
381 params.window_type = ShellWindow::WINDOW_TYPE_PANEL;
382 params.focused = false;
383 ShellWindow* window = CreateShellWindowFromParams(extension, params);
384 ++item_count;
385 ASSERT_EQ(item_count, launcher_model()->item_count());
386 const ash::LauncherItem& item = GetLastLauncherPanelItem();
387 EXPECT_EQ(ash::TYPE_APP_PANEL, item.type);
388 // Opening a panel does not activate it.
389 EXPECT_EQ(ash::STATUS_RUNNING, item.status);
390 CloseShellWindow(window);
391 --item_count;
392 EXPECT_EQ(item_count, launcher_model()->item_count());
393 }
394
395 #if defined(OS_CHROMEOS)
396 #define MAYBE_WindowActivation DISABLED_WindowActivation
397 #else
398 #define MAYBE_WindowActivation WindowActivation
399 #endif
400 // Confirm that app windows can be reactivated by clicking their icons and that 504 // Confirm that app windows can be reactivated by clicking their icons and that
401 // the correct activation order is maintained. 505 // the correct activation order is maintained.
402 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MAYBE_WindowActivation) { 506 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowActivation) {
403 int item_count = launcher_model()->item_count(); 507 int item_count = launcher_model()->item_count();
404 508
405 // First run app. 509 // First run app.
406 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); 510 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
407 ShellWindow* window1 = CreateShellWindow(extension1); 511 ShellWindow* window1 = CreateShellWindow(extension1);
408 ++item_count; 512 ++item_count;
409 ASSERT_EQ(item_count, launcher_model()->item_count()); 513 ASSERT_EQ(item_count, launcher_model()->item_count());
410 const ash::LauncherItem& item1 = GetLastLauncherItem(); 514 const ash::LauncherItem& item1 = GetLastLauncherItem();
411 ash::LauncherID item_id1 = item1.id; 515 ash::LauncherID item_id1 = item1.id;
412 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); 516 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
413 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); 517 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
414 518
415 // Then run second app. 519 // Then run second app.
416 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2"); 520 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2");
417 ShellWindow* window2 = CreateShellWindow(extension2); 521 ShellWindow* window2 = CreateShellWindow(extension2);
418 ++item_count; 522 ++item_count;
419 ASSERT_EQ(item_count, launcher_model()->item_count()); 523 ASSERT_EQ(item_count, launcher_model()->item_count());
420 const ash::LauncherItem& item2 = GetLastLauncherItem(); 524 const ash::LauncherItem& item2 = GetLastLauncherItem();
421 ash::LauncherID item_id2 = item2.id; 525 ash::LauncherID item_id2 = item2.id;
422 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item2.type); 526 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item2.type);
423 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); 527 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status);
424 528
425 EXPECT_NE(item_id1, item_id2); 529 EXPECT_NE(item_id1, item_id2);
426 EXPECT_EQ(ash::STATUS_RUNNING, 530 EXPECT_EQ(ash::STATUS_RUNNING,
427 launcher_model()->ItemByID(item_id1)->status); 531 launcher_model()->ItemByID(item_id1)->status);
428 532
429 // Activate first one. 533 // Activate first one.
430 launcher_->ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1)); 534 ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1));
431 EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id1)->status); 535 EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id1)->status);
432 EXPECT_EQ(ash::STATUS_RUNNING, 536 EXPECT_EQ(ash::STATUS_RUNNING,
433 launcher_model()->ItemByID(item_id2)->status); 537 launcher_model()->ItemByID(item_id2)->status);
434 EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); 538 EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow()));
435 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); 539 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow()));
436 540
437 // Activate second one. 541 // Activate second one.
438 launcher_->ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id2)); 542 ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id2));
439 EXPECT_EQ(ash::STATUS_RUNNING, 543 EXPECT_EQ(ash::STATUS_RUNNING,
440 launcher_model()->ItemByID(item_id1)->status); 544 launcher_model()->ItemByID(item_id1)->status);
441 EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id2)->status); 545 EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id2)->status);
442 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); 546 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow()));
443 EXPECT_TRUE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); 547 EXPECT_TRUE(ash::wm::IsActiveWindow(window2->GetNativeWindow()));
444 548
445 // Add window for app1. This will activate it. 549 // Add window for app1. This will activate it.
446 ShellWindow* window1b = CreateShellWindow(extension1); 550 ShellWindow* window1b = CreateShellWindow(extension1);
447 ash::wm::ActivateWindow(window1b->GetNativeWindow()); 551 ash::wm::ActivateWindow(window1b->GetNativeWindow());
448 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); 552 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow()));
449 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); 553 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow()));
450 EXPECT_TRUE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); 554 EXPECT_TRUE(ash::wm::IsActiveWindow(window1b->GetNativeWindow()));
451 555
452 // Activate launcher item for app1, this will activate the first app window. 556 // Activate launcher item for app1, this will activate the first app window.
453 launcher_->ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1)); 557 ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1));
454 EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); 558 EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow()));
455 EXPECT_FALSE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); 559 EXPECT_FALSE(ash::wm::IsActiveWindow(window1b->GetNativeWindow()));
456 launcher_->ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1)); 560 ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1));
457 EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); 561 EXPECT_TRUE(ash::wm::IsActiveWindow(window1b->GetNativeWindow()));
458 562
459 // Activate the second app again 563 // Activate the second app again
460 launcher_->ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id2)); 564 ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id2));
461 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); 565 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow()));
462 EXPECT_TRUE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); 566 EXPECT_TRUE(ash::wm::IsActiveWindow(window2->GetNativeWindow()));
463 EXPECT_FALSE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); 567 EXPECT_FALSE(ash::wm::IsActiveWindow(window1b->GetNativeWindow()));
464 568
465 // Activate the first app again 569 // Activate the first app again
466 launcher_->ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1)); 570 ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1));
467 EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); 571 EXPECT_TRUE(ash::wm::IsActiveWindow(window1b->GetNativeWindow()));
468 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); 572 EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow()));
469 EXPECT_FALSE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); 573 EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow()));
470 574
471 // Close second app. 575 // Close second app.
472 CloseShellWindow(window2); 576 CloseShellWindow(window2);
473 --item_count; 577 --item_count;
474 EXPECT_EQ(item_count, launcher_model()->item_count()); 578 EXPECT_EQ(item_count, launcher_model()->item_count());
475 // First app should be active again. 579 // First app should be active again.
476 EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id1)->status); 580 EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id1)->status);
477 581
478 // Close first app. 582 // Close first app.
479 CloseShellWindow(window1b); 583 CloseShellWindow(window1b);
480 CloseShellWindow(window1); 584 CloseShellWindow(window1);
481 --item_count; 585 --item_count;
482 EXPECT_EQ(item_count, launcher_model()->item_count()); 586 EXPECT_EQ(item_count, launcher_model()->item_count());
483 } 587 }
484 588
589 // Confirm that Click behavior for app windows is correnct.
590 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserNoMinimizeOnClick,
591 AppClickBehavior) {
592 // Launch a platform app and create a window for it.
593 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
594 ShellWindow* window1 = CreateShellWindow(extension1);
595 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
596 EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
597 // Confirm that a controller item was created and is the correct state.
598 const ash::LauncherItem& item1 = GetLastLauncherItem();
599 LauncherItemController* item1_controller = GetItemController(item1.id);
600 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
601 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
602 EXPECT_EQ(LauncherItemController::TYPE_APP, item1_controller->type());
603 // Clicking the item should have no effect.
604 TestEvent click_event(ui::ET_MOUSE_PRESSED);
605 item1_controller->Clicked(click_event);
606 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
607 EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
608 // Minimize the window and confirm that the controller item is updated.
609 window1->GetBaseWindow()->Minimize();
610 EXPECT_FALSE(window1->GetNativeWindow()->IsVisible());
611 EXPECT_FALSE(window1->GetBaseWindow()->IsActive());
612 EXPECT_EQ(ash::STATUS_RUNNING, item1.status);
613 // Clicking the item should activate the window.
614 item1_controller->Clicked(click_event);
615 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
616 EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
617 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
618 // Maximizing a window should preserve state after minimize + click.
619 window1->GetBaseWindow()->Maximize();
620 window1->GetBaseWindow()->Minimize();
621 item1_controller->Clicked(click_event);
622 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
623 EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
624 EXPECT_TRUE(window1->GetBaseWindow()->IsMaximized());
625 }
626
627 // Confirm the minimizing click behavior for apps.
628 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserMinimizeOnClick,
629 PackagedAppClickBehaviorInMinimizeMode) {
630 // Launch one platform app and create a window for it.
631 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
632 ShellWindow* window1 = CreateShellWindow(extension1);
633 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
634 EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
635
636 // Confirm that a controller item was created and is the correct state.
637 const ash::LauncherItem& item1 = GetLastLauncherItem();
638 LauncherItemController* item1_controller = GetItemController(item1.id);
639 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
640 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
641 EXPECT_EQ(LauncherItemController::TYPE_APP, item1_controller->type());
642 // Since it is already active, clicking it should minimize.
643 TestEvent click_event(ui::ET_MOUSE_PRESSED);
644 item1_controller->Clicked(click_event);
645 EXPECT_FALSE(window1->GetNativeWindow()->IsVisible());
646 EXPECT_FALSE(window1->GetBaseWindow()->IsActive());
647 EXPECT_TRUE(window1->GetBaseWindow()->IsMinimized());
648 EXPECT_EQ(ash::STATUS_RUNNING, item1.status);
649 // Clicking the item again should activate the window again.
650 item1_controller->Clicked(click_event);
651 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
652 EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
653 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
654 // Maximizing a window should preserve state after minimize + click.
655 window1->GetBaseWindow()->Maximize();
656 window1->GetBaseWindow()->Minimize();
657 item1_controller->Clicked(click_event);
658 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
659 EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
660 EXPECT_TRUE(window1->GetBaseWindow()->IsMaximized());
661 window1->GetBaseWindow()->Restore();
662 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
663 EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
664 EXPECT_FALSE(window1->GetBaseWindow()->IsMaximized());
665
666 // Creating a second window of the same type should change the behavior so
667 // that a click does not change the activation state.
668 ShellWindow* window1a = CreateShellWindow(extension1);
669 EXPECT_TRUE(window1a->GetNativeWindow()->IsVisible());
670 EXPECT_TRUE(window1a->GetBaseWindow()->IsActive());
671 // The first click does nothing.
672 item1_controller->Clicked(click_event);
673 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
674 EXPECT_TRUE(window1a->GetNativeWindow()->IsVisible());
675 EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
676 EXPECT_FALSE(window1a->GetBaseWindow()->IsActive());
677 // The second neither.
678 item1_controller->Clicked(click_event);
679 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
680 EXPECT_TRUE(window1a->GetNativeWindow()->IsVisible());
681 EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
682 EXPECT_FALSE(window1a->GetBaseWindow()->IsActive());
683 }
684
685 // Confirm that click behavior for app panels is correct.
686 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, AppPanelClickBehavior) {
687 // Enable experimental APIs to allow panel creation.
688 CommandLine::ForCurrentProcess()->AppendSwitch(
689 extensions::switches::kEnableExperimentalExtensionApis);
690 // Launch a platform app and create a panel window for it.
691 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
692 ShellWindow::CreateParams params;
693 params.window_type = ShellWindow::WINDOW_TYPE_PANEL;
694 params.focused = false;
695 ShellWindow* panel = CreateShellWindowFromParams(extension1, params);
696 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible());
697 // Panels should not be active by default.
698 EXPECT_FALSE(panel->GetBaseWindow()->IsActive());
699 // Confirm that a controller item was created and is the correct state.
700 const ash::LauncherItem& item1 = GetLastLauncherPanelItem();
701 LauncherItemController* item1_controller = GetItemController(item1.id);
702 EXPECT_EQ(ash::TYPE_APP_PANEL, item1.type);
703 EXPECT_EQ(ash::STATUS_RUNNING, item1.status);
704 EXPECT_EQ(LauncherItemController::TYPE_APP_PANEL, item1_controller->type());
705 // Click the item and confirm that the panel is activated.
706 TestEvent click_event(ui::ET_MOUSE_PRESSED);
707 item1_controller->Clicked(click_event);
708 EXPECT_TRUE(panel->GetBaseWindow()->IsActive());
709 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
710 // Click the item again and confirm that the panel is minimized.
711 item1_controller->Clicked(click_event);
712 EXPECT_TRUE(panel->GetBaseWindow()->IsMinimized());
713 EXPECT_EQ(ash::STATUS_RUNNING, item1.status);
714 // Click the item again and confirm that the panel is activated.
715 item1_controller->Clicked(click_event);
716 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible());
717 EXPECT_TRUE(panel->GetBaseWindow()->IsActive());
718 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
719 }
720
485 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, BrowserActivation) { 721 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, BrowserActivation) {
486 int item_count = launcher_model()->item_count(); 722 int item_count = launcher_model()->item_count();
487 723
488 // First run app. 724 // First run app.
489 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); 725 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
490 CreateShellWindow(extension1); 726 CreateShellWindow(extension1);
491 ++item_count; 727 ++item_count;
492 ASSERT_EQ(item_count, launcher_model()->item_count()); 728 ASSERT_EQ(item_count, launcher_model()->item_count());
493 const ash::LauncherItem& item1 = GetLastLauncherItem(); 729 const ash::LauncherItem& item1 = GetLastLauncherItem();
494 ash::LauncherID item_id1 = item1.id; 730 ash::LauncherID item_id1 = item1.id;
495 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); 731 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
496 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); 732 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
497 733
498 ash::wm::ActivateWindow(browser()->window()->GetNativeWindow()); 734 ash::wm::ActivateWindow(browser()->window()->GetNativeWindow());
499 EXPECT_EQ(ash::STATUS_RUNNING, 735 EXPECT_EQ(ash::STATUS_RUNNING,
500 launcher_model()->ItemByID(item_id1)->status); 736 launcher_model()->ItemByID(item_id1)->status);
501 } 737 }
502 738
503 // Test that draw attention sets the launcher item status. 739 // Test that opening an app sets the correct icon
504 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, DrawAttention) { 740 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, SetIcon) {
505 const Extension* extension = LoadAndLaunchPlatformApp("launch"); 741 TestShellWindowRegistryObserver test_observer(browser()->profile());
506 ShellWindow* shell_window = CreateShellWindow(extension); 742
507 const ash::LauncherItem& item = GetLastLauncherItem(); 743 // Enable experimental APIs to allow panel creation.
508 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); 744 CommandLine::ForCurrentProcess()->AppendSwitch(
509 // Set Minimize window to deactivate the launcher item. 745 extensions::switches::kEnableExperimentalExtensionApis);
510 shell_window->GetBaseWindow()->Minimize(); 746
511 EXPECT_EQ(ash::STATUS_RUNNING, item.status); 747 int base_launcher_item_count = launcher_model()->item_count();
512 // Set DrawAttention property. 748 ExtensionTestMessageListener launched_listener("Launched", false);
513 shell_window->GetNativeWindow()->SetProperty( 749 ExtensionTestMessageListener completed_listener("Completed", false);
514 aura::client::kDrawAttentionKey, true); 750 LoadAndLaunchPlatformApp("app_icon");
515 EXPECT_EQ(ash::STATUS_ATTENTION, item.status); 751 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
516 // Activate window, should clear DrawAttention. 752 ASSERT_TRUE(completed_listener.WaitUntilSatisfied());
517 shell_window->GetBaseWindow()->Activate(); 753
518 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); 754 // Now wait until the WebContent has decoded the icons and chrome has
519 EXPECT_FALSE(shell_window->GetNativeWindow()->GetProperty( 755 // processed it. This needs to be in a loop since the renderer runs in a
520 aura::client::kDrawAttentionKey)); 756 // different process.
757 while (test_observer.icon_updates() < 3) {
758 base::RunLoop run_loop;
759 run_loop.RunUntilIdle();
760 }
761
762 // This test creates one shell window and one panel window.
763 int launcher_item_count = launcher_model()->item_count();
764 ASSERT_EQ(base_launcher_item_count + 2, launcher_item_count);
765 // The Panel will be the last item, the app list second-to-last, the app
766 // third from last.
767 const ash::LauncherItem& app_item =
768 launcher_model()->items()[launcher_item_count - 3];
769 const ash::LauncherItem& panel_item =
770 launcher_model()->items()[launcher_item_count - 1];
771 const LauncherItemController* app_item_controller =
772 GetItemController(app_item.id);
773 const LauncherItemController* panel_item_controller =
774 GetItemController(panel_item.id);
775 // Icons for Apps are set by the ShellWindowLauncherController, so
776 // image_set_by_controller() should be set.
777 EXPECT_TRUE(app_item_controller->image_set_by_controller());
778 EXPECT_TRUE(panel_item_controller->image_set_by_controller());
779 // Ensure icon heights are correct (see test.js in app_icon/ test directory)
780 EXPECT_EQ(48, app_item.image.height());
781 EXPECT_EQ(64, panel_item.image.height());
521 } 782 }
522 783
523 // Test that we can launch an app with a shortcut. 784 // Test that we can launch an app with a shortcut.
524 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchPinned) { 785 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchPinned) {
525 TabStripModel* tab_strip = browser()->tab_strip_model(); 786 TabStripModel* tab_strip = browser()->tab_strip_model();
526 int tab_count = tab_strip->count(); 787 int tab_count = tab_strip->count();
527 ash::LauncherID shortcut_id = CreateShortcut("app1"); 788 ash::LauncherID shortcut_id = CreateShortcut("app1");
528 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 789 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
529 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 790 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
530 EXPECT_EQ(++tab_count, tab_strip->count()); 791 EXPECT_EQ(++tab_count, tab_strip->count());
531 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 792 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
532 WebContents* tab = tab_strip->GetActiveWebContents(); 793 WebContents* tab = tab_strip->GetActiveWebContents();
533 content::WindowedNotificationObserver close_observer( 794 content::WindowedNotificationObserver close_observer(
534 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 795 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
535 content::Source<WebContents>(tab)); 796 content::Source<WebContents>(tab));
536 browser()->tab_strip_model()->CloseSelectedTabs(); 797 browser()->tab_strip_model()->CloseSelectedTabs();
537 close_observer.Wait(); 798 close_observer.Wait();
538 EXPECT_EQ(--tab_count, tab_strip->count()); 799 EXPECT_EQ(--tab_count, tab_strip->count());
539 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 800 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 content::NotificationService::AllSources()); 840 content::NotificationService::AllSources());
580 chrome::NewEmptyWindow(browser()->profile(), chrome::HOST_DESKTOP_TYPE_ASH); 841 chrome::NewEmptyWindow(browser()->profile(), chrome::HOST_DESKTOP_TYPE_ASH);
581 open_observer.Wait(); 842 open_observer.Wait();
582 Browser* browser2 = content::Source<Browser>(open_observer.source()).ptr(); 843 Browser* browser2 = content::Source<Browser>(open_observer.source()).ptr();
583 aura::Window* window2 = browser2->window()->GetNativeWindow(); 844 aura::Window* window2 = browser2->window()->GetNativeWindow();
584 TabStripModel* tab_strip = browser2->tab_strip_model(); 845 TabStripModel* tab_strip = browser2->tab_strip_model();
585 int tab_count = tab_strip->count(); 846 int tab_count = tab_strip->count();
586 ash::wm::MaximizeWindow(window2); 847 ash::wm::MaximizeWindow(window2);
587 848
588 ash::LauncherID shortcut_id = CreateShortcut("app1"); 849 ash::LauncherID shortcut_id = CreateShortcut("app1");
589 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 850 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
590 EXPECT_EQ(++tab_count, tab_strip->count()); 851 EXPECT_EQ(++tab_count, tab_strip->count());
591 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 852 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
592 853
593 window1->Show(); 854 window1->Show();
594 ash::wm::ActivateWindow(window1); 855 ash::wm::ActivateWindow(window1);
595 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut_id)).status); 856 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut_id)).status);
596 857
597 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 858 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
598 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 859 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
599 } 860 }
600 861
601 // Activating the same app multiple times should launch only a single copy. 862 // Activating the same app multiple times should launch only a single copy.
602 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivateApp) { 863 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivateApp) {
603 TabStripModel* tab_strip = browser()->tab_strip_model(); 864 TabStripModel* tab_strip = browser()->tab_strip_model();
604 int tab_count = tab_strip->count(); 865 int tab_count = tab_strip->count();
605 const Extension* extension = 866 const Extension* extension =
606 LoadExtension(test_data_dir_.AppendASCII("app1")); 867 LoadExtension(test_data_dir_.AppendASCII("app1"));
607 868
(...skipping 20 matching lines...) Expand all
628 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleApps) { 889 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleApps) {
629 int item_count = model_->item_count(); 890 int item_count = model_->item_count();
630 TabStripModel* tab_strip = browser()->tab_strip_model(); 891 TabStripModel* tab_strip = browser()->tab_strip_model();
631 int tab_count = tab_strip->count(); 892 int tab_count = tab_strip->count();
632 ash::LauncherID shortcut1 = CreateShortcut("app1"); 893 ash::LauncherID shortcut1 = CreateShortcut("app1");
633 EXPECT_EQ(++item_count, model_->item_count()); 894 EXPECT_EQ(++item_count, model_->item_count());
634 ash::LauncherID shortcut2 = CreateShortcut("app2"); 895 ash::LauncherID shortcut2 = CreateShortcut("app2");
635 EXPECT_EQ(++item_count, model_->item_count()); 896 EXPECT_EQ(++item_count, model_->item_count());
636 897
637 // Launch first app. 898 // Launch first app.
638 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut1)); 899 ActivateLauncherItem(model_->ItemIndexByID(shortcut1));
639 EXPECT_EQ(++tab_count, tab_strip->count()); 900 EXPECT_EQ(++tab_count, tab_strip->count());
640 WebContents* tab1 = tab_strip->GetActiveWebContents(); 901 WebContents* tab1 = tab_strip->GetActiveWebContents();
641 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status); 902 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status);
642 903
643 // Launch second app. 904 // Launch second app.
644 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut2)); 905 ActivateLauncherItem(model_->ItemIndexByID(shortcut2));
645 EXPECT_EQ(++tab_count, tab_strip->count()); 906 EXPECT_EQ(++tab_count, tab_strip->count());
646 WebContents* tab2 = tab_strip->GetActiveWebContents(); 907 WebContents* tab2 = tab_strip->GetActiveWebContents();
647 ASSERT_NE(tab1, tab2); 908 ASSERT_NE(tab1, tab2);
648 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status); 909 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status);
649 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status); 910 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status);
650 911
651 // Reactivate first app. 912 // Reactivate first app.
652 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut1)); 913 ActivateLauncherItem(model_->ItemIndexByID(shortcut1));
653 EXPECT_EQ(tab_count, tab_strip->count()); 914 EXPECT_EQ(tab_count, tab_strip->count());
654 EXPECT_EQ(tab_strip->GetActiveWebContents(), tab1); 915 EXPECT_EQ(tab_strip->GetActiveWebContents(), tab1);
655 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status); 916 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status);
656 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut2)).status); 917 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut2)).status);
657 918
658 // Open second tab for second app. This should activate it. 919 // Open second tab for second app. This should activate it.
659 ui_test_utils::NavigateToURLWithDisposition( 920 ui_test_utils::NavigateToURLWithDisposition(
660 browser(), 921 browser(),
661 GURL("http://www.example.com/path3/foo.html"), 922 GURL("http://www.example.com/path3/foo.html"),
662 NEW_FOREGROUND_TAB, 923 NEW_FOREGROUND_TAB,
663 0); 924 0);
664 EXPECT_EQ(++tab_count, tab_strip->count()); 925 EXPECT_EQ(++tab_count, tab_strip->count());
665 WebContents* tab3 = tab_strip->GetActiveWebContents();
666 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status); 926 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status);
667 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status); 927 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status);
668 928
669 // Reactivate first app. 929 // Reactivate first app.
670 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut1)); 930 ActivateLauncherItem(model_->ItemIndexByID(shortcut1));
671 EXPECT_EQ(tab_count, tab_strip->count()); 931 EXPECT_EQ(tab_count, tab_strip->count());
672 EXPECT_EQ(tab_strip->GetActiveWebContents(), tab1); 932 EXPECT_EQ(tab_strip->GetActiveWebContents(), tab1);
673 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status); 933 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status);
674 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut2)).status); 934 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut2)).status);
675 935
676 // And second again. This time the second tab should become active. 936 // And second again. This time the second tab should become active.
677 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut2)); 937 ActivateLauncherItem(model_->ItemIndexByID(shortcut2));
678 EXPECT_EQ(tab_count, tab_strip->count()); 938 EXPECT_EQ(tab_count, tab_strip->count());
679 EXPECT_EQ(tab_strip->GetActiveWebContents(), tab3); 939 EXPECT_EQ(tab_strip->GetActiveWebContents(), tab2);
680 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status); 940 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status);
681 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status); 941 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status);
682 } 942 }
683 943
684 // Confirm that a page can be navigated from and to while maintaining the 944 // Confirm that a page can be navigated from and to while maintaining the
685 // correct running state. 945 // correct running state.
686 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, Navigation) { 946 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, Navigation) {
687 ash::LauncherID shortcut_id = CreateShortcut("app1"); 947 ash::LauncherID shortcut_id = CreateShortcut("app1");
688 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 948 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
689 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 949 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
690 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 950 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
691 951
692 // Navigate away. 952 // Navigate away.
693 ui_test_utils::NavigateToURL( 953 ui_test_utils::NavigateToURL(
694 browser(), GURL("http://www.example.com/path0/bar.html")); 954 browser(), GURL("http://www.example.com/path0/bar.html"));
695 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 955 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
696 956
697 // Navigate back. 957 // Navigate back.
698 ui_test_utils::NavigateToURL( 958 ui_test_utils::NavigateToURL(
699 browser(), GURL("http://www.example.com/path1/foo.html")); 959 browser(), GURL("http://www.example.com/path1/foo.html"));
700 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 960 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
701 } 961 }
702 962
703 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleOwnedTabs) { 963 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleOwnedTabs) {
704 TabStripModel* tab_strip = browser()->tab_strip_model(); 964 TabStripModel* tab_strip = browser()->tab_strip_model();
705 int tab_count = tab_strip->count(); 965 int tab_count = tab_strip->count();
706 ash::LauncherID shortcut_id = CreateShortcut("app1"); 966 ash::LauncherID shortcut_id = CreateShortcut("app1");
707 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 967 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
708 EXPECT_EQ(++tab_count, tab_strip->count()); 968 EXPECT_EQ(++tab_count, tab_strip->count());
709 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 969 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
970 WebContents* first_tab = tab_strip->GetActiveWebContents();
710 971
711 // Create new tab owned by app. 972 // Create new tab owned by app.
712 ui_test_utils::NavigateToURLWithDisposition( 973 ui_test_utils::NavigateToURLWithDisposition(
713 browser(), 974 browser(),
714 GURL("http://www.example.com/path2/bar.html"), 975 GURL("http://www.example.com/path2/bar.html"),
715 NEW_FOREGROUND_TAB, 976 NEW_FOREGROUND_TAB,
716 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 977 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
717 EXPECT_EQ(++tab_count, tab_strip->count()); 978 EXPECT_EQ(++tab_count, tab_strip->count());
718 // Confirm app is still active. 979 // Confirm app is still active.
719 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 980 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
720 WebContents* second_tab = tab_strip->GetActiveWebContents();
721 981
722 // Create new tab not owned by app. 982 // Create new tab not owned by app.
723 ui_test_utils::NavigateToURLWithDisposition( 983 ui_test_utils::NavigateToURLWithDisposition(
724 browser(), 984 browser(),
725 GURL("http://www.example.com/path3/foo.html"), 985 GURL("http://www.example.com/path3/foo.html"),
726 NEW_FOREGROUND_TAB, 986 NEW_FOREGROUND_TAB,
727 0); 987 0);
728 EXPECT_EQ(++tab_count, tab_strip->count()); 988 EXPECT_EQ(++tab_count, tab_strip->count());
729 // No longer active. 989 // No longer active.
730 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); 990 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status);
731 991
732 // Activating app makes second tab active again. 992 // Activating app makes first tab active again.
733 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 993 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
734 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 994 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
735 EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab); 995 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab);
736 } 996 }
737 997
738 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilter) { 998 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilter) {
739 ChromeLauncherController* controller =
740 static_cast<ChromeLauncherController*>(launcher_->delegate());
741 TabStripModel* tab_strip = browser()->tab_strip_model(); 999 TabStripModel* tab_strip = browser()->tab_strip_model();
742 int tab_count = tab_strip->count(); 1000 int tab_count = tab_strip->count();
743 ash::LauncherID shortcut_id = CreateShortcut("app1"); 1001 ash::LauncherID shortcut_id = CreateShortcut("app1");
744 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 1002 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
745 EXPECT_EQ(++tab_count, tab_strip->count()); 1003 EXPECT_EQ(++tab_count, tab_strip->count());
746 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 1004 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
747 WebContents* first_tab = tab_strip->GetActiveWebContents(); 1005 WebContents* first_tab = tab_strip->GetActiveWebContents();
748 1006
749 controller->SetRefocusURLPatternForTest( 1007 controller_->SetRefocusURLPatternForTest(
750 shortcut_id, GURL("http://www.example.com/path1/*")); 1008 shortcut_id, GURL("http://www.example.com/path1/*"));
751 // Create new tab owned by app. 1009 // Create new tab owned by app.
752 ui_test_utils::NavigateToURLWithDisposition( 1010 ui_test_utils::NavigateToURLWithDisposition(
753 browser(), 1011 browser(),
754 GURL("http://www.example.com/path2/bar.html"), 1012 GURL("http://www.example.com/path2/bar.html"),
755 NEW_FOREGROUND_TAB, 1013 NEW_FOREGROUND_TAB,
756 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1014 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
757 EXPECT_EQ(++tab_count, tab_strip->count()); 1015 EXPECT_EQ(++tab_count, tab_strip->count());
758 // Confirm app is still active. 1016 // Confirm app is still active.
759 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 1017 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
760 1018
761 // Create new tab not owned by app. 1019 // Create new tab not owned by app.
762 ui_test_utils::NavigateToURLWithDisposition( 1020 ui_test_utils::NavigateToURLWithDisposition(
763 browser(), 1021 browser(),
764 GURL("http://www.example.com/path3/foo.html"), 1022 GURL("http://www.example.com/path3/foo.html"),
765 NEW_FOREGROUND_TAB, 1023 NEW_FOREGROUND_TAB,
766 0); 1024 0);
767 EXPECT_EQ(++tab_count, tab_strip->count()); 1025 EXPECT_EQ(++tab_count, tab_strip->count());
768 // No longer active. 1026 // No longer active.
769 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); 1027 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status);
770 1028
771 // Activating app makes first tab active again, because second tab isn't 1029 // Activating app makes first tab active again, because second tab isn't
772 // in its refocus url path. 1030 // in its refocus url path.
773 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 1031 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
774 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 1032 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
775 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab); 1033 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab);
776 } 1034 }
777 1035
778 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilterLaunch) { 1036 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilterLaunch) {
779 ChromeLauncherController* controller =
780 static_cast<ChromeLauncherController*>(launcher_->delegate());
781 TabStripModel* tab_strip = browser()->tab_strip_model(); 1037 TabStripModel* tab_strip = browser()->tab_strip_model();
782 int tab_count = tab_strip->count(); 1038 int tab_count = tab_strip->count();
783 ash::LauncherID shortcut_id = CreateShortcut("app1"); 1039 ash::LauncherID shortcut_id = CreateShortcut("app1");
784 controller->SetRefocusURLPatternForTest( 1040 controller_->SetRefocusURLPatternForTest(
785 shortcut_id, GURL("http://www.example.com/path1/*")); 1041 shortcut_id, GURL("http://www.example.com/path1/*"));
786 1042
787 // Create new tab owned by app. 1043 // Create new tab.
788 ui_test_utils::NavigateToURLWithDisposition( 1044 ui_test_utils::NavigateToURLWithDisposition(
789 browser(), 1045 browser(),
790 GURL("http://www.example.com/path2/bar.html"), 1046 GURL("http://www.example2.com/path2/bar.html"),
791 NEW_FOREGROUND_TAB, 1047 NEW_FOREGROUND_TAB,
792 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1048 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
793 EXPECT_EQ(++tab_count, tab_strip->count()); 1049 EXPECT_EQ(++tab_count, tab_strip->count());
794 WebContents* first_tab = tab_strip->GetActiveWebContents(); 1050 WebContents* first_tab = tab_strip->GetActiveWebContents();
795 // Confirm app is active. 1051 // Confirm app is not active.
796 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 1052 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status);
797 1053
798 // Activating app should launch new tab, because second tab isn't 1054 // Activating app should launch new tab, because second tab isn't
799 // in its refocus url path. 1055 // in its refocus url path.
800 launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 1056 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
801 EXPECT_EQ(++tab_count, tab_strip->count()); 1057 EXPECT_EQ(++tab_count, tab_strip->count());
802 WebContents* second_tab = tab_strip->GetActiveWebContents(); 1058 WebContents* second_tab = tab_strip->GetActiveWebContents();
803 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 1059 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
804 EXPECT_NE(first_tab, second_tab); 1060 EXPECT_NE(first_tab, second_tab);
805 EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab); 1061 EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab);
806 } 1062 }
807 1063
1064 // Check the launcher activation state for applications and browser.
1065 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivationStateCheck) {
1066 TabStripModel* tab_strip = browser()->tab_strip_model();
1067 // Get the browser item index
1068 int browser_index = ash::launcher::GetBrowserItemIndex(*controller_->model());
1069 EXPECT_TRUE(browser_index >= 0);
1070
1071 // Even though we are just comming up, the browser should be active.
1072 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
1073
1074 ash::LauncherID shortcut_id = CreateShortcut("app1");
1075 controller_->SetRefocusURLPatternForTest(
1076 shortcut_id, GURL("http://www.example.com/path1/*"));
1077
1078 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status);
1079 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
1080
1081 // Create new tab which would be the running app.
1082 ui_test_utils::NavigateToURLWithDisposition(
1083 browser(),
1084 GURL("http://www.example.com/path1/bar.html"),
1085 NEW_FOREGROUND_TAB,
1086 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1087
1088 // There should never be two items active at the same time.
1089 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
1090 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[browser_index].status);
1091
1092 tab_strip->ActivateTabAt(0, false);
1093 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status);
1094 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
1095
1096 tab_strip->CloseWebContentsAt(1, TabStripModel::CLOSE_NONE);
1097 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status);
1098 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
1099
1100 ash::wm::DeactivateWindow(browser()->window()->GetNativeWindow());
1101 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status);
1102 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[browser_index].status);
1103 }
1104
1105 // Check that the launcher activation state for a V1 application stays closed
1106 // even after an asynchronous browser event comes in after the tab got
1107 // destroyed.
1108 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, AsyncActivationStateCheck) {
1109 TabStripModel* tab_strip = browser()->tab_strip_model();
1110
1111 ash::LauncherID shortcut_id = CreateShortcut("app1");
1112 controller_->SetRefocusURLPatternForTest(
1113 shortcut_id, GURL("http://www.example.com/path1/*"));
1114
1115 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status);
1116
1117 // Create new tab which would be the running app.
1118 ui_test_utils::NavigateToURLWithDisposition(
1119 browser(),
1120 GURL("http://www.example.com/path1/bar.html"),
1121 NEW_FOREGROUND_TAB,
1122 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1123
1124 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
1125 // To address the issue of crbug.com/174050, the tab we are about to close
1126 // has to be active.
1127 tab_strip->ActivateTabAt(1, false);
1128 EXPECT_EQ(1, tab_strip->active_index());
1129
1130 // Close the web contents.
1131 tab_strip->CloseWebContentsAt(1, TabStripModel::CLOSE_NONE);
1132 // The status should now be set to closed.
1133 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status);
1134 }
1135
1136 // Checks that a windowed application does not add an item to the browser list.
1137 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser,
1138 WindowedAppDoesNotAddToBrowser) {
1139 // Get the number of items in the browser menu.
1140 size_t items = NumberOfDetectedLauncherBrowsers(false);
1141 size_t running_browser = chrome::GetTotalBrowserCount();
1142 EXPECT_EQ(0u, items);
1143 EXPECT_EQ(0u, running_browser);
1144
1145 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_WINDOW, NEW_WINDOW);
1146
1147 // No new browser should get detected, even though one more is running.
1148 EXPECT_EQ(0u, NumberOfDetectedLauncherBrowsers(false));
1149 EXPECT_EQ(++running_browser, chrome::GetTotalBrowserCount());
1150
1151 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, NEW_WINDOW);
1152
1153 // A new browser should get detected and one more should be running.
1154 EXPECT_EQ(NumberOfDetectedLauncherBrowsers(false), 1u);
1155 EXPECT_EQ(++running_browser, chrome::GetTotalBrowserCount());
1156 }
1157
1158 // Checks the functionality to enumerate all browsers vs. all tabs.
1159 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser,
1160 EnumerateALlBrowsersAndTabs) {
1161 // Create at least one browser.
1162 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, NEW_WINDOW);
1163 size_t browsers = NumberOfDetectedLauncherBrowsers(false);
1164 size_t tabs = NumberOfDetectedLauncherBrowsers(true);
1165
1166 // Create a second browser.
1167 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, NEW_WINDOW);
1168
1169 EXPECT_EQ(++browsers, NumberOfDetectedLauncherBrowsers(false));
1170 EXPECT_EQ(++tabs, NumberOfDetectedLauncherBrowsers(true));
1171
1172 // Create only a tab.
1173 LoadAndLaunchExtension("app1",
1174 extension_misc::LAUNCH_TAB,
1175 NEW_FOREGROUND_TAB);
1176
1177 EXPECT_EQ(browsers, NumberOfDetectedLauncherBrowsers(false));
1178 EXPECT_EQ(++tabs, NumberOfDetectedLauncherBrowsers(true));
1179 }
1180
1181 // Check that the keyboard activation of a launcher item tabs properly through
1182 // the items at hand.
1183 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, AltNumberTabsTabbing) {
1184 TabStripModel* tab_strip = browser()->tab_strip_model();
1185
1186 ash::LauncherID shortcut_id = CreateShortcut("app");
1187 controller_->SetRefocusURLPatternForTest(
1188 shortcut_id, GURL("http://www.example.com/path/*"));
1189 std::string url = "http://www.example.com/path/bla";
1190
1191 int shortcut_index = model_->ItemIndexByID(shortcut_id);
1192
1193 // Create an application handled browser tab.
1194 ui_test_utils::NavigateToURLWithDisposition(
1195 browser(),
1196 GURL(url),
1197 NEW_FOREGROUND_TAB,
1198 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1199
1200 content::WebContents* content1 = tab_strip->GetActiveWebContents();
1201
1202 // Create some other browser tab.
1203 ui_test_utils::NavigateToURLWithDisposition(
1204 browser(),
1205 GURL("http://www.test.com"),
1206 NEW_FOREGROUND_TAB,
1207 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1208 content::WebContents* content1a = tab_strip->GetActiveWebContents();
1209
1210 // Make sure that the active tab is now our handled tab.
1211 EXPECT_NE(content1a, content1);
1212
1213 // The active tab should still be the unnamed tab. Then we switch and reach
1214 // the first app and stay there.
1215 EXPECT_EQ(content1a, tab_strip->GetActiveWebContents());
1216 ActivateLauncherItem(shortcut_index);
1217 EXPECT_EQ(content1, tab_strip->GetActiveWebContents());
1218 ActivateLauncherItem(shortcut_index);
1219 EXPECT_EQ(content1, tab_strip->GetActiveWebContents());
1220
1221 ui_test_utils::NavigateToURLWithDisposition(
1222 browser(),
1223 GURL(url),
1224 NEW_FOREGROUND_TAB,
1225 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1226 content::WebContents* content2 = tab_strip->GetActiveWebContents();
1227
1228 EXPECT_EQ(content2, browser()->tab_strip_model()->GetActiveWebContents());
1229 ActivateLauncherItem(shortcut_index);
1230 EXPECT_EQ(content1, browser()->tab_strip_model()->GetActiveWebContents());
1231 ActivateLauncherItem(shortcut_index);
1232 EXPECT_EQ(content2, browser()->tab_strip_model()->GetActiveWebContents());
1233 }
1234
1235 // Check that the keyboard activation of a launcher item tabs properly through
1236 // the items at hand.
1237 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest,
1238 AltNumberAppsTabbing) {
1239 // First run app.
1240 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
1241 ui::BaseWindow* window1 = CreateShellWindow(extension1)->GetBaseWindow();
1242 const ash::LauncherItem& item1 = GetLastLauncherItem();
1243 ash::LauncherID app_id = item1.id;
1244 int app_index = launcher_model()->ItemIndexByID(app_id);
1245
1246 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
1247 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
1248
1249 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2");
1250 ui::BaseWindow* window2 = CreateShellWindow(extension2)->GetBaseWindow();
1251
1252 // By now the browser should be active. Issue Alt keystrokes several times to
1253 // see that we stay on that application.
1254 EXPECT_TRUE(window2->IsActive());
1255 ActivateLauncherItem(app_index);
1256 EXPECT_TRUE(window1->IsActive());
1257 ActivateLauncherItem(app_index);
1258 EXPECT_TRUE(window1->IsActive());
1259
1260 ui::BaseWindow* window1a = CreateShellWindow(extension1)->GetBaseWindow();
1261
1262 EXPECT_TRUE(window1a->IsActive());
1263 EXPECT_FALSE(window1->IsActive());
1264 ActivateLauncherItem(app_index);
1265 EXPECT_TRUE(window1->IsActive());
1266 ActivateLauncherItem(app_index);
1267 EXPECT_TRUE(window1a->IsActive());
1268 }
1269
1270 // Test that we can launch a platform app panel and get a running item.
1271 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest,
1272 LaunchPanelWindow) {
1273 int item_count = launcher_model()->item_count();
1274 const Extension* extension = LoadAndLaunchPlatformApp("launch");
1275 ShellWindow::CreateParams params;
1276 params.window_type = ShellWindow::WINDOW_TYPE_PANEL;
1277 params.focused = false;
1278 ShellWindow* window = CreateShellWindowFromParams(extension, params);
1279 ++item_count;
1280 ASSERT_EQ(item_count, launcher_model()->item_count());
1281 const ash::LauncherItem& item = GetLastLauncherPanelItem();
1282 EXPECT_EQ(ash::TYPE_APP_PANEL, item.type);
1283 // Opening a panel does not activate it.
1284 EXPECT_EQ(ash::STATUS_RUNNING, item.status);
1285 CloseShellWindow(window);
1286 --item_count;
1287 EXPECT_EQ(item_count, launcher_model()->item_count());
1288 }
1289
1290 // Test attention states of windows.
1291 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowAttentionStatus) {
1292 const Extension* extension = LoadAndLaunchPlatformApp("launch");
1293 ShellWindow::CreateParams params;
1294 params.window_type = ShellWindow::WINDOW_TYPE_PANEL;
1295 params.focused = false;
1296 ShellWindow* panel = CreateShellWindowFromParams(extension, params);
1297 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible());
1298 // Panels should not be active by default.
1299 EXPECT_FALSE(panel->GetBaseWindow()->IsActive());
1300 // Confirm that a controller item was created and is the correct state.
1301 const ash::LauncherItem& item = GetLastLauncherPanelItem();
1302 LauncherItemController* item_controller = GetItemController(item.id);
1303 EXPECT_EQ(ash::TYPE_APP_PANEL, item.type);
1304 EXPECT_EQ(ash::STATUS_RUNNING, item.status);
1305 EXPECT_EQ(LauncherItemController::TYPE_APP_PANEL, item_controller->type());
1306
1307 // App windows should go to attention state.
1308 panel->GetNativeWindow()->SetProperty(aura::client::kDrawAttentionKey, true);
1309 EXPECT_EQ(ash::STATUS_ATTENTION, item.status);
1310
1311 // Click the item and confirm that the panel is activated.
1312 TestEvent click_event(ui::ET_MOUSE_PRESSED);
1313 item_controller->Clicked(click_event);
1314 EXPECT_TRUE(panel->GetBaseWindow()->IsActive());
1315 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
1316
1317 // Active windows don't show attention.
1318 panel->GetNativeWindow()->SetProperty(aura::client::kDrawAttentionKey, true);
1319 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
1320 }
1321
1322 // Checks that the browser Alt "tabbing" is properly done.
1323 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser,
1324 AltNumberBrowserTabbing) {
1325 // Get the number of items in the browser menu.
1326 EXPECT_EQ(0u, chrome::GetTotalBrowserCount());
1327 // The first activation should create a browser.
1328 launcher_->ActivateLauncherItem(0);
1329 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1330 // A second activation should not create a new instance.
1331 launcher_->ActivateLauncherItem(0);
1332 Browser* browser1 = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow());
1333 EXPECT_TRUE(browser1);
1334 aura::Window* window1 = browser1->window()->GetNativeWindow();
1335 Browser* browser2 = CreateBrowser(profile());
1336 aura::Window* window2 = browser2->window()->GetNativeWindow();
1337
1338 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
1339 EXPECT_NE(window1, window2);
1340 EXPECT_EQ(window2, ash::wm::GetActiveWindow());
1341
1342 // Activate multiple times the switcher to see that the windows get activated.
1343 launcher_->ActivateLauncherItem(0);
1344 EXPECT_EQ(window1, ash::wm::GetActiveWindow());
1345 launcher_->ActivateLauncherItem(0);
1346 EXPECT_EQ(window2, ash::wm::GetActiveWindow());
1347
1348 // Create a third browser - make sure that we do not toggle simply between
1349 // two windows.
1350 Browser* browser3 = CreateBrowser(profile());
1351 aura::Window* window3 = browser3->window()->GetNativeWindow();
1352
1353 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
1354 EXPECT_NE(window1, window3);
1355 EXPECT_NE(window2, window3);
1356 EXPECT_EQ(window3, ash::wm::GetActiveWindow());
1357
1358 launcher_->ActivateLauncherItem(0);
1359 EXPECT_EQ(window1, ash::wm::GetActiveWindow());
1360 launcher_->ActivateLauncherItem(0);
1361 EXPECT_EQ(window2, ash::wm::GetActiveWindow());
1362 launcher_->ActivateLauncherItem(0);
1363 EXPECT_EQ(window3, ash::wm::GetActiveWindow());
1364 launcher_->ActivateLauncherItem(0);
1365 EXPECT_EQ(window1, ash::wm::GetActiveWindow());
1366
1367 // Create anther app and make sure that none of our browsers is active.
1368 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, NEW_WINDOW);
1369 EXPECT_NE(window1, ash::wm::GetActiveWindow());
1370 EXPECT_NE(window2, ash::wm::GetActiveWindow());
1371
1372 // After activation our browser should be active again.
1373 launcher_->ActivateLauncherItem(0);
1374 EXPECT_EQ(window1, ash::wm::GetActiveWindow());
1375 }
1376
1377 // Checks that after a session restore, we do not start applications on an
1378 // activation.
1379 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivateAfterSessionRestore) {
1380 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1381
1382 // Create a known application.
1383 ash::LauncherID shortcut_id = CreateShortcut("app1");
1384
1385 // Create a new browser - without activating it - and load an "app" into it.
1386 Browser::CreateParams params =
1387 Browser::CreateParams(profile(), chrome::GetActiveDesktop());
1388 params.initial_show_state = ui::SHOW_STATE_INACTIVE;
1389 Browser* browser2 = new Browser(params);
1390 controller_->SetRefocusURLPatternForTest(
1391 shortcut_id, GURL("http://www.example.com/path/*"));
1392 std::string url = "http://www.example.com/path/bla";
1393 ui_test_utils::NavigateToURLWithDisposition(
1394 browser2,
1395 GURL(url),
1396 NEW_FOREGROUND_TAB,
1397 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1398
1399 // Remember the number of tabs for each browser.
1400 TabStripModel* tab_strip = browser()->tab_strip_model();
1401 int tab_count1 = tab_strip->count();
1402 TabStripModel* tab_strip2 = browser2->tab_strip_model();
1403 int tab_count2 = tab_strip2->count();
1404
1405 // Check that we have two browsers and the inactive browser remained inactive.
1406 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
1407 EXPECT_EQ(chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()),
1408 browser());
1409 // Check that the LRU browser list does only contain the original browser.
1410 BrowserList* ash_browser_list =
1411 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
1412 BrowserList::const_reverse_iterator it =
1413 ash_browser_list->begin_last_active();
1414 EXPECT_EQ(*it, browser());
1415 ++it;
1416 EXPECT_EQ(it, ash_browser_list->end_last_active());
1417
1418 // Now request to either activate an existing app or create a new one.
1419 controller_->ItemSelected(*model_->ItemByID(shortcut_id),
1420 ui::KeyEvent(ui::ET_KEY_RELEASED,
1421 ui::VKEY_RETURN,
1422 0,
1423 false));
1424
1425 // Check that we have set focus on the existing application and nothing new
1426 // was created.
1427 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
1428 EXPECT_EQ(tab_count1, tab_strip->count());
1429 EXPECT_EQ(tab_count2, tab_strip2->count());
1430 EXPECT_EQ(chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()),
1431 browser2);
1432 }
1433
1434 // Do various drag and drop interaction tests between the application list and
1435 // the launcher.
1436 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, DragAndDrop) {
1437 // Get a number of interfaces we need.
1438 aura::test::EventGenerator generator(
1439 ash::Shell::GetPrimaryRootWindow(), gfx::Point());
1440 ash::test::LauncherViewTestAPI test(launcher_->GetLauncherViewForTest());
1441 AppListService* service = AppListService::Get();
1442
1443 // There should be two items in our launcher by this time.
1444 EXPECT_EQ(2, model_->item_count());
1445 EXPECT_FALSE(service->IsAppListVisible());
1446
1447 // Open the app list menu and check that the drag and drop host was set.
1448 gfx::Rect app_list_bounds =
1449 test.launcher_view()->GetAppListButtonView()->GetBoundsInScreen();
1450 generator.MoveMouseTo(app_list_bounds.CenterPoint().x(),
1451 app_list_bounds.CenterPoint().y());
1452 base::MessageLoop::current()->RunUntilIdle();
1453 generator.ClickLeftButton();
1454
1455 EXPECT_TRUE(service->IsAppListVisible());
1456 app_list::AppsGridView* grid_view =
1457 app_list::AppsGridView::GetLastGridViewForTest();
1458 ASSERT_TRUE(grid_view);
1459 ASSERT_TRUE(grid_view->has_drag_and_drop_host_for_test());
1460
1461 // There should be 2 items in our application list.
1462 const views::ViewModel* vm_grid = grid_view->view_model_for_test();
1463 EXPECT_EQ(2, vm_grid->view_size());
1464
1465 // Test #1: Drag an app list which does not exist yet item into the
1466 // launcher. Keeping it dragged, see that a new item gets created. Continuing
1467 // to drag it out should remove it again.
1468
1469 // Get over item #1 of the application list and press the mouse button.
1470 views::View* item1 = vm_grid->view_at(1);
1471 gfx::Rect bounds_grid_1 = item1->GetBoundsInScreen();
1472 generator.MoveMouseTo(bounds_grid_1.CenterPoint().x(),
1473 bounds_grid_1.CenterPoint().y());
1474 base::MessageLoop::current()->RunUntilIdle();
1475 generator.PressLeftButton();
1476
1477 EXPECT_FALSE(grid_view->forward_events_to_drag_and_drop_host_for_test());
1478
1479 // Drag the item into the launcher and check that a new item gets created.
1480 const views::ViewModel* vm_launcher =
1481 test.launcher_view()->view_model_for_test();
1482 views::View* launcher1 = vm_launcher->view_at(1);
1483 gfx::Rect bounds_launcher_1 = launcher1->GetBoundsInScreen();
1484 generator.MoveMouseTo(bounds_launcher_1.CenterPoint().x(),
1485 bounds_launcher_1.CenterPoint().y());
1486 base::MessageLoop::current()->RunUntilIdle();
1487
1488 // Check that a new item got created.
1489 EXPECT_EQ(3, model_->item_count());
1490 EXPECT_TRUE(grid_view->forward_events_to_drag_and_drop_host_for_test());
1491
1492 // Move it where the item originally was and check that it disappears again.
1493 generator.MoveMouseTo(bounds_grid_1.CenterPoint().x(),
1494 bounds_grid_1.CenterPoint().y());
1495 base::MessageLoop::current()->RunUntilIdle();
1496 EXPECT_EQ(2, model_->item_count());
1497 EXPECT_FALSE(grid_view->forward_events_to_drag_and_drop_host_for_test());
1498
1499 // Dropping it should keep the launcher as it originally was.
1500 generator.ReleaseLeftButton();
1501 base::MessageLoop::current()->RunUntilIdle();
1502 EXPECT_EQ(2, model_->item_count());
1503 // There are a few animations which need finishing before we can continue.
1504 test.RunMessageLoopUntilAnimationsDone();
1505 // Move the mouse outside of the launcher.
1506 generator.MoveMouseTo(0, 0);
1507
1508 // Test #2: Check that the unknown item dropped into the launcher will
1509 // create a new item.
1510 generator.MoveMouseTo(bounds_grid_1.CenterPoint().x(),
1511 bounds_grid_1.CenterPoint().y());
1512 generator.PressLeftButton();
1513 generator.MoveMouseTo(bounds_launcher_1.CenterPoint().x(),
1514 bounds_launcher_1.CenterPoint().y());
1515 base::MessageLoop::current()->RunUntilIdle();
1516 EXPECT_EQ(3, model_->item_count());
1517 EXPECT_TRUE(grid_view->forward_events_to_drag_and_drop_host_for_test());
1518 generator.ReleaseLeftButton();
1519 base::MessageLoop::current()->RunUntilIdle();
1520 EXPECT_FALSE(grid_view->forward_events_to_drag_and_drop_host_for_test());
1521 EXPECT_EQ(3, model_->item_count()); // It should be still there.
1522 test.RunMessageLoopUntilAnimationsDone();
1523
1524 // Test #3: Check that the now known item dropped into the launcher will
1525 // not create a new item.
1526 generator.MoveMouseTo(bounds_grid_1.CenterPoint().x(),
1527 bounds_grid_1.CenterPoint().y());
1528 generator.PressLeftButton();
1529 generator.MoveMouseTo(bounds_launcher_1.CenterPoint().x(),
1530 bounds_launcher_1.CenterPoint().y());
1531 base::MessageLoop::current()->RunUntilIdle();
1532 EXPECT_EQ(3, model_->item_count()); // No new item got added.
1533 EXPECT_TRUE(grid_view->forward_events_to_drag_and_drop_host_for_test());
1534 generator.ReleaseLeftButton();
1535 base::MessageLoop::current()->RunUntilIdle();
1536 EXPECT_FALSE(grid_view->forward_events_to_drag_and_drop_host_for_test());
1537 EXPECT_EQ(3, model_->item_count()); // And it remains that way.
1538 }
1539
1540 // Check that clicking on an app launcher item launches a new browser.
1541 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ClickItem) {
1542 // Get a number of interfaces we need.
1543 aura::test::EventGenerator generator(
1544 ash::Shell::GetPrimaryRootWindow(), gfx::Point());
1545 ash::test::LauncherViewTestAPI test(launcher_->GetLauncherViewForTest());
1546 AppListService* service = AppListService::Get();
1547 // There should be two items in our launcher by this time.
1548 EXPECT_EQ(2, model_->item_count());
1549 EXPECT_FALSE(service->IsAppListVisible());
1550
1551 // Open the app list menu and check that the drag and drop host was set.
1552 gfx::Rect app_list_bounds =
1553 test.launcher_view()->GetAppListButtonView()->GetBoundsInScreen();
1554 generator.MoveMouseTo(app_list_bounds.CenterPoint().x(),
1555 app_list_bounds.CenterPoint().y());
1556 generator.ClickLeftButton();
1557 base::MessageLoop::current()->RunUntilIdle();
1558
1559 EXPECT_TRUE(service->IsAppListVisible());
1560 app_list::AppsGridView* grid_view =
1561 app_list::AppsGridView::GetLastGridViewForTest();
1562 ASSERT_TRUE(grid_view);
1563 const views::ViewModel* vm_grid = grid_view->view_model_for_test();
1564 EXPECT_EQ(2, vm_grid->view_size());
1565 gfx::Rect bounds_grid_1 = vm_grid->view_at(1)->GetBoundsInScreen();
1566 // Test now that a click does create a new application tab.
1567 TabStripModel* tab_strip = browser()->tab_strip_model();
1568 int tab_count = tab_strip->count();
1569 generator.MoveMouseTo(bounds_grid_1.CenterPoint().x(),
1570 bounds_grid_1.CenterPoint().y());
1571 generator.ClickLeftButton();
1572 base::MessageLoop::current()->RunUntilIdle();
1573 EXPECT_EQ(tab_count + 1, tab_strip->count());
1574 }
1575
1576 // Check LauncherItemController of Browser Shortcut functionality.
1577 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser,
1578 BrowserShortcutLauncherItemController) {
1579 LauncherItemController* item_controller =
1580 controller_->GetBrowserShortcutLauncherItemController();
1581
1582 // Get the number of browsers.
1583 size_t running_browser = chrome::GetTotalBrowserCount();
1584 EXPECT_EQ(0u, running_browser);
1585 EXPECT_FALSE(item_controller->IsOpen());
1586
1587 // Activate. This creates new browser
1588 item_controller->Activate();
1589 // New Window is created.
1590 running_browser = chrome::GetTotalBrowserCount();
1591 EXPECT_EQ(1u, running_browser);
1592 EXPECT_TRUE(item_controller->IsOpen());
1593
1594 // Minimize Window.
1595 aura::Window* window = ash::wm::GetActiveWindow();
1596 ash::wm::MinimizeWindow(window);
1597 EXPECT_TRUE(ash::wm::IsWindowMinimized(window));
1598
1599 // Activate again. This doesn't create new browser.
1600 // It activates window.
1601 item_controller->Activate();
1602 running_browser = chrome::GetTotalBrowserCount();
1603 EXPECT_EQ(1u, running_browser);
1604 EXPECT_TRUE(item_controller->IsOpen());
1605 EXPECT_FALSE(ash::wm::IsWindowMinimized(window));
1606 }
1607
1608 // Check that GetIDByWindow() returns |LauncherID| of the active tab.
1609 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MatchingLauncherIDandActiveTab) {
1610 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1611 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1612 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1613 EXPECT_EQ(2, model_->item_count());
1614
1615 aura::Window* window = browser()->window()->GetNativeWindow();
1616
1617 int browser_index = ash::launcher::GetBrowserItemIndex(*model_);
1618 ash::LauncherID browser_id = model_->items()[browser_index].id;
1619 EXPECT_EQ(browser_id, controller_->GetIDByWindow(window));
1620
1621 ash::LauncherID app_id = CreateShortcut("app1");
1622 EXPECT_EQ(3, model_->item_count());
1623
1624 // Creates a new tab for "app1" and checks that GetIDByWindow() returns
1625 // |LauncherID| of "app1".
1626 ActivateLauncherItem(model_->ItemIndexByID(app_id));
1627 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1628 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
1629 EXPECT_EQ(app_id, controller_->GetIDByWindow(window));
1630
1631 // Makes tab at index 0(NTP) as an active tab and checks that GetIDByWindow()
1632 // returns |LauncherID| of browser shortcut.
1633 browser()->tab_strip_model()->ActivateTabAt(0, false);
1634 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1635 EXPECT_EQ(browser_id, controller_->GetIDByWindow(window));
1636 }
1637
808 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, OverflowBubble) { 1638 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, OverflowBubble) {
809 // Make sure to have a browser window 1639 // Make sure to have a browser window
810 chrome::NewTab(browser()); 1640 chrome::NewTab(browser());
811 1641
812 // No overflow yet. 1642 // No overflow yet.
813 EXPECT_FALSE(launcher_->IsShowingOverflowBubble()); 1643 EXPECT_FALSE(launcher_->IsShowingOverflowBubble());
814 1644
815 ash::test::LauncherViewTestAPI test(launcher_->GetLauncherViewForTest()); 1645 ash::test::LauncherViewTestAPI test(launcher_->GetLauncherViewForTest());
816 1646
817 int items_added = 0; 1647 int items_added = 0;
818 while (!test.IsOverflowButtonVisible()) { 1648 while (!test.IsOverflowButtonVisible()) {
819 std::string fake_app_id = base::StringPrintf("fake_app_%d", items_added); 1649 std::string fake_app_id = base::StringPrintf("fake_app_%d", items_added);
820 PinFakeApp(fake_app_id); 1650 PinFakeApp(fake_app_id);
821 1651
822 ++items_added; 1652 ++items_added;
823 ASSERT_LT(items_added, 10000); 1653 ASSERT_LT(items_added, 10000);
824 } 1654 }
825 1655
826 // Now show overflow bubble. 1656 // Now show overflow bubble.
827 test.ShowOverflowBubble(); 1657 test.ShowOverflowBubble();
828 EXPECT_TRUE(launcher_->IsShowingOverflowBubble()); 1658 EXPECT_TRUE(launcher_->IsShowingOverflowBubble());
829 1659
830 // Unpin first pinned app and there should be no crash. 1660 // Unpin first pinned app and there should be no crash.
831 ChromeLauncherController* controller = 1661 controller_->UnpinAppsWithID(std::string("fake_app_0"));
832 static_cast<ChromeLauncherController*>(launcher_->delegate());
833 controller->UnpinAppsWithID(std::string("fake_app_0"));
834 1662
835 test.RunMessageLoopUntilAnimationsDone(); 1663 test.RunMessageLoopUntilAnimationsDone();
836 EXPECT_FALSE(launcher_->IsShowingOverflowBubble()); 1664 EXPECT_FALSE(launcher_->IsShowingOverflowBubble());
837 } 1665 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698