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

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

Issue 2833173002: mash: Support ShelfModel access in Chrome. (Closed)
Patch Set: Cleanup; Fix an Arc test by use CLC, not Ash's ShelfModel. Created 3 years, 6 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.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 <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
(...skipping 24 matching lines...) Expand all
35 #include "base/json/json_string_value_serializer.h" 35 #include "base/json/json_string_value_serializer.h"
36 #include "base/location.h" 36 #include "base/location.h"
37 #include "base/macros.h" 37 #include "base/macros.h"
38 #include "base/memory/ptr_util.h" 38 #include "base/memory/ptr_util.h"
39 #include "base/run_loop.h" 39 #include "base/run_loop.h"
40 #include "base/single_thread_task_runner.h" 40 #include "base/single_thread_task_runner.h"
41 #include "base/strings/utf_string_conversions.h" 41 #include "base/strings/utf_string_conversions.h"
42 #include "base/values.h" 42 #include "base/values.h"
43 #include "build/build_config.h" 43 #include "build/build_config.h"
44 #include "chrome/browser/chromeos/arc/arc_util.h" 44 #include "chrome/browser/chromeos/arc/arc_util.h"
45 #include "chrome/browser/chromeos/ash_config.h"
45 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" 46 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
46 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 47 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
47 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 48 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
48 #include "chrome/browser/extensions/extension_service.h" 49 #include "chrome/browser/extensions/extension_service.h"
49 #include "chrome/browser/extensions/test_extension_system.h" 50 #include "chrome/browser/extensions/test_extension_system.h"
50 #include "chrome/browser/lifetime/scoped_keep_alive.h" 51 #include "chrome/browser/lifetime/scoped_keep_alive.h"
51 #include "chrome/browser/prefs/browser_prefs.h" 52 #include "chrome/browser/prefs/browser_prefs.h"
52 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" 53 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
53 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" 54 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
54 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" 55 #include "chrome/browser/ui/app_list/arc/arc_app_test.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 156
156 void ShelfItemChanged(int index, const ash::ShelfItem& old_item) override { 157 void ShelfItemChanged(int index, const ash::ShelfItem& old_item) override {
157 ++changed_; 158 ++changed_;
158 last_index_ = index; 159 last_index_ = index;
159 } 160 }
160 161
161 void ShelfItemMoved(int start_index, int target_index) override { 162 void ShelfItemMoved(int start_index, int target_index) override {
162 last_index_ = target_index; 163 last_index_ = target_index;
163 } 164 }
164 165
166 void ShelfItemDelegateChanged(const ash::ShelfID&,
167 ash::ShelfItemDelegate*) override {}
168
165 void clear_counts() { 169 void clear_counts() {
166 added_ = 0; 170 added_ = 0;
167 removed_ = 0; 171 removed_ = 0;
168 changed_ = 0; 172 changed_ = 0;
169 last_index_ = 0; 173 last_index_ = 0;
170 } 174 }
171 175
172 int added() const { return added_; } 176 int added() const { return added_; }
173 int removed() const { return removed_; } 177 int removed() const { return removed_; }
174 int changed() const { return changed_; } 178 int changed() const { return changed_; }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 std::move(callback).Run(ash::SHELF_ACTION_WINDOW_ACTIVATED, base::nullopt); 273 std::move(callback).Run(ash::SHELF_ACTION_WINDOW_ACTIVATED, base::nullopt);
270 } 274 }
271 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override {} 275 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override {}
272 void Close() override {} 276 void Close() override {}
273 277
274 private: 278 private:
275 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController); 279 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController);
276 }; 280 };
277 281
278 // A test ShelfController implementation that tracks alignment and auto-hide. 282 // A test ShelfController implementation that tracks alignment and auto-hide.
279 class TestShelfController : public ash::mojom::ShelfController { 283 class TestShelfController : public ash::mojom::ShelfController,
284 public ash::mojom::ShelfModelObserver {
280 public: 285 public:
281 TestShelfController() : binding_(this) {} 286 TestShelfController() : binding_(this), model_observer_binding_(this) {}
282 ~TestShelfController() override {} 287 ~TestShelfController() override {}
283 288
284 ash::ShelfAlignment alignment() const { return alignment_; } 289 ash::ShelfAlignment alignment() const { return alignment_; }
285 ash::ShelfAutoHideBehavior auto_hide() const { return auto_hide_; } 290 ash::ShelfAutoHideBehavior auto_hide() const { return auto_hide_; }
286 291
287 size_t alignment_change_count() const { return alignment_change_count_; } 292 size_t alignment_change_count() const { return alignment_change_count_; }
288 size_t auto_hide_change_count() const { return auto_hide_change_count_; } 293 size_t auto_hide_change_count() const { return auto_hide_change_count_; }
289 294
295 size_t added_count() const { return added_count_; }
296 size_t removed_count() const { return removed_count_; }
297
298 ash::mojom::ShelfModelObserver* model_observer() {
299 return model_observer_.get();
300 }
301
290 ash::mojom::ShelfControllerPtr CreateInterfacePtrAndBind() { 302 ash::mojom::ShelfControllerPtr CreateInterfacePtrAndBind() {
291 return binding_.CreateInterfacePtrAndBind(); 303 return binding_.CreateInterfacePtrAndBind();
292 } 304 }
293 305
294 // ash::mojom::ShelfController: 306 // ash::mojom::ShelfController:
295 void AddObserver( 307 void AddObserver(
296 ash::mojom::ShelfObserverAssociatedPtrInfo observer) override { 308 ash::mojom::ShelfObserverAssociatedPtrInfo observer) override {
297 observer_.Bind(std::move(observer)); 309 observer_.Bind(std::move(observer));
298 } 310 }
311 void LinkShelfModels(ash::mojom::ShelfModelObserverPtr observer,
312 LinkShelfModelsCallback callback) override {
313 DCHECK_EQ(chromeos::GetAshConfig(), ash::Config::MASH);
314 model_observer_ = std::move(observer);
315 // Add an AppList item, as ash::ShelfController does in the mash config.
316 std::vector<ash::ShelfItem> items;
317 ash::ShelfItem app_list_item;
318 app_list_item.type = ash::TYPE_APP_LIST;
319 app_list_item.id = ash::ShelfID(kAppListId);
320 app_list_item.title = base::ASCIIToUTF16("Launcher");
321 items.push_back(app_list_item);
322 std::move(callback).Run(model_observer_binding_.CreateInterfacePtrAndBind(),
323 items);
324 }
299 void SetAlignment(ash::ShelfAlignment alignment, 325 void SetAlignment(ash::ShelfAlignment alignment,
300 int64_t display_id) override { 326 int64_t display_id) override {
301 alignment_change_count_++; 327 alignment_change_count_++;
302 alignment_ = alignment; 328 alignment_ = alignment;
303 observer_->OnAlignmentChanged(alignment_, display_id); 329 observer_->OnAlignmentChanged(alignment_, display_id);
304 } 330 }
305 void SetAutoHideBehavior(ash::ShelfAutoHideBehavior auto_hide, 331 void SetAutoHideBehavior(ash::ShelfAutoHideBehavior auto_hide,
306 int64_t display_id) override { 332 int64_t display_id) override {
307 auto_hide_change_count_++; 333 auto_hide_change_count_++;
308 auto_hide_ = auto_hide; 334 auto_hide_ = auto_hide;
309 observer_->OnAutoHideBehaviorChanged(auto_hide_, display_id); 335 observer_->OnAutoHideBehaviorChanged(auto_hide_, display_id);
310 } 336 }
311 void PinItem( 337
312 const ash::ShelfItem& item, 338 // ash::mojom::ShelfModelObserver:
313 ash::mojom::ShelfItemDelegateAssociatedPtrInfo delegate) override {} 339 void OnShelfItemAdded(int32_t, const ash::ShelfItem&) override {
314 void UnpinItem(const std::string& app_id) override {} 340 added_count_++;
315 void SetItemImage(const std::string& app_id, const SkBitmap& image) override {
316 } 341 }
342 void OnShelfItemRemoved(int32_t, const ash::ShelfItem&) override {
343 removed_count_++;
344 }
345 void OnShelfItemMoved(int32_t, int32_t) override {}
346 void OnShelfItemChanged(int32_t, const ash::ShelfItem&) override {}
347 void OnShelfItemDelegateChanged(const ash::ShelfID&,
348 ash::mojom::ShelfItemDelegatePtr) override {}
317 349
318 private: 350 private:
319 ash::ShelfAlignment alignment_ = ash::SHELF_ALIGNMENT_BOTTOM_LOCKED; 351 ash::ShelfAlignment alignment_ = ash::SHELF_ALIGNMENT_BOTTOM_LOCKED;
320 ash::ShelfAutoHideBehavior auto_hide_ = ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN; 352 ash::ShelfAutoHideBehavior auto_hide_ = ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN;
321 353
322 size_t alignment_change_count_ = 0; 354 size_t alignment_change_count_ = 0;
323 size_t auto_hide_change_count_ = 0; 355 size_t auto_hide_change_count_ = 0;
324 356
357 size_t added_count_ = 0;
358 size_t removed_count_ = 0;
359
325 ash::mojom::ShelfObserverAssociatedPtr observer_; 360 ash::mojom::ShelfObserverAssociatedPtr observer_;
361 ash::mojom::ShelfModelObserverPtr model_observer_;
326 mojo::Binding<ash::mojom::ShelfController> binding_; 362 mojo::Binding<ash::mojom::ShelfController> binding_;
363 mojo::Binding<ash::mojom::ShelfModelObserver> model_observer_binding_;
327 364
328 DISALLOW_COPY_AND_ASSIGN(TestShelfController); 365 DISALLOW_COPY_AND_ASSIGN(TestShelfController);
329 }; 366 };
330 367
331 // A callback that does nothing after shelf item selection handling. 368 // A callback that does nothing after shelf item selection handling.
332 void NoopCallback(ash::ShelfAction action, base::Optional<ash::MenuItemList>) {} 369 void NoopCallback(ash::ShelfAction action, base::Optional<ash::MenuItemList>) {}
333 370
334 // Simulates selection of the shelf item. 371 // Simulates selection of the shelf item.
335 void SelectItem(ash::ShelfItemDelegate* delegate) { 372 void SelectItem(ash::ShelfItemDelegate* delegate) {
336 std::unique_ptr<ui::Event> event = base::MakeUnique<ui::MouseEvent>( 373 std::unique_ptr<ui::Event> event = base::MakeUnique<ui::MouseEvent>(
(...skipping 29 matching lines...) Expand all
366 TestShelfController test_shelf_controller_; 403 TestShelfController test_shelf_controller_;
367 404
368 DISALLOW_COPY_AND_ASSIGN(TestChromeLauncherController); 405 DISALLOW_COPY_AND_ASSIGN(TestChromeLauncherController);
369 }; 406 };
370 407
371 // A shell delegate that owns a ChromeLauncherController, like production. 408 // A shell delegate that owns a ChromeLauncherController, like production.
372 // TODO(msw): Refine ChromeLauncherController lifetime management. 409 // TODO(msw): Refine ChromeLauncherController lifetime management.
373 // TODO(msw): Avoid relying on TestShellDelegate's ShelfInitializer. 410 // TODO(msw): Avoid relying on TestShellDelegate's ShelfInitializer.
374 class ChromeLauncherTestShellDelegate : public ash::test::TestShellDelegate { 411 class ChromeLauncherTestShellDelegate : public ash::test::TestShellDelegate {
375 public: 412 public:
376 ChromeLauncherTestShellDelegate() {} 413 explicit ChromeLauncherTestShellDelegate(ash::ShelfModel* shelf_model)
377 414 : shelf_model_(shelf_model) {}
378 // Create a ChromeLauncherController instance.
379 ChromeLauncherController* CreateLauncherController(Profile* profile) {
380 launcher_controller_ = base::MakeUnique<ChromeLauncherController>(
381 profile, ash::Shell::Get()->shelf_model());
382 return launcher_controller_.get();
383 }
384 415
385 // Create a TestChromeLauncherController instance. 416 // Create a TestChromeLauncherController instance.
386 TestChromeLauncherController* CreateTestLauncherController(Profile* profile) { 417 TestChromeLauncherController* CreateLauncherController(Profile* profile) {
387 auto controller = base::MakeUnique<TestChromeLauncherController>( 418 launcher_controller_ =
388 profile, ash::Shell::Get()->shelf_model()); 419 base::MakeUnique<TestChromeLauncherController>(profile, shelf_model_);
389 TestChromeLauncherController* controller_weak = controller.get(); 420 return launcher_controller_.get();
390 launcher_controller_ = std::move(controller);
391 launcher_controller_->Init();
392 return controller_weak;
393 } 421 }
394 422
395 // ash::test::TestShellDelegate: 423 // ash::test::TestShellDelegate:
396 void ShelfShutdown() override { launcher_controller_.reset(); } 424 void ShelfShutdown() override { launcher_controller_.reset(); }
397 425
398 private: 426 private:
399 std::unique_ptr<ChromeLauncherController> launcher_controller_; 427 ash::ShelfModel* shelf_model_;
428 std::unique_ptr<TestChromeLauncherController> launcher_controller_;
400 429
401 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherTestShellDelegate); 430 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherTestShellDelegate);
402 }; 431 };
403 432
404 class ChromeLauncherControllerTest : public BrowserWithTestWindowTest { 433 class ChromeLauncherControllerTest : public BrowserWithTestWindowTest {
405 protected: 434 protected:
406 ChromeLauncherControllerTest() 435 ChromeLauncherControllerTest()
407 : BrowserWithTestWindowTest(Browser::TYPE_TABBED, false) {} 436 : BrowserWithTestWindowTest(Browser::TYPE_TABBED, false) {}
408 437
409 ~ChromeLauncherControllerTest() override {} 438 ~ChromeLauncherControllerTest() override {}
410 439
411 void SetUp() override { 440 void SetUp() override {
412 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 441 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
413 command_line->AppendSwitch(switches::kUseFirstDisplayAsInternal); 442 command_line->AppendSwitch(switches::kUseFirstDisplayAsInternal);
414 443
415 app_list::AppListSyncableServiceFactory::SetUseInTesting(); 444 app_list::AppListSyncableServiceFactory::SetUseInTesting();
416 445
417 shell_delegate_ = new ChromeLauncherTestShellDelegate(); 446 // Add an AppList item, as ash::ShelfController does in non-mash configs.
447 if (chromeos::GetAshConfig() != ash::Config::MASH) {
448 ash::ShelfItem app_list_item;
449 app_list_item.type = ash::TYPE_APP_LIST;
450 app_list_item.id = ash::ShelfID(kAppListId);
451 app_list_item.title = base::ASCIIToUTF16("Launcher");
452 model_.Add(app_list_item);
453 }
454
455 shell_delegate_ = new ChromeLauncherTestShellDelegate(&model_);
418 ash_test_helper()->set_test_shell_delegate(shell_delegate_); 456 ash_test_helper()->set_test_shell_delegate(shell_delegate_);
419 457
420 BrowserWithTestWindowTest::SetUp(); 458 BrowserWithTestWindowTest::SetUp();
421 459
422 if (!profile_manager_) { 460 if (!profile_manager_) {
423 profile_manager_.reset( 461 profile_manager_.reset(
424 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 462 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
425 ASSERT_TRUE(profile_manager_->SetUp()); 463 ASSERT_TRUE(profile_manager_->SetUp());
426 } 464 }
427 465
428 model_ = ash::Shell::Get()->shelf_controller()->model();
429 model_observer_.reset(new TestShelfModelObserver); 466 model_observer_.reset(new TestShelfModelObserver);
430 model_->AddObserver(model_observer_.get()); 467 model_.AddObserver(model_observer_.get());
431 468
432 base::DictionaryValue manifest; 469 base::DictionaryValue manifest;
433 manifest.SetString(extensions::manifest_keys::kName, 470 manifest.SetString(extensions::manifest_keys::kName,
434 "launcher controller test extension"); 471 "launcher controller test extension");
435 manifest.SetString(extensions::manifest_keys::kVersion, "1"); 472 manifest.SetString(extensions::manifest_keys::kVersion, "1");
436 manifest.SetString(extensions::manifest_keys::kDescription, 473 manifest.SetString(extensions::manifest_keys::kDescription,
437 "for testing pinned apps"); 474 "for testing pinned apps");
438 475
439 base::DictionaryValue manifest_platform_app; 476 base::DictionaryValue manifest_platform_app;
440 manifest_platform_app.SetString(extensions::manifest_keys::kName, 477 manifest_platform_app.SetString(extensions::manifest_keys::kName,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 } 560 }
524 561
525 // Creates a running platform V2 app (not pinned) of type |app_id|. 562 // Creates a running platform V2 app (not pinned) of type |app_id|.
526 virtual void CreateRunningV2App(const std::string& app_id) { 563 virtual void CreateRunningV2App(const std::string& app_id) {
527 DCHECK(!test_controller_); 564 DCHECK(!test_controller_);
528 // Change the created launcher controller into a V2 app controller. 565 // Change the created launcher controller into a V2 app controller.
529 std::unique_ptr<TestV2AppLauncherItemController> controller = 566 std::unique_ptr<TestV2AppLauncherItemController> controller =
530 base::MakeUnique<TestV2AppLauncherItemController>(app_id); 567 base::MakeUnique<TestV2AppLauncherItemController>(app_id);
531 test_controller_ = controller.get(); 568 test_controller_ = controller.get();
532 ash::ShelfID id = launcher_controller_->InsertAppLauncherItem( 569 ash::ShelfID id = launcher_controller_->InsertAppLauncherItem(
533 std::move(controller), ash::STATUS_RUNNING, model_->item_count(), 570 std::move(controller), ash::STATUS_RUNNING, model_.item_count(),
534 ash::TYPE_APP); 571 ash::TYPE_APP);
535 DCHECK(launcher_controller_->IsPlatformApp(id)); 572 DCHECK(launcher_controller_->IsPlatformApp(id));
536 } 573 }
537 574
538 // Sets the stage for a multi user test. 575 // Sets the stage for a multi user test.
539 virtual void SetUpMultiUserScenario(syncer::SyncChangeList* user_a, 576 virtual void SetUpMultiUserScenario(syncer::SyncChangeList* user_a,
540 syncer::SyncChangeList* user_b) { 577 syncer::SyncChangeList* user_b) {
541 InitLauncherController(); 578 InitLauncherController();
542 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 579 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
543 580
(...skipping 27 matching lines...) Expand all
571 608
572 // Set user b preferences. 609 // Set user b preferences.
573 InsertAddPinChange(user_b, 0, extension6_->id()); 610 InsertAddPinChange(user_b, 0, extension6_->id());
574 InsertAddPinChange(user_b, 1, extension7_->id()); 611 InsertAddPinChange(user_b, 1, extension7_->id());
575 InsertAddPinChange(user_b, 2, extension8_->id()); 612 InsertAddPinChange(user_b, 2, extension8_->id());
576 InsertAddPinChange(user_b, 3, extension_misc::kChromeAppId); 613 InsertAddPinChange(user_b, 3, extension_misc::kChromeAppId);
577 } 614 }
578 615
579 void TearDown() override { 616 void TearDown() override {
580 arc_test_.TearDown(); 617 arc_test_.TearDown();
581 model_->RemoveObserver(model_observer_.get()); 618 model_.RemoveObserver(model_observer_.get());
582 model_observer_.reset(); 619 model_observer_.reset();
583 launcher_controller_ = nullptr; 620 launcher_controller_ = nullptr;
584 BrowserWithTestWindowTest::TearDown(); 621 BrowserWithTestWindowTest::TearDown();
585 } 622 }
586 623
587 BrowserWindow* CreateBrowserWindow() override { 624 BrowserWindow* CreateBrowserWindow() override {
588 return CreateTestBrowserWindowAura(); 625 return CreateTestBrowserWindowAura();
589 } 626 }
590 627
591 std::unique_ptr<Browser> CreateBrowserWithTestWindowForProfile( 628 std::unique_ptr<Browser> CreateBrowserWithTestWindowForProfile(
592 Profile* profile) { 629 Profile* profile) {
593 TestBrowserWindow* browser_window = CreateTestBrowserWindowAura(); 630 TestBrowserWindow* browser_window = CreateTestBrowserWindowAura();
594 new TestBrowserWindowOwner(browser_window); 631 new TestBrowserWindowOwner(browser_window);
595 return base::WrapUnique( 632 return base::WrapUnique(
596 CreateBrowser(profile, Browser::TYPE_TABBED, false, browser_window)); 633 CreateBrowser(profile, Browser::TYPE_TABBED, false, browser_window));
597 } 634 }
598 635
599 void AddAppListLauncherItem() { 636 void AddAppListLauncherItem() {
600 ash::ShelfItem app_list; 637 ash::ShelfItem app_list;
601 app_list.id = ash::ShelfID(kAppListId); 638 app_list.id = ash::ShelfID(kAppListId);
602 app_list.type = ash::TYPE_APP_LIST; 639 app_list.type = ash::TYPE_APP_LIST;
603 model_->Add(app_list); 640 model_.Add(app_list);
604 } 641 }
605 642
606 // Create a launcher controller instance, owned by the test shell delegate. 643 // Create a launcher controller instance, owned by the test shell delegate.
607 // Returns a pointer to the uninitialized controller. 644 // Returns a pointer to the uninitialized controller.
608 ChromeLauncherController* CreateLauncherController() { 645 ChromeLauncherController* CreateLauncherController() {
609 launcher_controller_ = shell_delegate_->CreateLauncherController(profile()); 646 launcher_controller_ = shell_delegate_->CreateLauncherController(profile());
610 return launcher_controller_; 647 return launcher_controller_;
611 } 648 }
612 649
613 // Create and initialize the controller, owned by the test shell delegate. 650 // Create and initialize the controller, owned by the test shell delegate.
(...skipping 12 matching lines...) Expand all
626 shell_delegate_->ShelfShutdown(); 663 shell_delegate_->ShelfShutdown();
627 } 664 }
628 665
629 // Destroy and recreate the controller; clear and reinitialize the ShelfModel. 666 // Destroy and recreate the controller; clear and reinitialize the ShelfModel.
630 // Returns a pointer to the uninitialized controller, owned by shell delegate. 667 // Returns a pointer to the uninitialized controller, owned by shell delegate.
631 // TODO(msw): This does not accurately represent ChromeLauncherController 668 // TODO(msw): This does not accurately represent ChromeLauncherController
632 // lifetime or usage in production, and does not accurately simulate restarts. 669 // lifetime or usage in production, and does not accurately simulate restarts.
633 ChromeLauncherController* RecreateLauncherController() { 670 ChromeLauncherController* RecreateLauncherController() {
634 // Destroy any existing controller first; only one may exist at a time. 671 // Destroy any existing controller first; only one may exist at a time.
635 ResetLauncherController(); 672 ResetLauncherController();
636 while (model_->item_count() > 0) 673 while (model_.item_count() > 0)
637 model_->RemoveItemAt(0); 674 model_.RemoveItemAt(0);
638 AddAppListLauncherItem(); 675 AddAppListLauncherItem();
639 return CreateLauncherController(); 676 return CreateLauncherController();
640 } 677 }
641 678
642 void StartAppSyncService(const syncer::SyncDataList& init_sync_list) { 679 void StartAppSyncService(const syncer::SyncDataList& init_sync_list) {
643 app_service_->MergeDataAndStartSyncing( 680 app_service_->MergeDataAndStartSyncing(
644 syncer::APP_LIST, init_sync_list, 681 syncer::APP_LIST, init_sync_list,
645 base::MakeUnique<syncer::FakeSyncChangeProcessor>(), 682 base::MakeUnique<syncer::FakeSyncChangeProcessor>(),
646 base::MakeUnique<syncer::SyncErrorFactoryMock>()); 683 base::MakeUnique<syncer::SyncErrorFactoryMock>());
647 EXPECT_EQ(init_sync_list.size(), app_service_->sync_items().size()); 684 EXPECT_EQ(init_sync_list.size(), app_service_->sync_items().size());
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 extension_misc::kChromeAppId, "Test", specifics); 858 extension_misc::kChromeAppId, "Test", specifics);
822 sync_list.push_back(syncer::SyncChange( 859 sync_list.push_back(syncer::SyncChange(
823 FROM_HERE, syncer::SyncChange::ACTION_UPDATE, sync_data)); 860 FROM_HERE, syncer::SyncChange::ACTION_UPDATE, sync_data));
824 app_service_->ProcessSyncChanges(FROM_HERE, sync_list); 861 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
825 } 862 }
826 863
827 // Gets the IDs of the currently pinned app items. 864 // Gets the IDs of the currently pinned app items.
828 void GetPinnedAppIds(ChromeLauncherController* controller, 865 void GetPinnedAppIds(ChromeLauncherController* controller,
829 std::vector<std::string>* app_ids) { 866 std::vector<std::string>* app_ids) {
830 app_ids->clear(); 867 app_ids->clear();
831 for (const auto& item : model_->items()) { 868 for (const auto& item : model_.items()) {
832 if (item.type == ash::TYPE_PINNED_APP) 869 if (item.type == ash::TYPE_PINNED_APP)
833 app_ids->push_back(item.id.app_id); 870 app_ids->push_back(item.id.app_id);
834 } 871 }
835 } 872 }
836 873
837 // Get the setup of the currently shown launcher items in one string. 874 // Get the setup of the currently shown launcher items in one string.
838 // Each pinned element will start with a big letter, each running but not 875 // Each pinned element will start with a big letter, each running but not
839 // pinned V1 app will start with a small letter and each running but not 876 // pinned V1 app will start with a small letter and each running but not
840 // pinned V2 app will start with a '*' + small letter. 877 // pinned V2 app will start with a '*' + small letter.
841 std::string GetPinnedAppStatus() { 878 std::string GetPinnedAppStatus() {
842 std::string result; 879 std::string result;
843 for (int i = 0; i < model_->item_count(); i++) { 880 for (int i = 0; i < model_.item_count(); i++) {
844 if (!result.empty()) 881 if (!result.empty())
845 result.append(", "); 882 result.append(", ");
846 switch (model_->items()[i].type) { 883 switch (model_.items()[i].type) {
847 case ash::TYPE_APP: { 884 case ash::TYPE_APP: {
848 if (launcher_controller_->IsPlatformApp(model_->items()[i].id)) 885 if (launcher_controller_->IsPlatformApp(model_.items()[i].id))
849 result += "*"; 886 result += "*";
850 const std::string& app = model_->items()[i].id.app_id; 887 const std::string& app = model_.items()[i].id.app_id;
851 EXPECT_FALSE(launcher_controller_->IsAppPinned(app)); 888 EXPECT_FALSE(launcher_controller_->IsAppPinned(app));
852 if (app == extension1_->id()) { 889 if (app == extension1_->id()) {
853 result += "app1"; 890 result += "app1";
854 } else if (app == extension2_->id()) { 891 } else if (app == extension2_->id()) {
855 result += "app2"; 892 result += "app2";
856 } else if (app == extension3_->id()) { 893 } else if (app == extension3_->id()) {
857 result += "app3"; 894 result += "app3";
858 } else if (app == extension4_->id()) { 895 } else if (app == extension4_->id()) {
859 result += "app4"; 896 result += "app4";
860 } else if (app == extension5_->id()) { 897 } else if (app == extension5_->id()) {
861 result += "app5"; 898 result += "app5";
862 } else if (app == extension6_->id()) { 899 } else if (app == extension6_->id()) {
863 result += "app6"; 900 result += "app6";
864 } else if (app == extension7_->id()) { 901 } else if (app == extension7_->id()) {
865 result += "app7"; 902 result += "app7";
866 } else if (app == extension8_->id()) { 903 } else if (app == extension8_->id()) {
867 result += "app8"; 904 result += "app8";
868 } else if (app == extension_platform_app_->id()) { 905 } else if (app == extension_platform_app_->id()) {
869 result += "platform_app"; 906 result += "platform_app";
870 } else { 907 } else {
871 result += "unknown"; 908 result += "unknown";
872 } 909 }
873 break; 910 break;
874 } 911 }
875 case ash::TYPE_PINNED_APP: { 912 case ash::TYPE_PINNED_APP: {
876 if (launcher_controller_->IsPlatformApp(model_->items()[i].id)) 913 if (launcher_controller_->IsPlatformApp(model_.items()[i].id))
877 result += "*"; 914 result += "*";
878 const std::string& app = model_->items()[i].id.app_id; 915 const std::string& app = model_.items()[i].id.app_id;
879 EXPECT_TRUE(launcher_controller_->IsAppPinned(app)); 916 EXPECT_TRUE(launcher_controller_->IsAppPinned(app));
880 if (app == extension1_->id()) { 917 if (app == extension1_->id()) {
881 result += "App1"; 918 result += "App1";
882 } else if (app == extension2_->id()) { 919 } else if (app == extension2_->id()) {
883 result += "App2"; 920 result += "App2";
884 } else if (app == extension3_->id()) { 921 } else if (app == extension3_->id()) {
885 result += "App3"; 922 result += "App3";
886 } else if (app == extension4_->id()) { 923 } else if (app == extension4_->id()) {
887 result += "App4"; 924 result += "App4";
888 } else if (app == extension5_->id()) { 925 } else if (app == extension5_->id()) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 scoped_refptr<Extension> extension7_; 1080 scoped_refptr<Extension> extension7_;
1044 scoped_refptr<Extension> extension8_; 1081 scoped_refptr<Extension> extension8_;
1045 scoped_refptr<Extension> extension_platform_app_; 1082 scoped_refptr<Extension> extension_platform_app_;
1046 scoped_refptr<Extension> arc_support_host_; 1083 scoped_refptr<Extension> arc_support_host_;
1047 1084
1048 ArcAppTest arc_test_; 1085 ArcAppTest arc_test_;
1049 bool auto_start_arc_test_ = false; 1086 bool auto_start_arc_test_ = false;
1050 ChromeLauncherController* launcher_controller_ = nullptr; 1087 ChromeLauncherController* launcher_controller_ = nullptr;
1051 ChromeLauncherTestShellDelegate* shell_delegate_ = nullptr; 1088 ChromeLauncherTestShellDelegate* shell_delegate_ = nullptr;
1052 std::unique_ptr<TestShelfModelObserver> model_observer_; 1089 std::unique_ptr<TestShelfModelObserver> model_observer_;
1053 ash::ShelfModel* model_ = nullptr; 1090 ash::ShelfModel model_;
1054 std::unique_ptr<TestingProfileManager> profile_manager_; 1091 std::unique_ptr<TestingProfileManager> profile_manager_;
1055 1092
1056 // |item_delegate_manager_| owns |test_controller_|. 1093 // |item_delegate_manager_| owns |test_controller_|.
1057 ash::ShelfItemDelegate* test_controller_ = nullptr; 1094 ash::ShelfItemDelegate* test_controller_ = nullptr;
1058 1095
1059 ExtensionService* extension_service_ = nullptr; 1096 ExtensionService* extension_service_ = nullptr;
1060 1097
1061 app_list::AppListSyncableService* app_service_ = nullptr; 1098 app_list::AppListSyncableService* app_service_ = nullptr;
1062 1099
1063 private: 1100 private:
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerMultiProfileWithArcTest); 1384 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerMultiProfileWithArcTest);
1348 }; 1385 };
1349 1386
1350 INSTANTIATE_TEST_CASE_P(, 1387 INSTANTIATE_TEST_CASE_P(,
1351 ChromeLauncherControllerMultiProfileWithArcTest, 1388 ChromeLauncherControllerMultiProfileWithArcTest,
1352 ::testing::Bool()); 1389 ::testing::Bool());
1353 1390
1354 TEST_F(ChromeLauncherControllerTest, DefaultApps) { 1391 TEST_F(ChromeLauncherControllerTest, DefaultApps) {
1355 InitLauncherController(); 1392 InitLauncherController();
1356 // The model should only contain the browser shortcut and app list items. 1393 // The model should only contain the browser shortcut and app list items.
1357 EXPECT_EQ(2, model_->item_count()); 1394 EXPECT_EQ(2, model_.item_count());
1358 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1395 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1359 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1396 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1360 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1397 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1361 1398
1362 // Installing |extension3_| should add it to the launcher - behind the 1399 // Installing |extension3_| should add it to the launcher - behind the
1363 // chrome icon. 1400 // chrome icon.
1364 extension_service_->AddExtension(extension3_.get()); 1401 extension_service_->AddExtension(extension3_.get());
1365 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); 1402 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus());
1366 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1403 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1367 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1404 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1420 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id1)); 1457 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id1));
1421 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 1458 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
1422 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id2)); 1459 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id2));
1423 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 1460 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1424 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3)); 1461 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3));
1425 1462
1426 EXPECT_EQ("AppList, App1, Chrome, Fake App 0, App2, Fake App 1, App3", 1463 EXPECT_EQ("AppList, App1, Chrome, Fake App 0, App2, Fake App 1, App3",
1427 GetPinnedAppStatus()); 1464 GetPinnedAppStatus());
1428 1465
1429 // Now move pins on ARC enabled platform. 1466 // Now move pins on ARC enabled platform.
1430 model_->Move(1, 4); 1467 model_.Move(1, 4);
1431 model_->Move(3, 1); 1468 model_.Move(3, 1);
1432 model_->Move(3, 5); 1469 model_.Move(3, 5);
1433 model_->Move(4, 2); 1470 model_.Move(4, 2);
1434 EXPECT_EQ("AppList, App2, Fake App 1, Chrome, App1, Fake App 0, App3", 1471 EXPECT_EQ("AppList, App2, Fake App 1, Chrome, App1, Fake App 0, App3",
1435 GetPinnedAppStatus()); 1472 GetPinnedAppStatus());
1436 1473
1437 copy_sync_list = app_service_->GetAllSyncData(syncer::APP_LIST); 1474 copy_sync_list = app_service_->GetAllSyncData(syncer::APP_LIST);
1438 1475
1439 ResetLauncherController(); 1476 ResetLauncherController();
1440 ResetPinModel(); 1477 ResetPinModel();
1441 1478
1442 SendPinChanges(syncer::SyncChangeList(), true); 1479 SendPinChanges(syncer::SyncChangeList(), true);
1443 StopAppSyncService(); 1480 StopAppSyncService();
1444 EXPECT_EQ(0U, app_service_->sync_items().size()); 1481 EXPECT_EQ(0U, app_service_->sync_items().size());
1445 1482
1446 // Move back to ARC disabled platform. 1483 // Move back to ARC disabled platform.
1447 // TODO(victorhsieh): Implement opt-out. 1484 // TODO(victorhsieh): Implement opt-out.
1448 if (arc::ShouldArcAlwaysStart()) 1485 if (arc::ShouldArcAlwaysStart())
1449 return; 1486 return;
1450 EnablePlayStore(false); 1487 EnablePlayStore(false);
1451 StartAppSyncService(copy_sync_list); 1488 StartAppSyncService(copy_sync_list);
1452 RecreateLauncherController()->Init(); 1489 RecreateLauncherController()->Init();
1453 1490
1454 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1491 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1455 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id1)); 1492 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id1));
1456 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 1493 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
1457 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id2)); 1494 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id2));
1458 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 1495 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1459 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3)); 1496 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3));
1460 EXPECT_EQ("AppList, App2, Chrome, App1, App3", GetPinnedAppStatus()); 1497 EXPECT_EQ("AppList, App2, Chrome, App1, App3", GetPinnedAppStatus());
1461 1498
1462 // Now move/remove pins on ARC disabled platform. 1499 // Now move/remove pins on ARC disabled platform.
1463 model_->Move(4, 2); 1500 model_.Move(4, 2);
1464 launcher_controller_->UnpinAppWithID(extension2_->id()); 1501 launcher_controller_->UnpinAppWithID(extension2_->id());
1465 EXPECT_EQ("AppList, App3, Chrome, App1", GetPinnedAppStatus()); 1502 EXPECT_EQ("AppList, App3, Chrome, App1", GetPinnedAppStatus());
1466 EnablePlayStore(true); 1503 EnablePlayStore(true);
1467 1504
1468 SendListOfArcApps(); 1505 SendListOfArcApps();
1469 1506
1470 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1507 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1471 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id1)); 1508 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id1));
1472 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1509 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1473 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id2)); 1510 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id2));
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1691 // Check that an update of an extension does not crash the system. 1728 // Check that an update of an extension does not crash the system.
1692 extension_service_->UnloadExtension(extension3_->id(), 1729 extension_service_->UnloadExtension(extension3_->id(),
1693 UnloadedExtensionReason::UPDATE); 1730 UnloadedExtensionReason::UPDATE);
1694 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); 1731 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus());
1695 } 1732 }
1696 1733
1697 // Test the V1 app interaction flow: run it, activate it, close it. 1734 // Test the V1 app interaction flow: run it, activate it, close it.
1698 TEST_F(ChromeLauncherControllerTest, V1AppRunActivateClose) { 1735 TEST_F(ChromeLauncherControllerTest, V1AppRunActivateClose) {
1699 InitLauncherController(); 1736 InitLauncherController();
1700 // The model should only contain the browser shortcut and app list items. 1737 // The model should only contain the browser shortcut and app list items.
1701 EXPECT_EQ(2, model_->item_count()); 1738 EXPECT_EQ(2, model_.item_count());
1702 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1739 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1703 EXPECT_EQ(nullptr, 1740 EXPECT_EQ(nullptr,
1704 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1741 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1705 1742
1706 // Reporting that the app is running should create a new shelf item. 1743 // Reporting that the app is running should create a new shelf item.
1707 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING); 1744 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING);
1708 EXPECT_EQ(3, model_->item_count()); 1745 EXPECT_EQ(3, model_.item_count());
1709 EXPECT_EQ(ash::TYPE_APP, model_->items()[2].type); 1746 EXPECT_EQ(ash::TYPE_APP, model_.items()[2].type);
1710 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[2].status); 1747 EXPECT_EQ(ash::STATUS_RUNNING, model_.items()[2].status);
1711 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1748 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1712 EXPECT_NE(nullptr, 1749 EXPECT_NE(nullptr,
1713 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1750 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1714 1751
1715 // Reporting an active status should just update the existing item. 1752 // Reporting an active status should just update the existing item.
1716 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_ACTIVE); 1753 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_ACTIVE);
1717 EXPECT_EQ(3, model_->item_count()); 1754 EXPECT_EQ(3, model_.item_count());
1718 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[2].status); 1755 EXPECT_EQ(ash::STATUS_ACTIVE, model_.items()[2].status);
1719 1756
1720 // Reporting that the app is closed should remove its shelf item. 1757 // Reporting that the app is closed should remove its shelf item.
1721 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED); 1758 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED);
1722 EXPECT_EQ(2, model_->item_count()); 1759 EXPECT_EQ(2, model_.item_count());
1723 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1760 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1724 EXPECT_EQ(nullptr, 1761 EXPECT_EQ(nullptr,
1725 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1762 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1726 1763
1727 // Reporting that the app is closed again should have no effect. 1764 // Reporting that the app is closed again should have no effect.
1728 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED); 1765 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED);
1729 EXPECT_EQ(2, model_->item_count()); 1766 EXPECT_EQ(2, model_.item_count());
1730 } 1767 }
1731 1768
1732 // Test the V1 app interaction flow: pin it, run it, close it, unpin it. 1769 // Test the V1 app interaction flow: pin it, run it, close it, unpin it.
1733 TEST_F(ChromeLauncherControllerTest, V1AppPinRunCloseUnpin) { 1770 TEST_F(ChromeLauncherControllerTest, V1AppPinRunCloseUnpin) {
1734 InitLauncherController(); 1771 InitLauncherController();
1735 // The model should only contain the browser shortcut and app list items. 1772 // The model should only contain the browser shortcut and app list items.
1736 EXPECT_EQ(2, model_->item_count()); 1773 EXPECT_EQ(2, model_.item_count());
1737 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1774 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1738 EXPECT_EQ(nullptr, 1775 EXPECT_EQ(nullptr,
1739 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1776 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1740 1777
1741 // Pinning the app should create a new shelf item. 1778 // Pinning the app should create a new shelf item.
1742 launcher_controller_->PinAppWithID(extension1_->id()); 1779 launcher_controller_->PinAppWithID(extension1_->id());
1743 EXPECT_EQ(3, model_->item_count()); 1780 EXPECT_EQ(3, model_.item_count());
1744 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 1781 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
1745 EXPECT_EQ(ash::STATUS_CLOSED, model_->items()[2].status); 1782 EXPECT_EQ(ash::STATUS_CLOSED, model_.items()[2].status);
1746 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1783 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1747 EXPECT_NE(nullptr, 1784 EXPECT_NE(nullptr,
1748 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1785 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1749 1786
1750 // Reporting that the app is running should just update the existing item. 1787 // Reporting that the app is running should just update the existing item.
1751 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING); 1788 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING);
1752 EXPECT_EQ(3, model_->item_count()); 1789 EXPECT_EQ(3, model_.item_count());
1753 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 1790 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
1754 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[2].status); 1791 EXPECT_EQ(ash::STATUS_RUNNING, model_.items()[2].status);
1755 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1792 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1756 EXPECT_NE(nullptr, 1793 EXPECT_NE(nullptr,
1757 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1794 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1758 1795
1759 // Reporting that the app is closed should just update the existing item. 1796 // Reporting that the app is closed should just update the existing item.
1760 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED); 1797 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED);
1761 EXPECT_EQ(3, model_->item_count()); 1798 EXPECT_EQ(3, model_.item_count());
1762 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 1799 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
1763 EXPECT_EQ(ash::STATUS_CLOSED, model_->items()[2].status); 1800 EXPECT_EQ(ash::STATUS_CLOSED, model_.items()[2].status);
1764 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1801 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1765 EXPECT_NE(nullptr, 1802 EXPECT_NE(nullptr,
1766 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1803 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1767 1804
1768 // Unpinning the app should remove its shelf item. 1805 // Unpinning the app should remove its shelf item.
1769 launcher_controller_->UnpinAppWithID(extension1_->id()); 1806 launcher_controller_->UnpinAppWithID(extension1_->id());
1770 EXPECT_EQ(2, model_->item_count()); 1807 EXPECT_EQ(2, model_.item_count());
1771 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1808 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1772 EXPECT_EQ(nullptr, 1809 EXPECT_EQ(nullptr,
1773 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1810 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1774 } 1811 }
1775 1812
1776 // Test the V1 app interaction flow: run it, pin it, close it, unpin it. 1813 // Test the V1 app interaction flow: run it, pin it, close it, unpin it.
1777 TEST_F(ChromeLauncherControllerTest, V1AppRunPinCloseUnpin) { 1814 TEST_F(ChromeLauncherControllerTest, V1AppRunPinCloseUnpin) {
1778 InitLauncherController(); 1815 InitLauncherController();
1779 // The model should only contain the browser shortcut and app list items. 1816 // The model should only contain the browser shortcut and app list items.
1780 EXPECT_EQ(2, model_->item_count()); 1817 EXPECT_EQ(2, model_.item_count());
1781 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1818 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1782 EXPECT_EQ(nullptr, 1819 EXPECT_EQ(nullptr,
1783 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1820 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1784 1821
1785 // Reporting that the app is running should create a new shelf item. 1822 // Reporting that the app is running should create a new shelf item.
1786 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING); 1823 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING);
1787 EXPECT_EQ(3, model_->item_count()); 1824 EXPECT_EQ(3, model_.item_count());
1788 EXPECT_EQ(ash::TYPE_APP, model_->items()[2].type); 1825 EXPECT_EQ(ash::TYPE_APP, model_.items()[2].type);
1789 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[2].status); 1826 EXPECT_EQ(ash::STATUS_RUNNING, model_.items()[2].status);
1790 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1827 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1791 EXPECT_NE(nullptr, 1828 EXPECT_NE(nullptr,
1792 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1829 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1793 1830
1794 // Pinning the app should just update the existing item. 1831 // Pinning the app should just update the existing item.
1795 launcher_controller_->PinAppWithID(extension1_->id()); 1832 launcher_controller_->PinAppWithID(extension1_->id());
1796 EXPECT_EQ(3, model_->item_count()); 1833 EXPECT_EQ(3, model_.item_count());
1797 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 1834 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
1798 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[2].status); 1835 EXPECT_EQ(ash::STATUS_RUNNING, model_.items()[2].status);
1799 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1836 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1800 EXPECT_NE(nullptr, 1837 EXPECT_NE(nullptr,
1801 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1838 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1802 1839
1803 // Reporting that the app is closed should just update the existing item. 1840 // Reporting that the app is closed should just update the existing item.
1804 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED); 1841 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED);
1805 EXPECT_EQ(3, model_->item_count()); 1842 EXPECT_EQ(3, model_.item_count());
1806 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 1843 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
1807 EXPECT_EQ(ash::STATUS_CLOSED, model_->items()[2].status); 1844 EXPECT_EQ(ash::STATUS_CLOSED, model_.items()[2].status);
1808 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1845 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1809 EXPECT_NE(nullptr, 1846 EXPECT_NE(nullptr,
1810 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1847 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1811 1848
1812 // Unpinning the app should remove its shelf item. 1849 // Unpinning the app should remove its shelf item.
1813 launcher_controller_->UnpinAppWithID(extension1_->id()); 1850 launcher_controller_->UnpinAppWithID(extension1_->id());
1814 EXPECT_EQ(2, model_->item_count()); 1851 EXPECT_EQ(2, model_.item_count());
1815 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1852 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1816 EXPECT_EQ(nullptr, 1853 EXPECT_EQ(nullptr,
1817 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1854 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1818 } 1855 }
1819 1856
1820 // Test the V1 app interaction flow: pin it, run it, unpin it, close it. 1857 // Test the V1 app interaction flow: pin it, run it, unpin it, close it.
1821 TEST_F(ChromeLauncherControllerTest, V1AppPinRunUnpinClose) { 1858 TEST_F(ChromeLauncherControllerTest, V1AppPinRunUnpinClose) {
1822 InitLauncherController(); 1859 InitLauncherController();
1823 // The model should only contain the browser shortcut and app list items. 1860 // The model should only contain the browser shortcut and app list items.
1824 EXPECT_EQ(2, model_->item_count()); 1861 EXPECT_EQ(2, model_.item_count());
1825 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1862 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1826 EXPECT_EQ(nullptr, 1863 EXPECT_EQ(nullptr,
1827 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1864 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1828 1865
1829 // Pinning the app should create a new shelf item. 1866 // Pinning the app should create a new shelf item.
1830 launcher_controller_->PinAppWithID(extension1_->id()); 1867 launcher_controller_->PinAppWithID(extension1_->id());
1831 EXPECT_EQ(3, model_->item_count()); 1868 EXPECT_EQ(3, model_.item_count());
1832 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 1869 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
1833 EXPECT_EQ(ash::STATUS_CLOSED, model_->items()[2].status); 1870 EXPECT_EQ(ash::STATUS_CLOSED, model_.items()[2].status);
1834 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1871 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1835 EXPECT_NE(nullptr, 1872 EXPECT_NE(nullptr,
1836 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1873 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1837 1874
1838 // Reporting that the app is running should just update the existing item. 1875 // Reporting that the app is running should just update the existing item.
1839 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING); 1876 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING);
1840 EXPECT_EQ(3, model_->item_count()); 1877 EXPECT_EQ(3, model_.item_count());
1841 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 1878 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
1842 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[2].status); 1879 EXPECT_EQ(ash::STATUS_RUNNING, model_.items()[2].status);
1843 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1880 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1844 EXPECT_NE(nullptr, 1881 EXPECT_NE(nullptr,
1845 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1882 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1846 1883
1847 // Unpinning the app should just update the existing item. 1884 // Unpinning the app should just update the existing item.
1848 launcher_controller_->UnpinAppWithID(extension1_->id()); 1885 launcher_controller_->UnpinAppWithID(extension1_->id());
1849 EXPECT_EQ(3, model_->item_count()); 1886 EXPECT_EQ(3, model_.item_count());
1850 EXPECT_EQ(ash::TYPE_APP, model_->items()[2].type); 1887 EXPECT_EQ(ash::TYPE_APP, model_.items()[2].type);
1851 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[2].status); 1888 EXPECT_EQ(ash::STATUS_RUNNING, model_.items()[2].status);
1852 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1889 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1853 EXPECT_NE(nullptr, 1890 EXPECT_NE(nullptr,
1854 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1891 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1855 1892
1856 // Reporting that the app is closed should remove its shelf item. 1893 // Reporting that the app is closed should remove its shelf item.
1857 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED); 1894 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED);
1858 EXPECT_EQ(2, model_->item_count()); 1895 EXPECT_EQ(2, model_.item_count());
1859 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1896 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1860 EXPECT_EQ(nullptr, 1897 EXPECT_EQ(nullptr,
1861 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1898 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1862 } 1899 }
1863 1900
1864 // Ensure unpinned V1 app ordering is properly restored after user changes. 1901 // Ensure unpinned V1 app ordering is properly restored after user changes.
1865 TEST_F(ChromeLauncherControllerTest, CheckRunningV1AppOrder) { 1902 TEST_F(ChromeLauncherControllerTest, CheckRunningV1AppOrder) {
1866 InitLauncherController(); 1903 InitLauncherController();
1867 // The model should only contain the browser shortcut and app list items. 1904 // The model should only contain the browser shortcut and app list items.
1868 EXPECT_EQ(2, model_->item_count()); 1905 EXPECT_EQ(2, model_.item_count());
1869 1906
1870 // Add a few running applications. 1907 // Add a few running applications.
1871 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING); 1908 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING);
1872 launcher_controller_->SetV1AppStatus(extension2_->id(), ash::STATUS_RUNNING); 1909 launcher_controller_->SetV1AppStatus(extension2_->id(), ash::STATUS_RUNNING);
1873 launcher_controller_->SetV1AppStatus(extension3_->id(), ash::STATUS_RUNNING); 1910 launcher_controller_->SetV1AppStatus(extension3_->id(), ash::STATUS_RUNNING);
1874 EXPECT_EQ(5, model_->item_count()); 1911 EXPECT_EQ(5, model_.item_count());
1875 // Note that this not only checks the order of applications but also the 1912 // Note that this not only checks the order of applications but also the
1876 // running type. 1913 // running type.
1877 EXPECT_EQ("AppList, Chrome, app1, app2, app3", GetPinnedAppStatus()); 1914 EXPECT_EQ("AppList, Chrome, app1, app2, app3", GetPinnedAppStatus());
1878 1915
1879 // Remember the current order of applications for the current user. 1916 // Remember the current order of applications for the current user.
1880 const AccountId& current_account_id = 1917 const AccountId& current_account_id =
1881 multi_user_util::GetAccountIdFromProfile(profile()); 1918 multi_user_util::GetAccountIdFromProfile(profile());
1882 RememberUnpinnedRunningApplicationOrder(); 1919 RememberUnpinnedRunningApplicationOrder();
1883 1920
1884 // Switch some items and check that restoring a user which was not yet 1921 // Switch some items and check that restoring a user which was not yet
1885 // remembered changes nothing. 1922 // remembered changes nothing.
1886 model_->Move(2, 3); 1923 model_.Move(2, 3);
1887 EXPECT_EQ("AppList, Chrome, app2, app1, app3", GetPinnedAppStatus()); 1924 EXPECT_EQ("AppList, Chrome, app2, app1, app3", GetPinnedAppStatus());
1888 const AccountId second_fake_account_id( 1925 const AccountId second_fake_account_id(
1889 AccountId::FromUserEmail("second-fake-user@fake.com")); 1926 AccountId::FromUserEmail("second-fake-user@fake.com"));
1890 RestoreUnpinnedRunningApplicationOrder(second_fake_account_id); 1927 RestoreUnpinnedRunningApplicationOrder(second_fake_account_id);
1891 EXPECT_EQ("AppList, Chrome, app2, app1, app3", GetPinnedAppStatus()); 1928 EXPECT_EQ("AppList, Chrome, app2, app1, app3", GetPinnedAppStatus());
1892 1929
1893 // Restoring the stored user should however do the right thing. 1930 // Restoring the stored user should however do the right thing.
1894 RestoreUnpinnedRunningApplicationOrder(current_account_id); 1931 RestoreUnpinnedRunningApplicationOrder(current_account_id);
1895 EXPECT_EQ("AppList, Chrome, app1, app2, app3", GetPinnedAppStatus()); 1932 EXPECT_EQ("AppList, Chrome, app1, app2, app3", GetPinnedAppStatus());
1896 1933
1897 // Switch again some items and even delete one - making sure that the missing 1934 // Switch again some items and even delete one - making sure that the missing
1898 // item gets properly handled. 1935 // item gets properly handled.
1899 model_->Move(3, 4); 1936 model_.Move(3, 4);
1900 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED); 1937 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED);
1901 EXPECT_EQ("AppList, Chrome, app3, app2", GetPinnedAppStatus()); 1938 EXPECT_EQ("AppList, Chrome, app3, app2", GetPinnedAppStatus());
1902 RestoreUnpinnedRunningApplicationOrder(current_account_id); 1939 RestoreUnpinnedRunningApplicationOrder(current_account_id);
1903 EXPECT_EQ("AppList, Chrome, app2, app3", GetPinnedAppStatus()); 1940 EXPECT_EQ("AppList, Chrome, app2, app3", GetPinnedAppStatus());
1904 1941
1905 // Check that removing more items does not crash and changes nothing. 1942 // Check that removing more items does not crash and changes nothing.
1906 launcher_controller_->SetV1AppStatus(extension2_->id(), ash::STATUS_CLOSED); 1943 launcher_controller_->SetV1AppStatus(extension2_->id(), ash::STATUS_CLOSED);
1907 RestoreUnpinnedRunningApplicationOrder(current_account_id); 1944 RestoreUnpinnedRunningApplicationOrder(current_account_id);
1908 EXPECT_EQ("AppList, Chrome, app3", GetPinnedAppStatus()); 1945 EXPECT_EQ("AppList, Chrome, app3", GetPinnedAppStatus());
1909 launcher_controller_->SetV1AppStatus(extension3_->id(), ash::STATUS_CLOSED); 1946 launcher_controller_->SetV1AppStatus(extension3_->id(), ash::STATUS_CLOSED);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1944 arc::LaunchApp(profile(), arc_shortcut_id, ui::EF_LEFT_MOUSE_BUTTON); 1981 arc::LaunchApp(profile(), arc_shortcut_id, ui::EF_LEFT_MOUSE_BUTTON);
1945 1982
1946 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_1)); 1983 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_1));
1947 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_2)); 1984 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_2));
1948 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_3)); 1985 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_3));
1949 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_shortcut)); 1986 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_shortcut));
1950 1987
1951 // We activated arc_app_id1 twice but expect one close for item controller 1988 // We activated arc_app_id1 twice but expect one close for item controller
1952 // stops launching request. 1989 // stops launching request.
1953 ash::ShelfItemDelegate* item_delegate = 1990 ash::ShelfItemDelegate* item_delegate =
1954 model_->GetShelfItemDelegate(shelf_id_app_1); 1991 model_.GetShelfItemDelegate(shelf_id_app_1);
1955 ASSERT_NE(nullptr, item_delegate); 1992 ASSERT_NE(nullptr, item_delegate);
1956 item_delegate->Close(); 1993 item_delegate->Close();
1957 base::RunLoop().RunUntilIdle(); 1994 base::RunLoop().RunUntilIdle();
1958 1995
1959 EXPECT_FALSE(launcher_controller_->GetItem(shelf_id_app_1)); 1996 EXPECT_FALSE(launcher_controller_->GetItem(shelf_id_app_1));
1960 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_2)); 1997 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_2));
1961 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_3)); 1998 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_3));
1962 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_shortcut)); 1999 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_shortcut));
1963 2000
1964 arc_test_.RestartArcInstance(); 2001 arc_test_.RestartArcInstance();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2000 launcher_controller_->PinAppWithID(app_id); 2037 launcher_controller_->PinAppWithID(app_id);
2001 EXPECT_TRUE(launcher_controller_->IsAppPinned(app_id)); 2038 EXPECT_TRUE(launcher_controller_->IsAppPinned(app_id));
2002 const ash::ShelfID shelf_id(app_id); 2039 const ash::ShelfID shelf_id(app_id);
2003 const ash::ShelfItem* item = launcher_controller_->GetItem(shelf_id); 2040 const ash::ShelfItem* item = launcher_controller_->GetItem(shelf_id);
2004 ASSERT_NE(nullptr, item); 2041 ASSERT_NE(nullptr, item);
2005 EXPECT_EQ(ash::STATUS_CLOSED, item->status); 2042 EXPECT_EQ(ash::STATUS_CLOSED, item->status);
2006 EXPECT_EQ(ash::TYPE_PINNED_APP, item->type); 2043 EXPECT_EQ(ash::TYPE_PINNED_APP, item->type);
2007 2044
2008 // Play Store app is ARC app that might be represented by native Chrome 2045 // Play Store app is ARC app that might be represented by native Chrome
2009 // platform app. 2046 // platform app.
2010 model_->SetShelfItemDelegate( 2047 model_.SetShelfItemDelegate(
2011 shelf_id, 2048 shelf_id,
2012 base::MakeUnique<ExtensionAppWindowLauncherItemController>(shelf_id)); 2049 base::MakeUnique<ExtensionAppWindowLauncherItemController>(shelf_id));
2013 launcher_controller_->SetItemStatus(shelf_id, ash::STATUS_RUNNING); 2050 launcher_controller_->SetItemStatus(shelf_id, ash::STATUS_RUNNING);
2014 2051
2015 // This launch request should be ignored in case of active app. 2052 // This launch request should be ignored in case of active app.
2016 arc::LaunchApp(profile(), app_id, ui::EF_LEFT_MOUSE_BUTTON); 2053 arc::LaunchApp(profile(), app_id, ui::EF_LEFT_MOUSE_BUTTON);
2017 EXPECT_FALSE(launcher_controller_->GetArcDeferredLauncher()->HasApp(app_id)); 2054 EXPECT_FALSE(launcher_controller_->GetArcDeferredLauncher()->HasApp(app_id));
2018 2055
2019 // Closing the app should leave a pinned but closed shelf item shortcut. 2056 // Closing the app should leave a pinned but closed shelf item shortcut.
2020 launcher_controller_->CloseLauncherItem(shelf_id); 2057 launcher_controller_->CloseLauncherItem(shelf_id);
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
2317 ASSERT_TRUE(window1 && window1->GetNativeWindow()); 2354 ASSERT_TRUE(window1 && window1->GetNativeWindow());
2318 arc_test_.app_instance()->SendTaskCreated(1, arc_test_.fake_apps()[0], 2355 arc_test_.app_instance()->SendTaskCreated(1, arc_test_.fake_apps()[0],
2319 std::string()); 2356 std::string());
2320 2357
2321 views::Widget* window2 = CreateArcWindow(window_app_id2); 2358 views::Widget* window2 = CreateArcWindow(window_app_id2);
2322 ASSERT_TRUE(window2 && window2->GetNativeWindow()); 2359 ASSERT_TRUE(window2 && window2->GetNativeWindow());
2323 arc_test_.app_instance()->SendTaskCreated(2, arc_test_.fake_apps()[0], 2360 arc_test_.app_instance()->SendTaskCreated(2, arc_test_.fake_apps()[0],
2324 std::string()); 2361 std::string());
2325 EXPECT_TRUE(launcher_controller_->GetItem(ash::ShelfID(arc_app_id))); 2362 EXPECT_TRUE(launcher_controller_->GetItem(ash::ShelfID(arc_app_id)));
2326 ash::ShelfItemDelegate* item_delegate = 2363 ash::ShelfItemDelegate* item_delegate =
2327 model_->GetShelfItemDelegate(ash::ShelfID(arc_app_id)); 2364 model_.GetShelfItemDelegate(ash::ShelfID(arc_app_id));
2328 ASSERT_TRUE(item_delegate); 2365 ASSERT_TRUE(item_delegate);
2329 2366
2330 // No custom icon set. Acitivating windows should not change icon. 2367 // No custom icon set. Acitivating windows should not change icon.
2331 EXPECT_FALSE(item_delegate->image_set_by_controller()); 2368 EXPECT_FALSE(item_delegate->image_set_by_controller());
2332 window1->Activate(); 2369 window1->Activate();
2333 EXPECT_FALSE(item_delegate->image_set_by_controller()); 2370 EXPECT_FALSE(item_delegate->image_set_by_controller());
2334 window2->Activate(); 2371 window2->Activate();
2335 EXPECT_FALSE(item_delegate->image_set_by_controller()); 2372 EXPECT_FALSE(item_delegate->image_set_by_controller());
2336 2373
2337 // Set custom icon on active item. Icon should change to custom. 2374 // Set custom icon on active item. Icon should change to custom.
(...skipping 20 matching lines...) Expand all
2358 EXPECT_FALSE(item_delegate->image_set_by_controller()); 2395 EXPECT_FALSE(item_delegate->image_set_by_controller());
2359 } 2396 }
2360 2397
2361 // Check that with multi profile V1 apps are properly added / removed from the 2398 // Check that with multi profile V1 apps are properly added / removed from the
2362 // shelf. 2399 // shelf.
2363 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2400 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
2364 V1AppUpdateOnUserSwitch) { 2401 V1AppUpdateOnUserSwitch) {
2365 // Create a browser item in the LauncherController. 2402 // Create a browser item in the LauncherController.
2366 InitLauncherController(); 2403 InitLauncherController();
2367 2404
2368 EXPECT_EQ(2, model_->item_count()); 2405 EXPECT_EQ(2, model_.item_count());
2369 { 2406 {
2370 // Create a "windowed gmail app". 2407 // Create a "windowed gmail app".
2371 std::unique_ptr<V1App> v1_app( 2408 std::unique_ptr<V1App> v1_app(
2372 CreateRunningV1App(profile(), extension_misc::kGmailAppId, kGmailUrl)); 2409 CreateRunningV1App(profile(), extension_misc::kGmailAppId, kGmailUrl));
2373 EXPECT_EQ(3, model_->item_count()); 2410 EXPECT_EQ(3, model_.item_count());
2374 2411
2375 // After switching to a second user the item should be gone. 2412 // After switching to a second user the item should be gone.
2376 std::string user2 = "user2"; 2413 std::string user2 = "user2";
2377 TestingProfile* profile2 = CreateMultiUserProfile(user2); 2414 TestingProfile* profile2 = CreateMultiUserProfile(user2);
2378 const AccountId account_id2( 2415 const AccountId account_id2(
2379 multi_user_util::GetAccountIdFromProfile(profile2)); 2416 multi_user_util::GetAccountIdFromProfile(profile2));
2380 const AccountId account_id( 2417 const AccountId account_id(
2381 multi_user_util::GetAccountIdFromProfile(profile())); 2418 multi_user_util::GetAccountIdFromProfile(profile()));
2382 SwitchActiveUser(account_id2); 2419 SwitchActiveUser(account_id2);
2383 EXPECT_EQ(2, model_->item_count()); 2420 EXPECT_EQ(2, model_.item_count());
2384 2421
2385 // After switching back the item should be back. 2422 // After switching back the item should be back.
2386 SwitchActiveUser(account_id); 2423 SwitchActiveUser(account_id);
2387 EXPECT_EQ(3, model_->item_count()); 2424 EXPECT_EQ(3, model_.item_count());
2388 // Note we destroy now the gmail app with the closure end. 2425 // Note we destroy now the gmail app with the closure end.
2389 } 2426 }
2390 EXPECT_EQ(2, model_->item_count()); 2427 EXPECT_EQ(2, model_.item_count());
2391 } 2428 }
2392 2429
2393 // Check edge cases with multi profile V1 apps in the shelf. 2430 // Check edge cases with multi profile V1 apps in the shelf.
2394 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2431 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
2395 V1AppUpdateOnUserSwitchEdgecases) { 2432 V1AppUpdateOnUserSwitchEdgecases) {
2396 // Create a browser item in the LauncherController. 2433 // Create a browser item in the LauncherController.
2397 InitLauncherController(); 2434 InitLauncherController();
2398 2435
2399 // First test: Create an app when the user is not active. 2436 // First test: Create an app when the user is not active.
2400 std::string user2 = "user2"; 2437 std::string user2 = "user2";
2401 TestingProfile* profile2 = CreateMultiUserProfile(user2); 2438 TestingProfile* profile2 = CreateMultiUserProfile(user2);
2402 const AccountId account_id2( 2439 const AccountId account_id2(
2403 multi_user_util::GetAccountIdFromProfile(profile2)); 2440 multi_user_util::GetAccountIdFromProfile(profile2));
2404 const AccountId account_id( 2441 const AccountId account_id(
2405 multi_user_util::GetAccountIdFromProfile(profile())); 2442 multi_user_util::GetAccountIdFromProfile(profile()));
2406 { 2443 {
2407 // Create a "windowed gmail app". 2444 // Create a "windowed gmail app".
2408 std::unique_ptr<V1App> v1_app( 2445 std::unique_ptr<V1App> v1_app(
2409 CreateRunningV1App(profile2, extension_misc::kGmailAppId, kGmailUrl)); 2446 CreateRunningV1App(profile2, extension_misc::kGmailAppId, kGmailUrl));
2410 EXPECT_EQ(2, model_->item_count()); 2447 EXPECT_EQ(2, model_.item_count());
2411 2448
2412 // However - switching to the user should show it. 2449 // However - switching to the user should show it.
2413 SwitchActiveUser(account_id2); 2450 SwitchActiveUser(account_id2);
2414 EXPECT_EQ(3, model_->item_count()); 2451 EXPECT_EQ(3, model_.item_count());
2415 2452
2416 // Second test: Remove the app when the user is not active and see that it 2453 // Second test: Remove the app when the user is not active and see that it
2417 // works. 2454 // works.
2418 SwitchActiveUser(account_id); 2455 SwitchActiveUser(account_id);
2419 EXPECT_EQ(2, model_->item_count()); 2456 EXPECT_EQ(2, model_.item_count());
2420 // Note: the closure ends and the browser will go away. 2457 // Note: the closure ends and the browser will go away.
2421 } 2458 }
2422 EXPECT_EQ(2, model_->item_count()); 2459 EXPECT_EQ(2, model_.item_count());
2423 SwitchActiveUser(account_id2); 2460 SwitchActiveUser(account_id2);
2424 EXPECT_EQ(2, model_->item_count()); 2461 EXPECT_EQ(2, model_.item_count());
2425 SwitchActiveUser(account_id); 2462 SwitchActiveUser(account_id);
2426 EXPECT_EQ(2, model_->item_count()); 2463 EXPECT_EQ(2, model_.item_count());
2427 } 2464 }
2428 2465
2429 // Check edge case where a visiting V1 app gets closed (crbug.com/321374). 2466 // Check edge case where a visiting V1 app gets closed (crbug.com/321374).
2430 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2467 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
2431 V1CloseOnVisitingDesktop) { 2468 V1CloseOnVisitingDesktop) {
2432 // Create a browser item in the LauncherController. 2469 // Create a browser item in the LauncherController.
2433 InitLauncherController(); 2470 InitLauncherController();
2434 2471
2435 chrome::MultiUserWindowManager* manager = 2472 chrome::MultiUserWindowManager* manager =
2436 chrome::MultiUserWindowManager::GetInstance(); 2473 chrome::MultiUserWindowManager::GetInstance();
2437 2474
2438 // First create an app when the user is active. 2475 // First create an app when the user is active.
2439 std::string user2 = "user2"; 2476 std::string user2 = "user2";
2440 TestingProfile* profile2 = CreateMultiUserProfile(user2); 2477 TestingProfile* profile2 = CreateMultiUserProfile(user2);
2441 const AccountId account_id( 2478 const AccountId account_id(
2442 multi_user_util::GetAccountIdFromProfile(profile())); 2479 multi_user_util::GetAccountIdFromProfile(profile()));
2443 const AccountId account_id2( 2480 const AccountId account_id2(
2444 multi_user_util::GetAccountIdFromProfile(profile2)); 2481 multi_user_util::GetAccountIdFromProfile(profile2));
2445 { 2482 {
2446 // Create a "windowed gmail app". 2483 // Create a "windowed gmail app".
2447 std::unique_ptr<V1App> v1_app(CreateRunningV1App( 2484 std::unique_ptr<V1App> v1_app(CreateRunningV1App(
2448 profile(), extension_misc::kGmailAppId, kGmailLaunchURL)); 2485 profile(), extension_misc::kGmailAppId, kGmailLaunchURL));
2449 EXPECT_EQ(3, model_->item_count()); 2486 EXPECT_EQ(3, model_.item_count());
2450 2487
2451 // Transfer the app to the other screen and switch users. 2488 // Transfer the app to the other screen and switch users.
2452 manager->ShowWindowForUser(v1_app->browser()->window()->GetNativeWindow(), 2489 manager->ShowWindowForUser(v1_app->browser()->window()->GetNativeWindow(),
2453 account_id2); 2490 account_id2);
2454 EXPECT_EQ(3, model_->item_count()); 2491 EXPECT_EQ(3, model_.item_count());
2455 SwitchActiveUser(account_id2); 2492 SwitchActiveUser(account_id2);
2456 EXPECT_EQ(2, model_->item_count()); 2493 EXPECT_EQ(2, model_.item_count());
2457 } 2494 }
2458 // After the app was destroyed, switch back. (which caused already a crash). 2495 // After the app was destroyed, switch back. (which caused already a crash).
2459 SwitchActiveUser(account_id); 2496 SwitchActiveUser(account_id);
2460 2497
2461 // Create the same app again - which was also causing the crash. 2498 // Create the same app again - which was also causing the crash.
2462 EXPECT_EQ(2, model_->item_count()); 2499 EXPECT_EQ(2, model_.item_count());
2463 { 2500 {
2464 // Create a "windowed gmail app". 2501 // Create a "windowed gmail app".
2465 std::unique_ptr<V1App> v1_app(CreateRunningV1App( 2502 std::unique_ptr<V1App> v1_app(CreateRunningV1App(
2466 profile(), extension_misc::kGmailAppId, kGmailLaunchURL)); 2503 profile(), extension_misc::kGmailAppId, kGmailLaunchURL));
2467 EXPECT_EQ(3, model_->item_count()); 2504 EXPECT_EQ(3, model_.item_count());
2468 } 2505 }
2469 SwitchActiveUser(account_id2); 2506 SwitchActiveUser(account_id2);
2470 EXPECT_EQ(2, model_->item_count()); 2507 EXPECT_EQ(2, model_.item_count());
2471 } 2508 }
2472 2509
2473 // Check edge cases with multi profile V1 apps in the shelf. 2510 // Check edge cases with multi profile V1 apps in the shelf.
2474 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2511 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
2475 V1AppUpdateOnUserSwitchEdgecases2) { 2512 V1AppUpdateOnUserSwitchEdgecases2) {
2476 // Create a browser item in the LauncherController. 2513 // Create a browser item in the LauncherController.
2477 InitLauncherController(); 2514 InitLauncherController();
2478 2515
2479 // First test: Create an app when the user is not active. 2516 // First test: Create an app when the user is not active.
2480 std::string user2 = "user2"; 2517 std::string user2 = "user2";
2481 TestingProfile* profile2 = CreateMultiUserProfile(user2); 2518 TestingProfile* profile2 = CreateMultiUserProfile(user2);
2482 const AccountId account_id( 2519 const AccountId account_id(
2483 multi_user_util::GetAccountIdFromProfile(profile())); 2520 multi_user_util::GetAccountIdFromProfile(profile()));
2484 const AccountId account_id2( 2521 const AccountId account_id2(
2485 multi_user_util::GetAccountIdFromProfile(profile2)); 2522 multi_user_util::GetAccountIdFromProfile(profile2));
2486 SwitchActiveUser(account_id2); 2523 SwitchActiveUser(account_id2);
2487 { 2524 {
2488 // Create a "windowed gmail app". 2525 // Create a "windowed gmail app".
2489 std::unique_ptr<V1App> v1_app( 2526 std::unique_ptr<V1App> v1_app(
2490 CreateRunningV1App(profile(), extension_misc::kGmailAppId, kGmailUrl)); 2527 CreateRunningV1App(profile(), extension_misc::kGmailAppId, kGmailUrl));
2491 EXPECT_EQ(2, model_->item_count()); 2528 EXPECT_EQ(2, model_.item_count());
2492 2529
2493 // However - switching to the user should show it. 2530 // However - switching to the user should show it.
2494 SwitchActiveUser(account_id); 2531 SwitchActiveUser(account_id);
2495 EXPECT_EQ(3, model_->item_count()); 2532 EXPECT_EQ(3, model_.item_count());
2496 2533
2497 // Second test: Remove the app when the user is not active and see that it 2534 // Second test: Remove the app when the user is not active and see that it
2498 // works. 2535 // works.
2499 SwitchActiveUser(account_id2); 2536 SwitchActiveUser(account_id2);
2500 EXPECT_EQ(2, model_->item_count()); 2537 EXPECT_EQ(2, model_.item_count());
2501 v1_app.reset(); 2538 v1_app.reset();
2502 } 2539 }
2503 EXPECT_EQ(2, model_->item_count()); 2540 EXPECT_EQ(2, model_.item_count());
2504 SwitchActiveUser(account_id); 2541 SwitchActiveUser(account_id);
2505 EXPECT_EQ(2, model_->item_count()); 2542 EXPECT_EQ(2, model_.item_count());
2506 SwitchActiveUser(account_id2); 2543 SwitchActiveUser(account_id2);
2507 EXPECT_EQ(2, model_->item_count()); 2544 EXPECT_EQ(2, model_.item_count());
2508 } 2545 }
2509 2546
2510 // Check that activating an item which is on another user's desktop, will bring 2547 // Check that activating an item which is on another user's desktop, will bring
2511 // it back. 2548 // it back.
2512 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2549 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
2513 TestLauncherActivationPullsBackWindow) { 2550 TestLauncherActivationPullsBackWindow) {
2514 // Create a browser item in the LauncherController. 2551 // Create a browser item in the LauncherController.
2515 InitLauncherController(); 2552 InitLauncherController();
2516 chrome::MultiUserWindowManager* manager = 2553 chrome::MultiUserWindowManager* manager =
2517 chrome::MultiUserWindowManager::GetInstance(); 2554 chrome::MultiUserWindowManager::GetInstance();
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
2740 2777
2741 base::ListValue policy_value; 2778 base::ListValue policy_value;
2742 InsertPrefValue(&policy_value, 0, extension1_->id()); 2779 InsertPrefValue(&policy_value, 0, extension1_->id());
2743 InsertPrefValue(&policy_value, 1, extension2_->id()); 2780 InsertPrefValue(&policy_value, 1, extension2_->id());
2744 profile()->GetTestingPrefService()->SetManagedPref( 2781 profile()->GetTestingPrefService()->SetManagedPref(
2745 prefs::kPolicyPinnedLauncherApps, policy_value.CreateDeepCopy()); 2782 prefs::kPolicyPinnedLauncherApps, policy_value.CreateDeepCopy());
2746 2783
2747 // Only |extension1_| should get pinned. |extension2_| is specified but not 2784 // Only |extension1_| should get pinned. |extension2_| is specified but not
2748 // installed, and |extension3_| is part of the default set, but that shouldn't 2785 // installed, and |extension3_| is part of the default set, but that shouldn't
2749 // take effect when the policy override is in place. 2786 // take effect when the policy override is in place.
2750 ASSERT_EQ(3, model_->item_count()); 2787 ASSERT_EQ(3, model_.item_count());
2751 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[1].type); 2788 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[1].type);
2752 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 2789 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
2753 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 2790 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
2754 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2791 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2755 2792
2756 // Installing |extension2_| should add it to the launcher. 2793 // Installing |extension2_| should add it to the launcher.
2757 extension_service_->AddExtension(extension2_.get()); 2794 extension_service_->AddExtension(extension2_.get());
2758 ASSERT_EQ(4, model_->item_count()); 2795 ASSERT_EQ(4, model_.item_count());
2759 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[1].type); 2796 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[1].type);
2760 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 2797 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
2761 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 2798 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
2762 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 2799 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
2763 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2800 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2764 2801
2765 // Removing |extension1_| from the policy should not be reflected in the 2802 // Removing |extension1_| from the policy should not be reflected in the
2766 // launcher and pin will exist. 2803 // launcher and pin will exist.
2767 policy_value.Remove(0, NULL); 2804 policy_value.Remove(0, NULL);
2768 profile()->GetTestingPrefService()->SetManagedPref( 2805 profile()->GetTestingPrefService()->SetManagedPref(
2769 prefs::kPolicyPinnedLauncherApps, policy_value.CreateDeepCopy()); 2806 prefs::kPolicyPinnedLauncherApps, policy_value.CreateDeepCopy());
2770 EXPECT_EQ(4, model_->item_count()); 2807 EXPECT_EQ(4, model_.item_count());
2771 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 2808 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
2772 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 2809 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
2773 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 2810 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
2774 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2811 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2775 } 2812 }
2776 2813
2777 TEST_F(ChromeLauncherControllerTest, UnpinWithUninstall) { 2814 TEST_F(ChromeLauncherControllerTest, UnpinWithUninstall) {
2778 extension_service_->AddExtension(extension3_.get()); 2815 extension_service_->AddExtension(extension3_.get());
2779 extension_service_->AddExtension(extension4_.get()); 2816 extension_service_->AddExtension(extension4_.get());
2780 2817
2781 InitLauncherController(); 2818 InitLauncherController();
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
3032 // refocus logic. 3069 // refocus logic.
3033 // Note that the extension matching logic is tested by the extension system 3070 // Note that the extension matching logic is tested by the extension system
3034 // and does not need a separate test here. 3071 // and does not need a separate test here.
3035 TEST_F(ChromeLauncherControllerTest, V1AppMenuGeneration) { 3072 TEST_F(ChromeLauncherControllerTest, V1AppMenuGeneration) {
3036 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); 3073 EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
3037 EXPECT_EQ(0, browser()->tab_strip_model()->count()); 3074 EXPECT_EQ(0, browser()->tab_strip_model()->count());
3038 3075
3039 InitLauncherControllerWithBrowser(); 3076 InitLauncherControllerWithBrowser();
3040 3077
3041 // The model should only contain the browser shortcut and app list items. 3078 // The model should only contain the browser shortcut and app list items.
3042 EXPECT_EQ(2, model_->item_count()); 3079 EXPECT_EQ(2, model_.item_count());
3043 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 3080 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
3044 3081
3045 // Installing |extension3_| pins it to the launcher. 3082 // Installing |extension3_| pins it to the launcher.
3046 const ash::ShelfID gmail_id(extension3_->id()); 3083 const ash::ShelfID gmail_id(extension3_->id());
3047 extension_service_->AddExtension(extension3_.get()); 3084 extension_service_->AddExtension(extension3_.get());
3048 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 3085 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
3049 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(kGmailUrl)); 3086 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(kGmailUrl));
3050 3087
3051 // Check the menu content. 3088 // Check the menu content.
3052 ash::ShelfItem item_browser; 3089 ash::ShelfItem item_browser;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
3145 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 3182 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
3146 V2AppHandlingTwoUsers) { 3183 V2AppHandlingTwoUsers) {
3147 InitLauncherController(); 3184 InitLauncherController();
3148 // Create a profile for our second user (will be destroyed by the framework). 3185 // Create a profile for our second user (will be destroyed by the framework).
3149 TestingProfile* profile2 = CreateMultiUserProfile("user2"); 3186 TestingProfile* profile2 = CreateMultiUserProfile("user2");
3150 const AccountId account_id( 3187 const AccountId account_id(
3151 multi_user_util::GetAccountIdFromProfile(profile())); 3188 multi_user_util::GetAccountIdFromProfile(profile()));
3152 const AccountId account_id2( 3189 const AccountId account_id2(
3153 multi_user_util::GetAccountIdFromProfile(profile2)); 3190 multi_user_util::GetAccountIdFromProfile(profile2));
3154 // Check that there is a browser and a app launcher. 3191 // Check that there is a browser and a app launcher.
3155 EXPECT_EQ(2, model_->item_count()); 3192 EXPECT_EQ(2, model_.item_count());
3156 3193
3157 // Add a v2 app. 3194 // Add a v2 app.
3158 V2App v2_app(profile(), extension1_.get()); 3195 V2App v2_app(profile(), extension1_.get());
3159 EXPECT_EQ(3, model_->item_count()); 3196 EXPECT_EQ(3, model_.item_count());
3160 3197
3161 // After switching users the item should go away. 3198 // After switching users the item should go away.
3162 SwitchActiveUser(account_id2); 3199 SwitchActiveUser(account_id2);
3163 EXPECT_EQ(2, model_->item_count()); 3200 EXPECT_EQ(2, model_.item_count());
3164 3201
3165 // And it should come back when switching back. 3202 // And it should come back when switching back.
3166 SwitchActiveUser(account_id); 3203 SwitchActiveUser(account_id);
3167 EXPECT_EQ(3, model_->item_count()); 3204 EXPECT_EQ(3, model_.item_count());
3168 } 3205 }
3169 3206
3170 // Check that V2 applications are creating items properly in edge cases: 3207 // Check that V2 applications are creating items properly in edge cases:
3171 // a background user creates a V2 app, gets active and inactive again and then 3208 // a background user creates a V2 app, gets active and inactive again and then
3172 // deletes the app. 3209 // deletes the app.
3173 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 3210 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
3174 V2AppHandlingTwoUsersEdgeCases) { 3211 V2AppHandlingTwoUsersEdgeCases) {
3175 InitLauncherController(); 3212 InitLauncherController();
3176 // Create a profile for our second user (will be destroyed by the framework). 3213 // Create a profile for our second user (will be destroyed by the framework).
3177 TestingProfile* profile2 = CreateMultiUserProfile("user2"); 3214 TestingProfile* profile2 = CreateMultiUserProfile("user2");
3178 const AccountId account_id( 3215 const AccountId account_id(
3179 multi_user_util::GetAccountIdFromProfile(profile())); 3216 multi_user_util::GetAccountIdFromProfile(profile()));
3180 const AccountId account_id2( 3217 const AccountId account_id2(
3181 multi_user_util::GetAccountIdFromProfile(profile2)); 3218 multi_user_util::GetAccountIdFromProfile(profile2));
3182 // Check that there is a browser and a app launcher. 3219 // Check that there is a browser and a app launcher.
3183 EXPECT_EQ(2, model_->item_count()); 3220 EXPECT_EQ(2, model_.item_count());
3184 3221
3185 // Switch to an inactive user. 3222 // Switch to an inactive user.
3186 SwitchActiveUser(account_id2); 3223 SwitchActiveUser(account_id2);
3187 EXPECT_EQ(2, model_->item_count()); 3224 EXPECT_EQ(2, model_.item_count());
3188 3225
3189 // Add the v2 app to the inactive user and check that no item was added to 3226 // Add the v2 app to the inactive user and check that no item was added to
3190 // the launcher. 3227 // the launcher.
3191 { 3228 {
3192 V2App v2_app(profile(), extension1_.get()); 3229 V2App v2_app(profile(), extension1_.get());
3193 EXPECT_EQ(2, model_->item_count()); 3230 EXPECT_EQ(2, model_.item_count());
3194 3231
3195 // Switch to the primary user and check that the item is shown. 3232 // Switch to the primary user and check that the item is shown.
3196 SwitchActiveUser(account_id); 3233 SwitchActiveUser(account_id);
3197 EXPECT_EQ(3, model_->item_count()); 3234 EXPECT_EQ(3, model_.item_count());
3198 3235
3199 // Switch to the second user and check that the item goes away - even if the 3236 // Switch to the second user and check that the item goes away - even if the
3200 // item gets closed. 3237 // item gets closed.
3201 SwitchActiveUser(account_id2); 3238 SwitchActiveUser(account_id2);
3202 EXPECT_EQ(2, model_->item_count()); 3239 EXPECT_EQ(2, model_.item_count());
3203 } 3240 }
3204 3241
3205 // After the application was killed there should be still 2 items. 3242 // After the application was killed there should be still 2 items.
3206 EXPECT_EQ(2, model_->item_count()); 3243 EXPECT_EQ(2, model_.item_count());
3207 3244
3208 // Switching then back to the default user should not show the additional item 3245 // Switching then back to the default user should not show the additional item
3209 // anymore. 3246 // anymore.
3210 SwitchActiveUser(account_id); 3247 SwitchActiveUser(account_id);
3211 EXPECT_EQ(2, model_->item_count()); 3248 EXPECT_EQ(2, model_.item_count());
3212 } 3249 }
3213 3250
3214 // Check that V2 applications will be made visible on the target desktop if 3251 // Check that V2 applications will be made visible on the target desktop if
3215 // another window of the same type got previously teleported there. 3252 // another window of the same type got previously teleported there.
3216 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 3253 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
3217 V2AppFollowsTeleportedWindow) { 3254 V2AppFollowsTeleportedWindow) {
3218 InitLauncherController(); 3255 InitLauncherController();
3219 chrome::MultiUserWindowManager* manager = 3256 chrome::MultiUserWindowManager* manager =
3220 chrome::MultiUserWindowManager::GetInstance(); 3257 chrome::MultiUserWindowManager::GetInstance();
3221 3258
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
3287 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 3324 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
3288 V2AppHiddenWindows) { 3325 V2AppHiddenWindows) {
3289 InitLauncherController(); 3326 InitLauncherController();
3290 3327
3291 TestingProfile* profile2 = CreateMultiUserProfile("user-2"); 3328 TestingProfile* profile2 = CreateMultiUserProfile("user-2");
3292 const AccountId account_id( 3329 const AccountId account_id(
3293 multi_user_util::GetAccountIdFromProfile(profile())); 3330 multi_user_util::GetAccountIdFromProfile(profile()));
3294 const AccountId account_id2( 3331 const AccountId account_id2(
3295 multi_user_util::GetAccountIdFromProfile(profile2)); 3332 multi_user_util::GetAccountIdFromProfile(profile2));
3296 SwitchActiveUser(account_id); 3333 SwitchActiveUser(account_id);
3297 EXPECT_EQ(2, model_->item_count()); 3334 EXPECT_EQ(2, model_.item_count());
3298 3335
3299 V2App v2_app_1(profile(), extension1_.get()); 3336 V2App v2_app_1(profile(), extension1_.get());
3300 EXPECT_EQ(3, model_->item_count()); 3337 EXPECT_EQ(3, model_.item_count());
3301 { 3338 {
3302 // Hide and show the app. 3339 // Hide and show the app.
3303 v2_app_1.window()->Hide(); 3340 v2_app_1.window()->Hide();
3304 EXPECT_EQ(2, model_->item_count()); 3341 EXPECT_EQ(2, model_.item_count());
3305 3342
3306 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE); 3343 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE);
3307 EXPECT_EQ(3, model_->item_count()); 3344 EXPECT_EQ(3, model_.item_count());
3308 } 3345 }
3309 { 3346 {
3310 // Switch user, hide and show the app and switch back. 3347 // Switch user, hide and show the app and switch back.
3311 SwitchActiveUser(account_id2); 3348 SwitchActiveUser(account_id2);
3312 EXPECT_EQ(2, model_->item_count()); 3349 EXPECT_EQ(2, model_.item_count());
3313 3350
3314 v2_app_1.window()->Hide(); 3351 v2_app_1.window()->Hide();
3315 EXPECT_EQ(2, model_->item_count()); 3352 EXPECT_EQ(2, model_.item_count());
3316 3353
3317 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE); 3354 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE);
3318 EXPECT_EQ(2, model_->item_count()); 3355 EXPECT_EQ(2, model_.item_count());
3319 3356
3320 SwitchActiveUser(account_id); 3357 SwitchActiveUser(account_id);
3321 EXPECT_EQ(3, model_->item_count()); 3358 EXPECT_EQ(3, model_.item_count());
3322 } 3359 }
3323 { 3360 {
3324 // Switch user, hide the app, switch back and then show it again. 3361 // Switch user, hide the app, switch back and then show it again.
3325 SwitchActiveUser(account_id2); 3362 SwitchActiveUser(account_id2);
3326 EXPECT_EQ(2, model_->item_count()); 3363 EXPECT_EQ(2, model_.item_count());
3327 3364
3328 v2_app_1.window()->Hide(); 3365 v2_app_1.window()->Hide();
3329 EXPECT_EQ(2, model_->item_count()); 3366 EXPECT_EQ(2, model_.item_count());
3330 3367
3331 SwitchActiveUser(account_id); 3368 SwitchActiveUser(account_id);
3332 // The following expectation does not work in current impl. It was working 3369 // The following expectation does not work in current impl. It was working
3333 // before because MultiUserWindowManagerChromeOS is not attached to user 3370 // before because MultiUserWindowManagerChromeOS is not attached to user
3334 // associated with profile() hence not actually handling windows for the 3371 // associated with profile() hence not actually handling windows for the
3335 // user. It is a real bug. See http://crbug.com/693634 3372 // user. It is a real bug. See http://crbug.com/693634
3336 // EXPECT_EQ(2, model_->item_count()); 3373 // EXPECT_EQ(2, model_.item_count());
3337 3374
3338 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE); 3375 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE);
3339 EXPECT_EQ(3, model_->item_count()); 3376 EXPECT_EQ(3, model_.item_count());
3340 } 3377 }
3341 { 3378 {
3342 // Create a second app, hide and show it and then hide both apps. 3379 // Create a second app, hide and show it and then hide both apps.
3343 V2App v2_app_2(profile(), extension1_.get()); 3380 V2App v2_app_2(profile(), extension1_.get());
3344 EXPECT_EQ(3, model_->item_count()); 3381 EXPECT_EQ(3, model_.item_count());
3345 3382
3346 v2_app_2.window()->Hide(); 3383 v2_app_2.window()->Hide();
3347 EXPECT_EQ(3, model_->item_count()); 3384 EXPECT_EQ(3, model_.item_count());
3348 3385
3349 v2_app_2.window()->Show(extensions::AppWindow::SHOW_ACTIVE); 3386 v2_app_2.window()->Show(extensions::AppWindow::SHOW_ACTIVE);
3350 EXPECT_EQ(3, model_->item_count()); 3387 EXPECT_EQ(3, model_.item_count());
3351 3388
3352 v2_app_1.window()->Hide(); 3389 v2_app_1.window()->Hide();
3353 v2_app_2.window()->Hide(); 3390 v2_app_2.window()->Hide();
3354 EXPECT_EQ(2, model_->item_count()); 3391 EXPECT_EQ(2, model_.item_count());
3355 } 3392 }
3356 } 3393 }
3357 3394
3358 // Checks that the generated menu list properly activates items. 3395 // Checks that the generated menu list properly activates items.
3359 TEST_F(ChromeLauncherControllerTest, V1AppMenuExecution) { 3396 TEST_F(ChromeLauncherControllerTest, V1AppMenuExecution) {
3360 InitLauncherControllerWithBrowser(); 3397 InitLauncherControllerWithBrowser();
3361 3398
3362 // Add |extension3_| to the launcher and add two items. 3399 // Add |extension3_| to the launcher and add two items.
3363 GURL gmail = GURL("https://mail.google.com/mail/u"); 3400 GURL gmail = GURL("https://mail.google.com/mail/u");
3364 const ash::ShelfID gmail_id(extension3_->id()); 3401 const ash::ShelfID gmail_id(extension3_->id());
3365 extension_service_->AddExtension(extension3_.get()); 3402 extension_service_->AddExtension(extension3_.get());
3366 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(kGmailUrl)); 3403 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(kGmailUrl));
3367 base::string16 title1 = ASCIIToUTF16("Test1"); 3404 base::string16 title1 = ASCIIToUTF16("Test1");
3368 NavigateAndCommitActiveTabWithTitle(browser(), GURL(kGmailUrl), title1); 3405 NavigateAndCommitActiveTabWithTitle(browser(), GURL(kGmailUrl), title1);
3369 chrome::NewTab(browser()); 3406 chrome::NewTab(browser());
3370 base::string16 title2 = ASCIIToUTF16("Test2"); 3407 base::string16 title2 = ASCIIToUTF16("Test2");
3371 NavigateAndCommitActiveTabWithTitle(browser(), GURL(kGmailUrl), title2); 3408 NavigateAndCommitActiveTabWithTitle(browser(), GURL(kGmailUrl), title2);
3372 3409
3373 // Check that the menu is properly set. 3410 // Check that the menu is properly set.
3374 ash::ShelfItem item_gmail; 3411 ash::ShelfItem item_gmail;
3375 item_gmail.type = ash::TYPE_PINNED_APP; 3412 item_gmail.type = ash::TYPE_PINNED_APP;
3376 item_gmail.id = gmail_id; 3413 item_gmail.id = gmail_id;
3377 base::string16 two_menu_items[] = {title1, title2}; 3414 base::string16 two_menu_items[] = {title1, title2};
3378 CheckAppMenu(launcher_controller_, item_gmail, 2, two_menu_items); 3415 CheckAppMenu(launcher_controller_, item_gmail, 2, two_menu_items);
3379 ash::ShelfItemDelegate* item_delegate = 3416 ash::ShelfItemDelegate* item_delegate = model_.GetShelfItemDelegate(gmail_id);
3380 model_->GetShelfItemDelegate(gmail_id);
3381 ASSERT_TRUE(item_delegate); 3417 ASSERT_TRUE(item_delegate);
3382 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); 3418 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
3383 // Execute the second item in the menu, after the title and two separators, 3419 // Execute the second item in the menu, after the title and two separators,
3384 // this shouldn't do anything since that item is already the active tab. 3420 // this shouldn't do anything since that item is already the active tab.
3385 { 3421 {
3386 ash::ShelfApplicationMenuModel menu( 3422 ash::ShelfApplicationMenuModel menu(
3387 base::string16(), 3423 base::string16(),
3388 launcher_controller_->GetAppMenuItemsForTesting(item_gmail), 3424 launcher_controller_->GetAppMenuItemsForTesting(item_gmail),
3389 item_delegate); 3425 item_delegate);
3390 menu.ActivatedAt(4); 3426 menu.ActivatedAt(4);
(...skipping 27 matching lines...) Expand all
3418 base::string16 title2 = ASCIIToUTF16("Test2"); 3454 base::string16 title2 = ASCIIToUTF16("Test2");
3419 NavigateAndCommitActiveTabWithTitle(browser(), GURL(kGmailUrl), title2); 3455 NavigateAndCommitActiveTabWithTitle(browser(), GURL(kGmailUrl), title2);
3420 3456
3421 // Check that the menu is properly set. 3457 // Check that the menu is properly set.
3422 ash::ShelfItem item_gmail; 3458 ash::ShelfItem item_gmail;
3423 item_gmail.type = ash::TYPE_PINNED_APP; 3459 item_gmail.type = ash::TYPE_PINNED_APP;
3424 item_gmail.id = gmail_id; 3460 item_gmail.id = gmail_id;
3425 base::string16 two_menu_items[] = {title1, title2}; 3461 base::string16 two_menu_items[] = {title1, title2};
3426 CheckAppMenu(launcher_controller_, item_gmail, 2, two_menu_items); 3462 CheckAppMenu(launcher_controller_, item_gmail, 2, two_menu_items);
3427 3463
3428 ash::ShelfItemDelegate* item_delegate = 3464 ash::ShelfItemDelegate* item_delegate = model_.GetShelfItemDelegate(gmail_id);
3429 model_->GetShelfItemDelegate(gmail_id);
3430 ASSERT_TRUE(item_delegate); 3465 ASSERT_TRUE(item_delegate);
3431 int tabs = browser()->tab_strip_model()->count(); 3466 int tabs = browser()->tab_strip_model()->count();
3432 // Activate the proper tab through the menu item. 3467 // Activate the proper tab through the menu item.
3433 { 3468 {
3434 ash::MenuItemList items = 3469 ash::MenuItemList items =
3435 launcher_controller_->GetAppMenuItemsForTesting(item_gmail); 3470 launcher_controller_->GetAppMenuItemsForTesting(item_gmail);
3436 item_delegate->ExecuteCommand(items[1]->command_id, ui::EF_NONE); 3471 item_delegate->ExecuteCommand(items[1]->command_id, ui::EF_NONE);
3437 EXPECT_EQ(tabs, browser()->tab_strip_model()->count()); 3472 EXPECT_EQ(tabs, browser()->tab_strip_model()->count());
3438 } 3473 }
3439 3474
3440 // Delete one tab through the menu item. 3475 // Delete one tab through the menu item.
3441 { 3476 {
3442 ash::MenuItemList items = 3477 ash::MenuItemList items =
3443 launcher_controller_->GetAppMenuItemsForTesting(item_gmail); 3478 launcher_controller_->GetAppMenuItemsForTesting(item_gmail);
3444 item_delegate->ExecuteCommand(items[1]->command_id, ui::EF_SHIFT_DOWN); 3479 item_delegate->ExecuteCommand(items[1]->command_id, ui::EF_SHIFT_DOWN);
3445 EXPECT_EQ(--tabs, browser()->tab_strip_model()->count()); 3480 EXPECT_EQ(--tabs, browser()->tab_strip_model()->count());
3446 } 3481 }
3447 } 3482 }
3448 3483
3449 // Tests that panels create launcher items correctly
3450 TEST_F(ChromeLauncherControllerTest, AppPanels) {
3451 InitLauncherController();
3452 model_observer_->clear_counts();
3453 const std::string app_id = extension1_->id();
3454
3455 // app_icon_loader is owned by ChromeLauncherController.
3456 TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl();
3457 app_icon_loader->AddSupportedApp(app_id);
3458 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader));
3459
3460 // Make an app panel; the ShelfItem is added by ash::ShelfWindowWatcher.
3461 std::unique_ptr<V2App> app_panel1 = base::MakeUnique<V2App>(
3462 profile(), extension1_.get(), extensions::AppWindow::WINDOW_TYPE_PANEL);
3463 EXPECT_TRUE(app_panel1->window()->GetNativeWindow()->IsVisible());
3464 int panel_index = model_observer_->last_index();
3465 EXPECT_EQ(1, model_observer_->added());
3466 EXPECT_EQ(1, app_icon_loader->fetch_count());
3467 model_observer_->clear_counts();
3468
3469 // App panels should have a separate identifier than the app id
3470 EXPECT_FALSE(launcher_controller_->GetItem(ash::ShelfID(app_id)));
3471
3472 // Setting the app image should not change the panel, which has a window icon.
3473 gfx::ImageSkia image;
3474 launcher_controller_->OnAppImageUpdated(app_id, image);
3475 EXPECT_EQ(0, model_observer_->changed());
3476 model_observer_->clear_counts();
3477
3478 // Make a second app panel and verify that it gets the same index as the first
3479 // panel, being added to the left of the existing panel.
3480 std::unique_ptr<V2App> app_panel2 = base::MakeUnique<V2App>(
3481 profile(), extension2_.get(), extensions::AppWindow::WINDOW_TYPE_PANEL);
3482 EXPECT_EQ(panel_index, model_observer_->last_index());
3483 EXPECT_EQ(1, model_observer_->added());
3484 model_observer_->clear_counts();
3485
3486 app_panel1.reset();
3487 app_panel2.reset();
3488 EXPECT_EQ(2, model_observer_->removed());
3489 }
3490
3491 // Tests that the Gmail extension matches more than the app itself claims with 3484 // Tests that the Gmail extension matches more than the app itself claims with
3492 // the manifest file. 3485 // the manifest file.
3493 TEST_F(ChromeLauncherControllerTest, GmailMatching) { 3486 TEST_F(ChromeLauncherControllerTest, GmailMatching) {
3494 InitLauncherControllerWithBrowser(); 3487 InitLauncherControllerWithBrowser();
3495 3488
3496 // Create a Gmail browser tab. 3489 // Create a Gmail browser tab.
3497 chrome::NewTab(browser()); 3490 chrome::NewTab(browser());
3498 base::string16 title = ASCIIToUTF16("Test"); 3491 base::string16 title = ASCIIToUTF16("Test");
3499 NavigateAndCommitActiveTabWithTitle(browser(), GURL(kGmailUrl), title); 3492 NavigateAndCommitActiveTabWithTitle(browser(), GURL(kGmailUrl), title);
3500 content::WebContents* content = 3493 content::WebContents* content =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3539 EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content)); 3532 EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content));
3540 } 3533 }
3541 3534
3542 // Verify that the launcher item positions are persisted and restored. 3535 // Verify that the launcher item positions are persisted and restored.
3543 TEST_F(ChromeLauncherControllerTest, PersistLauncherItemPositions) { 3536 TEST_F(ChromeLauncherControllerTest, PersistLauncherItemPositions) {
3544 InitLauncherController(); 3537 InitLauncherController();
3545 3538
3546 TestLauncherControllerHelper* helper = new TestLauncherControllerHelper; 3539 TestLauncherControllerHelper* helper = new TestLauncherControllerHelper;
3547 SetLauncherControllerHelper(helper); 3540 SetLauncherControllerHelper(helper);
3548 3541
3549 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); 3542 EXPECT_EQ(ash::TYPE_APP_LIST, model_.items()[0].type);
3550 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[1].type); 3543 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_.items()[1].type);
3551 3544
3552 TabStripModel* tab_strip_model = browser()->tab_strip_model(); 3545 TabStripModel* tab_strip_model = browser()->tab_strip_model();
3553 EXPECT_EQ(0, tab_strip_model->count()); 3546 EXPECT_EQ(0, tab_strip_model->count());
3554 chrome::NewTab(browser()); 3547 chrome::NewTab(browser());
3555 chrome::NewTab(browser()); 3548 chrome::NewTab(browser());
3556 EXPECT_EQ(2, tab_strip_model->count()); 3549 EXPECT_EQ(2, tab_strip_model->count());
3557 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 3550 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
3558 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); 3551 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2");
3559 3552
3560 EXPECT_FALSE(launcher_controller_->IsAppPinned("1")); 3553 EXPECT_FALSE(launcher_controller_->IsAppPinned("1"));
3561 launcher_controller_->PinAppWithID("1"); 3554 launcher_controller_->PinAppWithID("1");
3562 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); 3555 EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
3563 launcher_controller_->PinAppWithID("2"); 3556 launcher_controller_->PinAppWithID("2");
3564 3557
3565 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); 3558 EXPECT_EQ(ash::TYPE_APP_LIST, model_.items()[0].type);
3566 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[1].type); 3559 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_.items()[1].type);
3567 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 3560 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
3568 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[3].type); 3561 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[3].type);
3569 3562
3570 // Move browser shortcut item from index 1 to index 3. 3563 // Move browser shortcut item from index 1 to index 3.
3571 model_->Move(1, 3); 3564 model_.Move(1, 3);
3572 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); 3565 EXPECT_EQ(ash::TYPE_APP_LIST, model_.items()[0].type);
3573 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[1].type); 3566 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[1].type);
3574 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 3567 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
3575 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); 3568 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_.items()[3].type);
3576 3569
3577 RecreateLauncherController(); 3570 RecreateLauncherController();
3578 helper = new TestLauncherControllerHelper(profile()); 3571 helper = new TestLauncherControllerHelper(profile());
3579 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 3572 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
3580 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); 3573 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2");
3581 SetLauncherControllerHelper(helper); 3574 SetLauncherControllerHelper(helper);
3582 launcher_controller_->Init(); 3575 launcher_controller_->Init();
3583 3576
3584 // Check ShelfItems are restored after resetting ChromeLauncherController. 3577 // Check ShelfItems are restored after resetting ChromeLauncherController.
3585 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); 3578 EXPECT_EQ(ash::TYPE_APP_LIST, model_.items()[0].type);
3586 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[1].type); 3579 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[1].type);
3587 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 3580 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
3588 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); 3581 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_.items()[3].type);
3589 } 3582 }
3590 3583
3591 // Verifies pinned apps are persisted and restored. 3584 // Verifies pinned apps are persisted and restored.
3592 TEST_F(ChromeLauncherControllerTest, PersistPinned) { 3585 TEST_F(ChromeLauncherControllerTest, PersistPinned) {
3593 InitLauncherControllerWithBrowser(); 3586 InitLauncherControllerWithBrowser();
3594 size_t initial_size = model_->items().size(); 3587 size_t initial_size = model_.items().size();
3595 3588
3596 TabStripModel* tab_strip_model = browser()->tab_strip_model(); 3589 TabStripModel* tab_strip_model = browser()->tab_strip_model();
3597 EXPECT_EQ(1, tab_strip_model->count()); 3590 EXPECT_EQ(1, tab_strip_model->count());
3598 3591
3599 TestLauncherControllerHelper* helper = new TestLauncherControllerHelper; 3592 TestLauncherControllerHelper* helper = new TestLauncherControllerHelper;
3600 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 3593 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
3601 SetLauncherControllerHelper(helper); 3594 SetLauncherControllerHelper(helper);
3602 3595
3603 // app_icon_loader is owned by ChromeLauncherController. 3596 // app_icon_loader is owned by ChromeLauncherController.
3604 TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl; 3597 TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl;
3605 app_icon_loader->AddSupportedApp("1"); 3598 app_icon_loader->AddSupportedApp("1");
3606 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); 3599 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader));
3607 EXPECT_EQ(0, app_icon_loader->fetch_count()); 3600 EXPECT_EQ(0, app_icon_loader->fetch_count());
3608 3601
3609 launcher_controller_->PinAppWithID("1"); 3602 launcher_controller_->PinAppWithID("1");
3610 const int app_index = model_->ItemIndexByID(ash::ShelfID("1")); 3603 const int app_index = model_.ItemIndexByID(ash::ShelfID("1"));
3611 EXPECT_EQ(1, app_icon_loader->fetch_count()); 3604 EXPECT_EQ(1, app_icon_loader->fetch_count());
3612 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[app_index].type); 3605 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[app_index].type);
3613 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); 3606 EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
3614 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); 3607 EXPECT_FALSE(launcher_controller_->IsAppPinned("0"));
3615 EXPECT_EQ(initial_size + 1, model_->items().size()); 3608 EXPECT_EQ(initial_size + 1, model_.items().size());
3616 3609
3617 RecreateLauncherController(); 3610 RecreateLauncherController();
3618 helper = new TestLauncherControllerHelper(profile()); 3611 helper = new TestLauncherControllerHelper(profile());
3619 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 3612 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
3620 SetLauncherControllerHelper(helper); 3613 SetLauncherControllerHelper(helper);
3621 // app_icon_loader is owned by ChromeLauncherController. 3614 // app_icon_loader is owned by ChromeLauncherController.
3622 app_icon_loader = new TestAppIconLoaderImpl; 3615 app_icon_loader = new TestAppIconLoaderImpl;
3623 app_icon_loader->AddSupportedApp("1"); 3616 app_icon_loader->AddSupportedApp("1");
3624 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); 3617 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader));
3625 launcher_controller_->Init(); 3618 launcher_controller_->Init();
3626 3619
3627 EXPECT_EQ(1, app_icon_loader->fetch_count()); 3620 EXPECT_EQ(1, app_icon_loader->fetch_count());
3628 ASSERT_EQ(initial_size + 1, model_->items().size()); 3621 ASSERT_EQ(initial_size + 1, model_.items().size());
3629 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); 3622 EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
3630 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); 3623 EXPECT_FALSE(launcher_controller_->IsAppPinned("0"));
3631 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[app_index].type); 3624 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[app_index].type);
3632 3625
3633 launcher_controller_->UnpinAppWithID("1"); 3626 launcher_controller_->UnpinAppWithID("1");
3634 ASSERT_EQ(initial_size, model_->items().size()); 3627 ASSERT_EQ(initial_size, model_.items().size());
3635 } 3628 }
3636 3629
3637 TEST_F(ChromeLauncherControllerTest, MultipleAppIconLoaders) { 3630 TEST_F(ChromeLauncherControllerTest, MultipleAppIconLoaders) {
3638 InitLauncherControllerWithBrowser(); 3631 InitLauncherControllerWithBrowser();
3639 3632
3640 const ash::ShelfID shelf_id1(extension1_->id()); 3633 const ash::ShelfID shelf_id1(extension1_->id());
3641 const ash::ShelfID shelf_id2(extension2_->id()); 3634 const ash::ShelfID shelf_id2(extension2_->id());
3642 const ash::ShelfID shelf_id3(extension3_->id()); 3635 const ash::ShelfID shelf_id3(extension3_->id());
3643 // app_icon_loader1 and app_icon_loader2 are owned by 3636 // app_icon_loader1 and app_icon_loader2 are owned by
3644 // ChromeLauncherController. 3637 // ChromeLauncherController.
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
3788 3781
3789 NotifyOnTaskCreated(appinfo, 2 /* task_id */); 3782 NotifyOnTaskCreated(appinfo, 2 /* task_id */);
3790 views::Widget* window2 = CreateArcWindow("org.chromium.arc.2"); 3783 views::Widget* window2 = CreateArcWindow("org.chromium.arc.2");
3791 ASSERT_TRUE(window2); 3784 ASSERT_TRUE(window2);
3792 3785
3793 EXPECT_FALSE(window1->IsActive()); 3786 EXPECT_FALSE(window1->IsActive());
3794 EXPECT_TRUE(window2->IsActive()); 3787 EXPECT_TRUE(window2->IsActive());
3795 3788
3796 const std::string app_id = ArcAppTest::GetAppId(appinfo); 3789 const std::string app_id = ArcAppTest::GetAppId(appinfo);
3797 ash::ShelfItemDelegate* item_delegate = 3790 ash::ShelfItemDelegate* item_delegate =
3798 model_->GetShelfItemDelegate(ash::ShelfID(app_id)); 3791 model_.GetShelfItemDelegate(ash::ShelfID(app_id));
3799 ASSERT_TRUE(item_delegate); 3792 ASSERT_TRUE(item_delegate);
3800 3793
3801 // Selecting the item will show its application menu. It does not change the 3794 // Selecting the item will show its application menu. It does not change the
3802 // active window. 3795 // active window.
3803 SelectItem(item_delegate); 3796 SelectItem(item_delegate);
3804 EXPECT_FALSE(window1->IsActive()); 3797 EXPECT_FALSE(window1->IsActive());
3805 EXPECT_TRUE(window2->IsActive()); 3798 EXPECT_TRUE(window2->IsActive());
3806 3799
3807 // Command ids are just app window indices. Note, apps are registered in 3800 // Command ids are just app window indices. Note, apps are registered in
3808 // opposite order. Last created goes in front. 3801 // opposite order. Last created goes in front.
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
4128 EnablePlayStore(true); 4121 EnablePlayStore(true);
4129 4122
4130 // Pin Play Store. It should be pinned but not scheduled for deferred launch. 4123 // Pin Play Store. It should be pinned but not scheduled for deferred launch.
4131 launcher_controller_->PinAppWithID(arc::kPlayStoreAppId); 4124 launcher_controller_->PinAppWithID(arc::kPlayStoreAppId);
4132 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc::kPlayStoreAppId)); 4125 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc::kPlayStoreAppId));
4133 EXPECT_FALSE(launcher_controller_->GetArcDeferredLauncher()->HasApp( 4126 EXPECT_FALSE(launcher_controller_->GetArcDeferredLauncher()->HasApp(
4134 arc::kPlayStoreAppId)); 4127 arc::kPlayStoreAppId));
4135 4128
4136 // Simulate click. This should schedule Play Store for deferred launch. 4129 // Simulate click. This should schedule Play Store for deferred launch.
4137 ash::ShelfItemDelegate* item_delegate = 4130 ash::ShelfItemDelegate* item_delegate =
4138 model_->GetShelfItemDelegate(ash::ShelfID(arc::kPlayStoreAppId)); 4131 model_.GetShelfItemDelegate(ash::ShelfID(arc::kPlayStoreAppId));
4139 EXPECT_TRUE(item_delegate); 4132 EXPECT_TRUE(item_delegate);
4140 SelectItem(item_delegate); 4133 SelectItem(item_delegate);
4141 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc::kPlayStoreAppId)); 4134 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc::kPlayStoreAppId));
4142 EXPECT_TRUE(launcher_controller_->GetArcDeferredLauncher()->HasApp( 4135 EXPECT_TRUE(launcher_controller_->GetArcDeferredLauncher()->HasApp(
4143 arc::kPlayStoreAppId)); 4136 arc::kPlayStoreAppId));
4144 } 4137 }
4145 4138
4146 // Checks the case when several app items have the same ordinal position (which 4139 // Checks the case when several app items have the same ordinal position (which
4147 // is valid case). 4140 // is valid case).
4148 TEST_F(ChromeLauncherControllerTest, CheckPositionConflict) { 4141 TEST_F(ChromeLauncherControllerTest, CheckPositionConflict) {
(...skipping 20 matching lines...) Expand all
4169 app_service_->GetPinPosition(extension2_->id()); 4162 app_service_->GetPinPosition(extension2_->id());
4170 const syncer::StringOrdinal position_3 = 4163 const syncer::StringOrdinal position_3 =
4171 app_service_->GetPinPosition(extension3_->id()); 4164 app_service_->GetPinPosition(extension3_->id());
4172 EXPECT_TRUE(position_chrome.LessThan(position_1)); 4165 EXPECT_TRUE(position_chrome.LessThan(position_1));
4173 EXPECT_TRUE(position_1.Equals(position_2)); 4166 EXPECT_TRUE(position_1.Equals(position_2));
4174 EXPECT_TRUE(position_2.Equals(position_3)); 4167 EXPECT_TRUE(position_2.Equals(position_3));
4175 4168
4176 // Move Chrome between App1 and App2. 4169 // Move Chrome between App1 and App2.
4177 // Note, move target_index is in context when moved element is removed from 4170 // Note, move target_index is in context when moved element is removed from
4178 // array first. 4171 // array first.
4179 model_->Move(1, 2); 4172 model_.Move(1, 2);
4180 EXPECT_EQ("AppList, App1, Chrome, App2, App3", GetPinnedAppStatus()); 4173 EXPECT_EQ("AppList, App1, Chrome, App2, App3", GetPinnedAppStatus());
4181 4174
4182 // Expect sync positions for only Chrome is updated and its resolution is 4175 // Expect sync positions for only Chrome is updated and its resolution is
4183 // after all duplicated ordinals. 4176 // after all duplicated ordinals.
4184 EXPECT_TRUE(position_3.LessThan( 4177 EXPECT_TRUE(position_3.LessThan(
4185 app_service_->GetPinPosition(extension_misc::kChromeAppId))); 4178 app_service_->GetPinPosition(extension_misc::kChromeAppId)));
4186 EXPECT_TRUE( 4179 EXPECT_TRUE(
4187 position_1.Equals(app_service_->GetPinPosition(extension1_->id()))); 4180 position_1.Equals(app_service_->GetPinPosition(extension1_->id())));
4188 EXPECT_TRUE( 4181 EXPECT_TRUE(
4189 position_1.Equals(app_service_->GetPinPosition(extension1_->id()))); 4182 position_1.Equals(app_service_->GetPinPosition(extension1_->id())));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4227 4220
4228 // Tests that shelf profile preferences are loaded on login. 4221 // Tests that shelf profile preferences are loaded on login.
4229 TEST_F(ChromeLauncherControllerTest, PrefsLoadedOnLogin) { 4222 TEST_F(ChromeLauncherControllerTest, PrefsLoadedOnLogin) {
4230 PrefService* prefs = profile()->GetTestingPrefService(); 4223 PrefService* prefs = profile()->GetTestingPrefService();
4231 prefs->SetString(prefs::kShelfAlignmentLocal, "Left"); 4224 prefs->SetString(prefs::kShelfAlignmentLocal, "Left");
4232 prefs->SetString(prefs::kShelfAlignment, "Left"); 4225 prefs->SetString(prefs::kShelfAlignment, "Left");
4233 prefs->SetString(prefs::kShelfAutoHideBehaviorLocal, "Always"); 4226 prefs->SetString(prefs::kShelfAutoHideBehaviorLocal, "Always");
4234 prefs->SetString(prefs::kShelfAutoHideBehavior, "Always"); 4227 prefs->SetString(prefs::kShelfAutoHideBehavior, "Always");
4235 4228
4236 TestChromeLauncherController* test_launcher_controller = 4229 TestChromeLauncherController* test_launcher_controller =
4237 shell_delegate_->CreateTestLauncherController(profile()); 4230 shell_delegate_->CreateLauncherController(profile());
4231 test_launcher_controller->Init();
4238 4232
4239 // Simulate login for the test controller. 4233 // Simulate login for the test controller.
4240 test_launcher_controller->ReleaseProfile(); 4234 test_launcher_controller->ReleaseProfile();
4241 test_launcher_controller->AttachProfile(profile()); 4235 test_launcher_controller->AttachProfile(profile());
4242 base::RunLoop().RunUntilIdle(); 4236 base::RunLoop().RunUntilIdle();
4243 4237
4244 TestShelfController* shelf_controller = 4238 TestShelfController* shelf_controller =
4245 test_launcher_controller->test_shelf_controller(); 4239 test_launcher_controller->test_shelf_controller();
4246 ASSERT_TRUE(shelf_controller); 4240 ASSERT_TRUE(shelf_controller);
4247 EXPECT_EQ(ash::SHELF_ALIGNMENT_LEFT, shelf_controller->alignment()); 4241 EXPECT_EQ(ash::SHELF_ALIGNMENT_LEFT, shelf_controller->alignment());
4248 EXPECT_EQ(1u, shelf_controller->alignment_change_count()); 4242 EXPECT_EQ(1u, shelf_controller->alignment_change_count());
4249 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, 4243 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
4250 shelf_controller->auto_hide()); 4244 shelf_controller->auto_hide());
4251 EXPECT_EQ(1u, shelf_controller->auto_hide_change_count()); 4245 EXPECT_EQ(1u, shelf_controller->auto_hide_change_count());
4252 } 4246 }
4253 4247
4254 // Tests that the shelf controller's changes are not wastefully echoed back. 4248 // Tests that the shelf controller's changes are not wastefully echoed back.
4255 TEST_F(ChromeLauncherControllerTest, DoNotEchoShelfControllerChanges) { 4249 TEST_F(ChromeLauncherControllerTest, DoNotEchoShelfControllerChanges) {
4256 TestChromeLauncherController* test_launcher_controller = 4250 TestChromeLauncherController* test_launcher_controller =
4257 shell_delegate_->CreateTestLauncherController(profile()); 4251 shell_delegate_->CreateLauncherController(profile());
4252 test_launcher_controller->Init();
4258 4253
4259 // Simulate login for the test controller. 4254 // Simulate login for the test controller.
4260 test_launcher_controller->ReleaseProfile(); 4255 test_launcher_controller->ReleaseProfile();
4261 test_launcher_controller->AttachProfile(profile()); 4256 test_launcher_controller->AttachProfile(profile());
4262 base::RunLoop().RunUntilIdle(); 4257 base::RunLoop().RunUntilIdle();
4263 4258
4264 TestShelfController* shelf_controller = 4259 TestShelfController* shelf_controller =
4265 test_launcher_controller->test_shelf_controller(); 4260 test_launcher_controller->test_shelf_controller();
4266 ASSERT_TRUE(shelf_controller); 4261 ASSERT_TRUE(shelf_controller);
4267 EXPECT_EQ(ash::SHELF_ALIGNMENT_BOTTOM, shelf_controller->alignment()); 4262 EXPECT_EQ(ash::SHELF_ALIGNMENT_BOTTOM, shelf_controller->alignment());
(...skipping 17 matching lines...) Expand all
4285 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, 4280 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
4286 shelf_controller->auto_hide()); 4281 shelf_controller->auto_hide());
4287 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count()); 4282 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count());
4288 4283
4289 PrefService* prefs = profile()->GetTestingPrefService(); 4284 PrefService* prefs = profile()->GetTestingPrefService();
4290 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignmentLocal)); 4285 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignmentLocal));
4291 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignment)); 4286 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignment));
4292 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehaviorLocal)); 4287 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehaviorLocal));
4293 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehavior)); 4288 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehavior));
4294 } 4289 }
4290
4291 // Ensure Ash and Chrome ShelfModel changes are synchronized correctly.
4292 TEST_F(ChromeLauncherControllerTest, ShelfModelSyncsWithAsh) {
4293 const bool is_mash = chromeos::GetAshConfig() == ash::Config::MASH;
4294 TestChromeLauncherController* launcher_controller =
4295 shell_delegate_->CreateLauncherController(profile());
4296 // In non-mash configs, Chrome uses the same ShelfModel instace as Ash, and it
4297 // should already contain the AppList item. In mash, Chrome and Ash use two
4298 // separate ShelfModel instances that are only linked during initialization.
4299 EXPECT_EQ(is_mash ? 0 : 1, model_.item_count());
4300
4301 TestShelfController* shelf_controller =
4302 launcher_controller->test_shelf_controller();
4303 EXPECT_EQ(0u, shelf_controller->added_count());
4304 EXPECT_EQ(0u, shelf_controller->removed_count());
4305
4306 // Init should yield AppList and browser shelf items in Chrome's ShelfModel.
4307 launcher_controller->Init();
4308 EXPECT_EQ(is_mash ? 1 : 2, model_.item_count());
4309 EXPECT_EQ(is_mash ? extension_misc::kChromeAppId : kAppListId,
4310 model_.items()[0].id.app_id);
4311 // Ash's ShelfModel should have been notified about the browser item in mash.
4312 base::RunLoop().RunUntilIdle();
4313 EXPECT_EQ(2, model_.item_count());
4314 EXPECT_EQ(kAppListId, model_.items()[0].id.app_id);
4315 EXPECT_EQ(extension_misc::kChromeAppId, model_.items()[1].id.app_id);
4316 EXPECT_EQ(is_mash ? 1u : 0u, shelf_controller->added_count());
4317 EXPECT_EQ(0u, shelf_controller->removed_count());
4318
4319 // Simulate adding a shelf item in Ash; mash Chrome should sync the change.
4320 ash::ShelfItem item;
4321 item.type = ash::TYPE_PINNED_APP;
4322 item.id = ash::ShelfID(kDummyAppId);
4323 if (is_mash)
4324 shelf_controller->model_observer()->OnShelfItemAdded(2, item);
4325 else
4326 model_.Add(item);
4327 base::RunLoop().RunUntilIdle();
4328 EXPECT_EQ(3, model_.item_count());
4329 EXPECT_EQ(item.id, model_.items()[2].id);
4330 EXPECT_EQ(is_mash ? 1u : 0u, shelf_controller->added_count());
4331 EXPECT_EQ(0u, shelf_controller->removed_count());
4332
4333 // Simulate removing a shelf item in Ash; mash Chrome should sync the change.
4334 if (is_mash)
4335 shelf_controller->model_observer()->OnShelfItemRemoved(2, item);
4336 else
4337 model_.RemoveItemAt(2);
4338 base::RunLoop().RunUntilIdle();
4339 EXPECT_EQ(2, model_.item_count());
4340 EXPECT_EQ(is_mash ? 1u : 0u, shelf_controller->added_count());
4341 EXPECT_EQ(0u, shelf_controller->removed_count());
4342
4343 // Add an item in Chrome; Ash should be notified of the change in mash.
4344 model_.Add(item);
4345 EXPECT_EQ(3, model_.item_count());
4346 base::RunLoop().RunUntilIdle();
4347 EXPECT_EQ(is_mash ? 2u : 0u, shelf_controller->added_count());
4348 EXPECT_EQ(0u, shelf_controller->removed_count());
4349
4350 // Remove an item in Chrome; Ash should be notified of the change in mash.
4351 model_.RemoveItemAt(2);
4352 EXPECT_EQ(2, model_.item_count());
4353 base::RunLoop().RunUntilIdle();
4354 EXPECT_EQ(is_mash ? 2u : 0u, shelf_controller->added_count());
4355 EXPECT_EQ(is_mash ? 1u : 0u, shelf_controller->removed_count());
4356 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698