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

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

Issue 2791463002: mash: Remove ShelfDelegate; move functions to ShelfModel. (Closed)
Patch Set: Address comment. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 const ItemSelectedCallback& callback) override { 266 const ItemSelectedCallback& callback) override {
267 callback.Run(ash::SHELF_ACTION_WINDOW_ACTIVATED, base::nullopt); 267 callback.Run(ash::SHELF_ACTION_WINDOW_ACTIVATED, base::nullopt);
268 } 268 }
269 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override {} 269 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override {}
270 void Close() override {} 270 void Close() override {}
271 271
272 private: 272 private:
273 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController); 273 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController);
274 }; 274 };
275 275
276 // A test ShelfController implementation that tracks alignment and auto-hide.
277 class TestShelfController : public ash::mojom::ShelfController {
278 public:
279 TestShelfController() : binding_(this) {}
280 ~TestShelfController() override {}
281
282 ash::ShelfAlignment alignment() const { return alignment_; }
283 ash::ShelfAutoHideBehavior auto_hide() const { return auto_hide_; }
284
285 size_t alignment_change_count() const { return alignment_change_count_; }
286 size_t auto_hide_change_count() const { return auto_hide_change_count_; }
287
288 ash::mojom::ShelfControllerPtr CreateInterfacePtrAndBind() {
289 return binding_.CreateInterfacePtrAndBind();
290 }
291
292 // ash::mojom::ShelfController:
293 void AddObserver(
294 ash::mojom::ShelfObserverAssociatedPtrInfo observer) override {
295 observer_.Bind(std::move(observer));
296 }
297 void SetAlignment(ash::ShelfAlignment alignment,
298 int64_t display_id) override {
299 alignment_change_count_++;
300 alignment_ = alignment;
301 observer_->OnAlignmentChanged(alignment_, display_id);
302 }
303 void SetAutoHideBehavior(ash::ShelfAutoHideBehavior auto_hide,
304 int64_t display_id) override {
305 auto_hide_change_count_++;
306 auto_hide_ = auto_hide;
307 observer_->OnAutoHideBehaviorChanged(auto_hide_, display_id);
308 }
309 void PinItem(
310 const ash::ShelfItem& item,
311 ash::mojom::ShelfItemDelegateAssociatedPtrInfo delegate) override {}
312 void UnpinItem(const std::string& app_id) override {}
313 void SetItemImage(const std::string& app_id, const SkBitmap& image) override {
314 }
315
316 private:
317 ash::ShelfAlignment alignment_ = ash::SHELF_ALIGNMENT_BOTTOM_LOCKED;
318 ash::ShelfAutoHideBehavior auto_hide_ = ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN;
319
320 size_t alignment_change_count_ = 0;
321 size_t auto_hide_change_count_ = 0;
322
323 ash::mojom::ShelfObserverAssociatedPtr observer_;
324 mojo::Binding<ash::mojom::ShelfController> binding_;
325
326 DISALLOW_COPY_AND_ASSIGN(TestShelfController);
327 };
328
276 // A callback that does nothing after shelf item selection handling. 329 // A callback that does nothing after shelf item selection handling.
277 void NoopCallback(ash::ShelfAction action, base::Optional<ash::MenuItemList>) {} 330 void NoopCallback(ash::ShelfAction action, base::Optional<ash::MenuItemList>) {}
278 331
279 // Simulates selection of the shelf item. 332 // Simulates selection of the shelf item.
280 void SelectItem(ash::ShelfItemDelegate* delegate) { 333 void SelectItem(ash::ShelfItemDelegate* delegate) {
281 std::unique_ptr<ui::Event> event = base::MakeUnique<ui::MouseEvent>( 334 std::unique_ptr<ui::Event> event = base::MakeUnique<ui::MouseEvent>(
282 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), 335 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
283 ui::EF_NONE, 0); 336 ui::EF_NONE, 0);
284 delegate->ItemSelected(std::move(event), display::kInvalidDisplayId, 337 delegate->ItemSelected(std::move(event), display::kInvalidDisplayId,
285 ash::LAUNCH_FROM_UNKNOWN, base::Bind(&NoopCallback)); 338 ash::LAUNCH_FROM_UNKNOWN, base::Bind(&NoopCallback));
286 } 339 }
287 340
288 } // namespace 341 } // namespace
289 342
343 // A test ChromeLauncherControllerImpl subclass that uses TestShelfController.
344 class TestChromeLauncherControllerImpl : public ChromeLauncherControllerImpl {
345 public:
346 TestChromeLauncherControllerImpl(Profile* profile, ash::ShelfModel* model)
347 : ChromeLauncherControllerImpl(profile, model) {}
348
349 // ChromeLauncherControllerImpl:
350 using ChromeLauncherControllerImpl::ReleaseProfile;
351 bool ConnectToShelfController() override {
352 // Set the shelf controller pointer to a test instance; this is run in init.
353 if (!shelf_controller_.is_bound())
354 shelf_controller_ = test_shelf_controller_.CreateInterfacePtrAndBind();
355 return true;
356 }
357
358 TestShelfController* test_shelf_controller() {
359 return &test_shelf_controller_;
360 }
361
362 private:
363 TestShelfController test_shelf_controller_;
364
365 DISALLOW_COPY_AND_ASSIGN(TestChromeLauncherControllerImpl);
366 };
367
368 // A shell delegate that owns a ChromeLauncherController, like production.
369 // TODO(msw): Refine ChromeLauncherControllerImpl lifetime management.
370 // TODO(msw): Avoid relying on TestShellDelegate's ShelfInitializer.
371 class ChromeLauncherTestShellDelegate : public ash::test::TestShellDelegate {
372 public:
373 ChromeLauncherTestShellDelegate() {}
374
375 // Create a ChromeLauncherControllerImpl instance.
376 ChromeLauncherControllerImpl* CreateLauncherController(Profile* profile) {
377 launcher_controller_ = base::MakeUnique<ChromeLauncherControllerImpl>(
378 profile, ash::Shell::Get()->shelf_model());
379 return launcher_controller_.get();
380 }
381
382 // Create a TestChromeLauncherControllerImpl instance.
383 TestChromeLauncherControllerImpl* CreateTestLauncherController(
384 Profile* profile) {
385 auto controller = base::MakeUnique<TestChromeLauncherControllerImpl>(
386 profile, ash::Shell::Get()->shelf_model());
387 TestChromeLauncherControllerImpl* controller_weak = controller.get();
388 launcher_controller_ = std::move(controller);
389 launcher_controller_->Init();
390 return controller_weak;
391 }
392
393 // ash::test::TestShellDelegate:
394 void ShelfShutdown() override { launcher_controller_.reset(); }
395
396 private:
397 std::unique_ptr<ChromeLauncherControllerImpl> launcher_controller_;
398
399 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherTestShellDelegate);
400 };
401
290 class ChromeLauncherControllerImplTest : public BrowserWithTestWindowTest { 402 class ChromeLauncherControllerImplTest : public BrowserWithTestWindowTest {
291 protected: 403 protected:
292 ChromeLauncherControllerImplTest() 404 ChromeLauncherControllerImplTest()
293 : BrowserWithTestWindowTest(Browser::TYPE_TABBED, false) {} 405 : BrowserWithTestWindowTest(Browser::TYPE_TABBED, false) {}
294 406
295 ~ChromeLauncherControllerImplTest() override {} 407 ~ChromeLauncherControllerImplTest() override {}
296 408
297 void SetUp() override { 409 void SetUp() override {
298 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 410 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
299 command_line->AppendSwitch(switches::kUseFirstDisplayAsInternal); 411 command_line->AppendSwitch(switches::kUseFirstDisplayAsInternal);
300 412
301 app_list::AppListSyncableServiceFactory::SetUseInTesting(); 413 app_list::AppListSyncableServiceFactory::SetUseInTesting();
302 414
415 shell_delegate_ = new ChromeLauncherTestShellDelegate();
416 ash_test_helper()->set_test_shell_delegate(shell_delegate_);
417
303 BrowserWithTestWindowTest::SetUp(); 418 BrowserWithTestWindowTest::SetUp();
304 419
305 if (!profile_manager_) { 420 if (!profile_manager_) {
306 profile_manager_.reset( 421 profile_manager_.reset(
307 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 422 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
308 ASSERT_TRUE(profile_manager_->SetUp()); 423 ASSERT_TRUE(profile_manager_->SetUp());
309 } 424 }
310 425
311 model_ = ash::Shell::Get()->shelf_controller()->model(); 426 model_ = ash::Shell::Get()->shelf_controller()->model();
312 model_observer_.reset(new TestShelfModelObserver); 427 model_observer_.reset(new TestShelfModelObserver);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 return base::WrapUnique( 593 return base::WrapUnique(
479 CreateBrowser(profile, Browser::TYPE_TABBED, false, browser_window)); 594 CreateBrowser(profile, Browser::TYPE_TABBED, false, browser_window));
480 } 595 }
481 596
482 void AddAppListLauncherItem() { 597 void AddAppListLauncherItem() {
483 ash::ShelfItem app_list; 598 ash::ShelfItem app_list;
484 app_list.type = ash::TYPE_APP_LIST; 599 app_list.type = ash::TYPE_APP_LIST;
485 model_->Add(app_list); 600 model_->Add(app_list);
486 } 601 }
487 602
488 // Create a launcher controller instance and register it as the ShelfDelegate. 603 // Create a launcher controller instance, owned by the test shell delegate.
489 // Returns a pointer to the uninitialized controller, which is owned by Shell. 604 // Returns a pointer to the uninitialized controller.
490 ChromeLauncherControllerImpl* CreateLauncherController() { 605 ChromeLauncherControllerImpl* CreateLauncherController() {
491 // Shell owns ChromeLauncherController as its ShelfDelegate. The lifetime 606 launcher_controller_ = shell_delegate_->CreateLauncherController(profile());
492 // of this instance should match production behavior as closely as possible.
493 DCHECK(!ChromeLauncherController::instance());
494 std::unique_ptr<ChromeLauncherControllerImpl> launcher_controller =
495 base::MakeUnique<ChromeLauncherControllerImpl>(profile(), model_);
496 launcher_controller_ = launcher_controller.get();
497 ash::test::ShellTestApi().SetShelfDelegate(std::move(launcher_controller));
498 return launcher_controller_; 607 return launcher_controller_;
499 } 608 }
500 609
501 // Create and initialize the controller. 610 // Create and initialize the controller, owned by the test shell delegate.
502 // Returns a pointer to the initialized controller, which is owned by Shell.
503 void InitLauncherController() { CreateLauncherController()->Init(); } 611 void InitLauncherController() { CreateLauncherController()->Init(); }
504 612
505 // Create and initialize the controller; create a tab and show the browser. 613 // Create and initialize the controller; create a tab and show the browser.
506 void InitLauncherControllerWithBrowser() { 614 void InitLauncherControllerWithBrowser() {
507 InitLauncherController(); 615 InitLauncherController();
508 chrome::NewTab(browser()); 616 chrome::NewTab(browser());
509 browser()->window()->Show(); 617 browser()->window()->Show();
510 } 618 }
511 619
512 // Destroy Shell's controller instance and clear the local pointer. 620 // Destroy the launcher controller instance and clear the local pointer.
513 void ResetLauncherController() { 621 void ResetLauncherController() {
514 launcher_controller_ = nullptr; 622 launcher_controller_ = nullptr;
515 ash::test::ShellTestApi().SetShelfDelegate(nullptr); 623 shell_delegate_->ShelfShutdown();
516 } 624 }
517 625
518 // Destroy and recreate the controller; clear and reinitialize the ShelfModel. 626 // Destroy and recreate the controller; clear and reinitialize the ShelfModel.
519 // Returns a pointer to the uninitialized controller, which is owned by Shell. 627 // Returns a pointer to the uninitialized controller, owned by shell delegate.
520 // TODO(msw): This does not accurately represent ChromeLauncherControllerImpl 628 // TODO(msw): This does not accurately represent ChromeLauncherControllerImpl
521 // lifetime or usage in production, and does not accurately simulate restarts. 629 // lifetime or usage in production, and does not accurately simulate restarts.
522 ChromeLauncherControllerImpl* RecreateLauncherController() { 630 ChromeLauncherControllerImpl* RecreateLauncherController() {
523 // Destroy any existing controller first; only one may exist at a time. 631 // Destroy any existing controller first; only one may exist at a time.
524 ResetLauncherController(); 632 ResetLauncherController();
525 while (model_->item_count() > 0) 633 while (model_->item_count() > 0)
526 model_->RemoveItemAt(0); 634 model_->RemoveItemAt(0);
527 AddAppListLauncherItem(); 635 AddAppListLauncherItem();
528 return CreateLauncherController(); 636 return CreateLauncherController();
529 } 637 }
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 scoped_refptr<Extension> extension5_; 1040 scoped_refptr<Extension> extension5_;
933 scoped_refptr<Extension> extension6_; 1041 scoped_refptr<Extension> extension6_;
934 scoped_refptr<Extension> extension7_; 1042 scoped_refptr<Extension> extension7_;
935 scoped_refptr<Extension> extension8_; 1043 scoped_refptr<Extension> extension8_;
936 scoped_refptr<Extension> extension_platform_app_; 1044 scoped_refptr<Extension> extension_platform_app_;
937 scoped_refptr<Extension> arc_support_host_; 1045 scoped_refptr<Extension> arc_support_host_;
938 1046
939 ArcAppTest arc_test_; 1047 ArcAppTest arc_test_;
940 bool auto_start_arc_test_ = false; 1048 bool auto_start_arc_test_ = false;
941 ChromeLauncherControllerImpl* launcher_controller_ = nullptr; 1049 ChromeLauncherControllerImpl* launcher_controller_ = nullptr;
1050 ChromeLauncherTestShellDelegate* shell_delegate_ = nullptr;
942 std::unique_ptr<TestShelfModelObserver> model_observer_; 1051 std::unique_ptr<TestShelfModelObserver> model_observer_;
943 ash::ShelfModel* model_ = nullptr; 1052 ash::ShelfModel* model_ = nullptr;
944 std::unique_ptr<TestingProfileManager> profile_manager_; 1053 std::unique_ptr<TestingProfileManager> profile_manager_;
945 1054
946 // |item_delegate_manager_| owns |test_controller_|. 1055 // |item_delegate_manager_| owns |test_controller_|.
947 ash::ShelfItemDelegate* test_controller_ = nullptr; 1056 ash::ShelfItemDelegate* test_controller_ = nullptr;
948 1057
949 ExtensionService* extension_service_ = nullptr; 1058 ExtensionService* extension_service_ = nullptr;
950 1059
951 app_list::AppListSyncableService* app_service_ = nullptr; 1060 app_list::AppListSyncableService* app_service_ = nullptr;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 1210
1102 // Initialize the UserManager singleton to a fresh FakeUserManager instance. 1211 // Initialize the UserManager singleton to a fresh FakeUserManager instance.
1103 user_manager_enabler_.reset(new chromeos::ScopedUserManagerEnabler( 1212 user_manager_enabler_.reset(new chromeos::ScopedUserManagerEnabler(
1104 new chromeos::FakeChromeUserManager)); 1213 new chromeos::FakeChromeUserManager));
1105 1214
1106 // Initialize the WallpaperManager singleton. 1215 // Initialize the WallpaperManager singleton.
1107 chromeos::WallpaperManager::Initialize(); 1216 chromeos::WallpaperManager::Initialize();
1108 1217
1109 // Initialize the rest. 1218 // Initialize the rest.
1110 ChromeLauncherControllerImplTest::SetUp(); 1219 ChromeLauncherControllerImplTest::SetUp();
1111
1112 // Get some base objects.
1113 shell_delegate_ = static_cast<ash::test::TestShellDelegate*>(
1114 ash::Shell::Get()->shell_delegate());
1115 shell_delegate_->set_multi_profiles_enabled(true); 1220 shell_delegate_->set_multi_profiles_enabled(true);
1116 } 1221 }
1117 1222
1118 void TearDown() override { 1223 void TearDown() override {
1119 ChromeLauncherControllerImplTest::TearDown(); 1224 ChromeLauncherControllerImplTest::TearDown();
1120 user_manager_enabler_.reset(); 1225 user_manager_enabler_.reset();
1121 for (ProfileToNameMap::iterator it = created_profiles_.begin(); 1226 for (ProfileToNameMap::iterator it = created_profiles_.begin();
1122 it != created_profiles_.end(); ++it) 1227 it != created_profiles_.end(); ++it)
1123 profile_manager_->DeleteTestingProfile(it->second); 1228 profile_manager_->DeleteTestingProfile(it->second);
1124 chromeos::WallpaperManager::Shutdown(); 1229 chromeos::WallpaperManager::Shutdown();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 // this is only usable with a single v1 application. 1294 // this is only usable with a single v1 application.
1190 V1App* CreateRunningV1App(Profile* profile, 1295 V1App* CreateRunningV1App(Profile* profile,
1191 const std::string& app_name, 1296 const std::string& app_name,
1192 const std::string& url) { 1297 const std::string& url) {
1193 V1App* v1_app = new V1App(profile, app_name); 1298 V1App* v1_app = new V1App(profile, app_name);
1194 NavigateAndCommitActiveTabWithTitle(v1_app->browser(), GURL(url), 1299 NavigateAndCommitActiveTabWithTitle(v1_app->browser(), GURL(url),
1195 base::string16()); 1300 base::string16());
1196 return v1_app; 1301 return v1_app;
1197 } 1302 }
1198 1303
1199 ash::test::TestShellDelegate* shell_delegate() { return shell_delegate_; }
1200
1201 // Override BrowserWithTestWindowTest: 1304 // Override BrowserWithTestWindowTest:
1202 TestingProfile* CreateProfile() override { 1305 TestingProfile* CreateProfile() override {
1203 return CreateMultiUserProfile("user1"); 1306 return CreateMultiUserProfile("user1");
1204 } 1307 }
1205 void DestroyProfile(TestingProfile* profile) override { 1308 void DestroyProfile(TestingProfile* profile) override {
1206 // Delete the profile through our profile manager. 1309 // Delete the profile through our profile manager.
1207 ProfileToNameMap::iterator it = created_profiles_.find(profile); 1310 ProfileToNameMap::iterator it = created_profiles_.find(profile);
1208 DCHECK(it != created_profiles_.end()); 1311 DCHECK(it != created_profiles_.end());
1209 profile_manager_->DeleteTestingProfile(it->second); 1312 profile_manager_->DeleteTestingProfile(it->second);
1210 created_profiles_.erase(it); 1313 created_profiles_.erase(it);
1211 } 1314 }
1212 1315
1213 private: 1316 private:
1214 typedef std::map<Profile*, std::string> ProfileToNameMap; 1317 typedef std::map<Profile*, std::string> ProfileToNameMap;
1215 TestingProfileManager* profile_manager() { return profile_manager_.get(); } 1318 TestingProfileManager* profile_manager() { return profile_manager_.get(); }
1216 1319
1217 chromeos::FakeChromeUserManager* GetFakeUserManager() { 1320 chromeos::FakeChromeUserManager* GetFakeUserManager() {
1218 return static_cast<chromeos::FakeChromeUserManager*>( 1321 return static_cast<chromeos::FakeChromeUserManager*>(
1219 user_manager::UserManager::Get()); 1322 user_manager::UserManager::Get());
1220 } 1323 }
1221 1324
1222 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; 1325 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_;
1223 1326
1224 ash::test::TestShellDelegate* shell_delegate_;
1225
1226 ProfileToNameMap created_profiles_; 1327 ProfileToNameMap created_profiles_;
1227 1328
1228 DISALLOW_COPY_AND_ASSIGN( 1329 DISALLOW_COPY_AND_ASSIGN(
1229 MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest); 1330 MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest);
1230 }; 1331 };
1231 1332
1232 class ChromeLauncherControllerImplMultiProfileWithArcTest 1333 class ChromeLauncherControllerImplMultiProfileWithArcTest
1233 : public MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest , // NOLINT(whitespace/line_length) 1334 : public MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerImplTest , // NOLINT(whitespace/line_length)
1234 public ::testing::WithParamInterface<bool> { 1335 public ::testing::WithParamInterface<bool> {
1235 protected: 1336 protected:
(...skipping 2902 matching lines...) Expand 10 before | Expand all | Expand 10 after
4138 // Pinned state should not change. 4239 // Pinned state should not change.
4139 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); 4240 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus());
4140 launcher_controller_->UnpinAppWithID(extension2_->id()); 4241 launcher_controller_->UnpinAppWithID(extension2_->id());
4141 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); 4242 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus());
4142 4243
4143 // Resume syncing and sync information overrides local copy. 4244 // Resume syncing and sync information overrides local copy.
4144 StartAppSyncService(copy_sync_list); 4245 StartAppSyncService(copy_sync_list);
4145 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); 4246 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus());
4146 } 4247 }
4147 4248
4148 // A test ShelfController implementation that tracks alignment and auto-hide.
4149 class TestShelfController : public ash::mojom::ShelfController {
4150 public:
4151 TestShelfController() : binding_(this) {}
4152 ~TestShelfController() override {}
4153
4154 ash::ShelfAlignment alignment() const { return alignment_; }
4155 ash::ShelfAutoHideBehavior auto_hide() const { return auto_hide_; }
4156
4157 size_t alignment_change_count() const { return alignment_change_count_; }
4158 size_t auto_hide_change_count() const { return auto_hide_change_count_; }
4159
4160 ash::mojom::ShelfControllerPtr CreateInterfacePtrAndBind() {
4161 return binding_.CreateInterfacePtrAndBind();
4162 }
4163
4164 // ash::mojom::ShelfController:
4165 void AddObserver(
4166 ash::mojom::ShelfObserverAssociatedPtrInfo observer) override {
4167 observer_.Bind(std::move(observer));
4168 }
4169 void SetAlignment(ash::ShelfAlignment alignment,
4170 int64_t display_id) override {
4171 alignment_change_count_++;
4172 alignment_ = alignment;
4173 observer_->OnAlignmentChanged(alignment_, display_id);
4174 }
4175 void SetAutoHideBehavior(ash::ShelfAutoHideBehavior auto_hide,
4176 int64_t display_id) override {
4177 auto_hide_change_count_++;
4178 auto_hide_ = auto_hide;
4179 observer_->OnAutoHideBehaviorChanged(auto_hide_, display_id);
4180 }
4181 void PinItem(
4182 const ash::ShelfItem& item,
4183 ash::mojom::ShelfItemDelegateAssociatedPtrInfo delegate) override {}
4184 void UnpinItem(const std::string& app_id) override {}
4185 void SetItemImage(const std::string& app_id, const SkBitmap& image) override {
4186 }
4187
4188 private:
4189 ash::ShelfAlignment alignment_ = ash::SHELF_ALIGNMENT_BOTTOM_LOCKED;
4190 ash::ShelfAutoHideBehavior auto_hide_ = ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN;
4191
4192 size_t alignment_change_count_ = 0;
4193 size_t auto_hide_change_count_ = 0;
4194
4195 ash::mojom::ShelfObserverAssociatedPtr observer_;
4196 mojo::Binding<ash::mojom::ShelfController> binding_;
4197
4198 DISALLOW_COPY_AND_ASSIGN(TestShelfController);
4199 };
4200
4201 // A test ChromeLauncherControllerImpl sublcass that uses TestShelfController.
4202 class TestChromeLauncherControllerImpl : public ChromeLauncherControllerImpl {
4203 public:
4204 TestChromeLauncherControllerImpl(Profile* profile, ash::ShelfModel* model)
4205 : ChromeLauncherControllerImpl(profile, model) {}
4206
4207 // ChromeLauncherControllerImpl:
4208 using ChromeLauncherControllerImpl::ReleaseProfile;
4209 bool ConnectToShelfController() override {
4210 // Set the shelf controller pointer to a test instance; this is run in init.
4211 if (!shelf_controller_.is_bound())
4212 shelf_controller_ = test_shelf_controller_.CreateInterfacePtrAndBind();
4213 return true;
4214 }
4215
4216 TestShelfController* test_shelf_controller() {
4217 return &test_shelf_controller_;
4218 }
4219
4220 private:
4221 TestShelfController test_shelf_controller_;
4222
4223 DISALLOW_COPY_AND_ASSIGN(TestChromeLauncherControllerImpl);
4224 };
4225
4226 using ChromeLauncherControllerImplPrefTest = BrowserWithTestWindowTest;
4227
4228 // Tests that shelf profile preferences are loaded on login. 4249 // Tests that shelf profile preferences are loaded on login.
4229 TEST_F(ChromeLauncherControllerImplPrefTest, PrefsLoadedOnLogin) { 4250 TEST_F(ChromeLauncherControllerImplTest, PrefsLoadedOnLogin) {
4230 PrefService* prefs = profile()->GetTestingPrefService(); 4251 PrefService* prefs = profile()->GetTestingPrefService();
4231 prefs->SetString(prefs::kShelfAlignmentLocal, "Left"); 4252 prefs->SetString(prefs::kShelfAlignmentLocal, "Left");
4232 prefs->SetString(prefs::kShelfAlignment, "Left"); 4253 prefs->SetString(prefs::kShelfAlignment, "Left");
4233 prefs->SetString(prefs::kShelfAutoHideBehaviorLocal, "Always"); 4254 prefs->SetString(prefs::kShelfAutoHideBehaviorLocal, "Always");
4234 prefs->SetString(prefs::kShelfAutoHideBehavior, "Always"); 4255 prefs->SetString(prefs::kShelfAutoHideBehavior, "Always");
4235 4256
4236 ash::ShelfModel* model = ash::Shell::Get()->shelf_controller()->model(); 4257 TestChromeLauncherControllerImpl* test_launcher_controller =
4237 TestChromeLauncherControllerImpl test_launcher_controller(profile(), model); 4258 shell_delegate_->CreateTestLauncherController(profile());
4238 test_launcher_controller.Init();
4239 4259
4240 // Simulate login for the test controller. 4260 // Simulate login for the test controller.
4241 test_launcher_controller.ReleaseProfile(); 4261 test_launcher_controller->ReleaseProfile();
4242 test_launcher_controller.AttachProfile(profile()); 4262 test_launcher_controller->AttachProfile(profile());
4243 base::RunLoop().RunUntilIdle(); 4263 base::RunLoop().RunUntilIdle();
4244 4264
4245 TestShelfController* shelf_controller = 4265 TestShelfController* shelf_controller =
4246 test_launcher_controller.test_shelf_controller(); 4266 test_launcher_controller->test_shelf_controller();
4247 ASSERT_TRUE(shelf_controller); 4267 ASSERT_TRUE(shelf_controller);
4248 EXPECT_EQ(ash::SHELF_ALIGNMENT_LEFT, shelf_controller->alignment()); 4268 EXPECT_EQ(ash::SHELF_ALIGNMENT_LEFT, shelf_controller->alignment());
4249 EXPECT_EQ(1u, shelf_controller->alignment_change_count()); 4269 EXPECT_EQ(1u, shelf_controller->alignment_change_count());
4250 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, 4270 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
4251 shelf_controller->auto_hide()); 4271 shelf_controller->auto_hide());
4252 EXPECT_EQ(1u, shelf_controller->auto_hide_change_count()); 4272 EXPECT_EQ(1u, shelf_controller->auto_hide_change_count());
4253 } 4273 }
4254 4274
4255 // Tests that the shelf controller's changes are not wastefully echoed back. 4275 // Tests that the shelf controller's changes are not wastefully echoed back.
4256 TEST_F(ChromeLauncherControllerImplPrefTest, DoNotEchoShelfControllerChanges) { 4276 TEST_F(ChromeLauncherControllerImplTest, DoNotEchoShelfControllerChanges) {
4257 ash::ShelfModel* model = ash::Shell::Get()->shelf_controller()->model(); 4277 TestChromeLauncherControllerImpl* test_launcher_controller =
4258 TestChromeLauncherControllerImpl test_launcher_controller(profile(), model); 4278 shell_delegate_->CreateTestLauncherController(profile());
4259 test_launcher_controller.Init();
4260 4279
4261 // Simulate login for the test controller. 4280 // Simulate login for the test controller.
4262 test_launcher_controller.ReleaseProfile(); 4281 test_launcher_controller->ReleaseProfile();
4263 test_launcher_controller.AttachProfile(profile()); 4282 test_launcher_controller->AttachProfile(profile());
4264 base::RunLoop().RunUntilIdle(); 4283 base::RunLoop().RunUntilIdle();
4265 4284
4266 TestShelfController* shelf_controller = 4285 TestShelfController* shelf_controller =
4267 test_launcher_controller.test_shelf_controller(); 4286 test_launcher_controller->test_shelf_controller();
4268 ASSERT_TRUE(shelf_controller); 4287 ASSERT_TRUE(shelf_controller);
4269 EXPECT_EQ(ash::SHELF_ALIGNMENT_BOTTOM, shelf_controller->alignment()); 4288 EXPECT_EQ(ash::SHELF_ALIGNMENT_BOTTOM, shelf_controller->alignment());
4270 EXPECT_EQ(1u, shelf_controller->alignment_change_count()); 4289 EXPECT_EQ(1u, shelf_controller->alignment_change_count());
4271 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf_controller->auto_hide()); 4290 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf_controller->auto_hide());
4272 EXPECT_EQ(1u, shelf_controller->auto_hide_change_count()); 4291 EXPECT_EQ(1u, shelf_controller->auto_hide_change_count());
4273 4292
4274 // Changing settings via the shelf controller causes the launcher controller 4293 // Changing settings via the shelf controller causes the launcher controller
4275 // to update profile prefs. The launcher controller's prefs observation should 4294 // to update profile prefs. The launcher controller's prefs observation should
4276 // not cause those same changes to be echoed back to the shelf controller. 4295 // not cause those same changes to be echoed back to the shelf controller.
4277 int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 4296 int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
4278 shelf_controller->SetAlignment(ash::SHELF_ALIGNMENT_LEFT, display_id); 4297 shelf_controller->SetAlignment(ash::SHELF_ALIGNMENT_LEFT, display_id);
4279 EXPECT_EQ(2u, shelf_controller->alignment_change_count()); 4298 EXPECT_EQ(2u, shelf_controller->alignment_change_count());
4280 shelf_controller->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, 4299 shelf_controller->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
4281 display_id); 4300 display_id);
4282 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count()); 4301 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count());
4283 base::RunLoop().RunUntilIdle(); 4302 base::RunLoop().RunUntilIdle();
4284 4303
4285 EXPECT_EQ(ash::SHELF_ALIGNMENT_LEFT, shelf_controller->alignment()); 4304 EXPECT_EQ(ash::SHELF_ALIGNMENT_LEFT, shelf_controller->alignment());
4286 EXPECT_EQ(2u, shelf_controller->alignment_change_count()); 4305 EXPECT_EQ(2u, shelf_controller->alignment_change_count());
4287 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, 4306 EXPECT_EQ(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
4288 shelf_controller->auto_hide()); 4307 shelf_controller->auto_hide());
4289 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count()); 4308 EXPECT_EQ(2u, shelf_controller->auto_hide_change_count());
4290 4309
4291 PrefService* prefs = profile()->GetTestingPrefService(); 4310 PrefService* prefs = profile()->GetTestingPrefService();
4292 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignmentLocal)); 4311 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignmentLocal));
4293 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignment)); 4312 EXPECT_EQ("Left", prefs->GetString(prefs::kShelfAlignment));
4294 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehaviorLocal)); 4313 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehaviorLocal));
4295 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehavior)); 4314 EXPECT_EQ("Always", prefs->GetString(prefs::kShelfAutoHideBehavior));
4296 } 4315 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698