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

Side by Side Diff: ash/wm/screen_dimmer_unittest.cc

Issue 2332893002: Changes ownership of ScreenDimmer (Closed)
Patch Set: merge to tot Created 4 years, 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/wm/screen_dimmer.h" 5 #include "ash/wm/screen_dimmer.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "ash/aura/wm_window_aura.h" 9 #include "ash/aura/wm_window_aura.h"
10 #include "ash/common/wm/window_dimmer.h" 10 #include "ash/common/wm/window_dimmer.h"
11 #include "ash/common/wm_shell.h" 11 #include "ash/common/wm_shell.h"
12 #include "ash/common/wm_window_user_data.h" 12 #include "ash/common/wm_window_user_data.h"
13 #include "ash/root_window_controller.h" 13 #include "ash/root_window_controller.h"
14 #include "ash/shell.h" 14 #include "ash/shell.h"
15 #include "ash/test/ash_test_base.h" 15 #include "ash/test/ash_test_base.h"
16 #include "base/memory/ptr_util.h"
16 #include "ui/aura/test/test_windows.h" 17 #include "ui/aura/test/test_windows.h"
17 #include "ui/compositor/layer.h" 18 #include "ui/compositor/layer.h"
18 19
19 namespace ash { 20 namespace ash {
20 namespace test { 21 namespace test {
21 22
22 class ScreenDimmerTest : public AshTestBase { 23 class ScreenDimmerTest : public AshTestBase {
23 public: 24 public:
24 ScreenDimmerTest() : dimmer_(nullptr) {} 25 ScreenDimmerTest() {}
25 ~ScreenDimmerTest() override {} 26 ~ScreenDimmerTest() override {}
26 27
27 void SetUp() override { 28 void SetUp() override {
28 AshTestBase::SetUp(); 29 AshTestBase::SetUp();
29 dimmer_ = ScreenDimmer::GetForRoot(); 30 dimmer_ = base::MakeUnique<ScreenDimmer>(ScreenDimmer::Container::ROOT);
31 }
32
33 void TearDown() override {
34 dimmer_.reset();
35 AshTestBase::TearDown();
30 } 36 }
31 37
32 aura::Window* GetDimWindow() { 38 aura::Window* GetDimWindow() {
33 WindowDimmer* window_dimmer = 39 WindowDimmer* window_dimmer =
34 dimmer_->window_dimmers_->Get(WmShell::Get()->GetPrimaryRootWindow()); 40 dimmer_->window_dimmers_->Get(WmShell::Get()->GetPrimaryRootWindow());
35 return window_dimmer ? WmWindowAura::GetAuraWindow(window_dimmer->window()) 41 return window_dimmer ? WmWindowAura::GetAuraWindow(window_dimmer->window())
36 : nullptr; 42 : nullptr;
37 } 43 }
38 44
39 ui::Layer* GetDimWindowLayer() { 45 ui::Layer* GetDimWindowLayer() {
40 aura::Window* window = GetDimWindow(); 46 aura::Window* window = GetDimWindow();
41 return window ? window->layer() : nullptr; 47 return window ? window->layer() : nullptr;
42 } 48 }
43 49
44 protected: 50 protected:
45 ScreenDimmer* dimmer_; // not owned 51 std::unique_ptr<ScreenDimmer> dimmer_;
46 52
47 private: 53 private:
48 DISALLOW_COPY_AND_ASSIGN(ScreenDimmerTest); 54 DISALLOW_COPY_AND_ASSIGN(ScreenDimmerTest);
49 }; 55 };
50 56
51 TEST_F(ScreenDimmerTest, DimAndUndim) { 57 TEST_F(ScreenDimmerTest, DimAndUndim) {
52 // Don't create a layer until we need to. 58 // Don't create a layer until we need to.
53 EXPECT_EQ(nullptr, GetDimWindowLayer()); 59 EXPECT_EQ(nullptr, GetDimWindowLayer());
54 dimmer_->SetDimming(false); 60 dimmer_->SetDimming(false);
55 EXPECT_EQ(nullptr, GetDimWindowLayer()); 61 EXPECT_EQ(nullptr, GetDimWindowLayer());
(...skipping 28 matching lines...) Expand all
84 EXPECT_EQ(gfx::Rect(root_layer->bounds().size()).ToString(), 90 EXPECT_EQ(gfx::Rect(root_layer->bounds().size()).ToString(),
85 dimming_layer->bounds().ToString()); 91 dimming_layer->bounds().ToString());
86 92
87 // When we resize the root window, the dimming layer should be resized to 93 // When we resize the root window, the dimming layer should be resized to
88 // match. 94 // match.
89 gfx::Rect kNewBounds(400, 300); 95 gfx::Rect kNewBounds(400, 300);
90 Shell::GetPrimaryRootWindow()->GetHost()->SetBounds(kNewBounds); 96 Shell::GetPrimaryRootWindow()->GetHost()->SetBounds(kNewBounds);
91 EXPECT_EQ(kNewBounds.ToString(), dimming_layer->bounds().ToString()); 97 EXPECT_EQ(kNewBounds.ToString(), dimming_layer->bounds().ToString());
92 } 98 }
93 99
94 TEST_F(ScreenDimmerTest, RootDimmer) {
95 ScreenDimmer* root_dimmer = ScreenDimmer::GetForRoot();
96 // -100 is the magic number for root window.
97 EXPECT_EQ(root_dimmer, ScreenDimmer::FindForTest(-100));
98 EXPECT_EQ(nullptr, ScreenDimmer::FindForTest(-1));
99 }
100
101 TEST_F(ScreenDimmerTest, DimAtBottom) { 100 TEST_F(ScreenDimmerTest, DimAtBottom) {
102 ScreenDimmer* root_dimmer = ScreenDimmer::GetForRoot();
103 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 101 aura::Window* root_window = Shell::GetPrimaryRootWindow();
104 std::unique_ptr<aura::Window> window( 102 std::unique_ptr<aura::Window> window(
105 aura::test::CreateTestWindowWithId(1, root_window)); 103 aura::test::CreateTestWindowWithId(1, root_window));
106 root_dimmer->SetDimming(true); 104 dimmer_->SetDimming(true);
107 std::vector<aura::Window*>::const_iterator dim_iter = 105 std::vector<aura::Window*>::const_iterator dim_iter =
108 std::find(root_window->children().begin(), root_window->children().end(), 106 std::find(root_window->children().begin(), root_window->children().end(),
109 GetDimWindow()); 107 GetDimWindow());
110 ASSERT_TRUE(dim_iter != root_window->children().end()); 108 ASSERT_TRUE(dim_iter != root_window->children().end());
111 // Dim layer is at top. 109 // Dim layer is at top.
112 EXPECT_EQ(*dim_iter, *root_window->children().rbegin()); 110 EXPECT_EQ(*dim_iter, *root_window->children().rbegin());
113 111
114 root_dimmer->SetDimming(false); 112 dimmer_->SetDimming(false);
115 root_dimmer->set_at_bottom(true); 113 dimmer_->set_at_bottom(true);
116 root_dimmer->SetDimming(true); 114 dimmer_->SetDimming(true);
117 115
118 dim_iter = std::find(root_window->children().begin(), 116 dim_iter = std::find(root_window->children().begin(),
119 root_window->children().end(), GetDimWindow()); 117 root_window->children().end(), GetDimWindow());
120 ASSERT_TRUE(dim_iter != root_window->children().end()); 118 ASSERT_TRUE(dim_iter != root_window->children().end());
121 // Dom layer is at the bottom. 119 // Dom layer is at the bottom.
122 EXPECT_EQ(*dim_iter, *root_window->children().begin()); 120 EXPECT_EQ(*dim_iter, *root_window->children().begin());
123 } 121 }
124 122
125 } // namespace test 123 } // namespace test
126 } // namespace ash 124 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/screen_dimmer.cc ('k') | chrome/browser/chromeos/dbus/chrome_display_power_service_provider_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698