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

Side by Side Diff: ash/shelf/shelf_widget_unittest.cc

Issue 2889673002: chromeos: Refactor shelf to create ShelfView earlier in startup (Closed)
Patch Set: Move ShelfView to initializer list Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "ash/shelf/shelf_widget.h" 5 #include "ash/shelf/shelf_widget.h"
6 6
7 #include "ash/root_window_controller.h" 7 #include "ash/root_window_controller.h"
8 #include "ash/shelf/shelf_constants.h" 8 #include "ash/shelf/shelf_constants.h"
9 #include "ash/shelf/shelf_layout_manager.h" 9 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shelf/shelf_view.h" 10 #include "ash/shelf/shelf_view.h"
11 #include "ash/shelf/wm_shelf.h" 11 #include "ash/shelf/wm_shelf.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/shell_port.h" 13 #include "ash/shell_port.h"
14 #include "ash/system/status_area_widget.h" 14 #include "ash/system/status_area_widget.h"
15 #include "ash/test/ash_test_base.h" 15 #include "ash/test/ash_test_base.h"
16 #include "ash/test/ash_test_helper.h" 16 #include "ash/test/ash_test_helper.h"
17 #include "ash/test/shelf_view_test_api.h" 17 #include "ash/test/shelf_view_test_api.h"
18 #include "ash/test/test_shell_delegate.h"
18 #include "ash/wm/window_util.h" 19 #include "ash/wm/window_util.h"
19 #include "ash/wm_window.h" 20 #include "ash/wm_window.h"
20 #include "ui/aura/window_event_dispatcher.h" 21 #include "ui/aura/window_event_dispatcher.h"
21 #include "ui/display/display.h" 22 #include "ui/display/display.h"
22 #include "ui/events/event_utils.h" 23 #include "ui/events/event_utils.h"
23 #include "ui/views/view.h" 24 #include "ui/views/view.h"
24 #include "ui/views/widget/widget.h" 25 #include "ui/views/widget/widget.h"
25 26
26 namespace ash { 27 namespace ash {
27
28 namespace { 28 namespace {
29 29
30 ShelfWidget* GetShelfWidget() { 30 ShelfWidget* GetShelfWidget() {
31 return test::AshTestBase::GetPrimaryShelf()->shelf_widget(); 31 return test::AshTestBase::GetPrimaryShelf()->shelf_widget();
32 } 32 }
33 33
34 ShelfLayoutManager* GetShelfLayoutManager() { 34 ShelfLayoutManager* GetShelfLayoutManager() {
35 return GetShelfWidget()->shelf_layout_manager(); 35 return GetShelfWidget()->shelf_layout_manager();
36 } 36 }
37 37
38 } // namespace
39
40 using ShelfWidgetTest = test::AshTestBase;
41
42 void TestLauncherAlignment(WmWindow* root, 38 void TestLauncherAlignment(WmWindow* root,
43 ShelfAlignment alignment, 39 ShelfAlignment alignment,
44 const gfx::Rect& expected) { 40 const gfx::Rect& expected) {
45 root->GetRootWindowController()->GetShelf()->SetAlignment(alignment); 41 root->GetRootWindowController()->GetShelf()->SetAlignment(alignment);
46 EXPECT_EQ(expected.ToString(), 42 EXPECT_EQ(expected.ToString(),
47 root->GetDisplayNearestWindow().work_area().ToString()); 43 root->GetDisplayNearestWindow().work_area().ToString());
48 } 44 }
49 45
46 using ShelfWidgetTest = test::AshTestBase;
47
50 TEST_F(ShelfWidgetTest, TestAlignment) { 48 TEST_F(ShelfWidgetTest, TestAlignment) {
51 UpdateDisplay("400x400"); 49 UpdateDisplay("400x400");
52 { 50 {
53 SCOPED_TRACE("Single Bottom"); 51 SCOPED_TRACE("Single Bottom");
54 TestLauncherAlignment(ShellPort::Get()->GetPrimaryRootWindow(), 52 TestLauncherAlignment(ShellPort::Get()->GetPrimaryRootWindow(),
55 SHELF_ALIGNMENT_BOTTOM, gfx::Rect(0, 0, 400, 352)); 53 SHELF_ALIGNMENT_BOTTOM, gfx::Rect(0, 0, 400, 352));
56 } 54 }
57 { 55 {
58 SCOPED_TRACE("Single Locked"); 56 SCOPED_TRACE("Single Locked");
59 TestLauncherAlignment(ShellPort::Get()->GetPrimaryRootWindow(), 57 TestLauncherAlignment(ShellPort::Get()->GetPrimaryRootWindow(),
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 { 314 {
317 gfx::Point event_location(20, shelf_bounds.y() - 1); 315 gfx::Point event_location(20, shelf_bounds.y() - 1);
318 ui::TouchEvent touch( 316 ui::TouchEvent touch(
319 ui::ET_TOUCH_PRESSED, event_location, ui::EventTimeForNow(), 317 ui::ET_TOUCH_PRESSED, event_location, ui::EventTimeForNow(),
320 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0)); 318 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
321 EXPECT_EQ(shelf_widget->GetNativeWindow(), 319 EXPECT_EQ(shelf_widget->GetNativeWindow(),
322 targeter->FindTargetForEvent(root, &touch)); 320 targeter->FindTargetForEvent(root, &touch));
323 } 321 }
324 } 322 }
325 323
326 namespace { 324 class ShelfWidgetAfterLoginTest : public test::AshTestBase {
325 public:
326 ShelfWidgetAfterLoginTest() { set_start_session(false); }
327 ~ShelfWidgetAfterLoginTest() override = default;
327 328
328 // A ShellObserver that sets the shelf alignment and auto hide behavior when the 329 void TestShelf(ShelfAlignment alignment,
329 // shelf is created, to simulate ChromeLauncherController's behavior. 330 ShelfAutoHideBehavior auto_hide_behavior,
330 class ShelfInitializer : public ShellObserver { 331 ShelfVisibilityState expected_shelf_visibility_state,
331 public: 332 ShelfAutoHideState expected_shelf_auto_hide_state) {
332 ShelfInitializer(ShelfAlignment alignment, ShelfAutoHideBehavior auto_hide) 333 // Simulate login.
333 : alignment_(alignment), auto_hide_(auto_hide) {
334 Shell::Get()->AddShellObserver(this);
335 }
336 ~ShelfInitializer() override { Shell::Get()->RemoveShellObserver(this); }
337
338 // ShellObserver:
339 void OnShelfCreatedForRootWindow(WmWindow* root_window) override {
340 WmShelf* shelf = root_window->GetRootWindowController()->GetShelf();
341 shelf->SetAlignment(alignment_);
342 shelf->SetAutoHideBehavior(auto_hide_);
343 shelf->UpdateVisibilityState();
344 }
345
346 private:
347 ShelfAlignment alignment_;
348 ShelfAutoHideBehavior auto_hide_;
349
350 DISALLOW_COPY_AND_ASSIGN(ShelfInitializer);
351 };
352
353 class ShelfWidgetTestWithInitializer : public ShelfWidgetTest {
354 public:
355 ShelfWidgetTestWithInitializer() { set_start_session(false); }
356 ~ShelfWidgetTestWithInitializer() override {}
357
358 void TestCreateShelfWithInitialValues(
359 ShelfAlignment initial_alignment,
360 ShelfAutoHideBehavior initial_auto_hide_behavior,
361 ShelfVisibilityState expected_shelf_visibility_state,
362 ShelfAutoHideState expected_shelf_auto_hide_state) {
363 ShelfInitializer initializer(initial_alignment, initial_auto_hide_behavior);
364 SetUserLoggedIn(true); 334 SetUserLoggedIn(true);
365 SetSessionStarted(true); 335 SetSessionStarted(true);
366 336
337 // Shelf components are created.
msw 2017/05/16 22:42:00 Should this be disabling TestShellDelegate's Shelf
James Cook 2017/05/17 16:16:13 I added a new test to check the initial values and
367 ShelfWidget* shelf_widget = GetShelfWidget(); 338 ShelfWidget* shelf_widget = GetShelfWidget();
368 ASSERT_NE(nullptr, shelf_widget); 339 ASSERT_NE(nullptr, shelf_widget);
369 WmShelf* shelf = GetPrimaryShelf(); 340 WmShelf* shelf = GetPrimaryShelf();
370 ASSERT_NE(nullptr, shelf); 341 ASSERT_NE(nullptr, shelf);
371 ShelfLayoutManager* shelf_layout_manager = 342 ShelfLayoutManager* shelf_layout_manager =
372 shelf_widget->shelf_layout_manager(); 343 shelf_widget->shelf_layout_manager();
373 ASSERT_NE(nullptr, shelf_layout_manager); 344 ASSERT_NE(nullptr, shelf_layout_manager);
374 345
375 EXPECT_EQ(initial_alignment, shelf->alignment()); 346 // Simulate shelf settings being applied from profile prefs.
376 EXPECT_EQ(initial_auto_hide_behavior, shelf->auto_hide_behavior()); 347 shelf->SetAlignment(alignment);
348 shelf->SetAutoHideBehavior(auto_hide_behavior);
349 shelf->UpdateVisibilityState();
350
351 // Settings are applied correctly.
msw 2017/05/16 22:42:00 nit: "Ensure settings are applied correctly."
James Cook 2017/05/17 16:16:13 Done.
352 EXPECT_EQ(alignment, shelf->alignment());
353 EXPECT_EQ(auto_hide_behavior, shelf->auto_hide_behavior());
377 EXPECT_EQ(expected_shelf_visibility_state, 354 EXPECT_EQ(expected_shelf_visibility_state,
378 shelf_layout_manager->visibility_state()); 355 shelf_layout_manager->visibility_state());
379 EXPECT_EQ(expected_shelf_auto_hide_state, 356 EXPECT_EQ(expected_shelf_auto_hide_state,
380 shelf_layout_manager->auto_hide_state()); 357 shelf_layout_manager->auto_hide_state());
381 } 358 }
382 359
383 private: 360 private:
384 DISALLOW_COPY_AND_ASSIGN(ShelfWidgetTestWithInitializer); 361 DISALLOW_COPY_AND_ASSIGN(ShelfWidgetAfterLoginTest);
385 }; 362 };
386 363
387 } // namespace 364 TEST_F(ShelfWidgetAfterLoginTest, CreateAutoHideAlwaysShelf) {
388
389 TEST_F(ShelfWidgetTestWithInitializer, CreateAutoHideAlwaysShelf) {
390 // The actual auto hide state is shown because there are no open windows. 365 // The actual auto hide state is shown because there are no open windows.
391 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_BOTTOM, 366 TestShelf(SHELF_ALIGNMENT_BOTTOM, SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
392 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, 367 SHELF_AUTO_HIDE, SHELF_AUTO_HIDE_SHOWN);
393 SHELF_AUTO_HIDE, SHELF_AUTO_HIDE_SHOWN);
394 } 368 }
395 369
396 TEST_F(ShelfWidgetTestWithInitializer, CreateAutoHideNeverShelf) { 370 TEST_F(ShelfWidgetAfterLoginTest, CreateAutoHideNeverShelf) {
397 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. 371 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior.
398 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_LEFT, 372 TestShelf(SHELF_ALIGNMENT_LEFT, SHELF_AUTO_HIDE_BEHAVIOR_NEVER, SHELF_VISIBLE,
399 SHELF_AUTO_HIDE_BEHAVIOR_NEVER, 373 SHELF_AUTO_HIDE_HIDDEN);
400 SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN);
401 } 374 }
402 375
403 TEST_F(ShelfWidgetTestWithInitializer, CreateAutoHideAlwaysHideShelf) { 376 TEST_F(ShelfWidgetAfterLoginTest, CreateAutoHideAlwaysHideShelf) {
404 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. 377 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior.
405 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_RIGHT, 378 TestShelf(SHELF_ALIGNMENT_RIGHT, SHELF_AUTO_HIDE_ALWAYS_HIDDEN, SHELF_HIDDEN,
406 SHELF_AUTO_HIDE_ALWAYS_HIDDEN, SHELF_HIDDEN, 379 SHELF_AUTO_HIDE_HIDDEN);
407 SHELF_AUTO_HIDE_HIDDEN);
408 } 380 }
409 381
410 TEST_F(ShelfWidgetTestWithInitializer, CreateLockedShelf) { 382 TEST_F(ShelfWidgetAfterLoginTest, CreateLockedShelf) {
411 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. 383 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior.
412 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_BOTTOM_LOCKED, 384 TestShelf(SHELF_ALIGNMENT_BOTTOM_LOCKED, SHELF_AUTO_HIDE_BEHAVIOR_NEVER,
413 SHELF_AUTO_HIDE_BEHAVIOR_NEVER, 385 SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN);
414 SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN);
415 } 386 }
416 387
388 } // namespace
417 } // namespace ash 389 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698