| OLD | NEW |
| 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/common/wm/screen_dimmer.h" | 5 #include "ash/common/wm/screen_dimmer.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/common/window_user_data.h" |
| 9 #include "ash/common/wm/window_dimmer.h" | 10 #include "ash/common/wm/window_dimmer.h" |
| 10 #include "ash/common/wm_shell.h" | |
| 11 #include "ash/common/wm_window.h" | 11 #include "ash/common/wm_window.h" |
| 12 #include "ash/common/wm_window_user_data.h" | |
| 13 #include "ash/root_window_controller.h" | 12 #include "ash/root_window_controller.h" |
| 14 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 15 #include "ash/test/ash_test_base.h" | 14 #include "ash/test/ash_test_base.h" |
| 16 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 17 #include "ui/aura/test/test_windows.h" | 16 #include "ui/aura/test/test_windows.h" |
| 18 #include "ui/compositor/layer.h" | 17 #include "ui/compositor/layer.h" |
| 19 | 18 |
| 20 namespace ash { | 19 namespace ash { |
| 21 namespace test { | 20 namespace test { |
| 22 | 21 |
| 23 class ScreenDimmerTest : public AshTestBase { | 22 class ScreenDimmerTest : public AshTestBase { |
| 24 public: | 23 public: |
| 25 ScreenDimmerTest() {} | 24 ScreenDimmerTest() {} |
| 26 ~ScreenDimmerTest() override {} | 25 ~ScreenDimmerTest() override {} |
| 27 | 26 |
| 28 void SetUp() override { | 27 void SetUp() override { |
| 29 AshTestBase::SetUp(); | 28 AshTestBase::SetUp(); |
| 30 dimmer_ = base::MakeUnique<ScreenDimmer>(ScreenDimmer::Container::ROOT); | 29 dimmer_ = base::MakeUnique<ScreenDimmer>(ScreenDimmer::Container::ROOT); |
| 31 } | 30 } |
| 32 | 31 |
| 33 void TearDown() override { | 32 void TearDown() override { |
| 34 dimmer_.reset(); | 33 dimmer_.reset(); |
| 35 AshTestBase::TearDown(); | 34 AshTestBase::TearDown(); |
| 36 } | 35 } |
| 37 | 36 |
| 38 aura::Window* GetDimWindow() { | 37 aura::Window* GetDimWindow() { |
| 39 WindowDimmer* window_dimmer = | 38 WindowDimmer* window_dimmer = |
| 40 dimmer_->window_dimmers_->Get(WmShell::Get()->GetPrimaryRootWindow()); | 39 dimmer_->window_dimmers_->Get(Shell::GetPrimaryRootWindow()); |
| 41 return window_dimmer ? WmWindow::GetAuraWindow(window_dimmer->window()) | 40 return window_dimmer ? window_dimmer->window() : nullptr; |
| 42 : nullptr; | |
| 43 } | 41 } |
| 44 | 42 |
| 45 ui::Layer* GetDimWindowLayer() { | 43 ui::Layer* GetDimWindowLayer() { |
| 46 aura::Window* window = GetDimWindow(); | 44 aura::Window* window = GetDimWindow(); |
| 47 return window ? window->layer() : nullptr; | 45 return window ? window->layer() : nullptr; |
| 48 } | 46 } |
| 49 | 47 |
| 50 protected: | 48 protected: |
| 51 std::unique_ptr<ScreenDimmer> dimmer_; | 49 std::unique_ptr<ScreenDimmer> dimmer_; |
| 52 | 50 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 AshTestBase::TearDown(); | 123 AshTestBase::TearDown(); |
| 126 // ScreenDimmer is destroyed *after* the shell. | 124 // ScreenDimmer is destroyed *after* the shell. |
| 127 } | 125 } |
| 128 | 126 |
| 129 private: | 127 private: |
| 130 DISALLOW_COPY_AND_ASSIGN(ScreenDimmerShellDestructionTest); | 128 DISALLOW_COPY_AND_ASSIGN(ScreenDimmerShellDestructionTest); |
| 131 }; | 129 }; |
| 132 | 130 |
| 133 // This test verifies ScreenDimmer can be destroyed after the shell. The | 131 // This test verifies ScreenDimmer can be destroyed after the shell. The |
| 134 // interesting part of this test is in TearDown(), which creates a ScreenDimmer | 132 // interesting part of this test is in TearDown(), which creates a ScreenDimmer |
| 135 // that is deleted after WmShell. | 133 // that is deleted after Shell. |
| 136 TEST_F(ScreenDimmerShellDestructionTest, DontCrashIfScreenDimmerOutlivesShell) { | 134 TEST_F(ScreenDimmerShellDestructionTest, DontCrashIfScreenDimmerOutlivesShell) { |
| 137 } | 135 } |
| 138 | 136 |
| 139 } // namespace test | 137 } // namespace test |
| 140 } // namespace ash | 138 } // namespace ash |
| OLD | NEW |