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 "ui/views/corewm/shadow_controller.h" | 5 #include "ui/views/corewm/shadow_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "ui/aura/client/activation_client.h" | 11 #include "ui/aura/client/activation_client.h" |
12 #include "ui/aura/client/window_tree_client.h" | 12 #include "ui/aura/client/window_tree_client.h" |
13 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
14 #include "ui/aura/test/aura_test_base.h" | |
15 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
16 #include "ui/compositor/layer.h" | 15 #include "ui/compositor/layer.h" |
17 #include "ui/views/corewm/shadow.h" | 16 #include "ui/views/corewm/shadow.h" |
18 #include "ui/views/corewm/shadow_types.h" | 17 #include "ui/views/corewm/shadow_types.h" |
| 18 #include "ui/views/corewm/transient_window_manager.h" |
| 19 #include "ui/views/test/views_test_base.h" |
19 | 20 |
20 namespace views { | 21 namespace views { |
21 namespace corewm { | 22 namespace corewm { |
22 | 23 |
23 class ShadowControllerTest : public aura::test::AuraTestBase { | 24 class ShadowControllerTest : public ViewsTestBase { |
24 public: | 25 public: |
25 ShadowControllerTest() {} | 26 ShadowControllerTest() {} |
26 virtual ~ShadowControllerTest() {} | 27 virtual ~ShadowControllerTest() {} |
27 | 28 |
28 virtual void SetUp() OVERRIDE { | 29 virtual void SetUp() OVERRIDE { |
29 AuraTestBase::SetUp(); | 30 ViewsTestBase::SetUp(); |
30 aura::client::ActivationClient* activation_client = | 31 aura::client::ActivationClient* activation_client = |
31 aura::client::GetActivationClient(root_window()); | 32 aura::client::GetActivationClient(GetContext()); |
32 shadow_controller_.reset(new ShadowController(activation_client)); | 33 shadow_controller_.reset(new ShadowController(activation_client)); |
33 } | 34 } |
34 virtual void TearDown() OVERRIDE { | 35 virtual void TearDown() OVERRIDE { |
35 shadow_controller_.reset(); | 36 shadow_controller_.reset(); |
36 AuraTestBase::TearDown(); | 37 ViewsTestBase::TearDown(); |
37 } | 38 } |
38 | 39 |
39 protected: | 40 protected: |
40 ShadowController* shadow_controller() { return shadow_controller_.get(); } | 41 ShadowController* shadow_controller() { return shadow_controller_.get(); } |
41 | 42 |
42 void ActivateWindow(aura::Window* window) { | 43 void ActivateWindow(aura::Window* window) { |
43 DCHECK(window); | 44 DCHECK(window); |
44 DCHECK(window->GetRootWindow()); | 45 DCHECK(window->GetRootWindow()); |
45 aura::client::GetActivationClient(window->GetRootWindow())->ActivateWindow( | 46 aura::client::GetActivationClient(window->GetRootWindow())->ActivateWindow( |
46 window); | 47 window); |
47 } | 48 } |
48 | 49 |
| 50 void ParentWindow(aura::Window* window) { |
| 51 aura::client::ParentWindowWithContext(window, GetContext(), gfx::Rect()); |
| 52 } |
| 53 |
49 private: | 54 private: |
50 scoped_ptr<ShadowController> shadow_controller_; | 55 scoped_ptr<ShadowController> shadow_controller_; |
51 | 56 |
52 DISALLOW_COPY_AND_ASSIGN(ShadowControllerTest); | 57 DISALLOW_COPY_AND_ASSIGN(ShadowControllerTest); |
53 }; | 58 }; |
54 | 59 |
55 // Tests that various methods in Window update the Shadow object as expected. | 60 // Tests that various methods in Window update the Shadow object as expected. |
56 TEST_F(ShadowControllerTest, Shadow) { | 61 TEST_F(ShadowControllerTest, Shadow) { |
57 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 62 scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
58 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | 63 window->SetType(aura::client::WINDOW_TYPE_NORMAL); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); | 199 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); |
195 | 200 |
196 // Create a window that is transient to window1, and that has the 'hide on | 201 // Create a window that is transient to window1, and that has the 'hide on |
197 // deactivate' property set. Upon activation, window1 should still have an | 202 // deactivate' property set. Upon activation, window1 should still have an |
198 // active shadow. | 203 // active shadow. |
199 scoped_ptr<aura::Window> window2(new aura::Window(NULL)); | 204 scoped_ptr<aura::Window> window2(new aura::Window(NULL)); |
200 window2->SetType(aura::client::WINDOW_TYPE_NORMAL); | 205 window2->SetType(aura::client::WINDOW_TYPE_NORMAL); |
201 window2->Init(ui::LAYER_TEXTURED); | 206 window2->Init(ui::LAYER_TEXTURED); |
202 ParentWindow(window2.get()); | 207 ParentWindow(window2.get()); |
203 window2->SetBounds(gfx::Rect(11, 21, 301, 401)); | 208 window2->SetBounds(gfx::Rect(11, 21, 301, 401)); |
204 window1->AddTransientChild(window2.get()); | 209 AddTransientChild(window1.get(), window2.get()); |
205 aura::client::SetHideOnDeactivate(window2.get(), true); | 210 aura::client::SetHideOnDeactivate(window2.get(), true); |
206 window2->Show(); | 211 window2->Show(); |
207 ActivateWindow(window2.get()); | 212 ActivateWindow(window2.get()); |
208 | 213 |
209 // window1 is now inactive, but its shadow should still appear active. | 214 // window1 is now inactive, but its shadow should still appear active. |
210 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); | 215 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); |
211 } | 216 } |
212 | 217 |
213 } // namespace corewm | 218 } // namespace corewm |
214 } // namespace views | 219 } // namespace views |
OLD | NEW |