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

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: Sync and rebase. 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 using extensions::Extension; 121 using extensions::Extension;
121 using extensions::Manifest; 122 using extensions::Manifest;
122 using extensions::UnloadedExtensionReason; 123 using extensions::UnloadedExtensionReason;
123 using arc::mojom::OrientationLock; 124 using arc::mojom::OrientationLock;
124 125
125 namespace { 126 namespace {
126 constexpr char kOfflineGmailUrl[] = "https://mail.google.com/mail/mu/u"; 127 constexpr char kOfflineGmailUrl[] = "https://mail.google.com/mail/mu/u";
127 constexpr char kGmailUrl[] = "https://mail.google.com/mail/u"; 128 constexpr char kGmailUrl[] = "https://mail.google.com/mail/u";
128 constexpr char kGmailLaunchURL[] = "https://mail.google.com/mail/ca"; 129 constexpr char kGmailLaunchURL[] = "https://mail.google.com/mail/ca";
129 130
130 constexpr char kAppListId[] = "jlfapfmkapbjlfbpjedlinehodkccjee";
131
132 // An extension prefix. 131 // An extension prefix.
133 constexpr char kCrxAppPrefix[] = "_crx_"; 132 constexpr char kCrxAppPrefix[] = "_crx_";
134 133
135 // Dummy app id is used to put at least one pin record to prevent initializing 134 // Dummy app id is used to put at least one pin record to prevent initializing
136 // pin model with default apps that can affect some tests. 135 // pin model with default apps that can affect some tests.
137 constexpr char kDummyAppId[] = "dummyappid_dummyappid_dummyappid"; 136 constexpr char kDummyAppId[] = "dummyappid_dummyappid_dummyappid";
138 137
139 // ShelfModelObserver implementation that tracks what messages are invoked. 138 // ShelfModelObserver implementation that tracks what messages are invoked.
140 class TestShelfModelObserver : public ash::ShelfModelObserver { 139 class TestShelfModelObserver : public ash::ShelfModelObserver {
141 public: 140 public:
(...skipping 13 matching lines...) Expand all
155 154
156 void ShelfItemChanged(int index, const ash::ShelfItem& old_item) override { 155 void ShelfItemChanged(int index, const ash::ShelfItem& old_item) override {
157 ++changed_; 156 ++changed_;
158 last_index_ = index; 157 last_index_ = index;
159 } 158 }
160 159
161 void ShelfItemMoved(int start_index, int target_index) override { 160 void ShelfItemMoved(int start_index, int target_index) override {
162 last_index_ = target_index; 161 last_index_ = target_index;
163 } 162 }
164 163
164 void ShelfItemDelegateChanged(const ash::ShelfID&,
165 ash::ShelfItemDelegate*) override {}
166
165 void clear_counts() { 167 void clear_counts() {
166 added_ = 0; 168 added_ = 0;
167 removed_ = 0; 169 removed_ = 0;
168 changed_ = 0; 170 changed_ = 0;
169 last_index_ = 0; 171 last_index_ = 0;
170 } 172 }
171 173
172 int added() const { return added_; } 174 int added() const { return added_; }
173 int removed() const { return removed_; } 175 int removed() const { return removed_; }
174 int changed() const { return changed_; } 176 int changed() const { return changed_; }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 ItemSelectedCallback callback) override { 270 ItemSelectedCallback callback) override {
269 std::move(callback).Run(ash::SHELF_ACTION_WINDOW_ACTIVATED, base::nullopt); 271 std::move(callback).Run(ash::SHELF_ACTION_WINDOW_ACTIVATED, base::nullopt);
270 } 272 }
271 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override {} 273 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override {}
272 void Close() override {} 274 void Close() override {}
273 275
274 private: 276 private:
275 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController); 277 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController);
276 }; 278 };
277 279
278 // A test ShelfController implementation that tracks alignment and auto-hide. 280 // A test ShelfController implementation that tracks state and function calls.
279 class TestShelfController : public ash::mojom::ShelfController { 281 class TestShelfController : public ash::mojom::ShelfController {
280 public: 282 public:
281 TestShelfController() : binding_(this) {} 283 TestShelfController() : binding_(this) {}
282 ~TestShelfController() override {} 284 ~TestShelfController() override {}
283 285
284 ash::ShelfAlignment alignment() const { return alignment_; } 286 ash::ShelfAlignment alignment() const { return alignment_; }
285 ash::ShelfAutoHideBehavior auto_hide() const { return auto_hide_; } 287 ash::ShelfAutoHideBehavior auto_hide() const { return auto_hide_; }
286 288
287 size_t alignment_change_count() const { return alignment_change_count_; } 289 size_t alignment_change_count() const { return alignment_change_count_; }
288 size_t auto_hide_change_count() const { return auto_hide_change_count_; } 290 size_t auto_hide_change_count() const { return auto_hide_change_count_; }
289 291
292 size_t added_count() const { return added_count_; }
293 size_t removed_count() const { return removed_count_; }
294
290 ash::mojom::ShelfControllerPtr CreateInterfacePtrAndBind() { 295 ash::mojom::ShelfControllerPtr CreateInterfacePtrAndBind() {
291 return binding_.CreateInterfacePtrAndBind(); 296 return binding_.CreateInterfacePtrAndBind();
292 } 297 }
293 298
294 // ash::mojom::ShelfController: 299 // ash::mojom::ShelfController:
295 void AddObserver( 300 void AddObserver(
296 ash::mojom::ShelfObserverAssociatedPtrInfo observer) override { 301 ash::mojom::ShelfObserverAssociatedPtrInfo observer) override {
297 observer_.Bind(std::move(observer)); 302 observer_.Bind(std::move(observer));
298 } 303 }
299 void SetAlignment(ash::ShelfAlignment alignment, 304 void SetAlignment(ash::ShelfAlignment alignment,
300 int64_t display_id) override { 305 int64_t display_id) override {
301 alignment_change_count_++; 306 alignment_change_count_++;
302 alignment_ = alignment; 307 alignment_ = alignment;
303 observer_->OnAlignmentChanged(alignment_, display_id); 308 observer_->OnAlignmentChanged(alignment_, display_id);
304 } 309 }
305 void SetAutoHideBehavior(ash::ShelfAutoHideBehavior auto_hide, 310 void SetAutoHideBehavior(ash::ShelfAutoHideBehavior auto_hide,
306 int64_t display_id) override { 311 int64_t display_id) override {
307 auto_hide_change_count_++; 312 auto_hide_change_count_++;
308 auto_hide_ = auto_hide; 313 auto_hide_ = auto_hide;
309 observer_->OnAutoHideBehaviorChanged(auto_hide_, display_id); 314 observer_->OnAutoHideBehaviorChanged(auto_hide_, display_id);
310 } 315 }
311 void PinItem( 316 void AddShelfItem(int32_t, const ash::ShelfItem&) override { added_count_++; }
312 const ash::ShelfItem& item, 317 void RemoveShelfItem(const ash::ShelfID&) override { removed_count_++; }
313 ash::mojom::ShelfItemDelegateAssociatedPtrInfo delegate) override {} 318 void MoveShelfItem(const ash::ShelfID&, int32_t) override {}
314 void UnpinItem(const std::string& app_id) override {} 319 void UpdateShelfItem(const ash::ShelfItem&) override {}
315 void SetItemImage(const std::string& app_id, const SkBitmap& image) override { 320 void SetShelfItemDelegate(const ash::ShelfID&,
316 } 321 ash::mojom::ShelfItemDelegatePtr) override {}
317 322
318 private: 323 private:
319 ash::ShelfAlignment alignment_ = ash::SHELF_ALIGNMENT_BOTTOM_LOCKED; 324 ash::ShelfAlignment alignment_ = ash::SHELF_ALIGNMENT_BOTTOM_LOCKED;
320 ash::ShelfAutoHideBehavior auto_hide_ = ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN; 325 ash::ShelfAutoHideBehavior auto_hide_ = ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN;
321 326
322 size_t alignment_change_count_ = 0; 327 size_t alignment_change_count_ = 0;
323 size_t auto_hide_change_count_ = 0; 328 size_t auto_hide_change_count_ = 0;
324 329
330 size_t added_count_ = 0;
331 size_t removed_count_ = 0;
332
325 ash::mojom::ShelfObserverAssociatedPtr observer_; 333 ash::mojom::ShelfObserverAssociatedPtr observer_;
326 mojo::Binding<ash::mojom::ShelfController> binding_; 334 mojo::Binding<ash::mojom::ShelfController> binding_;
327 335
328 DISALLOW_COPY_AND_ASSIGN(TestShelfController); 336 DISALLOW_COPY_AND_ASSIGN(TestShelfController);
329 }; 337 };
330 338
331 // A callback that does nothing after shelf item selection handling. 339 // A callback that does nothing after shelf item selection handling.
332 void NoopCallback(ash::ShelfAction action, base::Optional<ash::MenuItemList>) {} 340 void NoopCallback(ash::ShelfAction action, base::Optional<ash::MenuItemList>) {}
333 341
334 // Simulates selection of the shelf item. 342 // Simulates selection of the shelf item.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 TestShelfController test_shelf_controller_; 374 TestShelfController test_shelf_controller_;
367 375
368 DISALLOW_COPY_AND_ASSIGN(TestChromeLauncherController); 376 DISALLOW_COPY_AND_ASSIGN(TestChromeLauncherController);
369 }; 377 };
370 378
371 // A shell delegate that owns a ChromeLauncherController, like production. 379 // A shell delegate that owns a ChromeLauncherController, like production.
372 // TODO(msw): Refine ChromeLauncherController lifetime management. 380 // TODO(msw): Refine ChromeLauncherController lifetime management.
373 // TODO(msw): Avoid relying on TestShellDelegate's ShelfInitializer. 381 // TODO(msw): Avoid relying on TestShellDelegate's ShelfInitializer.
374 class ChromeLauncherTestShellDelegate : public ash::test::TestShellDelegate { 382 class ChromeLauncherTestShellDelegate : public ash::test::TestShellDelegate {
375 public: 383 public:
376 ChromeLauncherTestShellDelegate() {} 384 explicit ChromeLauncherTestShellDelegate(ash::ShelfModel* shelf_model)
377 385 : 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 386
385 // Create a TestChromeLauncherController instance. 387 // Create a TestChromeLauncherController instance.
386 TestChromeLauncherController* CreateTestLauncherController(Profile* profile) { 388 TestChromeLauncherController* CreateLauncherController(Profile* profile) {
387 auto controller = base::MakeUnique<TestChromeLauncherController>( 389 launcher_controller_ =
388 profile, ash::Shell::Get()->shelf_model()); 390 base::MakeUnique<TestChromeLauncherController>(profile, shelf_model_);
389 TestChromeLauncherController* controller_weak = controller.get(); 391 return launcher_controller_.get();
390 launcher_controller_ = std::move(controller);
391 launcher_controller_->Init();
392 return controller_weak;
393 } 392 }
394 393
395 // ash::test::TestShellDelegate: 394 // ash::test::TestShellDelegate:
396 void ShelfShutdown() override { launcher_controller_.reset(); } 395 void ShelfShutdown() override { launcher_controller_.reset(); }
397 396
398 private: 397 private:
399 std::unique_ptr<ChromeLauncherController> launcher_controller_; 398 ash::ShelfModel* shelf_model_;
399 std::unique_ptr<TestChromeLauncherController> launcher_controller_;
400 400
401 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherTestShellDelegate); 401 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherTestShellDelegate);
402 }; 402 };
403 403
404 class ChromeLauncherControllerTest : public BrowserWithTestWindowTest { 404 class ChromeLauncherControllerTest : public BrowserWithTestWindowTest {
405 protected: 405 protected:
406 ChromeLauncherControllerTest() 406 ChromeLauncherControllerTest()
407 : BrowserWithTestWindowTest(Browser::TYPE_TABBED, false) {} 407 : BrowserWithTestWindowTest(Browser::TYPE_TABBED, false) {}
408 408
409 ~ChromeLauncherControllerTest() override {} 409 ~ChromeLauncherControllerTest() override {}
410 410
411 void SetUp() override { 411 void SetUp() override {
412 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 412 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
413 command_line->AppendSwitch(switches::kUseFirstDisplayAsInternal); 413 command_line->AppendSwitch(switches::kUseFirstDisplayAsInternal);
414 414
415 app_list::AppListSyncableServiceFactory::SetUseInTesting(); 415 app_list::AppListSyncableServiceFactory::SetUseInTesting();
416 416
417 shell_delegate_ = new ChromeLauncherTestShellDelegate(); 417 shell_delegate_ = new ChromeLauncherTestShellDelegate(&model_);
418 ash_test_helper()->set_test_shell_delegate(shell_delegate_); 418 ash_test_helper()->set_test_shell_delegate(shell_delegate_);
419 419
420 BrowserWithTestWindowTest::SetUp(); 420 BrowserWithTestWindowTest::SetUp();
421 421
422 if (!profile_manager_) { 422 if (!profile_manager_) {
423 profile_manager_.reset( 423 profile_manager_.reset(
424 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 424 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
425 ASSERT_TRUE(profile_manager_->SetUp()); 425 ASSERT_TRUE(profile_manager_->SetUp());
426 } 426 }
427 427
428 model_ = ash::Shell::Get()->shelf_controller()->model();
429 model_observer_.reset(new TestShelfModelObserver); 428 model_observer_.reset(new TestShelfModelObserver);
430 model_->AddObserver(model_observer_.get()); 429 model_.AddObserver(model_observer_.get());
431 430
432 base::DictionaryValue manifest; 431 base::DictionaryValue manifest;
433 manifest.SetString(extensions::manifest_keys::kName, 432 manifest.SetString(extensions::manifest_keys::kName,
434 "launcher controller test extension"); 433 "launcher controller test extension");
435 manifest.SetString(extensions::manifest_keys::kVersion, "1"); 434 manifest.SetString(extensions::manifest_keys::kVersion, "1");
436 manifest.SetString(extensions::manifest_keys::kDescription, 435 manifest.SetString(extensions::manifest_keys::kDescription,
437 "for testing pinned apps"); 436 "for testing pinned apps");
438 437
439 base::DictionaryValue manifest_platform_app; 438 base::DictionaryValue manifest_platform_app;
440 manifest_platform_app.SetString(extensions::manifest_keys::kName, 439 manifest_platform_app.SetString(extensions::manifest_keys::kName,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 } 522 }
524 523
525 // Creates a running platform V2 app (not pinned) of type |app_id|. 524 // Creates a running platform V2 app (not pinned) of type |app_id|.
526 virtual void CreateRunningV2App(const std::string& app_id) { 525 virtual void CreateRunningV2App(const std::string& app_id) {
527 DCHECK(!test_controller_); 526 DCHECK(!test_controller_);
528 // Change the created launcher controller into a V2 app controller. 527 // Change the created launcher controller into a V2 app controller.
529 std::unique_ptr<TestV2AppLauncherItemController> controller = 528 std::unique_ptr<TestV2AppLauncherItemController> controller =
530 base::MakeUnique<TestV2AppLauncherItemController>(app_id); 529 base::MakeUnique<TestV2AppLauncherItemController>(app_id);
531 test_controller_ = controller.get(); 530 test_controller_ = controller.get();
532 ash::ShelfID id = launcher_controller_->InsertAppLauncherItem( 531 ash::ShelfID id = launcher_controller_->InsertAppLauncherItem(
533 std::move(controller), ash::STATUS_RUNNING, model_->item_count(), 532 std::move(controller), ash::STATUS_RUNNING, model_.item_count(),
534 ash::TYPE_APP); 533 ash::TYPE_APP);
535 DCHECK(launcher_controller_->IsPlatformApp(id)); 534 DCHECK(launcher_controller_->IsPlatformApp(id));
536 } 535 }
537 536
538 // Sets the stage for a multi user test. 537 // Sets the stage for a multi user test.
539 virtual void SetUpMultiUserScenario(syncer::SyncChangeList* user_a, 538 virtual void SetUpMultiUserScenario(syncer::SyncChangeList* user_a,
540 syncer::SyncChangeList* user_b) { 539 syncer::SyncChangeList* user_b) {
541 InitLauncherController(); 540 InitLauncherController();
542 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 541 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
543 542
(...skipping 27 matching lines...) Expand all
571 570
572 // Set user b preferences. 571 // Set user b preferences.
573 InsertAddPinChange(user_b, 0, extension6_->id()); 572 InsertAddPinChange(user_b, 0, extension6_->id());
574 InsertAddPinChange(user_b, 1, extension7_->id()); 573 InsertAddPinChange(user_b, 1, extension7_->id());
575 InsertAddPinChange(user_b, 2, extension8_->id()); 574 InsertAddPinChange(user_b, 2, extension8_->id());
576 InsertAddPinChange(user_b, 3, extension_misc::kChromeAppId); 575 InsertAddPinChange(user_b, 3, extension_misc::kChromeAppId);
577 } 576 }
578 577
579 void TearDown() override { 578 void TearDown() override {
580 arc_test_.TearDown(); 579 arc_test_.TearDown();
581 model_->RemoveObserver(model_observer_.get()); 580 model_.RemoveObserver(model_observer_.get());
582 model_observer_.reset(); 581 model_observer_.reset();
583 launcher_controller_ = nullptr; 582 launcher_controller_ = nullptr;
584 BrowserWithTestWindowTest::TearDown(); 583 BrowserWithTestWindowTest::TearDown();
585 } 584 }
586 585
587 BrowserWindow* CreateBrowserWindow() override { 586 BrowserWindow* CreateBrowserWindow() override {
588 return CreateTestBrowserWindowAura(); 587 return CreateTestBrowserWindowAura();
589 } 588 }
590 589
591 std::unique_ptr<Browser> CreateBrowserWithTestWindowForProfile( 590 std::unique_ptr<Browser> CreateBrowserWithTestWindowForProfile(
592 Profile* profile) { 591 Profile* profile) {
593 TestBrowserWindow* browser_window = CreateTestBrowserWindowAura(); 592 TestBrowserWindow* browser_window = CreateTestBrowserWindowAura();
594 new TestBrowserWindowOwner(browser_window); 593 new TestBrowserWindowOwner(browser_window);
595 return base::WrapUnique( 594 return base::WrapUnique(
596 CreateBrowser(profile, Browser::TYPE_TABBED, false, browser_window)); 595 CreateBrowser(profile, Browser::TYPE_TABBED, false, browser_window));
597 } 596 }
598 597
599 void AddAppListLauncherItem() {
600 ash::ShelfItem app_list;
601 app_list.id = ash::ShelfID(kAppListId);
602 app_list.type = ash::TYPE_APP_LIST;
603 model_->Add(app_list);
604 }
605
606 // Create a launcher controller instance, owned by the test shell delegate. 598 // Create a launcher controller instance, owned by the test shell delegate.
607 // Returns a pointer to the uninitialized controller. 599 // Returns a pointer to the uninitialized controller.
608 ChromeLauncherController* CreateLauncherController() { 600 ChromeLauncherController* CreateLauncherController() {
609 launcher_controller_ = shell_delegate_->CreateLauncherController(profile()); 601 launcher_controller_ = shell_delegate_->CreateLauncherController(profile());
610 return launcher_controller_; 602 return launcher_controller_;
611 } 603 }
612 604
613 // Create and initialize the controller, owned by the test shell delegate. 605 // Create and initialize the controller, owned by the test shell delegate.
614 void InitLauncherController() { CreateLauncherController()->Init(); } 606 void InitLauncherController() { CreateLauncherController()->Init(); }
615 607
(...skipping 10 matching lines...) Expand all
626 shell_delegate_->ShelfShutdown(); 618 shell_delegate_->ShelfShutdown();
627 } 619 }
628 620
629 // Destroy and recreate the controller; clear and reinitialize the ShelfModel. 621 // Destroy and recreate the controller; clear and reinitialize the ShelfModel.
630 // Returns a pointer to the uninitialized controller, owned by shell delegate. 622 // Returns a pointer to the uninitialized controller, owned by shell delegate.
631 // TODO(msw): This does not accurately represent ChromeLauncherController 623 // TODO(msw): This does not accurately represent ChromeLauncherController
632 // lifetime or usage in production, and does not accurately simulate restarts. 624 // lifetime or usage in production, and does not accurately simulate restarts.
633 ChromeLauncherController* RecreateLauncherController() { 625 ChromeLauncherController* RecreateLauncherController() {
634 // Destroy any existing controller first; only one may exist at a time. 626 // Destroy any existing controller first; only one may exist at a time.
635 ResetLauncherController(); 627 ResetLauncherController();
636 while (model_->item_count() > 0) 628 DCHECK_GE(model_.item_count(), 1);
637 model_->RemoveItemAt(0); 629 DCHECK_EQ(ash::kAppListId, model_.items()[0].id.app_id);
638 AddAppListLauncherItem(); 630 while (model_.item_count() > 1)
631 model_.RemoveItemAt(1);
639 return CreateLauncherController(); 632 return CreateLauncherController();
640 } 633 }
641 634
642 void StartAppSyncService(const syncer::SyncDataList& init_sync_list) { 635 void StartAppSyncService(const syncer::SyncDataList& init_sync_list) {
643 app_service_->MergeDataAndStartSyncing( 636 app_service_->MergeDataAndStartSyncing(
644 syncer::APP_LIST, init_sync_list, 637 syncer::APP_LIST, init_sync_list,
645 base::MakeUnique<syncer::FakeSyncChangeProcessor>(), 638 base::MakeUnique<syncer::FakeSyncChangeProcessor>(),
646 base::MakeUnique<syncer::SyncErrorFactoryMock>()); 639 base::MakeUnique<syncer::SyncErrorFactoryMock>());
647 EXPECT_EQ(init_sync_list.size(), app_service_->sync_items().size()); 640 EXPECT_EQ(init_sync_list.size(), app_service_->sync_items().size());
648 } 641 }
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 extension_misc::kChromeAppId, "Test", specifics); 814 extension_misc::kChromeAppId, "Test", specifics);
822 sync_list.push_back(syncer::SyncChange( 815 sync_list.push_back(syncer::SyncChange(
823 FROM_HERE, syncer::SyncChange::ACTION_UPDATE, sync_data)); 816 FROM_HERE, syncer::SyncChange::ACTION_UPDATE, sync_data));
824 app_service_->ProcessSyncChanges(FROM_HERE, sync_list); 817 app_service_->ProcessSyncChanges(FROM_HERE, sync_list);
825 } 818 }
826 819
827 // Gets the IDs of the currently pinned app items. 820 // Gets the IDs of the currently pinned app items.
828 void GetPinnedAppIds(ChromeLauncherController* controller, 821 void GetPinnedAppIds(ChromeLauncherController* controller,
829 std::vector<std::string>* app_ids) { 822 std::vector<std::string>* app_ids) {
830 app_ids->clear(); 823 app_ids->clear();
831 for (const auto& item : model_->items()) { 824 for (const auto& item : model_.items()) {
832 if (item.type == ash::TYPE_PINNED_APP) 825 if (item.type == ash::TYPE_PINNED_APP)
833 app_ids->push_back(item.id.app_id); 826 app_ids->push_back(item.id.app_id);
834 } 827 }
835 } 828 }
836 829
837 // Get the setup of the currently shown launcher items in one string. 830 // 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 831 // 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 832 // pinned V1 app will start with a small letter and each running but not
840 // pinned V2 app will start with a '*' + small letter. 833 // pinned V2 app will start with a '*' + small letter.
841 std::string GetPinnedAppStatus() { 834 std::string GetPinnedAppStatus() {
842 std::string result; 835 std::string result;
843 for (int i = 0; i < model_->item_count(); i++) { 836 for (int i = 0; i < model_.item_count(); i++) {
844 if (!result.empty()) 837 if (!result.empty())
845 result.append(", "); 838 result.append(", ");
846 switch (model_->items()[i].type) { 839 switch (model_.items()[i].type) {
847 case ash::TYPE_APP: { 840 case ash::TYPE_APP: {
848 if (launcher_controller_->IsPlatformApp(model_->items()[i].id)) 841 if (launcher_controller_->IsPlatformApp(model_.items()[i].id))
849 result += "*"; 842 result += "*";
850 const std::string& app = model_->items()[i].id.app_id; 843 const std::string& app = model_.items()[i].id.app_id;
851 EXPECT_FALSE(launcher_controller_->IsAppPinned(app)); 844 EXPECT_FALSE(launcher_controller_->IsAppPinned(app));
852 if (app == extension1_->id()) { 845 if (app == extension1_->id()) {
853 result += "app1"; 846 result += "app1";
854 } else if (app == extension2_->id()) { 847 } else if (app == extension2_->id()) {
855 result += "app2"; 848 result += "app2";
856 } else if (app == extension3_->id()) { 849 } else if (app == extension3_->id()) {
857 result += "app3"; 850 result += "app3";
858 } else if (app == extension4_->id()) { 851 } else if (app == extension4_->id()) {
859 result += "app4"; 852 result += "app4";
860 } else if (app == extension5_->id()) { 853 } else if (app == extension5_->id()) {
861 result += "app5"; 854 result += "app5";
862 } else if (app == extension6_->id()) { 855 } else if (app == extension6_->id()) {
863 result += "app6"; 856 result += "app6";
864 } else if (app == extension7_->id()) { 857 } else if (app == extension7_->id()) {
865 result += "app7"; 858 result += "app7";
866 } else if (app == extension8_->id()) { 859 } else if (app == extension8_->id()) {
867 result += "app8"; 860 result += "app8";
868 } else if (app == extension_platform_app_->id()) { 861 } else if (app == extension_platform_app_->id()) {
869 result += "platform_app"; 862 result += "platform_app";
870 } else { 863 } else {
871 result += "unknown"; 864 result += "unknown";
872 } 865 }
873 break; 866 break;
874 } 867 }
875 case ash::TYPE_PINNED_APP: { 868 case ash::TYPE_PINNED_APP: {
876 if (launcher_controller_->IsPlatformApp(model_->items()[i].id)) 869 if (launcher_controller_->IsPlatformApp(model_.items()[i].id))
877 result += "*"; 870 result += "*";
878 const std::string& app = model_->items()[i].id.app_id; 871 const std::string& app = model_.items()[i].id.app_id;
879 EXPECT_TRUE(launcher_controller_->IsAppPinned(app)); 872 EXPECT_TRUE(launcher_controller_->IsAppPinned(app));
880 if (app == extension1_->id()) { 873 if (app == extension1_->id()) {
881 result += "App1"; 874 result += "App1";
882 } else if (app == extension2_->id()) { 875 } else if (app == extension2_->id()) {
883 result += "App2"; 876 result += "App2";
884 } else if (app == extension3_->id()) { 877 } else if (app == extension3_->id()) {
885 result += "App3"; 878 result += "App3";
886 } else if (app == extension4_->id()) { 879 } else if (app == extension4_->id()) {
887 result += "App4"; 880 result += "App4";
888 } else if (app == extension5_->id()) { 881 } else if (app == extension5_->id()) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 scoped_refptr<Extension> extension7_; 1036 scoped_refptr<Extension> extension7_;
1044 scoped_refptr<Extension> extension8_; 1037 scoped_refptr<Extension> extension8_;
1045 scoped_refptr<Extension> extension_platform_app_; 1038 scoped_refptr<Extension> extension_platform_app_;
1046 scoped_refptr<Extension> arc_support_host_; 1039 scoped_refptr<Extension> arc_support_host_;
1047 1040
1048 ArcAppTest arc_test_; 1041 ArcAppTest arc_test_;
1049 bool auto_start_arc_test_ = false; 1042 bool auto_start_arc_test_ = false;
1050 ChromeLauncherController* launcher_controller_ = nullptr; 1043 ChromeLauncherController* launcher_controller_ = nullptr;
1051 ChromeLauncherTestShellDelegate* shell_delegate_ = nullptr; 1044 ChromeLauncherTestShellDelegate* shell_delegate_ = nullptr;
1052 std::unique_ptr<TestShelfModelObserver> model_observer_; 1045 std::unique_ptr<TestShelfModelObserver> model_observer_;
1053 ash::ShelfModel* model_ = nullptr; 1046 ash::ShelfModel model_;
1054 std::unique_ptr<TestingProfileManager> profile_manager_; 1047 std::unique_ptr<TestingProfileManager> profile_manager_;
1055 1048
1056 // |item_delegate_manager_| owns |test_controller_|. 1049 // |item_delegate_manager_| owns |test_controller_|.
1057 ash::ShelfItemDelegate* test_controller_ = nullptr; 1050 ash::ShelfItemDelegate* test_controller_ = nullptr;
1058 1051
1059 ExtensionService* extension_service_ = nullptr; 1052 ExtensionService* extension_service_ = nullptr;
1060 1053
1061 app_list::AppListSyncableService* app_service_ = nullptr; 1054 app_list::AppListSyncableService* app_service_ = nullptr;
1062 1055
1063 private: 1056 private:
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerMultiProfileWithArcTest); 1340 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerMultiProfileWithArcTest);
1348 }; 1341 };
1349 1342
1350 INSTANTIATE_TEST_CASE_P(, 1343 INSTANTIATE_TEST_CASE_P(,
1351 ChromeLauncherControllerMultiProfileWithArcTest, 1344 ChromeLauncherControllerMultiProfileWithArcTest,
1352 ::testing::Bool()); 1345 ::testing::Bool());
1353 1346
1354 TEST_F(ChromeLauncherControllerTest, DefaultApps) { 1347 TEST_F(ChromeLauncherControllerTest, DefaultApps) {
1355 InitLauncherController(); 1348 InitLauncherController();
1356 // The model should only contain the browser shortcut and app list items. 1349 // The model should only contain the browser shortcut and app list items.
1357 EXPECT_EQ(2, model_->item_count()); 1350 EXPECT_EQ(2, model_.item_count());
1358 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1351 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1359 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1352 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1360 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1353 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1361 1354
1362 // Installing |extension3_| should add it to the launcher - behind the 1355 // Installing |extension3_| should add it to the launcher - behind the
1363 // chrome icon. 1356 // chrome icon.
1364 extension_service_->AddExtension(extension3_.get()); 1357 extension_service_->AddExtension(extension3_.get());
1365 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); 1358 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus());
1366 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1359 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1367 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1360 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)); 1413 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id1));
1421 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 1414 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
1422 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id2)); 1415 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id2));
1423 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 1416 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1424 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3)); 1417 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3));
1425 1418
1426 EXPECT_EQ("AppList, App1, Chrome, Fake App 0, App2, Fake App 1, App3", 1419 EXPECT_EQ("AppList, App1, Chrome, Fake App 0, App2, Fake App 1, App3",
1427 GetPinnedAppStatus()); 1420 GetPinnedAppStatus());
1428 1421
1429 // Now move pins on ARC enabled platform. 1422 // Now move pins on ARC enabled platform.
1430 model_->Move(1, 4); 1423 model_.Move(1, 4);
1431 model_->Move(3, 1); 1424 model_.Move(3, 1);
1432 model_->Move(3, 5); 1425 model_.Move(3, 5);
1433 model_->Move(4, 2); 1426 model_.Move(4, 2);
1434 EXPECT_EQ("AppList, App2, Fake App 1, Chrome, App1, Fake App 0, App3", 1427 EXPECT_EQ("AppList, App2, Fake App 1, Chrome, App1, Fake App 0, App3",
1435 GetPinnedAppStatus()); 1428 GetPinnedAppStatus());
1436 1429
1437 copy_sync_list = app_service_->GetAllSyncData(syncer::APP_LIST); 1430 copy_sync_list = app_service_->GetAllSyncData(syncer::APP_LIST);
1438 1431
1439 ResetLauncherController(); 1432 ResetLauncherController();
1440 ResetPinModel(); 1433 ResetPinModel();
1441 1434
1442 SendPinChanges(syncer::SyncChangeList(), true); 1435 SendPinChanges(syncer::SyncChangeList(), true);
1443 StopAppSyncService(); 1436 StopAppSyncService();
1444 EXPECT_EQ(0U, app_service_->sync_items().size()); 1437 EXPECT_EQ(0U, app_service_->sync_items().size());
1445 1438
1446 // Move back to ARC disabled platform. 1439 // Move back to ARC disabled platform.
1447 // TODO(victorhsieh): Implement opt-out. 1440 // TODO(victorhsieh): Implement opt-out.
1448 if (arc::ShouldArcAlwaysStart()) 1441 if (arc::ShouldArcAlwaysStart())
1449 return; 1442 return;
1450 EnablePlayStore(false); 1443 EnablePlayStore(false);
1451 StartAppSyncService(copy_sync_list); 1444 StartAppSyncService(copy_sync_list);
1452 RecreateLauncherController()->Init(); 1445 RecreateLauncherController()->Init();
1453 1446
1454 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1447 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1455 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id1)); 1448 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id1));
1456 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 1449 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
1457 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id2)); 1450 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id2));
1458 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 1451 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
1459 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3)); 1452 EXPECT_FALSE(launcher_controller_->IsAppPinned(arc_app_id3));
1460 EXPECT_EQ("AppList, App2, Chrome, App1, App3", GetPinnedAppStatus()); 1453 EXPECT_EQ("AppList, App2, Chrome, App1, App3", GetPinnedAppStatus());
1461 1454
1462 // Now move/remove pins on ARC disabled platform. 1455 // Now move/remove pins on ARC disabled platform.
1463 model_->Move(4, 2); 1456 model_.Move(4, 2);
1464 launcher_controller_->UnpinAppWithID(extension2_->id()); 1457 launcher_controller_->UnpinAppWithID(extension2_->id());
1465 EXPECT_EQ("AppList, App3, Chrome, App1", GetPinnedAppStatus()); 1458 EXPECT_EQ("AppList, App3, Chrome, App1", GetPinnedAppStatus());
1466 EnablePlayStore(true); 1459 EnablePlayStore(true);
1467 1460
1468 SendListOfArcApps(); 1461 SendListOfArcApps();
1469 1462
1470 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1463 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1471 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id1)); 1464 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id1));
1472 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1465 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1473 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc_app_id2)); 1466 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. 1684 // Check that an update of an extension does not crash the system.
1692 extension_service_->UnloadExtension(extension3_->id(), 1685 extension_service_->UnloadExtension(extension3_->id(),
1693 UnloadedExtensionReason::UPDATE); 1686 UnloadedExtensionReason::UPDATE);
1694 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); 1687 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus());
1695 } 1688 }
1696 1689
1697 // Test the V1 app interaction flow: run it, activate it, close it. 1690 // Test the V1 app interaction flow: run it, activate it, close it.
1698 TEST_F(ChromeLauncherControllerTest, V1AppRunActivateClose) { 1691 TEST_F(ChromeLauncherControllerTest, V1AppRunActivateClose) {
1699 InitLauncherController(); 1692 InitLauncherController();
1700 // The model should only contain the browser shortcut and app list items. 1693 // The model should only contain the browser shortcut and app list items.
1701 EXPECT_EQ(2, model_->item_count()); 1694 EXPECT_EQ(2, model_.item_count());
1702 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1695 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1703 EXPECT_EQ(nullptr, 1696 EXPECT_EQ(nullptr,
1704 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1697 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1705 1698
1706 // Reporting that the app is running should create a new shelf item. 1699 // Reporting that the app is running should create a new shelf item.
1707 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING); 1700 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING);
1708 EXPECT_EQ(3, model_->item_count()); 1701 EXPECT_EQ(3, model_.item_count());
1709 EXPECT_EQ(ash::TYPE_APP, model_->items()[2].type); 1702 EXPECT_EQ(ash::TYPE_APP, model_.items()[2].type);
1710 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[2].status); 1703 EXPECT_EQ(ash::STATUS_RUNNING, model_.items()[2].status);
1711 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1704 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1712 EXPECT_NE(nullptr, 1705 EXPECT_NE(nullptr,
1713 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1706 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1714 1707
1715 // Reporting an active status should just update the existing item. 1708 // Reporting an active status should just update the existing item.
1716 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_ACTIVE); 1709 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_ACTIVE);
1717 EXPECT_EQ(3, model_->item_count()); 1710 EXPECT_EQ(3, model_.item_count());
1718 EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[2].status); 1711 EXPECT_EQ(ash::STATUS_ACTIVE, model_.items()[2].status);
1719 1712
1720 // Reporting that the app is closed should remove its shelf item. 1713 // Reporting that the app is closed should remove its shelf item.
1721 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED); 1714 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED);
1722 EXPECT_EQ(2, model_->item_count()); 1715 EXPECT_EQ(2, model_.item_count());
1723 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1716 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1724 EXPECT_EQ(nullptr, 1717 EXPECT_EQ(nullptr,
1725 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1718 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1726 1719
1727 // Reporting that the app is closed again should have no effect. 1720 // Reporting that the app is closed again should have no effect.
1728 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED); 1721 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED);
1729 EXPECT_EQ(2, model_->item_count()); 1722 EXPECT_EQ(2, model_.item_count());
1730 } 1723 }
1731 1724
1732 // Test the V1 app interaction flow: pin it, run it, close it, unpin it. 1725 // Test the V1 app interaction flow: pin it, run it, close it, unpin it.
1733 TEST_F(ChromeLauncherControllerTest, V1AppPinRunCloseUnpin) { 1726 TEST_F(ChromeLauncherControllerTest, V1AppPinRunCloseUnpin) {
1734 InitLauncherController(); 1727 InitLauncherController();
1735 // The model should only contain the browser shortcut and app list items. 1728 // The model should only contain the browser shortcut and app list items.
1736 EXPECT_EQ(2, model_->item_count()); 1729 EXPECT_EQ(2, model_.item_count());
1737 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1730 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1738 EXPECT_EQ(nullptr, 1731 EXPECT_EQ(nullptr,
1739 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1732 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1740 1733
1741 // Pinning the app should create a new shelf item. 1734 // Pinning the app should create a new shelf item.
1742 launcher_controller_->PinAppWithID(extension1_->id()); 1735 launcher_controller_->PinAppWithID(extension1_->id());
1743 EXPECT_EQ(3, model_->item_count()); 1736 EXPECT_EQ(3, model_.item_count());
1744 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 1737 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
1745 EXPECT_EQ(ash::STATUS_CLOSED, model_->items()[2].status); 1738 EXPECT_EQ(ash::STATUS_CLOSED, model_.items()[2].status);
1746 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1739 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1747 EXPECT_NE(nullptr, 1740 EXPECT_NE(nullptr,
1748 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1741 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1749 1742
1750 // Reporting that the app is running should just update the existing item. 1743 // Reporting that the app is running should just update the existing item.
1751 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING); 1744 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING);
1752 EXPECT_EQ(3, model_->item_count()); 1745 EXPECT_EQ(3, model_.item_count());
1753 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 1746 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
1754 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[2].status); 1747 EXPECT_EQ(ash::STATUS_RUNNING, model_.items()[2].status);
1755 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1748 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1756 EXPECT_NE(nullptr, 1749 EXPECT_NE(nullptr,
1757 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1750 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1758 1751
1759 // Reporting that the app is closed should just update the existing item. 1752 // Reporting that the app is closed should just update the existing item.
1760 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED); 1753 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED);
1761 EXPECT_EQ(3, model_->item_count()); 1754 EXPECT_EQ(3, model_.item_count());
1762 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 1755 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
1763 EXPECT_EQ(ash::STATUS_CLOSED, model_->items()[2].status); 1756 EXPECT_EQ(ash::STATUS_CLOSED, model_.items()[2].status);
1764 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1757 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1765 EXPECT_NE(nullptr, 1758 EXPECT_NE(nullptr,
1766 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1759 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1767 1760
1768 // Unpinning the app should remove its shelf item. 1761 // Unpinning the app should remove its shelf item.
1769 launcher_controller_->UnpinAppWithID(extension1_->id()); 1762 launcher_controller_->UnpinAppWithID(extension1_->id());
1770 EXPECT_EQ(2, model_->item_count()); 1763 EXPECT_EQ(2, model_.item_count());
1771 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1764 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1772 EXPECT_EQ(nullptr, 1765 EXPECT_EQ(nullptr,
1773 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1766 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1774 } 1767 }
1775 1768
1776 // Test the V1 app interaction flow: run it, pin it, close it, unpin it. 1769 // Test the V1 app interaction flow: run it, pin it, close it, unpin it.
1777 TEST_F(ChromeLauncherControllerTest, V1AppRunPinCloseUnpin) { 1770 TEST_F(ChromeLauncherControllerTest, V1AppRunPinCloseUnpin) {
1778 InitLauncherController(); 1771 InitLauncherController();
1779 // 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.
1780 EXPECT_EQ(2, model_->item_count()); 1773 EXPECT_EQ(2, model_.item_count());
1781 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1774 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1782 EXPECT_EQ(nullptr, 1775 EXPECT_EQ(nullptr,
1783 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1776 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1784 1777
1785 // Reporting that the app is running should create a new shelf item. 1778 // Reporting that the app is running should create a new shelf item.
1786 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING); 1779 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING);
1787 EXPECT_EQ(3, model_->item_count()); 1780 EXPECT_EQ(3, model_.item_count());
1788 EXPECT_EQ(ash::TYPE_APP, model_->items()[2].type); 1781 EXPECT_EQ(ash::TYPE_APP, model_.items()[2].type);
1789 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[2].status); 1782 EXPECT_EQ(ash::STATUS_RUNNING, model_.items()[2].status);
1790 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1783 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1791 EXPECT_NE(nullptr, 1784 EXPECT_NE(nullptr,
1792 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1785 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1793 1786
1794 // Pinning the app should just update the existing item. 1787 // Pinning the app should just update the existing item.
1795 launcher_controller_->PinAppWithID(extension1_->id()); 1788 launcher_controller_->PinAppWithID(extension1_->id());
1796 EXPECT_EQ(3, model_->item_count()); 1789 EXPECT_EQ(3, model_.item_count());
1797 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 1790 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
1798 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[2].status); 1791 EXPECT_EQ(ash::STATUS_RUNNING, model_.items()[2].status);
1799 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1792 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1800 EXPECT_NE(nullptr, 1793 EXPECT_NE(nullptr,
1801 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1794 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1802 1795
1803 // 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.
1804 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED); 1797 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED);
1805 EXPECT_EQ(3, model_->item_count()); 1798 EXPECT_EQ(3, model_.item_count());
1806 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 1799 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
1807 EXPECT_EQ(ash::STATUS_CLOSED, model_->items()[2].status); 1800 EXPECT_EQ(ash::STATUS_CLOSED, model_.items()[2].status);
1808 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1801 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1809 EXPECT_NE(nullptr, 1802 EXPECT_NE(nullptr,
1810 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1803 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1811 1804
1812 // Unpinning the app should remove its shelf item. 1805 // Unpinning the app should remove its shelf item.
1813 launcher_controller_->UnpinAppWithID(extension1_->id()); 1806 launcher_controller_->UnpinAppWithID(extension1_->id());
1814 EXPECT_EQ(2, model_->item_count()); 1807 EXPECT_EQ(2, model_.item_count());
1815 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1808 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1816 EXPECT_EQ(nullptr, 1809 EXPECT_EQ(nullptr,
1817 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1810 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1818 } 1811 }
1819 1812
1820 // Test the V1 app interaction flow: pin it, run it, unpin it, close it. 1813 // Test the V1 app interaction flow: pin it, run it, unpin it, close it.
1821 TEST_F(ChromeLauncherControllerTest, V1AppPinRunUnpinClose) { 1814 TEST_F(ChromeLauncherControllerTest, V1AppPinRunUnpinClose) {
1822 InitLauncherController(); 1815 InitLauncherController();
1823 // 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.
1824 EXPECT_EQ(2, model_->item_count()); 1817 EXPECT_EQ(2, model_.item_count());
1825 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1818 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1826 EXPECT_EQ(nullptr, 1819 EXPECT_EQ(nullptr,
1827 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1820 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1828 1821
1829 // Pinning the app should create a new shelf item. 1822 // Pinning the app should create a new shelf item.
1830 launcher_controller_->PinAppWithID(extension1_->id()); 1823 launcher_controller_->PinAppWithID(extension1_->id());
1831 EXPECT_EQ(3, model_->item_count()); 1824 EXPECT_EQ(3, model_.item_count());
1832 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 1825 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
1833 EXPECT_EQ(ash::STATUS_CLOSED, model_->items()[2].status); 1826 EXPECT_EQ(ash::STATUS_CLOSED, model_.items()[2].status);
1834 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1827 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1835 EXPECT_NE(nullptr, 1828 EXPECT_NE(nullptr,
1836 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1829 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1837 1830
1838 // Reporting that the app is running should just update the existing item. 1831 // Reporting that the app is running should just update the existing item.
1839 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING); 1832 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING);
1840 EXPECT_EQ(3, model_->item_count()); 1833 EXPECT_EQ(3, model_.item_count());
1841 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 1834 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
1842 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[2].status); 1835 EXPECT_EQ(ash::STATUS_RUNNING, model_.items()[2].status);
1843 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 1836 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
1844 EXPECT_NE(nullptr, 1837 EXPECT_NE(nullptr,
1845 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1838 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1846 1839
1847 // Unpinning the app should just update the existing item. 1840 // Unpinning the app should just update the existing item.
1848 launcher_controller_->UnpinAppWithID(extension1_->id()); 1841 launcher_controller_->UnpinAppWithID(extension1_->id());
1849 EXPECT_EQ(3, model_->item_count()); 1842 EXPECT_EQ(3, model_.item_count());
1850 EXPECT_EQ(ash::TYPE_APP, model_->items()[2].type); 1843 EXPECT_EQ(ash::TYPE_APP, model_.items()[2].type);
1851 EXPECT_EQ(ash::STATUS_RUNNING, model_->items()[2].status); 1844 EXPECT_EQ(ash::STATUS_RUNNING, model_.items()[2].status);
1852 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1845 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1853 EXPECT_NE(nullptr, 1846 EXPECT_NE(nullptr,
1854 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1847 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1855 1848
1856 // Reporting that the app is closed should remove its shelf item. 1849 // Reporting that the app is closed should remove its shelf item.
1857 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED); 1850 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED);
1858 EXPECT_EQ(2, model_->item_count()); 1851 EXPECT_EQ(2, model_.item_count());
1859 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1852 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1860 EXPECT_EQ(nullptr, 1853 EXPECT_EQ(nullptr,
1861 launcher_controller_->GetItem(ash::ShelfID(extension1_->id()))); 1854 launcher_controller_->GetItem(ash::ShelfID(extension1_->id())));
1862 } 1855 }
1863 1856
1864 // Ensure unpinned V1 app ordering is properly restored after user changes. 1857 // Ensure unpinned V1 app ordering is properly restored after user changes.
1865 TEST_F(ChromeLauncherControllerTest, CheckRunningV1AppOrder) { 1858 TEST_F(ChromeLauncherControllerTest, CheckRunningV1AppOrder) {
1866 InitLauncherController(); 1859 InitLauncherController();
1867 // 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.
1868 EXPECT_EQ(2, model_->item_count()); 1861 EXPECT_EQ(2, model_.item_count());
1869 1862
1870 // Add a few running applications. 1863 // Add a few running applications.
1871 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING); 1864 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_RUNNING);
1872 launcher_controller_->SetV1AppStatus(extension2_->id(), ash::STATUS_RUNNING); 1865 launcher_controller_->SetV1AppStatus(extension2_->id(), ash::STATUS_RUNNING);
1873 launcher_controller_->SetV1AppStatus(extension3_->id(), ash::STATUS_RUNNING); 1866 launcher_controller_->SetV1AppStatus(extension3_->id(), ash::STATUS_RUNNING);
1874 EXPECT_EQ(5, model_->item_count()); 1867 EXPECT_EQ(5, model_.item_count());
1875 // Note that this not only checks the order of applications but also the 1868 // Note that this not only checks the order of applications but also the
1876 // running type. 1869 // running type.
1877 EXPECT_EQ("AppList, Chrome, app1, app2, app3", GetPinnedAppStatus()); 1870 EXPECT_EQ("AppList, Chrome, app1, app2, app3", GetPinnedAppStatus());
1878 1871
1879 // Remember the current order of applications for the current user. 1872 // Remember the current order of applications for the current user.
1880 const AccountId& current_account_id = 1873 const AccountId& current_account_id =
1881 multi_user_util::GetAccountIdFromProfile(profile()); 1874 multi_user_util::GetAccountIdFromProfile(profile());
1882 RememberUnpinnedRunningApplicationOrder(); 1875 RememberUnpinnedRunningApplicationOrder();
1883 1876
1884 // Switch some items and check that restoring a user which was not yet 1877 // Switch some items and check that restoring a user which was not yet
1885 // remembered changes nothing. 1878 // remembered changes nothing.
1886 model_->Move(2, 3); 1879 model_.Move(2, 3);
1887 EXPECT_EQ("AppList, Chrome, app2, app1, app3", GetPinnedAppStatus()); 1880 EXPECT_EQ("AppList, Chrome, app2, app1, app3", GetPinnedAppStatus());
1888 const AccountId second_fake_account_id( 1881 const AccountId second_fake_account_id(
1889 AccountId::FromUserEmail("second-fake-user@fake.com")); 1882 AccountId::FromUserEmail("second-fake-user@fake.com"));
1890 RestoreUnpinnedRunningApplicationOrder(second_fake_account_id); 1883 RestoreUnpinnedRunningApplicationOrder(second_fake_account_id);
1891 EXPECT_EQ("AppList, Chrome, app2, app1, app3", GetPinnedAppStatus()); 1884 EXPECT_EQ("AppList, Chrome, app2, app1, app3", GetPinnedAppStatus());
1892 1885
1893 // Restoring the stored user should however do the right thing. 1886 // Restoring the stored user should however do the right thing.
1894 RestoreUnpinnedRunningApplicationOrder(current_account_id); 1887 RestoreUnpinnedRunningApplicationOrder(current_account_id);
1895 EXPECT_EQ("AppList, Chrome, app1, app2, app3", GetPinnedAppStatus()); 1888 EXPECT_EQ("AppList, Chrome, app1, app2, app3", GetPinnedAppStatus());
1896 1889
1897 // Switch again some items and even delete one - making sure that the missing 1890 // Switch again some items and even delete one - making sure that the missing
1898 // item gets properly handled. 1891 // item gets properly handled.
1899 model_->Move(3, 4); 1892 model_.Move(3, 4);
1900 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED); 1893 launcher_controller_->SetV1AppStatus(extension1_->id(), ash::STATUS_CLOSED);
1901 EXPECT_EQ("AppList, Chrome, app3, app2", GetPinnedAppStatus()); 1894 EXPECT_EQ("AppList, Chrome, app3, app2", GetPinnedAppStatus());
1902 RestoreUnpinnedRunningApplicationOrder(current_account_id); 1895 RestoreUnpinnedRunningApplicationOrder(current_account_id);
1903 EXPECT_EQ("AppList, Chrome, app2, app3", GetPinnedAppStatus()); 1896 EXPECT_EQ("AppList, Chrome, app2, app3", GetPinnedAppStatus());
1904 1897
1905 // Check that removing more items does not crash and changes nothing. 1898 // Check that removing more items does not crash and changes nothing.
1906 launcher_controller_->SetV1AppStatus(extension2_->id(), ash::STATUS_CLOSED); 1899 launcher_controller_->SetV1AppStatus(extension2_->id(), ash::STATUS_CLOSED);
1907 RestoreUnpinnedRunningApplicationOrder(current_account_id); 1900 RestoreUnpinnedRunningApplicationOrder(current_account_id);
1908 EXPECT_EQ("AppList, Chrome, app3", GetPinnedAppStatus()); 1901 EXPECT_EQ("AppList, Chrome, app3", GetPinnedAppStatus());
1909 launcher_controller_->SetV1AppStatus(extension3_->id(), ash::STATUS_CLOSED); 1902 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); 1937 arc::LaunchApp(profile(), arc_shortcut_id, ui::EF_LEFT_MOUSE_BUTTON);
1945 1938
1946 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_1)); 1939 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_1));
1947 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_2)); 1940 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_2));
1948 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_3)); 1941 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_3));
1949 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_shortcut)); 1942 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_shortcut));
1950 1943
1951 // We activated arc_app_id1 twice but expect one close for item controller 1944 // We activated arc_app_id1 twice but expect one close for item controller
1952 // stops launching request. 1945 // stops launching request.
1953 ash::ShelfItemDelegate* item_delegate = 1946 ash::ShelfItemDelegate* item_delegate =
1954 model_->GetShelfItemDelegate(shelf_id_app_1); 1947 model_.GetShelfItemDelegate(shelf_id_app_1);
1955 ASSERT_NE(nullptr, item_delegate); 1948 ASSERT_NE(nullptr, item_delegate);
1956 item_delegate->Close(); 1949 item_delegate->Close();
1957 base::RunLoop().RunUntilIdle(); 1950 base::RunLoop().RunUntilIdle();
1958 1951
1959 EXPECT_FALSE(launcher_controller_->GetItem(shelf_id_app_1)); 1952 EXPECT_FALSE(launcher_controller_->GetItem(shelf_id_app_1));
1960 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_2)); 1953 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_2));
1961 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_3)); 1954 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_app_3));
1962 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_shortcut)); 1955 EXPECT_TRUE(launcher_controller_->GetItem(shelf_id_shortcut));
1963 1956
1964 arc_test_.RestartArcInstance(); 1957 arc_test_.RestartArcInstance();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2000 launcher_controller_->PinAppWithID(app_id); 1993 launcher_controller_->PinAppWithID(app_id);
2001 EXPECT_TRUE(launcher_controller_->IsAppPinned(app_id)); 1994 EXPECT_TRUE(launcher_controller_->IsAppPinned(app_id));
2002 const ash::ShelfID shelf_id(app_id); 1995 const ash::ShelfID shelf_id(app_id);
2003 const ash::ShelfItem* item = launcher_controller_->GetItem(shelf_id); 1996 const ash::ShelfItem* item = launcher_controller_->GetItem(shelf_id);
2004 ASSERT_NE(nullptr, item); 1997 ASSERT_NE(nullptr, item);
2005 EXPECT_EQ(ash::STATUS_CLOSED, item->status); 1998 EXPECT_EQ(ash::STATUS_CLOSED, item->status);
2006 EXPECT_EQ(ash::TYPE_PINNED_APP, item->type); 1999 EXPECT_EQ(ash::TYPE_PINNED_APP, item->type);
2007 2000
2008 // Play Store app is ARC app that might be represented by native Chrome 2001 // Play Store app is ARC app that might be represented by native Chrome
2009 // platform app. 2002 // platform app.
2010 model_->SetShelfItemDelegate( 2003 model_.SetShelfItemDelegate(
2011 shelf_id, 2004 shelf_id,
2012 base::MakeUnique<ExtensionAppWindowLauncherItemController>(shelf_id)); 2005 base::MakeUnique<ExtensionAppWindowLauncherItemController>(shelf_id));
2013 launcher_controller_->SetItemStatus(shelf_id, ash::STATUS_RUNNING); 2006 launcher_controller_->SetItemStatus(shelf_id, ash::STATUS_RUNNING);
2014 2007
2015 // This launch request should be ignored in case of active app. 2008 // This launch request should be ignored in case of active app.
2016 arc::LaunchApp(profile(), app_id, ui::EF_LEFT_MOUSE_BUTTON); 2009 arc::LaunchApp(profile(), app_id, ui::EF_LEFT_MOUSE_BUTTON);
2017 EXPECT_FALSE(launcher_controller_->GetArcDeferredLauncher()->HasApp(app_id)); 2010 EXPECT_FALSE(launcher_controller_->GetArcDeferredLauncher()->HasApp(app_id));
2018 2011
2019 // Closing the app should leave a pinned but closed shelf item shortcut. 2012 // Closing the app should leave a pinned but closed shelf item shortcut.
2020 launcher_controller_->CloseLauncherItem(shelf_id); 2013 launcher_controller_->CloseLauncherItem(shelf_id);
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
2317 ASSERT_TRUE(window1 && window1->GetNativeWindow()); 2310 ASSERT_TRUE(window1 && window1->GetNativeWindow());
2318 arc_test_.app_instance()->SendTaskCreated(1, arc_test_.fake_apps()[0], 2311 arc_test_.app_instance()->SendTaskCreated(1, arc_test_.fake_apps()[0],
2319 std::string()); 2312 std::string());
2320 2313
2321 views::Widget* window2 = CreateArcWindow(window_app_id2); 2314 views::Widget* window2 = CreateArcWindow(window_app_id2);
2322 ASSERT_TRUE(window2 && window2->GetNativeWindow()); 2315 ASSERT_TRUE(window2 && window2->GetNativeWindow());
2323 arc_test_.app_instance()->SendTaskCreated(2, arc_test_.fake_apps()[0], 2316 arc_test_.app_instance()->SendTaskCreated(2, arc_test_.fake_apps()[0],
2324 std::string()); 2317 std::string());
2325 EXPECT_TRUE(launcher_controller_->GetItem(ash::ShelfID(arc_app_id))); 2318 EXPECT_TRUE(launcher_controller_->GetItem(ash::ShelfID(arc_app_id)));
2326 ash::ShelfItemDelegate* item_delegate = 2319 ash::ShelfItemDelegate* item_delegate =
2327 model_->GetShelfItemDelegate(ash::ShelfID(arc_app_id)); 2320 model_.GetShelfItemDelegate(ash::ShelfID(arc_app_id));
2328 ASSERT_TRUE(item_delegate); 2321 ASSERT_TRUE(item_delegate);
2329 2322
2330 // No custom icon set. Acitivating windows should not change icon. 2323 // No custom icon set. Acitivating windows should not change icon.
2331 EXPECT_FALSE(item_delegate->image_set_by_controller()); 2324 EXPECT_FALSE(item_delegate->image_set_by_controller());
2332 window1->Activate(); 2325 window1->Activate();
2333 EXPECT_FALSE(item_delegate->image_set_by_controller()); 2326 EXPECT_FALSE(item_delegate->image_set_by_controller());
2334 window2->Activate(); 2327 window2->Activate();
2335 EXPECT_FALSE(item_delegate->image_set_by_controller()); 2328 EXPECT_FALSE(item_delegate->image_set_by_controller());
2336 2329
2337 // Set custom icon on active item. Icon should change to custom. 2330 // 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()); 2351 EXPECT_FALSE(item_delegate->image_set_by_controller());
2359 } 2352 }
2360 2353
2361 // Check that with multi profile V1 apps are properly added / removed from the 2354 // Check that with multi profile V1 apps are properly added / removed from the
2362 // shelf. 2355 // shelf.
2363 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2356 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
2364 V1AppUpdateOnUserSwitch) { 2357 V1AppUpdateOnUserSwitch) {
2365 // Create a browser item in the LauncherController. 2358 // Create a browser item in the LauncherController.
2366 InitLauncherController(); 2359 InitLauncherController();
2367 2360
2368 EXPECT_EQ(2, model_->item_count()); 2361 EXPECT_EQ(2, model_.item_count());
2369 { 2362 {
2370 // Create a "windowed gmail app". 2363 // Create a "windowed gmail app".
2371 std::unique_ptr<V1App> v1_app( 2364 std::unique_ptr<V1App> v1_app(
2372 CreateRunningV1App(profile(), extension_misc::kGmailAppId, kGmailUrl)); 2365 CreateRunningV1App(profile(), extension_misc::kGmailAppId, kGmailUrl));
2373 EXPECT_EQ(3, model_->item_count()); 2366 EXPECT_EQ(3, model_.item_count());
2374 2367
2375 // After switching to a second user the item should be gone. 2368 // After switching to a second user the item should be gone.
2376 std::string user2 = "user2"; 2369 std::string user2 = "user2";
2377 TestingProfile* profile2 = CreateMultiUserProfile(user2); 2370 TestingProfile* profile2 = CreateMultiUserProfile(user2);
2378 const AccountId account_id2( 2371 const AccountId account_id2(
2379 multi_user_util::GetAccountIdFromProfile(profile2)); 2372 multi_user_util::GetAccountIdFromProfile(profile2));
2380 const AccountId account_id( 2373 const AccountId account_id(
2381 multi_user_util::GetAccountIdFromProfile(profile())); 2374 multi_user_util::GetAccountIdFromProfile(profile()));
2382 SwitchActiveUser(account_id2); 2375 SwitchActiveUser(account_id2);
2383 EXPECT_EQ(2, model_->item_count()); 2376 EXPECT_EQ(2, model_.item_count());
2384 2377
2385 // After switching back the item should be back. 2378 // After switching back the item should be back.
2386 SwitchActiveUser(account_id); 2379 SwitchActiveUser(account_id);
2387 EXPECT_EQ(3, model_->item_count()); 2380 EXPECT_EQ(3, model_.item_count());
2388 // Note we destroy now the gmail app with the closure end. 2381 // Note we destroy now the gmail app with the closure end.
2389 } 2382 }
2390 EXPECT_EQ(2, model_->item_count()); 2383 EXPECT_EQ(2, model_.item_count());
2391 } 2384 }
2392 2385
2393 // Check edge cases with multi profile V1 apps in the shelf. 2386 // Check edge cases with multi profile V1 apps in the shelf.
2394 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2387 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
2395 V1AppUpdateOnUserSwitchEdgecases) { 2388 V1AppUpdateOnUserSwitchEdgecases) {
2396 // Create a browser item in the LauncherController. 2389 // Create a browser item in the LauncherController.
2397 InitLauncherController(); 2390 InitLauncherController();
2398 2391
2399 // First test: Create an app when the user is not active. 2392 // First test: Create an app when the user is not active.
2400 std::string user2 = "user2"; 2393 std::string user2 = "user2";
2401 TestingProfile* profile2 = CreateMultiUserProfile(user2); 2394 TestingProfile* profile2 = CreateMultiUserProfile(user2);
2402 const AccountId account_id2( 2395 const AccountId account_id2(
2403 multi_user_util::GetAccountIdFromProfile(profile2)); 2396 multi_user_util::GetAccountIdFromProfile(profile2));
2404 const AccountId account_id( 2397 const AccountId account_id(
2405 multi_user_util::GetAccountIdFromProfile(profile())); 2398 multi_user_util::GetAccountIdFromProfile(profile()));
2406 { 2399 {
2407 // Create a "windowed gmail app". 2400 // Create a "windowed gmail app".
2408 std::unique_ptr<V1App> v1_app( 2401 std::unique_ptr<V1App> v1_app(
2409 CreateRunningV1App(profile2, extension_misc::kGmailAppId, kGmailUrl)); 2402 CreateRunningV1App(profile2, extension_misc::kGmailAppId, kGmailUrl));
2410 EXPECT_EQ(2, model_->item_count()); 2403 EXPECT_EQ(2, model_.item_count());
2411 2404
2412 // However - switching to the user should show it. 2405 // However - switching to the user should show it.
2413 SwitchActiveUser(account_id2); 2406 SwitchActiveUser(account_id2);
2414 EXPECT_EQ(3, model_->item_count()); 2407 EXPECT_EQ(3, model_.item_count());
2415 2408
2416 // Second test: Remove the app when the user is not active and see that it 2409 // Second test: Remove the app when the user is not active and see that it
2417 // works. 2410 // works.
2418 SwitchActiveUser(account_id); 2411 SwitchActiveUser(account_id);
2419 EXPECT_EQ(2, model_->item_count()); 2412 EXPECT_EQ(2, model_.item_count());
2420 // Note: the closure ends and the browser will go away. 2413 // Note: the closure ends and the browser will go away.
2421 } 2414 }
2422 EXPECT_EQ(2, model_->item_count()); 2415 EXPECT_EQ(2, model_.item_count());
2423 SwitchActiveUser(account_id2); 2416 SwitchActiveUser(account_id2);
2424 EXPECT_EQ(2, model_->item_count()); 2417 EXPECT_EQ(2, model_.item_count());
2425 SwitchActiveUser(account_id); 2418 SwitchActiveUser(account_id);
2426 EXPECT_EQ(2, model_->item_count()); 2419 EXPECT_EQ(2, model_.item_count());
2427 } 2420 }
2428 2421
2429 // Check edge case where a visiting V1 app gets closed (crbug.com/321374). 2422 // Check edge case where a visiting V1 app gets closed (crbug.com/321374).
2430 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2423 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
2431 V1CloseOnVisitingDesktop) { 2424 V1CloseOnVisitingDesktop) {
2432 // Create a browser item in the LauncherController. 2425 // Create a browser item in the LauncherController.
2433 InitLauncherController(); 2426 InitLauncherController();
2434 2427
2435 chrome::MultiUserWindowManager* manager = 2428 chrome::MultiUserWindowManager* manager =
2436 chrome::MultiUserWindowManager::GetInstance(); 2429 chrome::MultiUserWindowManager::GetInstance();
2437 2430
2438 // First create an app when the user is active. 2431 // First create an app when the user is active.
2439 std::string user2 = "user2"; 2432 std::string user2 = "user2";
2440 TestingProfile* profile2 = CreateMultiUserProfile(user2); 2433 TestingProfile* profile2 = CreateMultiUserProfile(user2);
2441 const AccountId account_id( 2434 const AccountId account_id(
2442 multi_user_util::GetAccountIdFromProfile(profile())); 2435 multi_user_util::GetAccountIdFromProfile(profile()));
2443 const AccountId account_id2( 2436 const AccountId account_id2(
2444 multi_user_util::GetAccountIdFromProfile(profile2)); 2437 multi_user_util::GetAccountIdFromProfile(profile2));
2445 { 2438 {
2446 // Create a "windowed gmail app". 2439 // Create a "windowed gmail app".
2447 std::unique_ptr<V1App> v1_app(CreateRunningV1App( 2440 std::unique_ptr<V1App> v1_app(CreateRunningV1App(
2448 profile(), extension_misc::kGmailAppId, kGmailLaunchURL)); 2441 profile(), extension_misc::kGmailAppId, kGmailLaunchURL));
2449 EXPECT_EQ(3, model_->item_count()); 2442 EXPECT_EQ(3, model_.item_count());
2450 2443
2451 // Transfer the app to the other screen and switch users. 2444 // Transfer the app to the other screen and switch users.
2452 manager->ShowWindowForUser(v1_app->browser()->window()->GetNativeWindow(), 2445 manager->ShowWindowForUser(v1_app->browser()->window()->GetNativeWindow(),
2453 account_id2); 2446 account_id2);
2454 EXPECT_EQ(3, model_->item_count()); 2447 EXPECT_EQ(3, model_.item_count());
2455 SwitchActiveUser(account_id2); 2448 SwitchActiveUser(account_id2);
2456 EXPECT_EQ(2, model_->item_count()); 2449 EXPECT_EQ(2, model_.item_count());
2457 } 2450 }
2458 // After the app was destroyed, switch back. (which caused already a crash). 2451 // After the app was destroyed, switch back. (which caused already a crash).
2459 SwitchActiveUser(account_id); 2452 SwitchActiveUser(account_id);
2460 2453
2461 // Create the same app again - which was also causing the crash. 2454 // Create the same app again - which was also causing the crash.
2462 EXPECT_EQ(2, model_->item_count()); 2455 EXPECT_EQ(2, model_.item_count());
2463 { 2456 {
2464 // Create a "windowed gmail app". 2457 // Create a "windowed gmail app".
2465 std::unique_ptr<V1App> v1_app(CreateRunningV1App( 2458 std::unique_ptr<V1App> v1_app(CreateRunningV1App(
2466 profile(), extension_misc::kGmailAppId, kGmailLaunchURL)); 2459 profile(), extension_misc::kGmailAppId, kGmailLaunchURL));
2467 EXPECT_EQ(3, model_->item_count()); 2460 EXPECT_EQ(3, model_.item_count());
2468 } 2461 }
2469 SwitchActiveUser(account_id2); 2462 SwitchActiveUser(account_id2);
2470 EXPECT_EQ(2, model_->item_count()); 2463 EXPECT_EQ(2, model_.item_count());
2471 } 2464 }
2472 2465
2473 // Check edge cases with multi profile V1 apps in the shelf. 2466 // Check edge cases with multi profile V1 apps in the shelf.
2474 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2467 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
2475 V1AppUpdateOnUserSwitchEdgecases2) { 2468 V1AppUpdateOnUserSwitchEdgecases2) {
2476 // Create a browser item in the LauncherController. 2469 // Create a browser item in the LauncherController.
2477 InitLauncherController(); 2470 InitLauncherController();
2478 2471
2479 // First test: Create an app when the user is not active. 2472 // First test: Create an app when the user is not active.
2480 std::string user2 = "user2"; 2473 std::string user2 = "user2";
2481 TestingProfile* profile2 = CreateMultiUserProfile(user2); 2474 TestingProfile* profile2 = CreateMultiUserProfile(user2);
2482 const AccountId account_id( 2475 const AccountId account_id(
2483 multi_user_util::GetAccountIdFromProfile(profile())); 2476 multi_user_util::GetAccountIdFromProfile(profile()));
2484 const AccountId account_id2( 2477 const AccountId account_id2(
2485 multi_user_util::GetAccountIdFromProfile(profile2)); 2478 multi_user_util::GetAccountIdFromProfile(profile2));
2486 SwitchActiveUser(account_id2); 2479 SwitchActiveUser(account_id2);
2487 { 2480 {
2488 // Create a "windowed gmail app". 2481 // Create a "windowed gmail app".
2489 std::unique_ptr<V1App> v1_app( 2482 std::unique_ptr<V1App> v1_app(
2490 CreateRunningV1App(profile(), extension_misc::kGmailAppId, kGmailUrl)); 2483 CreateRunningV1App(profile(), extension_misc::kGmailAppId, kGmailUrl));
2491 EXPECT_EQ(2, model_->item_count()); 2484 EXPECT_EQ(2, model_.item_count());
2492 2485
2493 // However - switching to the user should show it. 2486 // However - switching to the user should show it.
2494 SwitchActiveUser(account_id); 2487 SwitchActiveUser(account_id);
2495 EXPECT_EQ(3, model_->item_count()); 2488 EXPECT_EQ(3, model_.item_count());
2496 2489
2497 // Second test: Remove the app when the user is not active and see that it 2490 // Second test: Remove the app when the user is not active and see that it
2498 // works. 2491 // works.
2499 SwitchActiveUser(account_id2); 2492 SwitchActiveUser(account_id2);
2500 EXPECT_EQ(2, model_->item_count()); 2493 EXPECT_EQ(2, model_.item_count());
2501 v1_app.reset(); 2494 v1_app.reset();
2502 } 2495 }
2503 EXPECT_EQ(2, model_->item_count()); 2496 EXPECT_EQ(2, model_.item_count());
2504 SwitchActiveUser(account_id); 2497 SwitchActiveUser(account_id);
2505 EXPECT_EQ(2, model_->item_count()); 2498 EXPECT_EQ(2, model_.item_count());
2506 SwitchActiveUser(account_id2); 2499 SwitchActiveUser(account_id2);
2507 EXPECT_EQ(2, model_->item_count()); 2500 EXPECT_EQ(2, model_.item_count());
2508 } 2501 }
2509 2502
2510 // Check that activating an item which is on another user's desktop, will bring 2503 // Check that activating an item which is on another user's desktop, will bring
2511 // it back. 2504 // it back.
2512 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2505 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
2513 TestLauncherActivationPullsBackWindow) { 2506 TestLauncherActivationPullsBackWindow) {
2514 // Create a browser item in the LauncherController. 2507 // Create a browser item in the LauncherController.
2515 InitLauncherController(); 2508 InitLauncherController();
2516 chrome::MultiUserWindowManager* manager = 2509 chrome::MultiUserWindowManager* manager =
2517 chrome::MultiUserWindowManager::GetInstance(); 2510 chrome::MultiUserWindowManager::GetInstance();
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
2740 2733
2741 base::ListValue policy_value; 2734 base::ListValue policy_value;
2742 InsertPrefValue(&policy_value, 0, extension1_->id()); 2735 InsertPrefValue(&policy_value, 0, extension1_->id());
2743 InsertPrefValue(&policy_value, 1, extension2_->id()); 2736 InsertPrefValue(&policy_value, 1, extension2_->id());
2744 profile()->GetTestingPrefService()->SetManagedPref( 2737 profile()->GetTestingPrefService()->SetManagedPref(
2745 prefs::kPolicyPinnedLauncherApps, policy_value.CreateDeepCopy()); 2738 prefs::kPolicyPinnedLauncherApps, policy_value.CreateDeepCopy());
2746 2739
2747 // Only |extension1_| should get pinned. |extension2_| is specified but not 2740 // Only |extension1_| should get pinned. |extension2_| is specified but not
2748 // installed, and |extension3_| is part of the default set, but that shouldn't 2741 // installed, and |extension3_| is part of the default set, but that shouldn't
2749 // take effect when the policy override is in place. 2742 // take effect when the policy override is in place.
2750 ASSERT_EQ(3, model_->item_count()); 2743 ASSERT_EQ(3, model_.item_count());
2751 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[1].type); 2744 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[1].type);
2752 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 2745 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
2753 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 2746 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
2754 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2747 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2755 2748
2756 // Installing |extension2_| should add it to the launcher. 2749 // Installing |extension2_| should add it to the launcher.
2757 extension_service_->AddExtension(extension2_.get()); 2750 extension_service_->AddExtension(extension2_.get());
2758 ASSERT_EQ(4, model_->item_count()); 2751 ASSERT_EQ(4, model_.item_count());
2759 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[1].type); 2752 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[1].type);
2760 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 2753 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
2761 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 2754 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
2762 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 2755 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
2763 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2756 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2764 2757
2765 // Removing |extension1_| from the policy should not be reflected in the 2758 // Removing |extension1_| from the policy should not be reflected in the
2766 // launcher and pin will exist. 2759 // launcher and pin will exist.
2767 policy_value.Remove(0, NULL); 2760 policy_value.Remove(0, NULL);
2768 profile()->GetTestingPrefService()->SetManagedPref( 2761 profile()->GetTestingPrefService()->SetManagedPref(
2769 prefs::kPolicyPinnedLauncherApps, policy_value.CreateDeepCopy()); 2762 prefs::kPolicyPinnedLauncherApps, policy_value.CreateDeepCopy());
2770 EXPECT_EQ(4, model_->item_count()); 2763 EXPECT_EQ(4, model_.item_count());
2771 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 2764 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
2772 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 2765 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
2773 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 2766 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
2774 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2767 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2775 } 2768 }
2776 2769
2777 TEST_F(ChromeLauncherControllerTest, UnpinWithUninstall) { 2770 TEST_F(ChromeLauncherControllerTest, UnpinWithUninstall) {
2778 extension_service_->AddExtension(extension3_.get()); 2771 extension_service_->AddExtension(extension3_.get());
2779 extension_service_->AddExtension(extension4_.get()); 2772 extension_service_->AddExtension(extension4_.get());
2780 2773
2781 InitLauncherController(); 2774 InitLauncherController();
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
3032 // refocus logic. 3025 // refocus logic.
3033 // Note that the extension matching logic is tested by the extension system 3026 // Note that the extension matching logic is tested by the extension system
3034 // and does not need a separate test here. 3027 // and does not need a separate test here.
3035 TEST_F(ChromeLauncherControllerTest, V1AppMenuGeneration) { 3028 TEST_F(ChromeLauncherControllerTest, V1AppMenuGeneration) {
3036 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); 3029 EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
3037 EXPECT_EQ(0, browser()->tab_strip_model()->count()); 3030 EXPECT_EQ(0, browser()->tab_strip_model()->count());
3038 3031
3039 InitLauncherControllerWithBrowser(); 3032 InitLauncherControllerWithBrowser();
3040 3033
3041 // The model should only contain the browser shortcut and app list items. 3034 // The model should only contain the browser shortcut and app list items.
3042 EXPECT_EQ(2, model_->item_count()); 3035 EXPECT_EQ(2, model_.item_count());
3043 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 3036 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
3044 3037
3045 // Installing |extension3_| pins it to the launcher. 3038 // Installing |extension3_| pins it to the launcher.
3046 const ash::ShelfID gmail_id(extension3_->id()); 3039 const ash::ShelfID gmail_id(extension3_->id());
3047 extension_service_->AddExtension(extension3_.get()); 3040 extension_service_->AddExtension(extension3_.get());
3048 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 3041 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
3049 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(kGmailUrl)); 3042 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(kGmailUrl));
3050 3043
3051 // Check the menu content. 3044 // Check the menu content.
3052 ash::ShelfItem item_browser; 3045 ash::ShelfItem item_browser;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
3145 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 3138 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
3146 V2AppHandlingTwoUsers) { 3139 V2AppHandlingTwoUsers) {
3147 InitLauncherController(); 3140 InitLauncherController();
3148 // Create a profile for our second user (will be destroyed by the framework). 3141 // Create a profile for our second user (will be destroyed by the framework).
3149 TestingProfile* profile2 = CreateMultiUserProfile("user2"); 3142 TestingProfile* profile2 = CreateMultiUserProfile("user2");
3150 const AccountId account_id( 3143 const AccountId account_id(
3151 multi_user_util::GetAccountIdFromProfile(profile())); 3144 multi_user_util::GetAccountIdFromProfile(profile()));
3152 const AccountId account_id2( 3145 const AccountId account_id2(
3153 multi_user_util::GetAccountIdFromProfile(profile2)); 3146 multi_user_util::GetAccountIdFromProfile(profile2));
3154 // Check that there is a browser and a app launcher. 3147 // Check that there is a browser and a app launcher.
3155 EXPECT_EQ(2, model_->item_count()); 3148 EXPECT_EQ(2, model_.item_count());
3156 3149
3157 // Add a v2 app. 3150 // Add a v2 app.
3158 V2App v2_app(profile(), extension1_.get()); 3151 V2App v2_app(profile(), extension1_.get());
3159 EXPECT_EQ(3, model_->item_count()); 3152 EXPECT_EQ(3, model_.item_count());
3160 3153
3161 // After switching users the item should go away. 3154 // After switching users the item should go away.
3162 SwitchActiveUser(account_id2); 3155 SwitchActiveUser(account_id2);
3163 EXPECT_EQ(2, model_->item_count()); 3156 EXPECT_EQ(2, model_.item_count());
3164 3157
3165 // And it should come back when switching back. 3158 // And it should come back when switching back.
3166 SwitchActiveUser(account_id); 3159 SwitchActiveUser(account_id);
3167 EXPECT_EQ(3, model_->item_count()); 3160 EXPECT_EQ(3, model_.item_count());
3168 } 3161 }
3169 3162
3170 // Check that V2 applications are creating items properly in edge cases: 3163 // 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 3164 // a background user creates a V2 app, gets active and inactive again and then
3172 // deletes the app. 3165 // deletes the app.
3173 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 3166 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
3174 V2AppHandlingTwoUsersEdgeCases) { 3167 V2AppHandlingTwoUsersEdgeCases) {
3175 InitLauncherController(); 3168 InitLauncherController();
3176 // Create a profile for our second user (will be destroyed by the framework). 3169 // Create a profile for our second user (will be destroyed by the framework).
3177 TestingProfile* profile2 = CreateMultiUserProfile("user2"); 3170 TestingProfile* profile2 = CreateMultiUserProfile("user2");
3178 const AccountId account_id( 3171 const AccountId account_id(
3179 multi_user_util::GetAccountIdFromProfile(profile())); 3172 multi_user_util::GetAccountIdFromProfile(profile()));
3180 const AccountId account_id2( 3173 const AccountId account_id2(
3181 multi_user_util::GetAccountIdFromProfile(profile2)); 3174 multi_user_util::GetAccountIdFromProfile(profile2));
3182 // Check that there is a browser and a app launcher. 3175 // Check that there is a browser and a app launcher.
3183 EXPECT_EQ(2, model_->item_count()); 3176 EXPECT_EQ(2, model_.item_count());
3184 3177
3185 // Switch to an inactive user. 3178 // Switch to an inactive user.
3186 SwitchActiveUser(account_id2); 3179 SwitchActiveUser(account_id2);
3187 EXPECT_EQ(2, model_->item_count()); 3180 EXPECT_EQ(2, model_.item_count());
3188 3181
3189 // Add the v2 app to the inactive user and check that no item was added to 3182 // Add the v2 app to the inactive user and check that no item was added to
3190 // the launcher. 3183 // the launcher.
3191 { 3184 {
3192 V2App v2_app(profile(), extension1_.get()); 3185 V2App v2_app(profile(), extension1_.get());
3193 EXPECT_EQ(2, model_->item_count()); 3186 EXPECT_EQ(2, model_.item_count());
3194 3187
3195 // Switch to the primary user and check that the item is shown. 3188 // Switch to the primary user and check that the item is shown.
3196 SwitchActiveUser(account_id); 3189 SwitchActiveUser(account_id);
3197 EXPECT_EQ(3, model_->item_count()); 3190 EXPECT_EQ(3, model_.item_count());
3198 3191
3199 // Switch to the second user and check that the item goes away - even if the 3192 // Switch to the second user and check that the item goes away - even if the
3200 // item gets closed. 3193 // item gets closed.
3201 SwitchActiveUser(account_id2); 3194 SwitchActiveUser(account_id2);
3202 EXPECT_EQ(2, model_->item_count()); 3195 EXPECT_EQ(2, model_.item_count());
3203 } 3196 }
3204 3197
3205 // After the application was killed there should be still 2 items. 3198 // After the application was killed there should be still 2 items.
3206 EXPECT_EQ(2, model_->item_count()); 3199 EXPECT_EQ(2, model_.item_count());
3207 3200
3208 // Switching then back to the default user should not show the additional item 3201 // Switching then back to the default user should not show the additional item
3209 // anymore. 3202 // anymore.
3210 SwitchActiveUser(account_id); 3203 SwitchActiveUser(account_id);
3211 EXPECT_EQ(2, model_->item_count()); 3204 EXPECT_EQ(2, model_.item_count());
3212 } 3205 }
3213 3206
3214 // Check that V2 applications will be made visible on the target desktop if 3207 // Check that V2 applications will be made visible on the target desktop if
3215 // another window of the same type got previously teleported there. 3208 // another window of the same type got previously teleported there.
3216 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 3209 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
3217 V2AppFollowsTeleportedWindow) { 3210 V2AppFollowsTeleportedWindow) {
3218 InitLauncherController(); 3211 InitLauncherController();
3219 chrome::MultiUserWindowManager* manager = 3212 chrome::MultiUserWindowManager* manager =
3220 chrome::MultiUserWindowManager::GetInstance(); 3213 chrome::MultiUserWindowManager::GetInstance();
3221 3214
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
3287 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 3280 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
3288 V2AppHiddenWindows) { 3281 V2AppHiddenWindows) {
3289 InitLauncherController(); 3282 InitLauncherController();
3290 3283
3291 TestingProfile* profile2 = CreateMultiUserProfile("user-2"); 3284 TestingProfile* profile2 = CreateMultiUserProfile("user-2");
3292 const AccountId account_id( 3285 const AccountId account_id(
3293 multi_user_util::GetAccountIdFromProfile(profile())); 3286 multi_user_util::GetAccountIdFromProfile(profile()));
3294 const AccountId account_id2( 3287 const AccountId account_id2(
3295 multi_user_util::GetAccountIdFromProfile(profile2)); 3288 multi_user_util::GetAccountIdFromProfile(profile2));
3296 SwitchActiveUser(account_id); 3289 SwitchActiveUser(account_id);
3297 EXPECT_EQ(2, model_->item_count()); 3290 EXPECT_EQ(2, model_.item_count());
3298 3291
3299 V2App v2_app_1(profile(), extension1_.get()); 3292 V2App v2_app_1(profile(), extension1_.get());
3300 EXPECT_EQ(3, model_->item_count()); 3293 EXPECT_EQ(3, model_.item_count());
3301 { 3294 {
3302 // Hide and show the app. 3295 // Hide and show the app.
3303 v2_app_1.window()->Hide(); 3296 v2_app_1.window()->Hide();
3304 EXPECT_EQ(2, model_->item_count()); 3297 EXPECT_EQ(2, model_.item_count());
3305 3298
3306 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE); 3299 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE);
3307 EXPECT_EQ(3, model_->item_count()); 3300 EXPECT_EQ(3, model_.item_count());
3308 } 3301 }
3309 { 3302 {
3310 // Switch user, hide and show the app and switch back. 3303 // Switch user, hide and show the app and switch back.
3311 SwitchActiveUser(account_id2); 3304 SwitchActiveUser(account_id2);
3312 EXPECT_EQ(2, model_->item_count()); 3305 EXPECT_EQ(2, model_.item_count());
3313 3306
3314 v2_app_1.window()->Hide(); 3307 v2_app_1.window()->Hide();
3315 EXPECT_EQ(2, model_->item_count()); 3308 EXPECT_EQ(2, model_.item_count());
3316 3309
3317 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE); 3310 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE);
3318 EXPECT_EQ(2, model_->item_count()); 3311 EXPECT_EQ(2, model_.item_count());
3319 3312
3320 SwitchActiveUser(account_id); 3313 SwitchActiveUser(account_id);
3321 EXPECT_EQ(3, model_->item_count()); 3314 EXPECT_EQ(3, model_.item_count());
3322 } 3315 }
3323 { 3316 {
3324 // Switch user, hide the app, switch back and then show it again. 3317 // Switch user, hide the app, switch back and then show it again.
3325 SwitchActiveUser(account_id2); 3318 SwitchActiveUser(account_id2);
3326 EXPECT_EQ(2, model_->item_count()); 3319 EXPECT_EQ(2, model_.item_count());
3327 3320
3328 v2_app_1.window()->Hide(); 3321 v2_app_1.window()->Hide();
3329 EXPECT_EQ(2, model_->item_count()); 3322 EXPECT_EQ(2, model_.item_count());
3330 3323
3331 SwitchActiveUser(account_id); 3324 SwitchActiveUser(account_id);
3332 // The following expectation does not work in current impl. It was working 3325 // The following expectation does not work in current impl. It was working
3333 // before because MultiUserWindowManagerChromeOS is not attached to user 3326 // before because MultiUserWindowManagerChromeOS is not attached to user
3334 // associated with profile() hence not actually handling windows for the 3327 // associated with profile() hence not actually handling windows for the
3335 // user. It is a real bug. See http://crbug.com/693634 3328 // user. It is a real bug. See http://crbug.com/693634
3336 // EXPECT_EQ(2, model_->item_count()); 3329 // EXPECT_EQ(2, model_.item_count());
3337 3330
3338 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE); 3331 v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE);
3339 EXPECT_EQ(3, model_->item_count()); 3332 EXPECT_EQ(3, model_.item_count());
3340 } 3333 }
3341 { 3334 {
3342 // Create a second app, hide and show it and then hide both apps. 3335 // Create a second app, hide and show it and then hide both apps.
3343 V2App v2_app_2(profile(), extension1_.get()); 3336 V2App v2_app_2(profile(), extension1_.get());
3344 EXPECT_EQ(3, model_->item_count()); 3337 EXPECT_EQ(3, model_.item_count());
3345 3338
3346 v2_app_2.window()->Hide(); 3339 v2_app_2.window()->Hide();
3347 EXPECT_EQ(3, model_->item_count()); 3340 EXPECT_EQ(3, model_.item_count());
3348 3341
3349 v2_app_2.window()->Show(extensions::AppWindow::SHOW_ACTIVE); 3342 v2_app_2.window()->Show(extensions::AppWindow::SHOW_ACTIVE);
3350 EXPECT_EQ(3, model_->item_count()); 3343 EXPECT_EQ(3, model_.item_count());
3351 3344
3352 v2_app_1.window()->Hide(); 3345 v2_app_1.window()->Hide();
3353 v2_app_2.window()->Hide(); 3346 v2_app_2.window()->Hide();
3354 EXPECT_EQ(2, model_->item_count()); 3347 EXPECT_EQ(2, model_.item_count());
3355 } 3348 }
3356 } 3349 }
3357 3350
3358 // Checks that the generated menu list properly activates items. 3351 // Checks that the generated menu list properly activates items.
3359 TEST_F(ChromeLauncherControllerTest, V1AppMenuExecution) { 3352 TEST_F(ChromeLauncherControllerTest, V1AppMenuExecution) {
3360 InitLauncherControllerWithBrowser(); 3353 InitLauncherControllerWithBrowser();
3361 3354
3362 // Add |extension3_| to the launcher and add two items. 3355 // Add |extension3_| to the launcher and add two items.
3363 GURL gmail = GURL("https://mail.google.com/mail/u"); 3356 GURL gmail = GURL("https://mail.google.com/mail/u");
3364 const ash::ShelfID gmail_id(extension3_->id()); 3357 const ash::ShelfID gmail_id(extension3_->id());
3365 extension_service_->AddExtension(extension3_.get()); 3358 extension_service_->AddExtension(extension3_.get());
3366 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(kGmailUrl)); 3359 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(kGmailUrl));
3367 base::string16 title1 = ASCIIToUTF16("Test1"); 3360 base::string16 title1 = ASCIIToUTF16("Test1");
3368 NavigateAndCommitActiveTabWithTitle(browser(), GURL(kGmailUrl), title1); 3361 NavigateAndCommitActiveTabWithTitle(browser(), GURL(kGmailUrl), title1);
3369 chrome::NewTab(browser()); 3362 chrome::NewTab(browser());
3370 base::string16 title2 = ASCIIToUTF16("Test2"); 3363 base::string16 title2 = ASCIIToUTF16("Test2");
3371 NavigateAndCommitActiveTabWithTitle(browser(), GURL(kGmailUrl), title2); 3364 NavigateAndCommitActiveTabWithTitle(browser(), GURL(kGmailUrl), title2);
3372 3365
3373 // Check that the menu is properly set. 3366 // Check that the menu is properly set.
3374 ash::ShelfItem item_gmail; 3367 ash::ShelfItem item_gmail;
3375 item_gmail.type = ash::TYPE_PINNED_APP; 3368 item_gmail.type = ash::TYPE_PINNED_APP;
3376 item_gmail.id = gmail_id; 3369 item_gmail.id = gmail_id;
3377 base::string16 two_menu_items[] = {title1, title2}; 3370 base::string16 two_menu_items[] = {title1, title2};
3378 CheckAppMenu(launcher_controller_, item_gmail, 2, two_menu_items); 3371 CheckAppMenu(launcher_controller_, item_gmail, 2, two_menu_items);
3379 ash::ShelfItemDelegate* item_delegate = 3372 ash::ShelfItemDelegate* item_delegate = model_.GetShelfItemDelegate(gmail_id);
3380 model_->GetShelfItemDelegate(gmail_id);
3381 ASSERT_TRUE(item_delegate); 3373 ASSERT_TRUE(item_delegate);
3382 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); 3374 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
3383 // Execute the second item in the menu, after the title and two separators, 3375 // 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. 3376 // this shouldn't do anything since that item is already the active tab.
3385 { 3377 {
3386 ash::ShelfApplicationMenuModel menu( 3378 ash::ShelfApplicationMenuModel menu(
3387 base::string16(), 3379 base::string16(),
3388 launcher_controller_->GetAppMenuItemsForTesting(item_gmail), 3380 launcher_controller_->GetAppMenuItemsForTesting(item_gmail),
3389 item_delegate); 3381 item_delegate);
3390 menu.ActivatedAt(4); 3382 menu.ActivatedAt(4);
(...skipping 27 matching lines...) Expand all
3418 base::string16 title2 = ASCIIToUTF16("Test2"); 3410 base::string16 title2 = ASCIIToUTF16("Test2");
3419 NavigateAndCommitActiveTabWithTitle(browser(), GURL(kGmailUrl), title2); 3411 NavigateAndCommitActiveTabWithTitle(browser(), GURL(kGmailUrl), title2);
3420 3412
3421 // Check that the menu is properly set. 3413 // Check that the menu is properly set.
3422 ash::ShelfItem item_gmail; 3414 ash::ShelfItem item_gmail;
3423 item_gmail.type = ash::TYPE_PINNED_APP; 3415 item_gmail.type = ash::TYPE_PINNED_APP;
3424 item_gmail.id = gmail_id; 3416 item_gmail.id = gmail_id;
3425 base::string16 two_menu_items[] = {title1, title2}; 3417 base::string16 two_menu_items[] = {title1, title2};
3426 CheckAppMenu(launcher_controller_, item_gmail, 2, two_menu_items); 3418 CheckAppMenu(launcher_controller_, item_gmail, 2, two_menu_items);
3427 3419
3428 ash::ShelfItemDelegate* item_delegate = 3420 ash::ShelfItemDelegate* item_delegate = model_.GetShelfItemDelegate(gmail_id);
3429 model_->GetShelfItemDelegate(gmail_id);
3430 ASSERT_TRUE(item_delegate); 3421 ASSERT_TRUE(item_delegate);
3431 int tabs = browser()->tab_strip_model()->count(); 3422 int tabs = browser()->tab_strip_model()->count();
3432 // Activate the proper tab through the menu item. 3423 // Activate the proper tab through the menu item.
3433 { 3424 {
3434 ash::MenuItemList items = 3425 ash::MenuItemList items =
3435 launcher_controller_->GetAppMenuItemsForTesting(item_gmail); 3426 launcher_controller_->GetAppMenuItemsForTesting(item_gmail);
3436 item_delegate->ExecuteCommand(items[1]->command_id, ui::EF_NONE); 3427 item_delegate->ExecuteCommand(items[1]->command_id, ui::EF_NONE);
3437 EXPECT_EQ(tabs, browser()->tab_strip_model()->count()); 3428 EXPECT_EQ(tabs, browser()->tab_strip_model()->count());
3438 } 3429 }
3439 3430
3440 // Delete one tab through the menu item. 3431 // Delete one tab through the menu item.
3441 { 3432 {
3442 ash::MenuItemList items = 3433 ash::MenuItemList items =
3443 launcher_controller_->GetAppMenuItemsForTesting(item_gmail); 3434 launcher_controller_->GetAppMenuItemsForTesting(item_gmail);
3444 item_delegate->ExecuteCommand(items[1]->command_id, ui::EF_SHIFT_DOWN); 3435 item_delegate->ExecuteCommand(items[1]->command_id, ui::EF_SHIFT_DOWN);
3445 EXPECT_EQ(--tabs, browser()->tab_strip_model()->count()); 3436 EXPECT_EQ(--tabs, browser()->tab_strip_model()->count());
3446 } 3437 }
3447 } 3438 }
3448 3439
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 3440 // Tests that the Gmail extension matches more than the app itself claims with
3492 // the manifest file. 3441 // the manifest file.
3493 TEST_F(ChromeLauncherControllerTest, GmailMatching) { 3442 TEST_F(ChromeLauncherControllerTest, GmailMatching) {
3494 InitLauncherControllerWithBrowser(); 3443 InitLauncherControllerWithBrowser();
3495 3444
3496 // Create a Gmail browser tab. 3445 // Create a Gmail browser tab.
3497 chrome::NewTab(browser()); 3446 chrome::NewTab(browser());
3498 base::string16 title = ASCIIToUTF16("Test"); 3447 base::string16 title = ASCIIToUTF16("Test");
3499 NavigateAndCommitActiveTabWithTitle(browser(), GURL(kGmailUrl), title); 3448 NavigateAndCommitActiveTabWithTitle(browser(), GURL(kGmailUrl), title);
3500 content::WebContents* content = 3449 content::WebContents* content =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3539 EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content)); 3488 EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content));
3540 } 3489 }
3541 3490
3542 // Verify that the launcher item positions are persisted and restored. 3491 // Verify that the launcher item positions are persisted and restored.
3543 TEST_F(ChromeLauncherControllerTest, PersistLauncherItemPositions) { 3492 TEST_F(ChromeLauncherControllerTest, PersistLauncherItemPositions) {
3544 InitLauncherController(); 3493 InitLauncherController();
3545 3494
3546 TestLauncherControllerHelper* helper = new TestLauncherControllerHelper; 3495 TestLauncherControllerHelper* helper = new TestLauncherControllerHelper;
3547 SetLauncherControllerHelper(helper); 3496 SetLauncherControllerHelper(helper);
3548 3497
3549 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); 3498 EXPECT_EQ(ash::TYPE_APP_LIST, model_.items()[0].type);
3550 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[1].type); 3499 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_.items()[1].type);
3551 3500
3552 TabStripModel* tab_strip_model = browser()->tab_strip_model(); 3501 TabStripModel* tab_strip_model = browser()->tab_strip_model();
3553 EXPECT_EQ(0, tab_strip_model->count()); 3502 EXPECT_EQ(0, tab_strip_model->count());
3554 chrome::NewTab(browser()); 3503 chrome::NewTab(browser());
3555 chrome::NewTab(browser()); 3504 chrome::NewTab(browser());
3556 EXPECT_EQ(2, tab_strip_model->count()); 3505 EXPECT_EQ(2, tab_strip_model->count());
3557 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 3506 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
3558 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); 3507 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2");
3559 3508
3560 EXPECT_FALSE(launcher_controller_->IsAppPinned("1")); 3509 EXPECT_FALSE(launcher_controller_->IsAppPinned("1"));
3561 launcher_controller_->PinAppWithID("1"); 3510 launcher_controller_->PinAppWithID("1");
3562 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); 3511 EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
3563 launcher_controller_->PinAppWithID("2"); 3512 launcher_controller_->PinAppWithID("2");
3564 3513
3565 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); 3514 EXPECT_EQ(ash::TYPE_APP_LIST, model_.items()[0].type);
3566 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[1].type); 3515 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_.items()[1].type);
3567 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 3516 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
3568 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[3].type); 3517 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[3].type);
3569 3518
3570 // Move browser shortcut item from index 1 to index 3. 3519 // Move browser shortcut item from index 1 to index 3.
3571 model_->Move(1, 3); 3520 model_.Move(1, 3);
3572 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); 3521 EXPECT_EQ(ash::TYPE_APP_LIST, model_.items()[0].type);
3573 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[1].type); 3522 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[1].type);
3574 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 3523 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
3575 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); 3524 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_.items()[3].type);
3576 3525
3577 RecreateLauncherController(); 3526 RecreateLauncherController();
3578 helper = new TestLauncherControllerHelper(profile()); 3527 helper = new TestLauncherControllerHelper(profile());
3579 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 3528 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
3580 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); 3529 helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2");
3581 SetLauncherControllerHelper(helper); 3530 SetLauncherControllerHelper(helper);
3582 launcher_controller_->Init(); 3531 launcher_controller_->Init();
3583 3532
3584 // Check ShelfItems are restored after resetting ChromeLauncherController. 3533 // Check ShelfItems are restored after resetting ChromeLauncherController.
3585 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); 3534 EXPECT_EQ(ash::TYPE_APP_LIST, model_.items()[0].type);
3586 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[1].type); 3535 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[1].type);
3587 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[2].type); 3536 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[2].type);
3588 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); 3537 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_.items()[3].type);
3589 } 3538 }
3590 3539
3591 // Verifies pinned apps are persisted and restored. 3540 // Verifies pinned apps are persisted and restored.
3592 TEST_F(ChromeLauncherControllerTest, PersistPinned) { 3541 TEST_F(ChromeLauncherControllerTest, PersistPinned) {
3593 InitLauncherControllerWithBrowser(); 3542 InitLauncherControllerWithBrowser();
3594 size_t initial_size = model_->items().size(); 3543 size_t initial_size = model_.items().size();
3595 3544
3596 TabStripModel* tab_strip_model = browser()->tab_strip_model(); 3545 TabStripModel* tab_strip_model = browser()->tab_strip_model();
3597 EXPECT_EQ(1, tab_strip_model->count()); 3546 EXPECT_EQ(1, tab_strip_model->count());
3598 3547
3599 TestLauncherControllerHelper* helper = new TestLauncherControllerHelper; 3548 TestLauncherControllerHelper* helper = new TestLauncherControllerHelper;
3600 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 3549 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
3601 SetLauncherControllerHelper(helper); 3550 SetLauncherControllerHelper(helper);
3602 3551
3603 // app_icon_loader is owned by ChromeLauncherController. 3552 // app_icon_loader is owned by ChromeLauncherController.
3604 TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl; 3553 TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl;
3605 app_icon_loader->AddSupportedApp("1"); 3554 app_icon_loader->AddSupportedApp("1");
3606 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); 3555 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader));
3607 EXPECT_EQ(0, app_icon_loader->fetch_count()); 3556 EXPECT_EQ(0, app_icon_loader->fetch_count());
3608 3557
3609 launcher_controller_->PinAppWithID("1"); 3558 launcher_controller_->PinAppWithID("1");
3610 const int app_index = model_->ItemIndexByID(ash::ShelfID("1")); 3559 const int app_index = model_.ItemIndexByID(ash::ShelfID("1"));
3611 EXPECT_EQ(1, app_icon_loader->fetch_count()); 3560 EXPECT_EQ(1, app_icon_loader->fetch_count());
3612 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[app_index].type); 3561 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[app_index].type);
3613 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); 3562 EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
3614 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); 3563 EXPECT_FALSE(launcher_controller_->IsAppPinned("0"));
3615 EXPECT_EQ(initial_size + 1, model_->items().size()); 3564 EXPECT_EQ(initial_size + 1, model_.items().size());
3616 3565
3617 RecreateLauncherController(); 3566 RecreateLauncherController();
3618 helper = new TestLauncherControllerHelper(profile()); 3567 helper = new TestLauncherControllerHelper(profile());
3619 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 3568 helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
3620 SetLauncherControllerHelper(helper); 3569 SetLauncherControllerHelper(helper);
3621 // app_icon_loader is owned by ChromeLauncherController. 3570 // app_icon_loader is owned by ChromeLauncherController.
3622 app_icon_loader = new TestAppIconLoaderImpl; 3571 app_icon_loader = new TestAppIconLoaderImpl;
3623 app_icon_loader->AddSupportedApp("1"); 3572 app_icon_loader->AddSupportedApp("1");
3624 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); 3573 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader));
3625 launcher_controller_->Init(); 3574 launcher_controller_->Init();
3626 3575
3627 EXPECT_EQ(1, app_icon_loader->fetch_count()); 3576 EXPECT_EQ(1, app_icon_loader->fetch_count());
3628 ASSERT_EQ(initial_size + 1, model_->items().size()); 3577 ASSERT_EQ(initial_size + 1, model_.items().size());
3629 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); 3578 EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
3630 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); 3579 EXPECT_FALSE(launcher_controller_->IsAppPinned("0"));
3631 EXPECT_EQ(ash::TYPE_PINNED_APP, model_->items()[app_index].type); 3580 EXPECT_EQ(ash::TYPE_PINNED_APP, model_.items()[app_index].type);
3632 3581
3633 launcher_controller_->UnpinAppWithID("1"); 3582 launcher_controller_->UnpinAppWithID("1");
3634 ASSERT_EQ(initial_size, model_->items().size()); 3583 ASSERT_EQ(initial_size, model_.items().size());
3635 } 3584 }
3636 3585
3637 TEST_F(ChromeLauncherControllerTest, MultipleAppIconLoaders) { 3586 TEST_F(ChromeLauncherControllerTest, MultipleAppIconLoaders) {
3638 InitLauncherControllerWithBrowser(); 3587 InitLauncherControllerWithBrowser();
3639 3588
3640 const ash::ShelfID shelf_id1(extension1_->id()); 3589 const ash::ShelfID shelf_id1(extension1_->id());
3641 const ash::ShelfID shelf_id2(extension2_->id()); 3590 const ash::ShelfID shelf_id2(extension2_->id());
3642 const ash::ShelfID shelf_id3(extension3_->id()); 3591 const ash::ShelfID shelf_id3(extension3_->id());
3643 // app_icon_loader1 and app_icon_loader2 are owned by 3592 // app_icon_loader1 and app_icon_loader2 are owned by
3644 // ChromeLauncherController. 3593 // ChromeLauncherController.
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
3788 3737
3789 NotifyOnTaskCreated(appinfo, 2 /* task_id */); 3738 NotifyOnTaskCreated(appinfo, 2 /* task_id */);
3790 views::Widget* window2 = CreateArcWindow("org.chromium.arc.2"); 3739 views::Widget* window2 = CreateArcWindow("org.chromium.arc.2");
3791 ASSERT_TRUE(window2); 3740 ASSERT_TRUE(window2);
3792 3741
3793 EXPECT_FALSE(window1->IsActive()); 3742 EXPECT_FALSE(window1->IsActive());
3794 EXPECT_TRUE(window2->IsActive()); 3743 EXPECT_TRUE(window2->IsActive());
3795 3744
3796 const std::string app_id = ArcAppTest::GetAppId(appinfo); 3745 const std::string app_id = ArcAppTest::GetAppId(appinfo);
3797 ash::ShelfItemDelegate* item_delegate = 3746 ash::ShelfItemDelegate* item_delegate =
3798 model_->GetShelfItemDelegate(ash::ShelfID(app_id)); 3747 model_.GetShelfItemDelegate(ash::ShelfID(app_id));
3799 ASSERT_TRUE(item_delegate); 3748 ASSERT_TRUE(item_delegate);
3800 3749
3801 // Selecting the item will show its application menu. It does not change the 3750 // Selecting the item will show its application menu. It does not change the
3802 // active window. 3751 // active window.
3803 SelectItem(item_delegate); 3752 SelectItem(item_delegate);
3804 EXPECT_FALSE(window1->IsActive()); 3753 EXPECT_FALSE(window1->IsActive());
3805 EXPECT_TRUE(window2->IsActive()); 3754 EXPECT_TRUE(window2->IsActive());
3806 3755
3807 // Command ids are just app window indices. Note, apps are registered in 3756 // Command ids are just app window indices. Note, apps are registered in
3808 // opposite order. Last created goes in front. 3757 // opposite order. Last created goes in front.
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
4128 EnablePlayStore(true); 4077 EnablePlayStore(true);
4129 4078
4130 // Pin Play Store. It should be pinned but not scheduled for deferred launch. 4079 // Pin Play Store. It should be pinned but not scheduled for deferred launch.
4131 launcher_controller_->PinAppWithID(arc::kPlayStoreAppId); 4080 launcher_controller_->PinAppWithID(arc::kPlayStoreAppId);
4132 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc::kPlayStoreAppId)); 4081 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc::kPlayStoreAppId));
4133 EXPECT_FALSE(launcher_controller_->GetArcDeferredLauncher()->HasApp( 4082 EXPECT_FALSE(launcher_controller_->GetArcDeferredLauncher()->HasApp(
4134 arc::kPlayStoreAppId)); 4083 arc::kPlayStoreAppId));
4135 4084
4136 // Simulate click. This should schedule Play Store for deferred launch. 4085 // Simulate click. This should schedule Play Store for deferred launch.
4137 ash::ShelfItemDelegate* item_delegate = 4086 ash::ShelfItemDelegate* item_delegate =
4138 model_->GetShelfItemDelegate(ash::ShelfID(arc::kPlayStoreAppId)); 4087 model_.GetShelfItemDelegate(ash::ShelfID(arc::kPlayStoreAppId));
4139 EXPECT_TRUE(item_delegate); 4088 EXPECT_TRUE(item_delegate);
4140 SelectItem(item_delegate); 4089 SelectItem(item_delegate);
4141 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc::kPlayStoreAppId)); 4090 EXPECT_TRUE(launcher_controller_->IsAppPinned(arc::kPlayStoreAppId));
4142 EXPECT_TRUE(launcher_controller_->GetArcDeferredLauncher()->HasApp( 4091 EXPECT_TRUE(launcher_controller_->GetArcDeferredLauncher()->HasApp(
4143 arc::kPlayStoreAppId)); 4092 arc::kPlayStoreAppId));
4144 } 4093 }
4145 4094
4146 // Checks the case when several app items have the same ordinal position (which 4095 // Checks the case when several app items have the same ordinal position (which
4147 // is valid case). 4096 // is valid case).
4148 TEST_F(ChromeLauncherControllerTest, CheckPositionConflict) { 4097 TEST_F(ChromeLauncherControllerTest, CheckPositionConflict) {
(...skipping 20 matching lines...) Expand all
4169 app_service_->GetPinPosition(extension2_->id()); 4118 app_service_->GetPinPosition(extension2_->id());
4170 const syncer::StringOrdinal position_3 = 4119 const syncer::StringOrdinal position_3 =
4171 app_service_->GetPinPosition(extension3_->id()); 4120 app_service_->GetPinPosition(extension3_->id());
4172 EXPECT_TRUE(position_chrome.LessThan(position_1)); 4121 EXPECT_TRUE(position_chrome.LessThan(position_1));
4173 EXPECT_TRUE(position_1.Equals(position_2)); 4122 EXPECT_TRUE(position_1.Equals(position_2));
4174 EXPECT_TRUE(position_2.Equals(position_3)); 4123 EXPECT_TRUE(position_2.Equals(position_3));
4175 4124
4176 // Move Chrome between App1 and App2. 4125 // Move Chrome between App1 and App2.
4177 // Note, move target_index is in context when moved element is removed from 4126 // Note, move target_index is in context when moved element is removed from
4178 // array first. 4127 // array first.
4179 model_->Move(1, 2); 4128 model_.Move(1, 2);
4180 EXPECT_EQ("AppList, App1, Chrome, App2, App3", GetPinnedAppStatus()); 4129 EXPECT_EQ("AppList, App1, Chrome, App2, App3", GetPinnedAppStatus());
4181 4130
4182 // Expect sync positions for only Chrome is updated and its resolution is 4131 // Expect sync positions for only Chrome is updated and its resolution is
4183 // after all duplicated ordinals. 4132 // after all duplicated ordinals.
4184 EXPECT_TRUE(position_3.LessThan( 4133 EXPECT_TRUE(position_3.LessThan(
4185 app_service_->GetPinPosition(extension_misc::kChromeAppId))); 4134 app_service_->GetPinPosition(extension_misc::kChromeAppId)));
4186 EXPECT_TRUE( 4135 EXPECT_TRUE(
4187 position_1.Equals(app_service_->GetPinPosition(extension1_->id()))); 4136 position_1.Equals(app_service_->GetPinPosition(extension1_->id())));
4188 EXPECT_TRUE( 4137 EXPECT_TRUE(
4189 position_1.Equals(app_service_->GetPinPosition(extension1_->id()))); 4138 position_1.Equals(app_service_->GetPinPosition(extension1_->id())));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4227 4176
4228 // Tests that shelf profile preferences are loaded on login. 4177 // Tests that shelf profile preferences are loaded on login.
4229 TEST_F(ChromeLauncherControllerTest, PrefsLoadedOnLogin) { 4178 TEST_F(ChromeLauncherControllerTest, PrefsLoadedOnLogin) {
4230 PrefService* prefs = profile()->GetTestingPrefService(); 4179 PrefService* prefs = profile()->GetTestingPrefService();
4231 prefs->SetString(prefs::kShelfAlignmentLocal, "Left"); 4180 prefs->SetString(prefs::kShelfAlignmentLocal, "Left");
4232 prefs->SetString(prefs::kShelfAlignment, "Left"); 4181 prefs->SetString(prefs::kShelfAlignment, "Left");
4233 prefs->SetString(prefs::kShelfAutoHideBehaviorLocal, "Always"); 4182 prefs->SetString(prefs::kShelfAutoHideBehaviorLocal, "Always");
4234 prefs->SetString(prefs::kShelfAutoHideBehavior, "Always"); 4183 prefs->SetString(prefs::kShelfAutoHideBehavior, "Always");
4235 4184
4236 TestChromeLauncherController* test_launcher_controller = 4185 TestChromeLauncherController* test_launcher_controller =
4237 shell_delegate_->CreateTestLauncherController(profile()); 4186 shell_delegate_->CreateLauncherController(profile());
4187 test_launcher_controller->Init();
4238 4188
4239 // Simulate login for the test controller. 4189 // Simulate login for the test controller.
4240 test_launcher_controller->ReleaseProfile(); 4190 test_launcher_controller->ReleaseProfile();
4241 test_launcher_controller->AttachProfile(profile()); 4191 test_launcher_controller->AttachProfile(profile());
4242 base::RunLoop().RunUntilIdle(); 4192 base::RunLoop().RunUntilIdle();
4243 4193
4244 TestShelfController* shelf_controller = 4194 TestShelfController* shelf_controller =
4245 test_launcher_controller->test_shelf_controller(); 4195 test_launcher_controller->test_shelf_controller();
4246 ASSERT_TRUE(shelf_controller); 4196 ASSERT_TRUE(shelf_controller);
4247 EXPECT_EQ(ash::SHELF_ALIGNMENT_LEFT, shelf_controller->alignment()); 4197 EXPECT_EQ(ash::SHELF_ALIGNMENT_LEFT, shelf_controller->alignment());
4248 EXPECT_EQ(1u, shelf_controller->alignment_change_count()); 4198 EXPECT_EQ(1u, shelf_controller->alignment_change_count());
4249 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, 4199 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
4250 shelf_controller->auto_hide()); 4200 shelf_controller->auto_hide());
4251 EXPECT_EQ(1u, shelf_controller->auto_hide_change_count()); 4201 EXPECT_EQ(1u, shelf_controller->auto_hide_change_count());
4252 } 4202 }
4253 4203
4254 // Tests that the shelf controller's changes are not wastefully echoed back. 4204 // Tests that the shelf controller's changes are not wastefully echoed back.
4255 TEST_F(ChromeLauncherControllerTest, DoNotEchoShelfControllerChanges) { 4205 TEST_F(ChromeLauncherControllerTest, DoNotEchoShelfControllerChanges) {
4256 TestChromeLauncherController* test_launcher_controller = 4206 TestChromeLauncherController* test_launcher_controller =
4257 shell_delegate_->CreateTestLauncherController(profile()); 4207 shell_delegate_->CreateLauncherController(profile());
4208 test_launcher_controller->Init();
4258 4209
4259 // Simulate login for the test controller. 4210 // Simulate login for the test controller.
4260 test_launcher_controller->ReleaseProfile(); 4211 test_launcher_controller->ReleaseProfile();
4261 test_launcher_controller->AttachProfile(profile()); 4212 test_launcher_controller->AttachProfile(profile());
4262 base::RunLoop().RunUntilIdle(); 4213 base::RunLoop().RunUntilIdle();
4263 4214
4264 TestShelfController* shelf_controller = 4215 TestShelfController* shelf_controller =
4265 test_launcher_controller->test_shelf_controller(); 4216 test_launcher_controller->test_shelf_controller();
4266 ASSERT_TRUE(shelf_controller); 4217 ASSERT_TRUE(shelf_controller);
4267 EXPECT_EQ(ash::SHELF_ALIGNMENT_BOTTOM, shelf_controller->alignment()); 4218 EXPECT_EQ(ash::SHELF_ALIGNMENT_BOTTOM, shelf_controller->alignment());
(...skipping 17 matching lines...) Expand all
4285 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, 4236 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
4286 shelf_controller->auto_hide()); 4237 shelf_controller->auto_hide());
4287 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count()); 4238 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count());
4288 4239
4289 PrefService* prefs = profile()->GetTestingPrefService(); 4240 PrefService* prefs = profile()->GetTestingPrefService();
4290 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignmentLocal)); 4241 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignmentLocal));
4291 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignment)); 4242 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignment));
4292 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehaviorLocal)); 4243 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehaviorLocal));
4293 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehavior)); 4244 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehavior));
4294 } 4245 }
4246
4247 // Ensure Ash and Chrome ShelfModel changes are synchronized correctly in Mash.
4248 TEST_F(ChromeLauncherControllerTest, ShelfModelSyncMash) {
4249 if (chromeos::GetAshConfig() != ash::Config::MASH)
4250 return;
4251
4252 // The ShelfModel constructor adds an AppList shelf item.
4253 TestChromeLauncherController* launcher_controller =
4254 shell_delegate_->CreateLauncherController(profile());
4255 TestShelfController* shelf_controller =
4256 launcher_controller->test_shelf_controller();
4257 EXPECT_EQ(0u, shelf_controller->added_count());
4258 EXPECT_EQ(0u, shelf_controller->removed_count());
4259 EXPECT_EQ(1, model_.item_count());
4260 EXPECT_EQ(ash::kAppListId, model_.items()[0].id.app_id);
4261
4262 // Init should add the browser shelf item to Chrome's ShelfModel.
4263 // Ash's ShelfController should be notified about the new browser item.
4264 launcher_controller->Init();
4265 base::RunLoop().RunUntilIdle();
4266 EXPECT_EQ(2, model_.item_count());
4267 EXPECT_EQ(extension_misc::kChromeAppId, model_.items()[1].id.app_id);
4268 EXPECT_EQ(1u, shelf_controller->added_count());
4269 EXPECT_EQ(0u, shelf_controller->removed_count());
4270
4271 // Add a shelf item using the ShelfController interface.
4272 ash::ShelfItem item;
4273 item.type = ash::TYPE_PINNED_APP;
4274 item.id = ash::ShelfID(kDummyAppId);
4275 shelf_controller->AddShelfItem(2, item);
4276 base::RunLoop().RunUntilIdle();
4277 EXPECT_EQ(2u, shelf_controller->added_count());
James Cook 2017/05/31 20:02:30 optional: This test might be slightly easier to re
msw 2017/05/31 20:32:26 I'm going to leave it as-is, the benefit doesn't o
4278 EXPECT_EQ(0u, shelf_controller->removed_count());
4279
4280 // Remove a shelf item using the ShelfController interface.
4281 shelf_controller->RemoveShelfItem(item.id);
4282 base::RunLoop().RunUntilIdle();
4283 EXPECT_EQ(2u, shelf_controller->added_count());
4284 EXPECT_EQ(1u, shelf_controller->removed_count());
4285
4286 // Add an item to Chrome's model; ShelfController should be notified.
4287 model_.Add(item);
4288 EXPECT_EQ(3, model_.item_count());
4289 base::RunLoop().RunUntilIdle();
4290 EXPECT_EQ(3u, shelf_controller->added_count());
4291 EXPECT_EQ(1u, shelf_controller->removed_count());
4292
4293 // Remove an item from Chrome's model; ShelfController should be notified.
4294 model_.RemoveItemAt(2);
4295 EXPECT_EQ(2, model_.item_count());
4296 base::RunLoop().RunUntilIdle();
4297 EXPECT_EQ(3u, shelf_controller->added_count());
4298 EXPECT_EQ(2u, shelf_controller->removed_count());
4299 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698