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

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

Issue 23068021: Remove PerBrowser launcher, reland step 1 of 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | 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_per_app.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/display/display_controller.h"
12 #include "ash/launcher/launcher.h" 12 #include "ash/launcher/launcher.h"
13 #include "ash/launcher/launcher_model.h" 13 #include "ash/launcher/launcher_model.h"
14 #include "ash/launcher/launcher_util.h" 14 #include "ash/launcher/launcher_util.h"
15 #include "ash/launcher/launcher_view.h" 15 #include "ash/launcher/launcher_view.h"
16 #include "ash/shell.h" 16 #include "ash/shell.h"
17 #include "ash/test/launcher_view_test_api.h" 17 #include "ash/test/launcher_view_test_api.h"
18 #include "ash/test/shell_test_api.h" 18 #include "ash/test/shell_test_api.h"
19 #include "ash/wm/window_util.h" 19 #include "ash/wm/window_util.h"
20 #include "base/strings/stringprintf.h"
20 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
21 #include "chrome/browser/apps/app_browsertest_util.h" 22 #include "chrome/browser/apps/app_browsertest_util.h"
22 #include "chrome/browser/automation/automation_util.h" 23 #include "chrome/browser/automation/automation_util.h"
23 #include "chrome/browser/chrome_notification_types.h" 24 #include "chrome/browser/chrome_notification_types.h"
24 #include "chrome/browser/extensions/extension_apitest.h" 25 #include "chrome/browser/extensions/extension_apitest.h"
25 #include "chrome/browser/extensions/extension_browsertest.h" 26 #include "chrome/browser/extensions/extension_browsertest.h"
26 #include "chrome/browser/extensions/extension_function_test_utils.h" 27 #include "chrome/browser/extensions/extension_function_test_utils.h"
27 #include "chrome/browser/extensions/extension_service.h" 28 #include "chrome/browser/extensions/extension_service.h"
28 #include "chrome/browser/extensions/extension_system.h" 29 #include "chrome/browser/extensions/extension_system.h"
29 #include "chrome/browser/extensions/extension_test_message_listener.h" 30 #include "chrome/browser/extensions/extension_test_message_listener.h"
30 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/browser/ui/app_list/app_list_service.h" 32 #include "chrome/browser/ui/app_list/app_list_service.h"
32 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" 33 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h"
33 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h"
34 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" 34 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
35 #include "chrome/browser/ui/browser.h" 35 #include "chrome/browser/ui/browser.h"
36 #include "chrome/browser/ui/browser_commands.h" 36 #include "chrome/browser/ui/browser_commands.h"
37 #include "chrome/browser/ui/browser_finder.h" 37 #include "chrome/browser/ui/browser_finder.h"
38 #include "chrome/browser/ui/browser_list.h" 38 #include "chrome/browser/ui/browser_list.h"
39 #include "chrome/browser/ui/browser_window.h" 39 #include "chrome/browser/ui/browser_window.h"
40 #include "chrome/browser/ui/extensions/application_launch.h" 40 #include "chrome/browser/ui/extensions/application_launch.h"
41 #include "chrome/browser/ui/host_desktop.h" 41 #include "chrome/browser/ui/host_desktop.h"
42 #include "chrome/browser/ui/tabs/tab_strip_model.h" 42 #include "chrome/browser/ui/tabs/tab_strip_model.h"
43 #include "chrome/common/chrome_switches.h" 43 #include "chrome/common/chrome_switches.h"
44 #include "chrome/common/extensions/extension_constants.h" 44 #include "chrome/common/extensions/extension_constants.h"
45 #include "chrome/test/base/ui_test_utils.h" 45 #include "chrome/test/base/ui_test_utils.h"
46 #include "content/public/browser/notification_service.h" 46 #include "content/public/browser/notification_service.h"
47 #include "content/public/browser/notification_source.h" 47 #include "content/public/browser/notification_source.h"
48 #include "content/public/browser/web_contents.h" 48 #include "content/public/browser/web_contents.h"
49 #include "extensions/common/switches.h" 49 #include "extensions/common/switches.h"
50 #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" 51 #include "ui/app_list/views/apps_grid_view.h"
52 #include "ui/aura/client/aura_constants.h"
52 #include "ui/aura/test/event_generator.h" 53 #include "ui/aura/test/event_generator.h"
53 #include "ui/aura/window.h" 54 #include "ui/aura/window.h"
54 #include "ui/base/events/event.h" 55 #include "ui/base/events/event.h"
55 56
56 using apps::ShellWindow; 57 using apps::ShellWindow;
57 using extensions::Extension; 58 using extensions::Extension;
58 using content::WebContents; 59 using content::WebContents;
59 60
60 namespace { 61 namespace {
61 62
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 98
98 private: 99 private:
99 Profile* profile_; 100 Profile* profile_;
100 int icon_updates_; 101 int icon_updates_;
101 102
102 DISALLOW_COPY_AND_ASSIGN(TestShellWindowRegistryObserver); 103 DISALLOW_COPY_AND_ASSIGN(TestShellWindowRegistryObserver);
103 }; 104 };
104 105
105 } // namespace 106 } // namespace
106 107
107 // TODO(skuhne): Change name back to LauncherPlatformAppBrowserTest when the 108 class LauncherPlatformAppBrowserTest
108 // old launcher gets ripped out.
109 class LauncherPlatformPerAppAppBrowserTest
110 : public extensions::PlatformAppBrowserTest { 109 : public extensions::PlatformAppBrowserTest {
111 protected: 110 protected:
112 LauncherPlatformPerAppAppBrowserTest() 111 LauncherPlatformAppBrowserTest() : launcher_(NULL), controller_(NULL) {
113 : launcher_(NULL),
114 controller_(NULL) {
115 } 112 }
116 113
117 virtual ~LauncherPlatformPerAppAppBrowserTest() {} 114 virtual ~LauncherPlatformAppBrowserTest() {}
118 115
119 virtual void RunTestOnMainThreadLoop() OVERRIDE { 116 virtual void RunTestOnMainThreadLoop() OVERRIDE {
120 launcher_ = ash::Launcher::ForPrimaryDisplay(); 117 launcher_ = ash::Launcher::ForPrimaryDisplay();
121 controller_ = 118 controller_ = ChromeLauncherController::instance();
122 static_cast<ChromeLauncherControllerPerApp*>(launcher_->delegate());
123 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop(); 119 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop();
124 } 120 }
125 121
126 ash::LauncherModel* launcher_model() { 122 ash::LauncherModel* launcher_model() {
127 return ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); 123 return ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model();
128 } 124 }
129 125
130 ash::LauncherID CreateAppShortcutLauncherItem(const std::string& name) { 126 ash::LauncherID CreateAppShortcutLauncherItem(const std::string& name) {
131 return controller_->CreateAppShortcutLauncherItem( 127 return controller_->CreateAppShortcutLauncherItem(
132 name, controller_->model()->item_count()); 128 name, controller_->model()->item_count());
(...skipping 27 matching lines...) Expand all
160 } 156 }
161 return num_items; 157 return num_items;
162 } 158 }
163 159
164 // Activate the launcher item with the given |id|. 160 // Activate the launcher item with the given |id|.
165 void ActivateLauncherItem(int id) { 161 void ActivateLauncherItem(int id) {
166 launcher_->ActivateLauncherItem(id); 162 launcher_->ActivateLauncherItem(id);
167 } 163 }
168 164
169 ash::Launcher* launcher_; 165 ash::Launcher* launcher_;
170 ChromeLauncherControllerPerApp* controller_; 166 ChromeLauncherController* controller_;
171 167
172 private: 168 private:
173 169
174 DISALLOW_COPY_AND_ASSIGN(LauncherPlatformPerAppAppBrowserTest); 170 DISALLOW_COPY_AND_ASSIGN(LauncherPlatformAppBrowserTest);
175 }; 171 };
176 172
177 // TODO(skuhne): Change name back to LauncherAppBrowserTest when the 173 class LauncherAppBrowserTest : public ExtensionBrowserTest {
178 // old launcher gets ripped out.
179 class LauncherPerAppAppBrowserTest : public ExtensionBrowserTest {
180 protected: 174 protected:
181 LauncherPerAppAppBrowserTest() 175 LauncherAppBrowserTest() : launcher_(NULL), model_(NULL), controller_(NULL) {
182 : launcher_(NULL),
183 model_(NULL) {
184 } 176 }
185 177
186 virtual ~LauncherPerAppAppBrowserTest() {} 178 virtual ~LauncherAppBrowserTest() {}
187 179
188 virtual void RunTestOnMainThreadLoop() OVERRIDE { 180 virtual void RunTestOnMainThreadLoop() OVERRIDE {
189 launcher_ = ash::Launcher::ForPrimaryDisplay(); 181 launcher_ = ash::Launcher::ForPrimaryDisplay();
190 model_ = 182 model_ =
191 ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); 183 ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model();
184 controller_ = ChromeLauncherController::instance();
192 return ExtensionBrowserTest::RunTestOnMainThreadLoop(); 185 return ExtensionBrowserTest::RunTestOnMainThreadLoop();
193 } 186 }
194 187
195 size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) { 188 size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) {
196 ChromeLauncherControllerPerApp* controller =
197 static_cast<ChromeLauncherControllerPerApp*>(launcher_->delegate());
198 LauncherItemController* item_controller = 189 LauncherItemController* item_controller =
199 controller->GetBrowserShortcutLauncherItemController(); 190 controller_->GetBrowserShortcutLauncherItemController();
200 int items = item_controller->GetApplicationList( 191 int items = item_controller->GetApplicationList(
201 show_all_tabs ? ui::EF_SHIFT_DOWN : 0).size(); 192 show_all_tabs ? ui::EF_SHIFT_DOWN : 0).size();
202 // If we have at least one item, we have also a title which we remove here. 193 // If we have at least one item, we have also a title which we remove here.
203 return items ? (items - 1) : 0; 194 return items ? (items - 1) : 0;
204 } 195 }
205 196
206 const Extension* LoadAndLaunchExtension( 197 const Extension* LoadAndLaunchExtension(
207 const char* name, 198 const char* name,
208 extension_misc::LaunchContainer container, 199 extension_misc::LaunchContainer container,
209 WindowOpenDisposition disposition) { 200 WindowOpenDisposition disposition) {
(...skipping 16 matching lines...) Expand all
226 ExtensionService* service = extensions::ExtensionSystem::Get( 217 ExtensionService* service = extensions::ExtensionSystem::Get(
227 profile())->extension_service(); 218 profile())->extension_service();
228 LoadExtension(test_data_dir_.AppendASCII(name)); 219 LoadExtension(test_data_dir_.AppendASCII(name));
229 220
230 // First get app_id. 221 // First get app_id.
231 const Extension* extension = 222 const Extension* extension =
232 service->GetExtensionById(last_loaded_extension_id_, false); 223 service->GetExtensionById(last_loaded_extension_id_, false);
233 const std::string app_id = extension->id(); 224 const std::string app_id = extension->id();
234 225
235 // Then create a shortcut. 226 // Then create a shortcut.
236 ChromeLauncherController* controller =
237 static_cast<ChromeLauncherController*>(launcher_->delegate());
238 int item_count = model_->item_count(); 227 int item_count = model_->item_count();
239 ash::LauncherID shortcut_id = controller->CreateAppShortcutLauncherItem( 228 ash::LauncherID shortcut_id = controller_->CreateAppShortcutLauncherItem(
240 app_id, 229 app_id,
241 item_count); 230 item_count);
242 controller->PersistPinnedState(); 231 controller_->PersistPinnedState();
243 EXPECT_EQ(++item_count, model_->item_count()); 232 EXPECT_EQ(++item_count, model_->item_count());
244 const ash::LauncherItem& item = *model_->ItemByID(shortcut_id); 233 const ash::LauncherItem& item = *model_->ItemByID(shortcut_id);
245 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); 234 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type);
246 return item.id; 235 return item.id;
247 } 236 }
248 237
249 // Activate the launcher item with the given |id|. 238 // Activate the launcher item with the given |id|.
250 void ActivateLauncherItem(int id) { 239 void ActivateLauncherItem(int id) {
251 launcher_->ActivateLauncherItem(id); 240 launcher_->ActivateLauncherItem(id);
252 } 241 }
253 242
243 ash::LauncherID PinFakeApp(const std::string& name) {
244 return controller_->CreateAppShortcutLauncherItem(
245 name, model_->item_count());
246 }
247
254 ash::Launcher* launcher_; 248 ash::Launcher* launcher_;
255 ash::LauncherModel* model_; 249 ash::LauncherModel* model_;
250 ChromeLauncherController* controller_;
256 251
257 private: 252 private:
258 253
259 DISALLOW_COPY_AND_ASSIGN(LauncherPerAppAppBrowserTest); 254 DISALLOW_COPY_AND_ASSIGN(LauncherAppBrowserTest);
260 }; 255 };
261 256
262 // TODO(skuhne): Change name to LauncherAppBrowserTestNoBrowser when the 257 class LauncherAppBrowserTestNoDefaultBrowser : public LauncherAppBrowserTest {
263 // old launcher gets ripped out.
264 class LauncherPerAppAppBrowserTestNoDefaultBrowser
265 : public LauncherPerAppAppBrowserTest {
266 protected: 258 protected:
267 LauncherPerAppAppBrowserTestNoDefaultBrowser() {} 259 LauncherAppBrowserTestNoDefaultBrowser() {}
268 virtual ~LauncherPerAppAppBrowserTestNoDefaultBrowser() {} 260 virtual ~LauncherAppBrowserTestNoDefaultBrowser() {}
269 261
270 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 262 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
271 LauncherPerAppAppBrowserTest::SetUpCommandLine(command_line); 263 LauncherAppBrowserTest::SetUpCommandLine(command_line);
272 command_line->AppendSwitch(switches::kNoStartupWindow); 264 command_line->AppendSwitch(switches::kNoStartupWindow);
273 } 265 }
274 266
275 private: 267 private:
276 268
277 DISALLOW_COPY_AND_ASSIGN(LauncherPerAppAppBrowserTestNoDefaultBrowser); 269 DISALLOW_COPY_AND_ASSIGN(LauncherAppBrowserTestNoDefaultBrowser);
278 }; 270 };
279 271
280 // Since the default for minimizing on click might change, I added both classes 272 // Since the default for minimizing on click might change, I added both classes
281 // to either get the minimize on click or not. 273 // to either get the minimize on click or not.
282 class LauncherPerAppAppBrowserNoMinimizeOnClick 274 class LauncherAppBrowserNoMinimizeOnClick
283 : public LauncherPlatformPerAppAppBrowserTest { 275 : public LauncherPlatformAppBrowserTest {
284 protected: 276 protected:
285 LauncherPerAppAppBrowserNoMinimizeOnClick() {} 277 LauncherAppBrowserNoMinimizeOnClick() {}
286 virtual ~LauncherPerAppAppBrowserNoMinimizeOnClick() {} 278 virtual ~LauncherAppBrowserNoMinimizeOnClick() {}
287 279
288 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 280 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
289 LauncherPlatformPerAppAppBrowserTest::SetUpCommandLine(command_line); 281 LauncherPlatformAppBrowserTest::SetUpCommandLine(command_line);
290 command_line->AppendSwitch( 282 command_line->AppendSwitch(
291 switches::kDisableMinimizeOnSecondLauncherItemClick); 283 switches::kDisableMinimizeOnSecondLauncherItemClick);
292 } 284 }
293 285
294 private: 286 private:
295 287
296 DISALLOW_COPY_AND_ASSIGN(LauncherPerAppAppBrowserNoMinimizeOnClick); 288 DISALLOW_COPY_AND_ASSIGN(LauncherAppBrowserNoMinimizeOnClick);
297 }; 289 };
298 290
299 typedef LauncherPlatformPerAppAppBrowserTest 291 typedef LauncherPlatformAppBrowserTest LauncherAppBrowserMinimizeOnClick;
300 LauncherPerAppAppBrowserMinimizeOnClick;
301 292
302 // 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.
303 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, LaunchUnpinned) { 294 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) {
304 int item_count = launcher_model()->item_count(); 295 int item_count = launcher_model()->item_count();
305 const Extension* extension = LoadAndLaunchPlatformApp("launch"); 296 const Extension* extension = LoadAndLaunchPlatformApp("launch");
306 ShellWindow* window = CreateShellWindow(extension); 297 ShellWindow* window = CreateShellWindow(extension);
307 ++item_count; 298 ++item_count;
308 ASSERT_EQ(item_count, launcher_model()->item_count()); 299 ASSERT_EQ(item_count, launcher_model()->item_count());
309 const ash::LauncherItem& item = GetLastLauncherItem(); 300 const ash::LauncherItem& item = GetLastLauncherItem();
310 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); 301 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type);
311 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); 302 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
312 CloseShellWindow(window); 303 CloseShellWindow(window);
313 --item_count; 304 --item_count;
314 EXPECT_EQ(item_count, launcher_model()->item_count()); 305 EXPECT_EQ(item_count, launcher_model()->item_count());
315 } 306 }
316 307
317 // Test that we can launch a platform app that already has a shortcut. 308 // Test that we can launch a platform app that already has a shortcut.
318 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, LaunchPinned) { 309 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) {
319 int item_count = launcher_model()->item_count(); 310 int item_count = launcher_model()->item_count();
320 311
321 // First get app_id. 312 // First get app_id.
322 const Extension* extension = LoadAndLaunchPlatformApp("launch"); 313 const Extension* extension = LoadAndLaunchPlatformApp("launch");
323 const std::string app_id = extension->id(); 314 const std::string app_id = extension->id();
324 315
325 // Then create a shortcut. 316 // Then create a shortcut.
326 ash::LauncherID shortcut_id = CreateAppShortcutLauncherItem(app_id); 317 ash::LauncherID shortcut_id = CreateAppShortcutLauncherItem(app_id);
327 ++item_count; 318 ++item_count;
328 ASSERT_EQ(item_count, launcher_model()->item_count()); 319 ASSERT_EQ(item_count, launcher_model()->item_count());
(...skipping 10 matching lines...) Expand all
339 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); 330 EXPECT_EQ(ash::STATUS_ACTIVE, item.status);
340 331
341 // Then close it, make sure there's still an item. 332 // Then close it, make sure there's still an item.
342 CloseShellWindow(window); 333 CloseShellWindow(window);
343 ASSERT_EQ(item_count, launcher_model()->item_count()); 334 ASSERT_EQ(item_count, launcher_model()->item_count());
344 item = *launcher_model()->ItemByID(shortcut_id); 335 item = *launcher_model()->ItemByID(shortcut_id);
345 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); 336 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type);
346 EXPECT_EQ(ash::STATUS_CLOSED, item.status); 337 EXPECT_EQ(ash::STATUS_CLOSED, item.status);
347 } 338 }
348 339
349 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, PinRunning) { 340 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, PinRunning) {
350 // Run. 341 // Run.
351 int item_count = launcher_model()->item_count(); 342 int item_count = launcher_model()->item_count();
352 const Extension* extension = LoadAndLaunchPlatformApp("launch"); 343 const Extension* extension = LoadAndLaunchPlatformApp("launch");
353 ShellWindow* window = CreateShellWindow(extension); 344 ShellWindow* window = CreateShellWindow(extension);
354 ++item_count; 345 ++item_count;
355 ASSERT_EQ(item_count, launcher_model()->item_count()); 346 ASSERT_EQ(item_count, launcher_model()->item_count());
356 const ash::LauncherItem& item1 = GetLastLauncherItem(); 347 const ash::LauncherItem& item1 = GetLastLauncherItem();
357 ash::LauncherID id = item1.id; 348 ash::LauncherID id = item1.id;
358 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); 349 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
359 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); 350 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
(...skipping 17 matching lines...) Expand all
377 ++item_count; 368 ++item_count;
378 ASSERT_EQ(item_count, launcher_model()->item_count()); 369 ASSERT_EQ(item_count, launcher_model()->item_count());
379 EXPECT_LT(launcher_model()->ItemIndexByID(id), 370 EXPECT_LT(launcher_model()->ItemIndexByID(id),
380 launcher_model()->ItemIndexByID(bar_id)); 371 launcher_model()->ItemIndexByID(bar_id));
381 372
382 // Then close it, make sure the item remains. 373 // Then close it, make sure the item remains.
383 CloseShellWindow(window); 374 CloseShellWindow(window);
384 ASSERT_EQ(item_count, launcher_model()->item_count()); 375 ASSERT_EQ(item_count, launcher_model()->item_count());
385 } 376 }
386 377
387 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, UnpinRunning) { 378 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) {
388 int item_count = launcher_model()->item_count(); 379 int item_count = launcher_model()->item_count();
389 380
390 // First get app_id. 381 // First get app_id.
391 const Extension* extension = LoadAndLaunchPlatformApp("launch"); 382 const Extension* extension = LoadAndLaunchPlatformApp("launch");
392 const std::string app_id = extension->id(); 383 const std::string app_id = extension->id();
393 384
394 // Then create a shortcut. 385 // Then create a shortcut.
395 ash::LauncherID shortcut_id = CreateAppShortcutLauncherItem(app_id); 386 ash::LauncherID shortcut_id = CreateAppShortcutLauncherItem(app_id);
396 ++item_count; 387 ++item_count;
397 ASSERT_EQ(item_count, launcher_model()->item_count()); 388 ASSERT_EQ(item_count, launcher_model()->item_count());
(...skipping 27 matching lines...) Expand all
425 EXPECT_GT(launcher_model()->ItemIndexByID(shortcut_id), 416 EXPECT_GT(launcher_model()->ItemIndexByID(shortcut_id),
426 launcher_model()->ItemIndexByID(foo_id)); 417 launcher_model()->ItemIndexByID(foo_id));
427 418
428 // Then close it, make sure the item's gone. 419 // Then close it, make sure the item's gone.
429 CloseShellWindow(window); 420 CloseShellWindow(window);
430 --item_count; 421 --item_count;
431 ASSERT_EQ(item_count, launcher_model()->item_count()); 422 ASSERT_EQ(item_count, launcher_model()->item_count());
432 } 423 }
433 424
434 // Test that we can launch a platform app with more than one window. 425 // Test that we can launch a platform app with more than one window.
435 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, MultipleWindows) { 426 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) {
436 int item_count = launcher_model()->item_count(); 427 int item_count = launcher_model()->item_count();
437 428
438 // First run app. 429 // First run app.
439 const Extension* extension = LoadAndLaunchPlatformApp("launch"); 430 const Extension* extension = LoadAndLaunchPlatformApp("launch");
440 ShellWindow* window1 = CreateShellWindow(extension); 431 ShellWindow* window1 = CreateShellWindow(extension);
441 ++item_count; 432 ++item_count;
442 ASSERT_EQ(item_count, launcher_model()->item_count()); 433 ASSERT_EQ(item_count, launcher_model()->item_count());
443 const ash::LauncherItem& item = GetLastLauncherItem(); 434 const ash::LauncherItem& item1 = GetLastLauncherItem();
444 ash::LauncherID item_id = item.id; 435 ash::LauncherID item_id = item1.id;
445 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); 436 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
446 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); 437 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
447 EXPECT_EQ(2, GetNumApplicationMenuItems(item)); // Title + 1 window 438 EXPECT_EQ(2, GetNumApplicationMenuItems(item1)); // Title + 1 window
448 439
449 // Add second window. 440 // Add second window.
450 ShellWindow* window2 = CreateShellWindow(extension); 441 ShellWindow* window2 = CreateShellWindow(extension);
451 // Confirm item stays. 442 // Confirm item stays.
452 ASSERT_EQ(item_count, launcher_model()->item_count()); 443 ASSERT_EQ(item_count, launcher_model()->item_count());
453 const ash::LauncherItem& item2 = *launcher_model()->ItemByID(item_id); 444 const ash::LauncherItem& item2 = *launcher_model()->ItemByID(item_id);
454 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); 445 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status);
455 EXPECT_EQ(3, GetNumApplicationMenuItems(item2)); // Title + 2 windows 446 EXPECT_EQ(3, GetNumApplicationMenuItems(item2)); // Title + 2 windows
456 447
457 // Close second window. 448 // Close second window.
458 CloseShellWindow(window2); 449 CloseShellWindow(window2);
459 // Confirm item stays. 450 // Confirm item stays.
460 ASSERT_EQ(item_count, launcher_model()->item_count()); 451 ASSERT_EQ(item_count, launcher_model()->item_count());
461 const ash::LauncherItem& item3 = *launcher_model()->ItemByID(item_id); 452 const ash::LauncherItem& item3 = *launcher_model()->ItemByID(item_id);
462 EXPECT_EQ(ash::STATUS_ACTIVE, item3.status); 453 EXPECT_EQ(ash::STATUS_ACTIVE, item3.status);
463 EXPECT_EQ(2, GetNumApplicationMenuItems(item3)); // Title + 1 window 454 EXPECT_EQ(2, GetNumApplicationMenuItems(item3)); // Title + 1 window
464 455
465 // Close first window. 456 // Close first window.
466 CloseShellWindow(window1); 457 CloseShellWindow(window1);
467 // Confirm item is removed. 458 // Confirm item is removed.
468 --item_count; 459 --item_count;
469 ASSERT_EQ(item_count, launcher_model()->item_count()); 460 ASSERT_EQ(item_count, launcher_model()->item_count());
470 } 461 }
471 462
472 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, MultipleApps) { 463 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) {
473 int item_count = launcher_model()->item_count(); 464 int item_count = launcher_model()->item_count();
474 465
475 // First run app. 466 // First run app.
476 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); 467 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
477 ShellWindow* window1 = CreateShellWindow(extension1); 468 ShellWindow* window1 = CreateShellWindow(extension1);
478 ++item_count; 469 ++item_count;
479 ASSERT_EQ(item_count, launcher_model()->item_count()); 470 ASSERT_EQ(item_count, launcher_model()->item_count());
480 const ash::LauncherItem& item1 = GetLastLauncherItem(); 471 const ash::LauncherItem& item1 = GetLastLauncherItem();
481 ash::LauncherID item_id1 = item1.id; 472 ash::LauncherID item_id1 = item1.id;
482 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); 473 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
(...skipping 18 matching lines...) Expand all
501 --item_count; 492 --item_count;
502 ASSERT_EQ(item_count, launcher_model()->item_count()); 493 ASSERT_EQ(item_count, launcher_model()->item_count());
503 // First app should be active again. 494 // First app should be active again.
504 EXPECT_EQ(ash::STATUS_ACTIVE, 495 EXPECT_EQ(ash::STATUS_ACTIVE,
505 launcher_model()->ItemByID(item_id1)->status); 496 launcher_model()->ItemByID(item_id1)->status);
506 497
507 // Close first app. 498 // Close first app.
508 CloseShellWindow(window1); 499 CloseShellWindow(window1);
509 --item_count; 500 --item_count;
510 ASSERT_EQ(item_count, launcher_model()->item_count()); 501 ASSERT_EQ(item_count, launcher_model()->item_count());
511
512 } 502 }
513 503
514 // 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
515 // the correct activation order is maintained. 505 // the correct activation order is maintained.
516 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, WindowActivation) { 506 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowActivation) {
517 int item_count = launcher_model()->item_count(); 507 int item_count = launcher_model()->item_count();
518 508
519 // First run app. 509 // First run app.
520 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); 510 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
521 ShellWindow* window1 = CreateShellWindow(extension1); 511 ShellWindow* window1 = CreateShellWindow(extension1);
522 ++item_count; 512 ++item_count;
523 ASSERT_EQ(item_count, launcher_model()->item_count()); 513 ASSERT_EQ(item_count, launcher_model()->item_count());
524 const ash::LauncherItem& item1 = GetLastLauncherItem(); 514 const ash::LauncherItem& item1 = GetLastLauncherItem();
525 ash::LauncherID item_id1 = item1.id; 515 ash::LauncherID item_id1 = item1.id;
526 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); 516 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id1)->status); 580 EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id1)->status);
591 581
592 // Close first app. 582 // Close first app.
593 CloseShellWindow(window1b); 583 CloseShellWindow(window1b);
594 CloseShellWindow(window1); 584 CloseShellWindow(window1);
595 --item_count; 585 --item_count;
596 EXPECT_EQ(item_count, launcher_model()->item_count()); 586 EXPECT_EQ(item_count, launcher_model()->item_count());
597 } 587 }
598 588
599 // Confirm that Click behavior for app windows is correnct. 589 // Confirm that Click behavior for app windows is correnct.
600 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserNoMinimizeOnClick, 590 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserNoMinimizeOnClick,
601 AppClickBehavior) { 591 AppClickBehavior) {
602 // Launch a platform app and create a window for it. 592 // Launch a platform app and create a window for it.
603 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); 593 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
604 ShellWindow* window1 = CreateShellWindow(extension1); 594 ShellWindow* window1 = CreateShellWindow(extension1);
605 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); 595 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
606 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); 596 EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
607 // Confirm that a controller item was created and is the correct state. 597 // Confirm that a controller item was created and is the correct state.
608 const ash::LauncherItem& item1 = GetLastLauncherItem(); 598 const ash::LauncherItem& item1 = GetLastLauncherItem();
609 LauncherItemController* item1_controller = GetItemController(item1.id); 599 LauncherItemController* item1_controller = GetItemController(item1.id);
610 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); 600 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
(...skipping 17 matching lines...) Expand all
628 // Maximizing a window should preserve state after minimize + click. 618 // Maximizing a window should preserve state after minimize + click.
629 window1->GetBaseWindow()->Maximize(); 619 window1->GetBaseWindow()->Maximize();
630 window1->GetBaseWindow()->Minimize(); 620 window1->GetBaseWindow()->Minimize();
631 item1_controller->Clicked(click_event); 621 item1_controller->Clicked(click_event);
632 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); 622 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
633 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); 623 EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
634 EXPECT_TRUE(window1->GetBaseWindow()->IsMaximized()); 624 EXPECT_TRUE(window1->GetBaseWindow()->IsMaximized());
635 } 625 }
636 626
637 // Confirm the minimizing click behavior for apps. 627 // Confirm the minimizing click behavior for apps.
638 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserMinimizeOnClick, 628 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserMinimizeOnClick,
639 PackagedAppClickBehaviorInMinimizeMode) { 629 PackagedAppClickBehaviorInMinimizeMode) {
640 // Launch one platform app and create a window for it. 630 // Launch one platform app and create a window for it.
641 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); 631 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
642 ShellWindow* window1 = CreateShellWindow(extension1); 632 ShellWindow* window1 = CreateShellWindow(extension1);
643 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); 633 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
644 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); 634 EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
645 635
646 // Confirm that a controller item was created and is the correct state. 636 // Confirm that a controller item was created and is the correct state.
647 const ash::LauncherItem& item1 = GetLastLauncherItem(); 637 const ash::LauncherItem& item1 = GetLastLauncherItem();
648 LauncherItemController* item1_controller = GetItemController(item1.id); 638 LauncherItemController* item1_controller = GetItemController(item1.id);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 EXPECT_FALSE(window1a->GetBaseWindow()->IsActive()); 676 EXPECT_FALSE(window1a->GetBaseWindow()->IsActive());
687 // The second neither. 677 // The second neither.
688 item1_controller->Clicked(click_event); 678 item1_controller->Clicked(click_event);
689 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); 679 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible());
690 EXPECT_TRUE(window1a->GetNativeWindow()->IsVisible()); 680 EXPECT_TRUE(window1a->GetNativeWindow()->IsVisible());
691 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); 681 EXPECT_TRUE(window1->GetBaseWindow()->IsActive());
692 EXPECT_FALSE(window1a->GetBaseWindow()->IsActive()); 682 EXPECT_FALSE(window1a->GetBaseWindow()->IsActive());
693 } 683 }
694 684
695 // Confirm that click behavior for app panels is correct. 685 // Confirm that click behavior for app panels is correct.
696 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, 686 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, AppPanelClickBehavior) {
697 AppPanelClickBehavior) {
698 // Enable experimental APIs to allow panel creation. 687 // Enable experimental APIs to allow panel creation.
699 CommandLine::ForCurrentProcess()->AppendSwitch( 688 CommandLine::ForCurrentProcess()->AppendSwitch(
700 extensions::switches::kEnableExperimentalExtensionApis); 689 extensions::switches::kEnableExperimentalExtensionApis);
701 // Launch a platform app and create a panel window for it. 690 // Launch a platform app and create a panel window for it.
702 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); 691 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
703 ShellWindow::CreateParams params; 692 ShellWindow::CreateParams params;
704 params.window_type = ShellWindow::WINDOW_TYPE_PANEL; 693 params.window_type = ShellWindow::WINDOW_TYPE_PANEL;
705 params.focused = false; 694 params.focused = false;
706 ShellWindow* panel = CreateShellWindowFromParams(extension1, params); 695 ShellWindow* panel = CreateShellWindowFromParams(extension1, params);
707 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); 696 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible());
(...skipping 14 matching lines...) Expand all
722 item1_controller->Clicked(click_event); 711 item1_controller->Clicked(click_event);
723 EXPECT_TRUE(panel->GetBaseWindow()->IsMinimized()); 712 EXPECT_TRUE(panel->GetBaseWindow()->IsMinimized());
724 EXPECT_EQ(ash::STATUS_RUNNING, item1.status); 713 EXPECT_EQ(ash::STATUS_RUNNING, item1.status);
725 // Click the item again and confirm that the panel is activated. 714 // Click the item again and confirm that the panel is activated.
726 item1_controller->Clicked(click_event); 715 item1_controller->Clicked(click_event);
727 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); 716 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible());
728 EXPECT_TRUE(panel->GetBaseWindow()->IsActive()); 717 EXPECT_TRUE(panel->GetBaseWindow()->IsActive());
729 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); 718 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
730 } 719 }
731 720
732 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, 721 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, BrowserActivation) {
733 BrowserActivation) {
734 int item_count = launcher_model()->item_count(); 722 int item_count = launcher_model()->item_count();
735 723
736 // First run app. 724 // First run app.
737 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); 725 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
738 CreateShellWindow(extension1); 726 CreateShellWindow(extension1);
739 ++item_count; 727 ++item_count;
740 ASSERT_EQ(item_count, launcher_model()->item_count()); 728 ASSERT_EQ(item_count, launcher_model()->item_count());
741 const ash::LauncherItem& item1 = GetLastLauncherItem(); 729 const ash::LauncherItem& item1 = GetLastLauncherItem();
742 ash::LauncherID item_id1 = item1.id; 730 ash::LauncherID item_id1 = item1.id;
743 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); 731 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
744 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); 732 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
745 733
746 ash::wm::ActivateWindow(browser()->window()->GetNativeWindow()); 734 ash::wm::ActivateWindow(browser()->window()->GetNativeWindow());
747 EXPECT_EQ(ash::STATUS_RUNNING, 735 EXPECT_EQ(ash::STATUS_RUNNING,
748 launcher_model()->ItemByID(item_id1)->status); 736 launcher_model()->ItemByID(item_id1)->status);
749 } 737 }
750 738
751 // Test that opening an app sets the correct icon 739 // Test that opening an app sets the correct icon
752 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, SetIcon) { 740 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, SetIcon) {
753 TestShellWindowRegistryObserver test_observer(browser()->profile()); 741 TestShellWindowRegistryObserver test_observer(browser()->profile());
754 742
755 // Enable experimental APIs to allow panel creation. 743 // Enable experimental APIs to allow panel creation.
756 CommandLine::ForCurrentProcess()->AppendSwitch( 744 CommandLine::ForCurrentProcess()->AppendSwitch(
757 extensions::switches::kEnableExperimentalExtensionApis); 745 extensions::switches::kEnableExperimentalExtensionApis);
758 746
759 int base_launcher_item_count = launcher_model()->item_count(); 747 int base_launcher_item_count = launcher_model()->item_count();
760 ExtensionTestMessageListener launched_listener("Launched", false); 748 ExtensionTestMessageListener launched_listener("Launched", false);
761 ExtensionTestMessageListener completed_listener("Completed", false); 749 ExtensionTestMessageListener completed_listener("Completed", false);
762 LoadAndLaunchPlatformApp("app_icon"); 750 LoadAndLaunchPlatformApp("app_icon");
(...skipping 24 matching lines...) Expand all
787 // Icons for Apps are set by the ShellWindowLauncherController, so 775 // Icons for Apps are set by the ShellWindowLauncherController, so
788 // image_set_by_controller() should be set. 776 // image_set_by_controller() should be set.
789 EXPECT_TRUE(app_item_controller->image_set_by_controller()); 777 EXPECT_TRUE(app_item_controller->image_set_by_controller());
790 EXPECT_TRUE(panel_item_controller->image_set_by_controller()); 778 EXPECT_TRUE(panel_item_controller->image_set_by_controller());
791 // Ensure icon heights are correct (see test.js in app_icon/ test directory) 779 // Ensure icon heights are correct (see test.js in app_icon/ test directory)
792 EXPECT_EQ(48, app_item.image.height()); 780 EXPECT_EQ(48, app_item.image.height());
793 EXPECT_EQ(64, panel_item.image.height()); 781 EXPECT_EQ(64, panel_item.image.height());
794 } 782 }
795 783
796 // Test that we can launch an app with a shortcut. 784 // Test that we can launch an app with a shortcut.
797 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchPinned) { 785 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchPinned) {
798 TabStripModel* tab_strip = browser()->tab_strip_model(); 786 TabStripModel* tab_strip = browser()->tab_strip_model();
799 int tab_count = tab_strip->count(); 787 int tab_count = tab_strip->count();
800 ash::LauncherID shortcut_id = CreateShortcut("app1"); 788 ash::LauncherID shortcut_id = CreateShortcut("app1");
801 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 789 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
802 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 790 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
803 EXPECT_EQ(++tab_count, tab_strip->count()); 791 EXPECT_EQ(++tab_count, tab_strip->count());
804 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 792 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
805 WebContents* tab = tab_strip->GetActiveWebContents(); 793 WebContents* tab = tab_strip->GetActiveWebContents();
806 content::WindowedNotificationObserver close_observer( 794 content::WindowedNotificationObserver close_observer(
807 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 795 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
808 content::Source<WebContents>(tab)); 796 content::Source<WebContents>(tab));
809 browser()->tab_strip_model()->CloseSelectedTabs(); 797 browser()->tab_strip_model()->CloseSelectedTabs();
810 close_observer.Wait(); 798 close_observer.Wait();
811 EXPECT_EQ(--tab_count, tab_strip->count()); 799 EXPECT_EQ(--tab_count, tab_strip->count());
812 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 800 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
813 } 801 }
814 802
815 // Launch the app first and then create the shortcut. 803 // Launch the app first and then create the shortcut.
816 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchUnpinned) { 804 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchUnpinned) {
817 TabStripModel* tab_strip = browser()->tab_strip_model(); 805 TabStripModel* tab_strip = browser()->tab_strip_model();
818 int tab_count = tab_strip->count(); 806 int tab_count = tab_strip->count();
819 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, 807 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB,
820 NEW_FOREGROUND_TAB); 808 NEW_FOREGROUND_TAB);
821 EXPECT_EQ(++tab_count, tab_strip->count()); 809 EXPECT_EQ(++tab_count, tab_strip->count());
822 ash::LauncherID shortcut_id = CreateShortcut("app1"); 810 ash::LauncherID shortcut_id = CreateShortcut("app1");
823 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 811 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
824 WebContents* tab = tab_strip->GetActiveWebContents(); 812 WebContents* tab = tab_strip->GetActiveWebContents();
825 content::WindowedNotificationObserver close_observer( 813 content::WindowedNotificationObserver close_observer(
826 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 814 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
827 content::Source<WebContents>(tab)); 815 content::Source<WebContents>(tab));
828 browser()->tab_strip_model()->CloseSelectedTabs(); 816 browser()->tab_strip_model()->CloseSelectedTabs();
829 close_observer.Wait(); 817 close_observer.Wait();
830 EXPECT_EQ(--tab_count, tab_strip->count()); 818 EXPECT_EQ(--tab_count, tab_strip->count());
831 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 819 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
832 } 820 }
833 821
834 // Launches an app in the background and then tries to open it. This is test for 822 // Launches an app in the background and then tries to open it. This is test for
835 // a crash we had. 823 // a crash we had.
836 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchInBackground) { 824 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchInBackground) {
837 TabStripModel* tab_strip = browser()->tab_strip_model(); 825 TabStripModel* tab_strip = browser()->tab_strip_model();
838 int tab_count = tab_strip->count(); 826 int tab_count = tab_strip->count();
839 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, 827 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB,
840 NEW_BACKGROUND_TAB); 828 NEW_BACKGROUND_TAB);
841 EXPECT_EQ(++tab_count, tab_strip->count()); 829 EXPECT_EQ(++tab_count, tab_strip->count());
842 ChromeLauncherController::instance()->LaunchApp(last_loaded_extension_id_, 0); 830 ChromeLauncherController::instance()->LaunchApp(last_loaded_extension_id_, 0);
843 } 831 }
844 832
845 // Confirm that clicking a icon for an app running in one of 2 maxmized windows 833 // Confirm that clicking a icon for an app running in one of 2 maxmized windows
846 // activates the right window. 834 // activates the right window.
847 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchMaximized) { 835 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchMaximized) {
848 aura::Window* window1 = browser()->window()->GetNativeWindow(); 836 aura::Window* window1 = browser()->window()->GetNativeWindow();
849 ash::wm::MaximizeWindow(window1); 837 ash::wm::MaximizeWindow(window1);
850 content::WindowedNotificationObserver open_observer( 838 content::WindowedNotificationObserver open_observer(
851 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 839 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
852 content::NotificationService::AllSources()); 840 content::NotificationService::AllSources());
853 chrome::NewEmptyWindow(browser()->profile(), chrome::HOST_DESKTOP_TYPE_ASH); 841 chrome::NewEmptyWindow(browser()->profile(), chrome::HOST_DESKTOP_TYPE_ASH);
854 open_observer.Wait(); 842 open_observer.Wait();
855 Browser* browser2 = content::Source<Browser>(open_observer.source()).ptr(); 843 Browser* browser2 = content::Source<Browser>(open_observer.source()).ptr();
856 aura::Window* window2 = browser2->window()->GetNativeWindow(); 844 aura::Window* window2 = browser2->window()->GetNativeWindow();
857 TabStripModel* tab_strip = browser2->tab_strip_model(); 845 TabStripModel* tab_strip = browser2->tab_strip_model();
858 int tab_count = tab_strip->count(); 846 int tab_count = tab_strip->count();
859 ash::wm::MaximizeWindow(window2); 847 ash::wm::MaximizeWindow(window2);
860 848
861 ash::LauncherID shortcut_id = CreateShortcut("app1"); 849 ash::LauncherID shortcut_id = CreateShortcut("app1");
862 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 850 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
863 EXPECT_EQ(++tab_count, tab_strip->count()); 851 EXPECT_EQ(++tab_count, tab_strip->count());
864 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 852 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
865 853
866 window1->Show(); 854 window1->Show();
867 ash::wm::ActivateWindow(window1); 855 ash::wm::ActivateWindow(window1);
868 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut_id)).status); 856 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut_id)).status);
869 857
870 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 858 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
871 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 859 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
872 } 860 }
873 861
874 // 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.
875 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, ActivateApp) { 863 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivateApp) {
876 TabStripModel* tab_strip = browser()->tab_strip_model(); 864 TabStripModel* tab_strip = browser()->tab_strip_model();
877 int tab_count = tab_strip->count(); 865 int tab_count = tab_strip->count();
878 const Extension* extension = 866 const Extension* extension =
879 LoadExtension(test_data_dir_.AppendASCII("app1")); 867 LoadExtension(test_data_dir_.AppendASCII("app1"));
880 868
881 ChromeLauncherController::instance()->ActivateApp(extension->id(), 0); 869 ChromeLauncherController::instance()->ActivateApp(extension->id(), 0);
882 EXPECT_EQ(++tab_count, tab_strip->count()); 870 EXPECT_EQ(++tab_count, tab_strip->count());
883 ChromeLauncherController::instance()->ActivateApp(extension->id(), 0); 871 ChromeLauncherController::instance()->ActivateApp(extension->id(), 0);
884 EXPECT_EQ(tab_count, tab_strip->count()); 872 EXPECT_EQ(tab_count, tab_strip->count());
885 } 873 }
886 874
887 // Launching the same app multiple times should launch a copy for each call. 875 // Launching the same app multiple times should launch a copy for each call.
888 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchApp) { 876 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchApp) {
889 TabStripModel* tab_strip = browser()->tab_strip_model(); 877 TabStripModel* tab_strip = browser()->tab_strip_model();
890 int tab_count = tab_strip->count(); 878 int tab_count = tab_strip->count();
891 const Extension* extension = 879 const Extension* extension =
892 LoadExtension(test_data_dir_.AppendASCII("app1")); 880 LoadExtension(test_data_dir_.AppendASCII("app1"));
893 881
894 ChromeLauncherController::instance()->LaunchApp(extension->id(), 0); 882 ChromeLauncherController::instance()->LaunchApp(extension->id(), 0);
895 EXPECT_EQ(++tab_count, tab_strip->count()); 883 EXPECT_EQ(++tab_count, tab_strip->count());
896 ChromeLauncherController::instance()->LaunchApp(extension->id(), 0); 884 ChromeLauncherController::instance()->LaunchApp(extension->id(), 0);
897 EXPECT_EQ(++tab_count, tab_strip->count()); 885 EXPECT_EQ(++tab_count, tab_strip->count());
898 } 886 }
899 887
900 // Launch 2 apps and toggle which is active. 888 // Launch 2 apps and toggle which is active.
901 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, MultipleApps) { 889 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleApps) {
902 int item_count = model_->item_count(); 890 int item_count = model_->item_count();
903 TabStripModel* tab_strip = browser()->tab_strip_model(); 891 TabStripModel* tab_strip = browser()->tab_strip_model();
904 int tab_count = tab_strip->count(); 892 int tab_count = tab_strip->count();
905 ash::LauncherID shortcut1 = CreateShortcut("app1"); 893 ash::LauncherID shortcut1 = CreateShortcut("app1");
906 EXPECT_EQ(++item_count, model_->item_count()); 894 EXPECT_EQ(++item_count, model_->item_count());
907 ash::LauncherID shortcut2 = CreateShortcut("app2"); 895 ash::LauncherID shortcut2 = CreateShortcut("app2");
908 EXPECT_EQ(++item_count, model_->item_count()); 896 EXPECT_EQ(++item_count, model_->item_count());
909 897
910 // Launch first app. 898 // Launch first app.
911 ActivateLauncherItem(model_->ItemIndexByID(shortcut1)); 899 ActivateLauncherItem(model_->ItemIndexByID(shortcut1));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 // And second again. This time the second tab should become active. 936 // And second again. This time the second tab should become active.
949 ActivateLauncherItem(model_->ItemIndexByID(shortcut2)); 937 ActivateLauncherItem(model_->ItemIndexByID(shortcut2));
950 EXPECT_EQ(tab_count, tab_strip->count()); 938 EXPECT_EQ(tab_count, tab_strip->count());
951 EXPECT_EQ(tab_strip->GetActiveWebContents(), tab2); 939 EXPECT_EQ(tab_strip->GetActiveWebContents(), tab2);
952 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status); 940 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status);
953 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status); 941 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status);
954 } 942 }
955 943
956 // 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
957 // correct running state. 945 // correct running state.
958 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, Navigation) { 946 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, Navigation) {
959 ash::LauncherID shortcut_id = CreateShortcut("app1"); 947 ash::LauncherID shortcut_id = CreateShortcut("app1");
960 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 948 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
961 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 949 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
962 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 950 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
963 951
964 // Navigate away. 952 // Navigate away.
965 ui_test_utils::NavigateToURL( 953 ui_test_utils::NavigateToURL(
966 browser(), GURL("http://www.example.com/path0/bar.html")); 954 browser(), GURL("http://www.example.com/path0/bar.html"));
967 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 955 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
968 956
969 // Navigate back. 957 // Navigate back.
970 ui_test_utils::NavigateToURL( 958 ui_test_utils::NavigateToURL(
971 browser(), GURL("http://www.example.com/path1/foo.html")); 959 browser(), GURL("http://www.example.com/path1/foo.html"));
972 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 960 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
973 } 961 }
974 962
975 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, MultipleOwnedTabs) { 963 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleOwnedTabs) {
976 TabStripModel* tab_strip = browser()->tab_strip_model(); 964 TabStripModel* tab_strip = browser()->tab_strip_model();
977 int tab_count = tab_strip->count(); 965 int tab_count = tab_strip->count();
978 ash::LauncherID shortcut_id = CreateShortcut("app1"); 966 ash::LauncherID shortcut_id = CreateShortcut("app1");
979 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 967 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
980 EXPECT_EQ(++tab_count, tab_strip->count()); 968 EXPECT_EQ(++tab_count, tab_strip->count());
981 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 969 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
982 WebContents* first_tab = tab_strip->GetActiveWebContents(); 970 WebContents* first_tab = tab_strip->GetActiveWebContents();
983 971
984 // Create new tab owned by app. 972 // Create new tab owned by app.
985 ui_test_utils::NavigateToURLWithDisposition( 973 ui_test_utils::NavigateToURLWithDisposition(
(...skipping 14 matching lines...) Expand all
1000 EXPECT_EQ(++tab_count, tab_strip->count()); 988 EXPECT_EQ(++tab_count, tab_strip->count());
1001 // No longer active. 989 // No longer active.
1002 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); 990 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status);
1003 991
1004 // Activating app makes first tab active again. 992 // Activating app makes first tab active again.
1005 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 993 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
1006 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 994 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
1007 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab); 995 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab);
1008 } 996 }
1009 997
1010 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, RefocusFilter) { 998 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilter) {
1011 ChromeLauncherController* controller =
1012 static_cast<ChromeLauncherController*>(launcher_->delegate());
1013 TabStripModel* tab_strip = browser()->tab_strip_model(); 999 TabStripModel* tab_strip = browser()->tab_strip_model();
1014 int tab_count = tab_strip->count(); 1000 int tab_count = tab_strip->count();
1015 ash::LauncherID shortcut_id = CreateShortcut("app1"); 1001 ash::LauncherID shortcut_id = CreateShortcut("app1");
1016 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 1002 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
1017 EXPECT_EQ(++tab_count, tab_strip->count()); 1003 EXPECT_EQ(++tab_count, tab_strip->count());
1018 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 1004 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
1019 WebContents* first_tab = tab_strip->GetActiveWebContents(); 1005 WebContents* first_tab = tab_strip->GetActiveWebContents();
1020 1006
1021 controller->SetRefocusURLPatternForTest( 1007 controller_->SetRefocusURLPatternForTest(
1022 shortcut_id, GURL("http://www.example.com/path1/*")); 1008 shortcut_id, GURL("http://www.example.com/path1/*"));
1023 // Create new tab owned by app. 1009 // Create new tab owned by app.
1024 ui_test_utils::NavigateToURLWithDisposition( 1010 ui_test_utils::NavigateToURLWithDisposition(
1025 browser(), 1011 browser(),
1026 GURL("http://www.example.com/path2/bar.html"), 1012 GURL("http://www.example.com/path2/bar.html"),
1027 NEW_FOREGROUND_TAB, 1013 NEW_FOREGROUND_TAB,
1028 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1014 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1029 EXPECT_EQ(++tab_count, tab_strip->count()); 1015 EXPECT_EQ(++tab_count, tab_strip->count());
1030 // Confirm app is still active. 1016 // Confirm app is still active.
1031 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 1017 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
1032 1018
1033 // Create new tab not owned by app. 1019 // Create new tab not owned by app.
1034 ui_test_utils::NavigateToURLWithDisposition( 1020 ui_test_utils::NavigateToURLWithDisposition(
1035 browser(), 1021 browser(),
1036 GURL("http://www.example.com/path3/foo.html"), 1022 GURL("http://www.example.com/path3/foo.html"),
1037 NEW_FOREGROUND_TAB, 1023 NEW_FOREGROUND_TAB,
1038 0); 1024 0);
1039 EXPECT_EQ(++tab_count, tab_strip->count()); 1025 EXPECT_EQ(++tab_count, tab_strip->count());
1040 // No longer active. 1026 // No longer active.
1041 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); 1027 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status);
1042 1028
1043 // 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
1044 // in its refocus url path. 1030 // in its refocus url path.
1045 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 1031 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
1046 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 1032 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
1047 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab); 1033 EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab);
1048 } 1034 }
1049 1035
1050 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, RefocusFilterLaunch) { 1036 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilterLaunch) {
1051 ChromeLauncherController* controller =
1052 static_cast<ChromeLauncherController*>(launcher_->delegate());
1053 TabStripModel* tab_strip = browser()->tab_strip_model(); 1037 TabStripModel* tab_strip = browser()->tab_strip_model();
1054 int tab_count = tab_strip->count(); 1038 int tab_count = tab_strip->count();
1055 ash::LauncherID shortcut_id = CreateShortcut("app1"); 1039 ash::LauncherID shortcut_id = CreateShortcut("app1");
1056 controller->SetRefocusURLPatternForTest( 1040 controller_->SetRefocusURLPatternForTest(
1057 shortcut_id, GURL("http://www.example.com/path1/*")); 1041 shortcut_id, GURL("http://www.example.com/path1/*"));
1058 1042
1059 // Create new tab. 1043 // Create new tab.
1060 ui_test_utils::NavigateToURLWithDisposition( 1044 ui_test_utils::NavigateToURLWithDisposition(
1061 browser(), 1045 browser(),
1062 GURL("http://www.example2.com/path2/bar.html"), 1046 GURL("http://www.example2.com/path2/bar.html"),
1063 NEW_FOREGROUND_TAB, 1047 NEW_FOREGROUND_TAB,
1064 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1048 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1065 EXPECT_EQ(++tab_count, tab_strip->count()); 1049 EXPECT_EQ(++tab_count, tab_strip->count());
1066 WebContents* first_tab = tab_strip->GetActiveWebContents(); 1050 WebContents* first_tab = tab_strip->GetActiveWebContents();
1067 // Confirm app is not active. 1051 // Confirm app is not active.
1068 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); 1052 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status);
1069 1053
1070 // Activating app should launch new tab, because second tab isn't 1054 // Activating app should launch new tab, because second tab isn't
1071 // in its refocus url path. 1055 // in its refocus url path.
1072 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); 1056 ActivateLauncherItem(model_->ItemIndexByID(shortcut_id));
1073 EXPECT_EQ(++tab_count, tab_strip->count()); 1057 EXPECT_EQ(++tab_count, tab_strip->count());
1074 WebContents* second_tab = tab_strip->GetActiveWebContents(); 1058 WebContents* second_tab = tab_strip->GetActiveWebContents();
1075 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 1059 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
1076 EXPECT_NE(first_tab, second_tab); 1060 EXPECT_NE(first_tab, second_tab);
1077 EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab); 1061 EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab);
1078 } 1062 }
1079 1063
1080 // Check the launcher activation state for applications and browser. 1064 // Check the launcher activation state for applications and browser.
1081 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, ActivationStateCheck) { 1065 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivationStateCheck) {
1082 ChromeLauncherController* controller =
1083 static_cast<ChromeLauncherController*>(launcher_->delegate());
1084 TabStripModel* tab_strip = browser()->tab_strip_model(); 1066 TabStripModel* tab_strip = browser()->tab_strip_model();
1085 // Get the browser item index 1067 // Get the browser item index
1086 int browser_index = ash::launcher::GetBrowserItemIndex(*controller->model()); 1068 int browser_index = ash::launcher::GetBrowserItemIndex(*controller_->model());
1087 EXPECT_TRUE(browser_index >= 0); 1069 EXPECT_TRUE(browser_index >= 0);
1088 1070
1089 // Even though we are just comming up, the browser should be active. 1071 // Even though we are just comming up, the browser should be active.
1090 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status); 1072 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
1091 1073
1092 ash::LauncherID shortcut_id = CreateShortcut("app1"); 1074 ash::LauncherID shortcut_id = CreateShortcut("app1");
1093 controller->SetRefocusURLPatternForTest( 1075 controller_->SetRefocusURLPatternForTest(
1094 shortcut_id, GURL("http://www.example.com/path1/*")); 1076 shortcut_id, GURL("http://www.example.com/path1/*"));
1095 1077
1096 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); 1078 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status);
1097 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status); 1079 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
1098 1080
1099 // Create new tab which would be the running app. 1081 // Create new tab which would be the running app.
1100 ui_test_utils::NavigateToURLWithDisposition( 1082 ui_test_utils::NavigateToURLWithDisposition(
1101 browser(), 1083 browser(),
1102 GURL("http://www.example.com/path1/bar.html"), 1084 GURL("http://www.example.com/path1/bar.html"),
1103 NEW_FOREGROUND_TAB, 1085 NEW_FOREGROUND_TAB,
(...skipping 12 matching lines...) Expand all
1116 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status); 1098 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
1117 1099
1118 ash::wm::DeactivateWindow(browser()->window()->GetNativeWindow()); 1100 ash::wm::DeactivateWindow(browser()->window()->GetNativeWindow());
1119 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); 1101 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status);
1120 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[browser_index].status); 1102 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[browser_index].status);
1121 } 1103 }
1122 1104
1123 // Check that the launcher activation state for a V1 application stays closed 1105 // Check that the launcher activation state for a V1 application stays closed
1124 // even after an asynchronous browser event comes in after the tab got 1106 // even after an asynchronous browser event comes in after the tab got
1125 // destroyed. 1107 // destroyed.
1126 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, 1108 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, AsyncActivationStateCheck) {
1127 AsyncActivationStateCheck) {
1128 ChromeLauncherController* controller =
1129 static_cast<ChromeLauncherController*>(launcher_->delegate());
1130 TabStripModel* tab_strip = browser()->tab_strip_model(); 1109 TabStripModel* tab_strip = browser()->tab_strip_model();
1131 1110
1132 ash::LauncherID shortcut_id = CreateShortcut("app1"); 1111 ash::LauncherID shortcut_id = CreateShortcut("app1");
1133 controller->SetRefocusURLPatternForTest( 1112 controller_->SetRefocusURLPatternForTest(
1134 shortcut_id, GURL("http://www.example.com/path1/*")); 1113 shortcut_id, GURL("http://www.example.com/path1/*"));
1135 1114
1136 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); 1115 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status);
1137 1116
1138 // Create new tab which would be the running app. 1117 // Create new tab which would be the running app.
1139 ui_test_utils::NavigateToURLWithDisposition( 1118 ui_test_utils::NavigateToURLWithDisposition(
1140 browser(), 1119 browser(),
1141 GURL("http://www.example.com/path1/bar.html"), 1120 GURL("http://www.example.com/path1/bar.html"),
1142 NEW_FOREGROUND_TAB, 1121 NEW_FOREGROUND_TAB,
1143 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1122 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1144 1123
1145 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); 1124 EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status);
1146 // To address the issue of crbug.com/174050, the tab we are about to close 1125 // To address the issue of crbug.com/174050, the tab we are about to close
1147 // has to be active. 1126 // has to be active.
1148 tab_strip->ActivateTabAt(1, false); 1127 tab_strip->ActivateTabAt(1, false);
1149 EXPECT_EQ(1, tab_strip->active_index()); 1128 EXPECT_EQ(1, tab_strip->active_index());
1150 1129
1151 // Close the web contents. 1130 // Close the web contents.
1152 tab_strip->CloseWebContentsAt(1, TabStripModel::CLOSE_NONE); 1131 tab_strip->CloseWebContentsAt(1, TabStripModel::CLOSE_NONE);
1153 // The status should now be set to closed. 1132 // The status should now be set to closed.
1154 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); 1133 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status);
1155 } 1134 }
1156 1135
1157 // Checks that a windowed application does not add an item to the browser list. 1136 // Checks that a windowed application does not add an item to the browser list.
1158 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTestNoDefaultBrowser, 1137 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser,
1159 WindowedAppDoesNotAddToBrowser) { 1138 WindowedAppDoesNotAddToBrowser) {
1160 // Get the number of items in the browser menu. 1139 // Get the number of items in the browser menu.
1161 size_t items = NumberOfDetectedLauncherBrowsers(false); 1140 size_t items = NumberOfDetectedLauncherBrowsers(false);
1162 size_t running_browser = chrome::GetTotalBrowserCount(); 1141 size_t running_browser = chrome::GetTotalBrowserCount();
1163 EXPECT_EQ(0u, items); 1142 EXPECT_EQ(0u, items);
1164 EXPECT_EQ(0u, running_browser); 1143 EXPECT_EQ(0u, running_browser);
1165 1144
1166 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_WINDOW, NEW_WINDOW); 1145 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_WINDOW, NEW_WINDOW);
1167 1146
1168 // No new browser should get detected, even though one more is running. 1147 // No new browser should get detected, even though one more is running.
1169 EXPECT_EQ(0u, NumberOfDetectedLauncherBrowsers(false)); 1148 EXPECT_EQ(0u, NumberOfDetectedLauncherBrowsers(false));
1170 EXPECT_EQ(++running_browser, chrome::GetTotalBrowserCount()); 1149 EXPECT_EQ(++running_browser, chrome::GetTotalBrowserCount());
1171 1150
1172 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, NEW_WINDOW); 1151 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, NEW_WINDOW);
1173 1152
1174 // A new browser should get detected and one more should be running. 1153 // A new browser should get detected and one more should be running.
1175 EXPECT_EQ(NumberOfDetectedLauncherBrowsers(false), 1u); 1154 EXPECT_EQ(NumberOfDetectedLauncherBrowsers(false), 1u);
1176 EXPECT_EQ(++running_browser, chrome::GetTotalBrowserCount()); 1155 EXPECT_EQ(++running_browser, chrome::GetTotalBrowserCount());
1177 } 1156 }
1178 1157
1179 // Checks the functionality to enumerate all browsers vs. all tabs. 1158 // Checks the functionality to enumerate all browsers vs. all tabs.
1180 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTestNoDefaultBrowser, 1159 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser,
1181 EnumerateALlBrowsersAndTabs) { 1160 EnumerateALlBrowsersAndTabs) {
1182 // Create at least one browser. 1161 // Create at least one browser.
1183 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, NEW_WINDOW); 1162 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, NEW_WINDOW);
1184 size_t browsers = NumberOfDetectedLauncherBrowsers(false); 1163 size_t browsers = NumberOfDetectedLauncherBrowsers(false);
1185 size_t tabs = NumberOfDetectedLauncherBrowsers(true); 1164 size_t tabs = NumberOfDetectedLauncherBrowsers(true);
1186 1165
1187 // Create a second browser. 1166 // Create a second browser.
1188 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, NEW_WINDOW); 1167 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, NEW_WINDOW);
1189 1168
1190 EXPECT_EQ(++browsers, NumberOfDetectedLauncherBrowsers(false)); 1169 EXPECT_EQ(++browsers, NumberOfDetectedLauncherBrowsers(false));
1191 EXPECT_EQ(++tabs, NumberOfDetectedLauncherBrowsers(true)); 1170 EXPECT_EQ(++tabs, NumberOfDetectedLauncherBrowsers(true));
1192 1171
1193 // Create only a tab. 1172 // Create only a tab.
1194 LoadAndLaunchExtension("app1", 1173 LoadAndLaunchExtension("app1",
1195 extension_misc::LAUNCH_TAB, 1174 extension_misc::LAUNCH_TAB,
1196 NEW_FOREGROUND_TAB); 1175 NEW_FOREGROUND_TAB);
1197 1176
1198 EXPECT_EQ(browsers, NumberOfDetectedLauncherBrowsers(false)); 1177 EXPECT_EQ(browsers, NumberOfDetectedLauncherBrowsers(false));
1199 EXPECT_EQ(++tabs, NumberOfDetectedLauncherBrowsers(true)); 1178 EXPECT_EQ(++tabs, NumberOfDetectedLauncherBrowsers(true));
1200 } 1179 }
1201 1180
1202 // Check that the keyboard activation of a launcher item tabs properly through 1181 // Check that the keyboard activation of a launcher item tabs properly through
1203 // the items at hand. 1182 // the items at hand.
1204 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, AltNumberTabsTabbing) { 1183 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, AltNumberTabsTabbing) {
1205 TabStripModel* tab_strip = browser()->tab_strip_model(); 1184 TabStripModel* tab_strip = browser()->tab_strip_model();
1206 ChromeLauncherController* controller =
1207 static_cast<ChromeLauncherController*>(launcher_->delegate());
1208 1185
1209 ash::LauncherID shortcut_id = CreateShortcut("app"); 1186 ash::LauncherID shortcut_id = CreateShortcut("app");
1210 controller->SetRefocusURLPatternForTest( 1187 controller_->SetRefocusURLPatternForTest(
1211 shortcut_id, GURL("http://www.example.com/path/*")); 1188 shortcut_id, GURL("http://www.example.com/path/*"));
1212 std::string url = "http://www.example.com/path/bla"; 1189 std::string url = "http://www.example.com/path/bla";
1213 1190
1214 int shortcut_index = model_->ItemIndexByID(shortcut_id); 1191 int shortcut_index = model_->ItemIndexByID(shortcut_id);
1215 1192
1216 // Create an application handled browser tab. 1193 // Create an application handled browser tab.
1217 ui_test_utils::NavigateToURLWithDisposition( 1194 ui_test_utils::NavigateToURLWithDisposition(
1218 browser(), 1195 browser(),
1219 GURL(url), 1196 GURL(url),
1220 NEW_FOREGROUND_TAB, 1197 NEW_FOREGROUND_TAB,
(...skipping 29 matching lines...) Expand all
1250 1227
1251 EXPECT_EQ(content2, browser()->tab_strip_model()->GetActiveWebContents()); 1228 EXPECT_EQ(content2, browser()->tab_strip_model()->GetActiveWebContents());
1252 ActivateLauncherItem(shortcut_index); 1229 ActivateLauncherItem(shortcut_index);
1253 EXPECT_EQ(content1, browser()->tab_strip_model()->GetActiveWebContents()); 1230 EXPECT_EQ(content1, browser()->tab_strip_model()->GetActiveWebContents());
1254 ActivateLauncherItem(shortcut_index); 1231 ActivateLauncherItem(shortcut_index);
1255 EXPECT_EQ(content2, browser()->tab_strip_model()->GetActiveWebContents()); 1232 EXPECT_EQ(content2, browser()->tab_strip_model()->GetActiveWebContents());
1256 } 1233 }
1257 1234
1258 // Check that the keyboard activation of a launcher item tabs properly through 1235 // Check that the keyboard activation of a launcher item tabs properly through
1259 // the items at hand. 1236 // the items at hand.
1260 IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, 1237 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest,
1261 AltNumberAppsTabbing) { 1238 AltNumberAppsTabbing) {
1262 // First run app. 1239 // First run app.
1263 const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); 1240 const Extension* extension1 = LoadAndLaunchPlatformApp("launch");
1264 ui::BaseWindow* window1 = CreateShellWindow(extension1)->GetBaseWindow(); 1241 ui::BaseWindow* window1 = CreateShellWindow(extension1)->GetBaseWindow();
1265 const ash::LauncherItem& item1 = GetLastLauncherItem(); 1242 const ash::LauncherItem& item1 = GetLastLauncherItem();
1266 ash::LauncherID app_id = item1.id; 1243 ash::LauncherID app_id = item1.id;
1267 int app_index = launcher_model()->ItemIndexByID(app_id); 1244 int app_index = launcher_model()->ItemIndexByID(app_id);
1268 1245
1269 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); 1246 EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type);
1270 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); 1247 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
(...skipping 12 matching lines...) Expand all
1283 ui::BaseWindow* window1a = CreateShellWindow(extension1)->GetBaseWindow(); 1260 ui::BaseWindow* window1a = CreateShellWindow(extension1)->GetBaseWindow();
1284 1261
1285 EXPECT_TRUE(window1a->IsActive()); 1262 EXPECT_TRUE(window1a->IsActive());
1286 EXPECT_FALSE(window1->IsActive()); 1263 EXPECT_FALSE(window1->IsActive());
1287 ActivateLauncherItem(app_index); 1264 ActivateLauncherItem(app_index);
1288 EXPECT_TRUE(window1->IsActive()); 1265 EXPECT_TRUE(window1->IsActive());
1289 ActivateLauncherItem(app_index); 1266 ActivateLauncherItem(app_index);
1290 EXPECT_TRUE(window1a->IsActive()); 1267 EXPECT_TRUE(window1a->IsActive());
1291 } 1268 }
1292 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
1293 // Checks that the browser Alt "tabbing" is properly done. 1322 // Checks that the browser Alt "tabbing" is properly done.
1294 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTestNoDefaultBrowser, 1323 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser,
1295 AltNumberBrowserTabbing) { 1324 AltNumberBrowserTabbing) {
1296 // Get the number of items in the browser menu. 1325 // Get the number of items in the browser menu.
1297 EXPECT_EQ(0u, chrome::GetTotalBrowserCount()); 1326 EXPECT_EQ(0u, chrome::GetTotalBrowserCount());
1298 // The first activation should create a browser. 1327 // The first activation should create a browser.
1299 launcher_->ActivateLauncherItem(0); 1328 launcher_->ActivateLauncherItem(0);
1300 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); 1329 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1301 // A second activation should not create a new instance. 1330 // A second activation should not create a new instance.
1302 launcher_->ActivateLauncherItem(0); 1331 launcher_->ActivateLauncherItem(0);
1303 Browser* browser1 = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); 1332 Browser* browser1 = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow());
1304 EXPECT_TRUE(browser1); 1333 EXPECT_TRUE(browser1);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 EXPECT_NE(window1, ash::wm::GetActiveWindow()); 1369 EXPECT_NE(window1, ash::wm::GetActiveWindow());
1341 EXPECT_NE(window2, ash::wm::GetActiveWindow()); 1370 EXPECT_NE(window2, ash::wm::GetActiveWindow());
1342 1371
1343 // After activation our browser should be active again. 1372 // After activation our browser should be active again.
1344 launcher_->ActivateLauncherItem(0); 1373 launcher_->ActivateLauncherItem(0);
1345 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); 1374 EXPECT_EQ(window1, ash::wm::GetActiveWindow());
1346 } 1375 }
1347 1376
1348 // Checks that after a session restore, we do not start applications on an 1377 // Checks that after a session restore, we do not start applications on an
1349 // activation. 1378 // activation.
1350 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, 1379 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivateAfterSessionRestore) {
1351 ActivateAfterSessionRestore) {
1352 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); 1380 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1353 1381
1354 // Create a known application. 1382 // Create a known application.
1355 ChromeLauncherController* controller =
1356 static_cast<ChromeLauncherController*>(launcher_->delegate());
1357 ash::LauncherID shortcut_id = CreateShortcut("app1"); 1383 ash::LauncherID shortcut_id = CreateShortcut("app1");
1358 1384
1359 // Create a new browser - without activating it - and load an "app" into it. 1385 // Create a new browser - without activating it - and load an "app" into it.
1360 Browser::CreateParams params = 1386 Browser::CreateParams params =
1361 Browser::CreateParams(profile(), chrome::GetActiveDesktop()); 1387 Browser::CreateParams(profile(), chrome::GetActiveDesktop());
1362 params.initial_show_state = ui::SHOW_STATE_INACTIVE; 1388 params.initial_show_state = ui::SHOW_STATE_INACTIVE;
1363 Browser* browser2 = new Browser(params); 1389 Browser* browser2 = new Browser(params);
1364 controller->SetRefocusURLPatternForTest( 1390 controller_->SetRefocusURLPatternForTest(
1365 shortcut_id, GURL("http://www.example.com/path/*")); 1391 shortcut_id, GURL("http://www.example.com/path/*"));
1366 std::string url = "http://www.example.com/path/bla"; 1392 std::string url = "http://www.example.com/path/bla";
1367 ui_test_utils::NavigateToURLWithDisposition( 1393 ui_test_utils::NavigateToURLWithDisposition(
1368 browser2, 1394 browser2,
1369 GURL(url), 1395 GURL(url),
1370 NEW_FOREGROUND_TAB, 1396 NEW_FOREGROUND_TAB,
1371 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1397 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1372 1398
1373 // Remember the number of tabs for each browser. 1399 // Remember the number of tabs for each browser.
1374 TabStripModel* tab_strip = browser()->tab_strip_model(); 1400 TabStripModel* tab_strip = browser()->tab_strip_model();
1375 int tab_count1 = tab_strip->count(); 1401 int tab_count1 = tab_strip->count();
1376 TabStripModel* tab_strip2 = browser2->tab_strip_model(); 1402 TabStripModel* tab_strip2 = browser2->tab_strip_model();
1377 int tab_count2 = tab_strip2->count(); 1403 int tab_count2 = tab_strip2->count();
1378 1404
1379 // Check that we have two browsers and the inactive browser remained inactive. 1405 // Check that we have two browsers and the inactive browser remained inactive.
1380 EXPECT_EQ(2u, chrome::GetTotalBrowserCount()); 1406 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
1381 EXPECT_EQ(chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()), 1407 EXPECT_EQ(chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()),
1382 browser()); 1408 browser());
1383 // Check that the LRU browser list does only contain the original browser. 1409 // Check that the LRU browser list does only contain the original browser.
1384 BrowserList* ash_browser_list = 1410 BrowserList* ash_browser_list =
1385 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); 1411 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
1386 BrowserList::const_reverse_iterator it = 1412 BrowserList::const_reverse_iterator it =
1387 ash_browser_list->begin_last_active(); 1413 ash_browser_list->begin_last_active();
1388 EXPECT_EQ(*it, browser()); 1414 EXPECT_EQ(*it, browser());
1389 ++it; 1415 ++it;
1390 EXPECT_EQ(it, ash_browser_list->end_last_active()); 1416 EXPECT_EQ(it, ash_browser_list->end_last_active());
1391 1417
1392 // Now request to either activate an existing app or create a new one. 1418 // Now request to either activate an existing app or create a new one.
1393 controller->ItemSelected(*model_->ItemByID(shortcut_id), 1419 controller_->ItemSelected(*model_->ItemByID(shortcut_id),
1394 ui::KeyEvent(ui::ET_KEY_RELEASED, 1420 ui::KeyEvent(ui::ET_KEY_RELEASED,
1395 ui::VKEY_RETURN, 1421 ui::VKEY_RETURN,
1396 0, 1422 0,
1397 false)); 1423 false));
1398 1424
1399 // Check that we have set focus on the existing application and nothing new 1425 // Check that we have set focus on the existing application and nothing new
1400 // was created. 1426 // was created.
1401 EXPECT_EQ(2u, chrome::GetTotalBrowserCount()); 1427 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
1402 EXPECT_EQ(tab_count1, tab_strip->count()); 1428 EXPECT_EQ(tab_count1, tab_strip->count());
1403 EXPECT_EQ(tab_count2, tab_strip2->count()); 1429 EXPECT_EQ(tab_count2, tab_strip2->count());
1404 EXPECT_EQ(chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()), 1430 EXPECT_EQ(chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()),
1405 browser2); 1431 browser2);
1406 } 1432 }
1407 1433
1408 // Do various drag and drop interaction tests between the application list and 1434 // Do various drag and drop interaction tests between the application list and
1409 // the launcher. 1435 // the launcher.
1410 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, DragAndDrop) { 1436 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, DragAndDrop) {
1411 // Get a number of interfaces we need. 1437 // Get a number of interfaces we need.
1412 aura::test::EventGenerator generator( 1438 aura::test::EventGenerator generator(
1413 ash::Shell::GetPrimaryRootWindow(), gfx::Point()); 1439 ash::Shell::GetPrimaryRootWindow(), gfx::Point());
1414 ash::test::LauncherViewTestAPI test(launcher_->GetLauncherViewForTest()); 1440 ash::test::LauncherViewTestAPI test(launcher_->GetLauncherViewForTest());
1415 AppListService* service = AppListService::Get(); 1441 AppListService* service = AppListService::Get();
1416 1442
1417 // There should be two items in our launcher by this time. 1443 // There should be two items in our launcher by this time.
1418 EXPECT_EQ(2, model_->item_count()); 1444 EXPECT_EQ(2, model_->item_count());
1419 EXPECT_FALSE(service->IsAppListVisible()); 1445 EXPECT_FALSE(service->IsAppListVisible());
1420 1446
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 base::MessageLoop::current()->RunUntilIdle(); 1531 base::MessageLoop::current()->RunUntilIdle();
1506 EXPECT_EQ(3, model_->item_count()); // No new item got added. 1532 EXPECT_EQ(3, model_->item_count()); // No new item got added.
1507 EXPECT_TRUE(grid_view->forward_events_to_drag_and_drop_host_for_test()); 1533 EXPECT_TRUE(grid_view->forward_events_to_drag_and_drop_host_for_test());
1508 generator.ReleaseLeftButton(); 1534 generator.ReleaseLeftButton();
1509 base::MessageLoop::current()->RunUntilIdle(); 1535 base::MessageLoop::current()->RunUntilIdle();
1510 EXPECT_FALSE(grid_view->forward_events_to_drag_and_drop_host_for_test()); 1536 EXPECT_FALSE(grid_view->forward_events_to_drag_and_drop_host_for_test());
1511 EXPECT_EQ(3, model_->item_count()); // And it remains that way. 1537 EXPECT_EQ(3, model_->item_count()); // And it remains that way.
1512 } 1538 }
1513 1539
1514 // Check that clicking on an app launcher item launches a new browser. 1540 // Check that clicking on an app launcher item launches a new browser.
1515 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, ClickItem) { 1541 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ClickItem) {
1516 // Get a number of interfaces we need. 1542 // Get a number of interfaces we need.
1517 aura::test::EventGenerator generator( 1543 aura::test::EventGenerator generator(
1518 ash::Shell::GetPrimaryRootWindow(), gfx::Point()); 1544 ash::Shell::GetPrimaryRootWindow(), gfx::Point());
1519 ash::test::LauncherViewTestAPI test(launcher_->GetLauncherViewForTest()); 1545 ash::test::LauncherViewTestAPI test(launcher_->GetLauncherViewForTest());
1520 AppListService* service = AppListService::Get(); 1546 AppListService* service = AppListService::Get();
1521 // There should be two items in our launcher by this time. 1547 // There should be two items in our launcher by this time.
1522 EXPECT_EQ(2, model_->item_count()); 1548 EXPECT_EQ(2, model_->item_count());
1523 EXPECT_FALSE(service->IsAppListVisible()); 1549 EXPECT_FALSE(service->IsAppListVisible());
1524 1550
1525 // Open the app list menu and check that the drag and drop host was set. 1551 // Open the app list menu and check that the drag and drop host was set.
(...skipping 15 matching lines...) Expand all
1541 TabStripModel* tab_strip = browser()->tab_strip_model(); 1567 TabStripModel* tab_strip = browser()->tab_strip_model();
1542 int tab_count = tab_strip->count(); 1568 int tab_count = tab_strip->count();
1543 generator.MoveMouseTo(bounds_grid_1.CenterPoint().x(), 1569 generator.MoveMouseTo(bounds_grid_1.CenterPoint().x(),
1544 bounds_grid_1.CenterPoint().y()); 1570 bounds_grid_1.CenterPoint().y());
1545 generator.ClickLeftButton(); 1571 generator.ClickLeftButton();
1546 base::MessageLoop::current()->RunUntilIdle(); 1572 base::MessageLoop::current()->RunUntilIdle();
1547 EXPECT_EQ(tab_count + 1, tab_strip->count()); 1573 EXPECT_EQ(tab_count + 1, tab_strip->count());
1548 } 1574 }
1549 1575
1550 // Check LauncherItemController of Browser Shortcut functionality. 1576 // Check LauncherItemController of Browser Shortcut functionality.
1551 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTestNoDefaultBrowser, 1577 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser,
1552 BrowserShortcutLauncherItemController) { 1578 BrowserShortcutLauncherItemController) {
1553 ChromeLauncherControllerPerApp* controller =
1554 static_cast<ChromeLauncherControllerPerApp*>(launcher_->delegate());
1555 LauncherItemController* item_controller = 1579 LauncherItemController* item_controller =
1556 controller->GetBrowserShortcutLauncherItemController(); 1580 controller_->GetBrowserShortcutLauncherItemController();
1557 1581
1558 // Get the number of browsers. 1582 // Get the number of browsers.
1559 size_t running_browser = chrome::GetTotalBrowserCount(); 1583 size_t running_browser = chrome::GetTotalBrowserCount();
1560 EXPECT_EQ(0u, running_browser); 1584 EXPECT_EQ(0u, running_browser);
1561 EXPECT_FALSE(item_controller->IsOpen()); 1585 EXPECT_FALSE(item_controller->IsOpen());
1562 1586
1563 // Activate. This creates new browser 1587 // Activate. This creates new browser
1564 item_controller->Activate(); 1588 item_controller->Activate();
1565 // New Window is created. 1589 // New Window is created.
1566 running_browser = chrome::GetTotalBrowserCount(); 1590 running_browser = chrome::GetTotalBrowserCount();
1567 EXPECT_EQ(1u, running_browser); 1591 EXPECT_EQ(1u, running_browser);
1568 EXPECT_TRUE(item_controller->IsOpen()); 1592 EXPECT_TRUE(item_controller->IsOpen());
1569 1593
1570 // Minimize Window. 1594 // Minimize Window.
1571 aura::Window* window = ash::wm::GetActiveWindow(); 1595 aura::Window* window = ash::wm::GetActiveWindow();
1572 ash::wm::MinimizeWindow(window); 1596 ash::wm::MinimizeWindow(window);
1573 EXPECT_TRUE(ash::wm::IsWindowMinimized(window)); 1597 EXPECT_TRUE(ash::wm::IsWindowMinimized(window));
1574 1598
1575 // Activate again. This doesn't create new browser. 1599 // Activate again. This doesn't create new browser.
1576 // It activates window. 1600 // It activates window.
1577 item_controller->Activate(); 1601 item_controller->Activate();
1578 running_browser = chrome::GetTotalBrowserCount(); 1602 running_browser = chrome::GetTotalBrowserCount();
1579 EXPECT_EQ(1u, running_browser); 1603 EXPECT_EQ(1u, running_browser);
1580 EXPECT_TRUE(item_controller->IsOpen()); 1604 EXPECT_TRUE(item_controller->IsOpen());
1581 EXPECT_FALSE(ash::wm::IsWindowMinimized(window)); 1605 EXPECT_FALSE(ash::wm::IsWindowMinimized(window));
1582 } 1606 }
1583 1607
1584 // Check that GetIDByWindow() returns |LauncherID| of the active tab. 1608 // Check that GetIDByWindow() returns |LauncherID| of the active tab.
1585 IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, 1609 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MatchingLauncherIDandActiveTab) {
1586 MatchingLauncherIDandActiveTab) {
1587 ChromeLauncherControllerPerApp* controller =
1588 static_cast<ChromeLauncherControllerPerApp*>(launcher_->delegate());
1589
1590 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); 1610 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1591 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 1611 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1592 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); 1612 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1593 EXPECT_EQ(2, model_->item_count()); 1613 EXPECT_EQ(2, model_->item_count());
1594 1614
1595 aura::Window* window = browser()->window()->GetNativeWindow(); 1615 aura::Window* window = browser()->window()->GetNativeWindow();
1596 1616
1597 int browser_index = ash::launcher::GetBrowserItemIndex(*model_); 1617 int browser_index = ash::launcher::GetBrowserItemIndex(*model_);
1598 ash::LauncherID browser_id = model_->items()[browser_index].id; 1618 ash::LauncherID browser_id = model_->items()[browser_index].id;
1599 EXPECT_EQ(browser_id, controller->GetIDByWindow(window)); 1619 EXPECT_EQ(browser_id, controller_->GetIDByWindow(window));
1600 1620
1601 ash::LauncherID app_id = CreateShortcut("app1"); 1621 ash::LauncherID app_id = CreateShortcut("app1");
1602 EXPECT_EQ(3, model_->item_count()); 1622 EXPECT_EQ(3, model_->item_count());
1603 1623
1604 // Creates a new tab for "app1" and checks that GetIDByWindow() returns 1624 // Creates a new tab for "app1" and checks that GetIDByWindow() returns
1605 // |LauncherID| of "app1". 1625 // |LauncherID| of "app1".
1606 ActivateLauncherItem(model_->ItemIndexByID(app_id)); 1626 ActivateLauncherItem(model_->ItemIndexByID(app_id));
1607 EXPECT_EQ(2, browser()->tab_strip_model()->count()); 1627 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1608 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); 1628 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
1609 EXPECT_EQ(app_id, controller->GetIDByWindow(window)); 1629 EXPECT_EQ(app_id, controller_->GetIDByWindow(window));
1610 1630
1611 // Makes tab at index 0(NTP) as an active tab and checks that GetIDByWindow() 1631 // Makes tab at index 0(NTP) as an active tab and checks that GetIDByWindow()
1612 // returns |LauncherID| of browser shortcut. 1632 // returns |LauncherID| of browser shortcut.
1613 browser()->tab_strip_model()->ActivateTabAt(0, false); 1633 browser()->tab_strip_model()->ActivateTabAt(0, false);
1614 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); 1634 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1615 EXPECT_EQ(browser_id, controller->GetIDByWindow(window)); 1635 EXPECT_EQ(browser_id, controller_->GetIDByWindow(window));
1616 } 1636 }
1637
1638 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, OverflowBubble) {
1639 // Make sure to have a browser window
1640 chrome::NewTab(browser());
1641
1642 // No overflow yet.
1643 EXPECT_FALSE(launcher_->IsShowingOverflowBubble());
1644
1645 ash::test::LauncherViewTestAPI test(launcher_->GetLauncherViewForTest());
1646
1647 int items_added = 0;
1648 while (!test.IsOverflowButtonVisible()) {
1649 std::string fake_app_id = base::StringPrintf("fake_app_%d", items_added);
1650 PinFakeApp(fake_app_id);
1651
1652 ++items_added;
1653 ASSERT_LT(items_added, 10000);
1654 }
1655
1656 // Now show overflow bubble.
1657 test.ShowOverflowBubble();
1658 EXPECT_TRUE(launcher_->IsShowingOverflowBubble());
1659
1660 // Unpin first pinned app and there should be no crash.
1661 controller_->UnpinAppsWithID(std::string("fake_app_0"));
1662
1663 test.RunMessageLoopUntilAnimationsDone();
1664 EXPECT_FALSE(launcher_->IsShowingOverflowBubble());
1665 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698