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

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

Issue 2839933005: mash: Merge ChromeLauncherController and *Impl subclass. (Closed)
Patch Set: Cleanup Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_impl.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "ash/public/cpp/app_launch_id.h" 9 #include "ash/public/cpp/app_launch_id.h"
10 #include "ash/public/cpp/shelf_item_delegate.h" 10 #include "ash/public/cpp/shelf_item_delegate.h"
11 #include "ash/public/cpp/window_properties.h" 11 #include "ash/public/cpp/window_properties.h"
12 #include "ash/shelf/app_list_button.h" 12 #include "ash/shelf/app_list_button.h"
13 #include "ash/shelf/shelf_button.h" 13 #include "ash/shelf/shelf_button.h"
14 #include "ash/shelf/shelf_constants.h" 14 #include "ash/shelf/shelf_constants.h"
15 #include "ash/shelf/shelf_model.h" 15 #include "ash/shelf/shelf_model.h"
(...skipping 14 matching lines...) Expand all
30 #include "base/strings/utf_string_conversions.h" 30 #include "base/strings/utf_string_conversions.h"
31 #include "build/build_config.h" 31 #include "build/build_config.h"
32 #include "chrome/browser/apps/app_browsertest_util.h" 32 #include "chrome/browser/apps/app_browsertest_util.h"
33 #include "chrome/browser/chrome_notification_types.h" 33 #include "chrome/browser/chrome_notification_types.h"
34 #include "chrome/browser/extensions/extension_apitest.h" 34 #include "chrome/browser/extensions/extension_apitest.h"
35 #include "chrome/browser/extensions/extension_browsertest.h" 35 #include "chrome/browser/extensions/extension_browsertest.h"
36 #include "chrome/browser/extensions/extension_function_test_utils.h" 36 #include "chrome/browser/extensions/extension_function_test_utils.h"
37 #include "chrome/browser/extensions/extension_service.h" 37 #include "chrome/browser/extensions/extension_service.h"
38 #include "chrome/browser/extensions/launch_util.h" 38 #include "chrome/browser/extensions/launch_util.h"
39 #include "chrome/browser/profiles/profile.h" 39 #include "chrome/browser/profiles/profile.h"
40 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
40 #include "chrome/browser/ui/app_list/app_list_service.h" 41 #include "chrome/browser/ui/app_list/app_list_service.h"
41 #include "chrome/browser/ui/ash/app_list/test/app_list_service_ash_test_api.h" 42 #include "chrome/browser/ui/ash/app_list/test/app_list_service_ash_test_api.h"
42 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" 43 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h"
43 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" 44 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h"
44 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" 45 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
45 #include "chrome/browser/ui/ash/session_controller_client.h" 46 #include "chrome/browser/ui/ash/session_controller_client.h"
46 #include "chrome/browser/ui/browser.h" 47 #include "chrome/browser/ui/browser.h"
47 #include "chrome/browser/ui/browser_commands.h" 48 #include "chrome/browser/ui/browser_commands.h"
48 #include "chrome/browser/ui/browser_finder.h" 49 #include "chrome/browser/ui/browser_finder.h"
49 #include "chrome/browser/ui/browser_list.h" 50 #include "chrome/browser/ui/browser_list.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 #include "ui/events/event_constants.h" 84 #include "ui/events/event_constants.h"
84 #include "ui/events/test/event_generator.h" 85 #include "ui/events/test/event_generator.h"
85 86
86 using ash::WmShelf; 87 using ash::WmShelf;
87 using extensions::AppWindow; 88 using extensions::AppWindow;
88 using extensions::Extension; 89 using extensions::Extension;
89 using content::WebContents; 90 using content::WebContents;
90 91
91 namespace { 92 namespace {
92 93
93 ChromeLauncherControllerImpl* GetChromeLauncherControllerImpl() { 94 ChromeLauncherController* GetChromeLauncherController() {
James Cook 2017/04/26 22:17:13 This method isn't needed anymore.
msw 2017/04/26 23:20:15 Done.
94 return static_cast<ChromeLauncherControllerImpl*>( 95 return static_cast<ChromeLauncherController*>(
95 ChromeLauncherController::instance()); 96 ChromeLauncherController::instance());
96 } 97 }
97 98
98 // A callback that records the action taken when a shelf item is selected. 99 // A callback that records the action taken when a shelf item is selected.
99 void SelectItemCallback(ash::ShelfAction* action_taken, 100 void SelectItemCallback(ash::ShelfAction* action_taken,
100 base::RunLoop* run_loop, 101 base::RunLoop* run_loop,
101 ash::ShelfAction action, 102 ash::ShelfAction action,
102 base::Optional<ash::MenuItemList>) { 103 base::Optional<ash::MenuItemList>) {
103 *action_taken = action; 104 *action_taken = action;
104 run_loop->Quit(); 105 run_loop->Quit();
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 : public extensions::PlatformAppBrowserTest { 222 : public extensions::PlatformAppBrowserTest {
222 protected: 223 protected:
223 LauncherPlatformAppBrowserTest() : controller_(nullptr) {} 224 LauncherPlatformAppBrowserTest() : controller_(nullptr) {}
224 225
225 ~LauncherPlatformAppBrowserTest() override {} 226 ~LauncherPlatformAppBrowserTest() override {}
226 227
227 void SetUpOnMainThread() override { 228 void SetUpOnMainThread() override {
228 // Ensure ash starts the session and creates the shelf and controller. 229 // Ensure ash starts the session and creates the shelf and controller.
229 SessionControllerClient::FlushForTesting(); 230 SessionControllerClient::FlushForTesting();
230 231
231 controller_ = GetChromeLauncherControllerImpl(); 232 controller_ = GetChromeLauncherController();
232 ASSERT_TRUE(controller_); 233 ASSERT_TRUE(controller_);
233 extensions::PlatformAppBrowserTest::SetUpOnMainThread(); 234 extensions::PlatformAppBrowserTest::SetUpOnMainThread();
234 } 235 }
235 236
236 ash::ShelfModel* shelf_model() { return ash::Shell::Get()->shelf_model(); } 237 ash::ShelfModel* shelf_model() { return ash::Shell::Get()->shelf_model(); }
237 238
238 ash::ShelfID CreateAppShortcutLauncherItem( 239 ash::ShelfID CreateAppShortcutLauncherItem(
239 const ash::AppLaunchId& app_launch_id) { 240 const ash::AppLaunchId& app_launch_id) {
240 return controller_->CreateAppShortcutLauncherItem( 241 return controller_->CreateAppShortcutLauncherItem(
241 app_launch_id, shelf_model()->item_count()); 242 app_launch_id, shelf_model()->item_count());
242 } 243 }
243 244
244 const ash::ShelfItem& GetLastLauncherItem() { 245 const ash::ShelfItem& GetLastLauncherItem() {
245 // Unless there are any panels, the item at index [count - 1] will be 246 // Unless there are any panels, the item at index [count - 1] will be
246 // the desired item. 247 // the desired item.
247 return shelf_model()->items()[shelf_model()->item_count() - 1]; 248 return shelf_model()->items()[shelf_model()->item_count() - 1];
248 } 249 }
249 250
250 const ash::ShelfItem& GetLastLauncherPanelItem() { 251 const ash::ShelfItem& GetLastLauncherPanelItem() {
251 // Panels show up on the right side of the shelf, so the desired item 252 // Panels show up on the right side of the shelf, so the desired item
252 // will be the last one. 253 // will be the last one.
253 return shelf_model()->items()[shelf_model()->item_count() - 1]; 254 return shelf_model()->items()[shelf_model()->item_count() - 1];
254 } 255 }
255 256
256 ash::ShelfItemDelegate* GetShelfItemDelegate(ash::ShelfID id) { 257 ash::ShelfItemDelegate* GetShelfItemDelegate(ash::ShelfID id) {
257 return shelf_model()->GetShelfItemDelegate(id); 258 return shelf_model()->GetShelfItemDelegate(id);
258 } 259 }
259 260
260 ChromeLauncherControllerImpl* controller_; 261 ChromeLauncherController* controller_;
261 262
262 private: 263 private:
263 DISALLOW_COPY_AND_ASSIGN(LauncherPlatformAppBrowserTest); 264 DISALLOW_COPY_AND_ASSIGN(LauncherPlatformAppBrowserTest);
264 }; 265 };
265 266
266 enum RipOffCommand { 267 enum RipOffCommand {
267 // Drag the item off the shelf and let the mouse go. 268 // Drag the item off the shelf and let the mouse go.
268 RIP_OFF_ITEM, 269 RIP_OFF_ITEM,
269 // Drag the item off the shelf, move the mouse back and then let go. 270 // Drag the item off the shelf, move the mouse back and then let go.
270 RIP_OFF_ITEM_AND_RETURN, 271 RIP_OFF_ITEM_AND_RETURN,
271 // Drag the item off the shelf and then issue a cancel command. 272 // Drag the item off the shelf and then issue a cancel command.
272 RIP_OFF_ITEM_AND_CANCEL, 273 RIP_OFF_ITEM_AND_CANCEL,
273 // Drag the item off the shelf and do not release the mouse. 274 // Drag the item off the shelf and do not release the mouse.
274 RIP_OFF_ITEM_AND_DONT_RELEASE_MOUSE, 275 RIP_OFF_ITEM_AND_DONT_RELEASE_MOUSE,
275 }; 276 };
276 277
277 class ShelfAppBrowserTest : public ExtensionBrowserTest { 278 class ShelfAppBrowserTest : public ExtensionBrowserTest {
278 protected: 279 protected:
279 ShelfAppBrowserTest() : shelf_(NULL), model_(NULL), controller_(NULL) { 280 ShelfAppBrowserTest() : shelf_(NULL), model_(NULL), controller_(NULL) {}
280 }
281 281
282 ~ShelfAppBrowserTest() override {} 282 ~ShelfAppBrowserTest() override {}
283 283
284 void SetUpOnMainThread() override { 284 void SetUpOnMainThread() override {
285 // Ensure ash starts the session and creates the shelf and controller. 285 // Ensure ash starts the session and creates the shelf and controller.
286 SessionControllerClient::FlushForTesting(); 286 SessionControllerClient::FlushForTesting();
287 287
288 shelf_ = 288 shelf_ =
289 ash::WmShelf::ForWindow(ash::ShellPort::Get()->GetPrimaryRootWindow()); 289 ash::WmShelf::ForWindow(ash::ShellPort::Get()->GetPrimaryRootWindow());
290 model_ = ash::Shell::Get()->shelf_model(); 290 model_ = ash::Shell::Get()->shelf_model();
291 controller_ = GetChromeLauncherControllerImpl(); 291 controller_ = GetChromeLauncherController();
292 ASSERT_TRUE(controller_); 292 ASSERT_TRUE(controller_);
293 ExtensionBrowserTest::SetUpOnMainThread(); 293 ExtensionBrowserTest::SetUpOnMainThread();
294 } 294 }
295 295
296 size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) { 296 size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) {
297 ash::ShelfItemDelegate* item_controller = 297 ash::ShelfItemDelegate* item_controller =
298 controller_->GetBrowserShortcutLauncherItemController(); 298 controller_->GetBrowserShortcutLauncherItemController();
299 return item_controller 299 return item_controller
300 ->GetAppMenuItems(show_all_tabs ? ui::EF_SHIFT_DOWN : 0) 300 ->GetAppMenuItems(show_all_tabs ? ui::EF_SHIFT_DOWN : 0)
301 .size(); 301 .size();
302 } 302 }
303 303
304 const Extension* LoadAndLaunchExtension( 304 const Extension* LoadAndLaunchExtension(const char* name,
305 const char* name, 305 extensions::LaunchContainer container,
306 extensions::LaunchContainer container, 306 WindowOpenDisposition disposition) {
307 WindowOpenDisposition disposition) {
308 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII(name))); 307 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII(name)));
309 308
310 ExtensionService* service = extensions::ExtensionSystem::Get( 309 ExtensionService* service =
311 profile())->extension_service(); 310 extensions::ExtensionSystem::Get(profile())->extension_service();
312 const Extension* extension = 311 const Extension* extension =
313 service->GetExtensionById(last_loaded_extension_id(), false); 312 service->GetExtensionById(last_loaded_extension_id(), false);
314 EXPECT_TRUE(extension); 313 EXPECT_TRUE(extension);
315 314
316 OpenApplication(AppLaunchParams(profile(), extension, container, 315 OpenApplication(AppLaunchParams(profile(), extension, container,
317 disposition, extensions::SOURCE_TEST)); 316 disposition, extensions::SOURCE_TEST));
318 return extension; 317 return extension;
319 } 318 }
320 319
321 ash::ShelfID CreateShortcut(const char* name) { 320 ash::ShelfID CreateShortcut(const char* name) {
322 ExtensionService* service = extensions::ExtensionSystem::Get( 321 ExtensionService* service =
323 profile())->extension_service(); 322 extensions::ExtensionSystem::Get(profile())->extension_service();
324 LoadExtension(test_data_dir_.AppendASCII(name)); 323 LoadExtension(test_data_dir_.AppendASCII(name));
325 324
326 // First get app_id. 325 // First get app_id.
327 const Extension* extension = 326 const Extension* extension =
328 service->GetExtensionById(last_loaded_extension_id(), false); 327 service->GetExtensionById(last_loaded_extension_id(), false);
329 const std::string app_id = extension->id(); 328 const std::string app_id = extension->id();
330 329
331 // Then create a shortcut. 330 // Then create a shortcut.
332 int item_count = model_->item_count(); 331 int item_count = model_->item_count();
333 ash::ShelfID shortcut_id = controller_->CreateAppShortcutLauncherItem( 332 ash::ShelfID shortcut_id = controller_->CreateAppShortcutLauncherItem(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 DCHECK(root_window); 395 DCHECK(root_window);
397 return root_window; 396 return root_window;
398 } 397 }
399 398
400 bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { 399 bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) {
401 return menu->GetIndexOfCommandId(command_id) != -1; 400 return menu->GetIndexOfCommandId(command_id) != -1;
402 } 401 }
403 402
404 ash::WmShelf* shelf_; 403 ash::WmShelf* shelf_;
405 ash::ShelfModel* model_; 404 ash::ShelfModel* model_;
406 ChromeLauncherControllerImpl* controller_; 405 ChromeLauncherController* controller_;
407 406
408 private: 407 private:
409 DISALLOW_COPY_AND_ASSIGN(ShelfAppBrowserTest); 408 DISALLOW_COPY_AND_ASSIGN(ShelfAppBrowserTest);
410 }; 409 };
411 410
412 class ShelfAppBrowserTestNoDefaultBrowser : public ShelfAppBrowserTest { 411 class ShelfAppBrowserTestNoDefaultBrowser : public ShelfAppBrowserTest {
413 protected: 412 protected:
414 ShelfAppBrowserTestNoDefaultBrowser() {} 413 ShelfAppBrowserTestNoDefaultBrowser() {}
415 ~ShelfAppBrowserTestNoDefaultBrowser() override {} 414 ~ShelfAppBrowserTestNoDefaultBrowser() override {}
416 415
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched"); 596 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched");
598 AppWindow* window1 = CreateAppWindow(browser()->profile(), extension1); 597 AppWindow* window1 = CreateAppWindow(browser()->profile(), extension1);
599 ++item_count; 598 ++item_count;
600 ASSERT_EQ(item_count, shelf_model()->item_count()); 599 ASSERT_EQ(item_count, shelf_model()->item_count());
601 const ash::ShelfItem& item1 = GetLastLauncherItem(); 600 const ash::ShelfItem& item1 = GetLastLauncherItem();
602 ash::ShelfID item_id1 = item1.id; 601 ash::ShelfID item_id1 = item1.id;
603 EXPECT_EQ(ash::TYPE_APP, item1.type); 602 EXPECT_EQ(ash::TYPE_APP, item1.type);
604 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); 603 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
605 604
606 // Then run second app. 605 // Then run second app.
607 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2", 606 const Extension* extension2 =
608 "Launched"); 607 LoadAndLaunchPlatformApp("launch_2", "Launched");
609 AppWindow* window2 = CreateAppWindow(browser()->profile(), extension2); 608 AppWindow* window2 = CreateAppWindow(browser()->profile(), extension2);
610 ++item_count; 609 ++item_count;
611 ASSERT_EQ(item_count, shelf_model()->item_count()); 610 ASSERT_EQ(item_count, shelf_model()->item_count());
612 const ash::ShelfItem& item2 = GetLastLauncherItem(); 611 const ash::ShelfItem& item2 = GetLastLauncherItem();
613 ash::ShelfID item_id2 = item2.id; 612 ash::ShelfID item_id2 = item2.id;
614 EXPECT_EQ(ash::TYPE_APP, item2.type); 613 EXPECT_EQ(ash::TYPE_APP, item2.type);
615 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); 614 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status);
616 615
617 EXPECT_NE(item_id1, item_id2); 616 EXPECT_NE(item_id1, item_id2);
618 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id1)->status); 617 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id1)->status);
(...skipping 20 matching lines...) Expand all
639 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched"); 638 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched");
640 AppWindow* window1 = CreateAppWindow(browser()->profile(), extension1); 639 AppWindow* window1 = CreateAppWindow(browser()->profile(), extension1);
641 ++item_count; 640 ++item_count;
642 ASSERT_EQ(item_count, shelf_model()->item_count()); 641 ASSERT_EQ(item_count, shelf_model()->item_count());
643 const ash::ShelfItem& item1 = GetLastLauncherItem(); 642 const ash::ShelfItem& item1 = GetLastLauncherItem();
644 ash::ShelfID item_id1 = item1.id; 643 ash::ShelfID item_id1 = item1.id;
645 EXPECT_EQ(ash::TYPE_APP, item1.type); 644 EXPECT_EQ(ash::TYPE_APP, item1.type);
646 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); 645 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
647 646
648 // Then run second app. 647 // Then run second app.
649 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2", 648 const Extension* extension2 =
650 "Launched"); 649 LoadAndLaunchPlatformApp("launch_2", "Launched");
651 AppWindow* window2 = CreateAppWindow(browser()->profile(), extension2); 650 AppWindow* window2 = CreateAppWindow(browser()->profile(), extension2);
652 ++item_count; 651 ++item_count;
653 ASSERT_EQ(item_count, shelf_model()->item_count()); 652 ASSERT_EQ(item_count, shelf_model()->item_count());
654 const ash::ShelfItem& item2 = GetLastLauncherItem(); 653 const ash::ShelfItem& item2 = GetLastLauncherItem();
655 ash::ShelfID item_id2 = item2.id; 654 ash::ShelfID item_id2 = item2.id;
656 EXPECT_EQ(ash::TYPE_APP, item2.type); 655 EXPECT_EQ(ash::TYPE_APP, item2.type);
657 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); 656 EXPECT_EQ(ash::STATUS_ACTIVE, item2.status);
658 657
659 EXPECT_NE(item_id1, item_id2); 658 EXPECT_NE(item_id1, item_id2);
660 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id1)->status); 659 EXPECT_EQ(ash::STATUS_RUNNING, shelf_model()->ItemByID(item_id1)->status);
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 1068
1070 // Confirm that a page can be navigated from and to while maintaining the 1069 // Confirm that a page can be navigated from and to while maintaining the
1071 // correct running state. 1070 // correct running state.
1072 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, Navigation) { 1071 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, Navigation) {
1073 ash::ShelfID shortcut_id = CreateShortcut("app1"); 1072 ash::ShelfID shortcut_id = CreateShortcut("app1");
1074 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 1073 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
1075 WmShelf::ActivateShelfItem(model_->ItemIndexByID(shortcut_id)); 1074 WmShelf::ActivateShelfItem(model_->ItemIndexByID(shortcut_id));
1076 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 1075 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
1077 1076
1078 // Navigate away. 1077 // Navigate away.
1079 ui_test_utils::NavigateToURL( 1078 ui_test_utils::NavigateToURL(browser(),
1080 browser(), GURL("http://www.example.com/path0/bar.html")); 1079 GURL("http://www.example.com/path0/bar.html"));
1081 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 1080 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
1082 1081
1083 // Navigate back. 1082 // Navigate back.
1084 ui_test_utils::NavigateToURL( 1083 ui_test_utils::NavigateToURL(browser(),
1085 browser(), GURL("http://www.example.com/path1/foo.html")); 1084 GURL("http://www.example.com/path1/foo.html"));
1086 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 1085 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
1087 } 1086 }
1088 1087
1089 // Confirm that a tab can be moved between browsers while maintaining the 1088 // Confirm that a tab can be moved between browsers while maintaining the
1090 // correct running state. 1089 // correct running state.
1091 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, TabDragAndDrop) { 1090 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, TabDragAndDrop) {
1092 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); 1091 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1093 TabStripModel* tab_strip_model1 = browser()->tab_strip_model(); 1092 TabStripModel* tab_strip_model1 = browser()->tab_strip_model();
1094 EXPECT_EQ(1, tab_strip_model1->count()); 1093 EXPECT_EQ(1, tab_strip_model1->count());
1095 const int browser_index = GetIndexOfShelfItemType(ash::TYPE_BROWSER_SHORTCUT); 1094 const int browser_index = GetIndexOfShelfItemType(ash::TYPE_BROWSER_SHORTCUT);
(...skipping 14 matching lines...) Expand all
1110 Browser* browser2 = CreateBrowser(profile()); 1109 Browser* browser2 = CreateBrowser(profile());
1111 EXPECT_EQ(2u, chrome::GetTotalBrowserCount()); 1110 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
1112 TabStripModel* tab_strip_model2 = browser2->tab_strip_model(); 1111 TabStripModel* tab_strip_model2 = browser2->tab_strip_model();
1113 EXPECT_EQ(1, tab_strip_model2->count()); 1112 EXPECT_EQ(1, tab_strip_model2->count());
1114 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status); 1113 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status);
1115 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut_id)).status); 1114 EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut_id)).status);
1116 1115
1117 // Detach a tab at index 1 (app1) from |tab_strip_model1| and insert it as an 1116 // Detach a tab at index 1 (app1) from |tab_strip_model1| and insert it as an
1118 // active tab at index 1 to |tab_strip_model2|. 1117 // active tab at index 1 to |tab_strip_model2|.
1119 content::WebContents* detached_tab = tab_strip_model1->DetachWebContentsAt(1); 1118 content::WebContents* detached_tab = tab_strip_model1->DetachWebContentsAt(1);
1120 tab_strip_model2->InsertWebContentsAt(1, 1119 tab_strip_model2->InsertWebContentsAt(1, detached_tab,
1121 detached_tab,
1122 TabStripModel::ADD_ACTIVE); 1120 TabStripModel::ADD_ACTIVE);
1123 EXPECT_EQ(1, tab_strip_model1->count()); 1121 EXPECT_EQ(1, tab_strip_model1->count());
1124 EXPECT_EQ(2, tab_strip_model2->count()); 1122 EXPECT_EQ(2, tab_strip_model2->count());
1125 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[browser_index].status); 1123 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[browser_index].status);
1126 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 1124 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
1127 1125
1128 tab_strip_model1->CloseAllTabs(); 1126 tab_strip_model1->CloseAllTabs();
1129 tab_strip_model2->CloseAllTabs(); 1127 tab_strip_model2->CloseAllTabs();
1130 } 1128 }
1131 1129
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_WINDOW, 1325 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_WINDOW,
1328 WindowOpenDisposition::NEW_WINDOW); 1326 WindowOpenDisposition::NEW_WINDOW);
1329 app_browser = FindBrowserForApp(extension->id()); 1327 app_browser = FindBrowserForApp(extension->id());
1330 ASSERT_TRUE(app_browser); 1328 ASSERT_TRUE(app_browser);
1331 window = app_browser->window()->GetNativeWindow(); 1329 window = app_browser->window()->GetNativeWindow();
1332 EXPECT_FALSE(ash::wm::GetWindowState(window)->IsMaximized()); 1330 EXPECT_FALSE(ash::wm::GetWindowState(window)->IsMaximized());
1333 } 1331 }
1334 1332
1335 // Checks that a windowed application does not add an item to the browser list. 1333 // Checks that a windowed application does not add an item to the browser list.
1336 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTestNoDefaultBrowser, 1334 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTestNoDefaultBrowser,
1337 WindowedAppDoesNotAddToBrowser) { 1335 WindowedAppDoesNotAddToBrowser) {
1338 // Get the number of items in the browser menu. 1336 // Get the number of items in the browser menu.
1339 size_t items = NumberOfDetectedLauncherBrowsers(false); 1337 size_t items = NumberOfDetectedLauncherBrowsers(false);
1340 size_t running_browser = chrome::GetTotalBrowserCount(); 1338 size_t running_browser = chrome::GetTotalBrowserCount();
1341 EXPECT_EQ(0u, items); 1339 EXPECT_EQ(0u, items);
1342 EXPECT_EQ(0u, running_browser); 1340 EXPECT_EQ(0u, running_browser);
1343 1341
1344 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_WINDOW, 1342 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_WINDOW,
1345 WindowOpenDisposition::NEW_WINDOW); 1343 WindowOpenDisposition::NEW_WINDOW);
1346 1344
1347 // No new browser should get detected, even though one more is running. 1345 // No new browser should get detected, even though one more is running.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1424 1422
1425 EXPECT_EQ(content2, browser()->tab_strip_model()->GetActiveWebContents()); 1423 EXPECT_EQ(content2, browser()->tab_strip_model()->GetActiveWebContents());
1426 WmShelf::ActivateShelfItem(shortcut_index); 1424 WmShelf::ActivateShelfItem(shortcut_index);
1427 EXPECT_EQ(content1, browser()->tab_strip_model()->GetActiveWebContents()); 1425 EXPECT_EQ(content1, browser()->tab_strip_model()->GetActiveWebContents());
1428 WmShelf::ActivateShelfItem(shortcut_index); 1426 WmShelf::ActivateShelfItem(shortcut_index);
1429 EXPECT_EQ(content2, browser()->tab_strip_model()->GetActiveWebContents()); 1427 EXPECT_EQ(content2, browser()->tab_strip_model()->GetActiveWebContents());
1430 } 1428 }
1431 1429
1432 // Check that the keyboard activation of a launcher item tabs properly through 1430 // Check that the keyboard activation of a launcher item tabs properly through
1433 // the items at hand. 1431 // the items at hand.
1434 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, 1432 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, AltNumberAppsTabbing) {
1435 AltNumberAppsTabbing) {
1436 // First run app. 1433 // First run app.
1437 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched"); 1434 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched");
1438 ui::BaseWindow* window1 = 1435 ui::BaseWindow* window1 =
1439 CreateAppWindow(browser()->profile(), extension1)->GetBaseWindow(); 1436 CreateAppWindow(browser()->profile(), extension1)->GetBaseWindow();
1440 const ash::ShelfItem& item1 = GetLastLauncherItem(); 1437 const ash::ShelfItem& item1 = GetLastLauncherItem();
1441 ash::ShelfID app_id = item1.id; 1438 ash::ShelfID app_id = item1.id;
1442 int app_index = shelf_model()->ItemIndexByID(app_id); 1439 int app_index = shelf_model()->ItemIndexByID(app_id);
1443 1440
1444 EXPECT_EQ(ash::TYPE_APP, item1.type); 1441 EXPECT_EQ(ash::TYPE_APP, item1.type);
1445 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); 1442 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
1446 1443
1447 const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2", 1444 const Extension* extension2 =
1448 "Launched"); 1445 LoadAndLaunchPlatformApp("launch_2", "Launched");
1449 ui::BaseWindow* window2 = 1446 ui::BaseWindow* window2 =
1450 CreateAppWindow(browser()->profile(), extension2)->GetBaseWindow(); 1447 CreateAppWindow(browser()->profile(), extension2)->GetBaseWindow();
1451 1448
1452 // By now the browser should be active. Issue Alt keystrokes several times to 1449 // By now the browser should be active. Issue Alt keystrokes several times to
1453 // see that we stay on that application. 1450 // see that we stay on that application.
1454 EXPECT_TRUE(window2->IsActive()); 1451 EXPECT_TRUE(window2->IsActive());
1455 WmShelf::ActivateShelfItem(app_index); 1452 WmShelf::ActivateShelfItem(app_index);
1456 EXPECT_TRUE(window1->IsActive()); 1453 EXPECT_TRUE(window1->IsActive());
1457 WmShelf::ActivateShelfItem(app_index); 1454 WmShelf::ActivateShelfItem(app_index);
1458 EXPECT_TRUE(window1->IsActive()); 1455 EXPECT_TRUE(window1->IsActive());
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
2002 CreateShortcut("app1"); 1999 CreateShortcut("app1");
2003 test.RunMessageLoopUntilAnimationsDone(); 2000 test.RunMessageLoopUntilAnimationsDone();
2004 EXPECT_EQ(3, model_->item_count()); 2001 EXPECT_EQ(3, model_->item_count());
2005 2002
2006 // Test #1: Ripping out the browser item should not change anything. 2003 // Test #1: Ripping out the browser item should not change anything.
2007 int browser_index = GetIndexOfShelfItemType(ash::TYPE_BROWSER_SHORTCUT); 2004 int browser_index = GetIndexOfShelfItemType(ash::TYPE_BROWSER_SHORTCUT);
2008 EXPECT_LE(0, browser_index); 2005 EXPECT_LE(0, browser_index);
2009 RipOffItemIndex(browser_index, &generator, &test, RIP_OFF_ITEM); 2006 RipOffItemIndex(browser_index, &generator, &test, RIP_OFF_ITEM);
2010 // => It should not have been removed and the location should be unchanged. 2007 // => It should not have been removed and the location should be unchanged.
2011 EXPECT_EQ(3, model_->item_count()); 2008 EXPECT_EQ(3, model_->item_count());
2012 EXPECT_EQ(browser_index, 2009 EXPECT_EQ(browser_index, GetIndexOfShelfItemType(ash::TYPE_BROWSER_SHORTCUT));
2013 GetIndexOfShelfItemType(ash::TYPE_BROWSER_SHORTCUT));
2014 // Make sure that the hide state has been unset after the snap back animation 2010 // Make sure that the hide state has been unset after the snap back animation
2015 // finished. 2011 // finished.
2016 ash::ShelfButton* button = test.GetButton(browser_index); 2012 ash::ShelfButton* button = test.GetButton(browser_index);
2017 EXPECT_FALSE(button->state() & ash::ShelfButton::STATE_HIDDEN); 2013 EXPECT_FALSE(button->state() & ash::ShelfButton::STATE_HIDDEN);
2018 2014
2019 // Test #2: Ripping out the application and canceling the operation should 2015 // Test #2: Ripping out the application and canceling the operation should
2020 // not change anything. 2016 // not change anything.
2021 int app_index = GetIndexOfShelfItemType(ash::TYPE_PINNED_APP); 2017 int app_index = GetIndexOfShelfItemType(ash::TYPE_PINNED_APP);
2022 EXPECT_LE(0, app_index); 2018 EXPECT_LE(0, app_index);
2023 RipOffItemIndex(app_index, &generator, &test, RIP_OFF_ITEM_AND_CANCEL); 2019 RipOffItemIndex(app_index, &generator, &test, RIP_OFF_ITEM_AND_CANCEL);
(...skipping 14 matching lines...) Expand all
2038 // => It should not have been removed and the location should be unchanged. 2034 // => It should not have been removed and the location should be unchanged.
2039 EXPECT_EQ(2, model_->item_count()); 2035 EXPECT_EQ(2, model_->item_count());
2040 EXPECT_EQ(-1, GetIndexOfShelfItemType(ash::TYPE_PINNED_APP)); 2036 EXPECT_EQ(-1, GetIndexOfShelfItemType(ash::TYPE_PINNED_APP));
2041 2037
2042 // Test #5: Uninstalling an application while it is being ripped off should 2038 // Test #5: Uninstalling an application while it is being ripped off should
2043 // not crash. 2039 // not crash.
2044 CreateShortcut("app2"); 2040 CreateShortcut("app2");
2045 test.RunMessageLoopUntilAnimationsDone(); 2041 test.RunMessageLoopUntilAnimationsDone();
2046 int app2_index = GetIndexOfShelfItemType(ash::TYPE_PINNED_APP); 2042 int app2_index = GetIndexOfShelfItemType(ash::TYPE_PINNED_APP);
2047 EXPECT_EQ(3, model_->item_count()); // And it remains that way. 2043 EXPECT_EQ(3, model_->item_count()); // And it remains that way.
2048 RipOffItemIndex(app2_index, 2044 RipOffItemIndex(app2_index, &generator, &test,
2049 &generator,
2050 &test,
2051 RIP_OFF_ITEM_AND_DONT_RELEASE_MOUSE); 2045 RIP_OFF_ITEM_AND_DONT_RELEASE_MOUSE);
2052 controller_->UnpinAppWithID("app2"); 2046 controller_->UnpinAppWithID("app2");
2053 test.RunMessageLoopUntilAnimationsDone(); 2047 test.RunMessageLoopUntilAnimationsDone();
2054 EXPECT_EQ(2, model_->item_count()); // The item should now be gone. 2048 EXPECT_EQ(2, model_->item_count()); // The item should now be gone.
2055 generator.ReleaseLeftButton(); 2049 generator.ReleaseLeftButton();
2056 base::RunLoop().RunUntilIdle(); 2050 base::RunLoop().RunUntilIdle();
2057 EXPECT_EQ(2, model_->item_count()); // And it remains that way. 2051 EXPECT_EQ(2, model_->item_count()); // And it remains that way.
2058 EXPECT_EQ(-1, GetIndexOfShelfItemType(ash::TYPE_PINNED_APP)); 2052 EXPECT_EQ(-1, GetIndexOfShelfItemType(ash::TYPE_PINNED_APP));
2059 2053
2060 // Test #6: Ripping out the application when the overflow button exists. 2054 // Test #6: Ripping out the application when the overflow button exists.
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
2278 chrome::SettingsWindowManager::GetInstance(); 2272 chrome::SettingsWindowManager::GetInstance();
2279 ash::ShelfModel* shelf_model = ash::Shell::Get()->shelf_model(); 2273 ash::ShelfModel* shelf_model = ash::Shell::Get()->shelf_model();
2280 2274
2281 // Get the number of items in the shelf and browser menu. 2275 // Get the number of items in the shelf and browser menu.
2282 int item_count = shelf_model->item_count(); 2276 int item_count = shelf_model->item_count();
2283 size_t browser_count = NumberOfDetectedLauncherBrowsers(false); 2277 size_t browser_count = NumberOfDetectedLauncherBrowsers(false);
2284 2278
2285 // Open a settings window. Number of browser items should remain unchanged, 2279 // Open a settings window. Number of browser items should remain unchanged,
2286 // number of shelf items should increase. 2280 // number of shelf items should increase.
2287 settings_manager->ShowChromePageForProfile( 2281 settings_manager->ShowChromePageForProfile(
2288 browser()->profile(), 2282 browser()->profile(), chrome::GetSettingsUrl(std::string()));
2289 chrome::GetSettingsUrl(std::string()));
2290 Browser* settings_browser = 2283 Browser* settings_browser =
2291 settings_manager->FindBrowserForProfile(browser()->profile()); 2284 settings_manager->FindBrowserForProfile(browser()->profile());
2292 ASSERT_TRUE(settings_browser); 2285 ASSERT_TRUE(settings_browser);
2293 EXPECT_EQ(browser_count, NumberOfDetectedLauncherBrowsers(false)); 2286 EXPECT_EQ(browser_count, NumberOfDetectedLauncherBrowsers(false));
2294 EXPECT_EQ(item_count + 1, shelf_model->item_count()); 2287 EXPECT_EQ(item_count + 1, shelf_model->item_count());
2295 2288
2296 // TODO(stevenjb): Test multiprofile on Chrome OS when test support is addded. 2289 // TODO(stevenjb): Test multiprofile on Chrome OS when test support is addded.
2297 // crbug.com/230464. 2290 // crbug.com/230464.
2298 } 2291 }
2299 2292
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
2409 2402
2410 // Close all windows via the menu item. 2403 // Close all windows via the menu item.
2411 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); 2404 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE);
2412 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); 2405 EXPECT_EQ(0u, BrowserList::GetInstance()->size());
2413 2406
2414 // Check if "Close" is removed from the context menu. 2407 // Check if "Close" is removed from the context menu.
2415 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); 2408 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu();
2416 ASSERT_FALSE( 2409 ASSERT_FALSE(
2417 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); 2410 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE));
2418 } 2411 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698