File: visibility_controller_unittest.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (114 lines) | stat: -rw-r--r-- 4,602 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/wm/core/visibility_controller.h"

#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/wm/core/window_animations.h"

namespace wm {

typedef aura::test::AuraTestBase VisibilityControllerTest;

// Check that a transparency change to 0 will not cause a hide call to be
// ignored.
TEST_F(VisibilityControllerTest, AnimateTransparencyToZeroAndHideHides) {
  // We cannot disable animations for this test.
  ui::ScopedAnimationDurationScaleMode test_duration_mode(
      ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);

  VisibilityController controller;
  aura::client::SetVisibilityClient(root_window(), &controller);

  SetChildWindowVisibilityChangesAnimated(root_window());

  aura::test::TestWindowDelegate d;
  std::unique_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
      &d, -2, gfx::Rect(0, 0, 50, 50), root_window()));
  ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
  settings.SetTransitionDuration(base::Milliseconds(5));

  EXPECT_TRUE(window->layer()->visible());
  EXPECT_TRUE(window->IsVisible());

  window->layer()->SetOpacity(0.0);
  EXPECT_TRUE(window->layer()->visible());
  EXPECT_TRUE(window->IsVisible());
  EXPECT_TRUE(window->layer()->GetAnimator()->
      IsAnimatingProperty(ui::LayerAnimationElement::OPACITY));
  EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity());

  // Check that the visibility is correct after the hide animation has finished.
  window->Hide();
  window->layer()->GetAnimator()->StopAnimating();
  EXPECT_FALSE(window->layer()->visible());
  EXPECT_FALSE(window->IsVisible());
}

// Check that a hiding animation would not change a window's bounds in screen.
TEST_F(VisibilityControllerTest, HideAnimationWindowBoundsTest) {
  // We cannot disable animations for this test.
  ui::ScopedAnimationDurationScaleMode test_duration_mode(
      ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);

  VisibilityController controller;
  aura::client::SetVisibilityClient(root_window(), &controller);

  // Set bound expectation.
  gfx::Rect expected_bounds(4, 5, 123, 245);
  aura::test::TestWindowDelegate d;
  std::unique_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
      &d, -2, expected_bounds, root_window()));
  window->Show();
  SetWindowVisibilityChangesAnimated(window.get());
  SetWindowVisibilityAnimationDuration(window.get(), base::Milliseconds(5));
  SetWindowVisibilityAnimationType(window.get(),
                                   WINDOW_VISIBILITY_ANIMATION_TYPE_DROP);
  // Check that the bound is correct after the hide animation has finished.
  window->Hide();
  window->layer()->GetAnimator()->StopAnimating();
  EXPECT_EQ(expected_bounds, window->GetBoundsInScreen());
}

// Test if SetWindowVisibilityChagngesAnimated will animate the specified
// window.
TEST_F(VisibilityControllerTest, SetWindowVisibilityChagnesAnimated) {
  // We cannot disable animations for this test.
  ui::ScopedAnimationDurationScaleMode test_duration_mode(
      ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);

  VisibilityController controller;
  aura::client::SetVisibilityClient(root_window(), &controller);

  aura::test::TestWindowDelegate d;
  std::unique_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
      &d, -2, gfx::Rect(0, 0, 50, 50), root_window()));
  // Test using Show animation because Hide animation detaches the window's
  // layer.
  window->Hide();
  ASSERT_FALSE(window->IsVisible());

  SetWindowVisibilityChangesAnimated(window.get());
  SetWindowVisibilityAnimationDuration(window.get(), base::Milliseconds(5));
  SetWindowVisibilityAnimationType(window.get(),
                                   WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
  window->Show();
  EXPECT_TRUE(window->layer()->GetAnimator()->is_animating());
  EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity());
  EXPECT_EQ(0.0f, window->layer()->opacity());

  window->layer()->GetAnimator()->StopAnimating();
  EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity());
  EXPECT_EQ(1.0f, window->layer()->opacity());
}

}  // namespace wm