OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/aura/window.h" | 5 #include "ui/aura/window.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 return CreateTestWindowWithDelegate(new ColorTestWindowDelegate(color), | 173 return CreateTestWindowWithDelegate(new ColorTestWindowDelegate(color), |
174 id, bounds, parent); | 174 id, bounds, parent); |
175 } | 175 } |
176 | 176 |
177 Window* CreateTestWindowWithDelegate(WindowDelegate* delegate, | 177 Window* CreateTestWindowWithDelegate(WindowDelegate* delegate, |
178 int id, | 178 int id, |
179 const gfx::Rect& bounds, | 179 const gfx::Rect& bounds, |
180 Window* parent) { | 180 Window* parent) { |
181 Window* window = new Window(delegate); | 181 Window* window = new Window(delegate); |
182 window->set_id(id); | 182 window->set_id(id); |
183 window->Init(ui::Layer::LAYER_HAS_TEXTURE); | 183 window->Init(ui::Layer::LAYER_HAS_TEXTURE, |
| 184 Window::LAYER_INITIALLY_INVISIBLE); |
184 window->SetBounds(bounds); | 185 window->SetBounds(bounds); |
185 window->Show(); | 186 window->Show(); |
186 window->SetParent(parent); | 187 window->SetParent(parent); |
187 return window; | 188 return window; |
188 } | 189 } |
189 | 190 |
190 private: | 191 private: |
191 DISALLOW_COPY_AND_ASSIGN(WindowTest); | 192 DISALLOW_COPY_AND_ASSIGN(WindowTest); |
192 }; | 193 }; |
193 | 194 |
194 } // namespace | 195 } // namespace |
195 | 196 |
196 TEST_F(WindowTest, GetChildById) { | 197 TEST_F(WindowTest, GetChildById) { |
197 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); | 198 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); |
198 scoped_ptr<Window> w11(CreateTestWindowWithId(11, w1.get())); | 199 scoped_ptr<Window> w11(CreateTestWindowWithId(11, w1.get())); |
199 scoped_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); | 200 scoped_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); |
200 scoped_ptr<Window> w12(CreateTestWindowWithId(12, w1.get())); | 201 scoped_ptr<Window> w12(CreateTestWindowWithId(12, w1.get())); |
201 | 202 |
202 EXPECT_EQ(NULL, w1->GetChildById(57)); | 203 EXPECT_EQ(NULL, w1->GetChildById(57)); |
203 EXPECT_EQ(w12.get(), w1->GetChildById(12)); | 204 EXPECT_EQ(w12.get(), w1->GetChildById(12)); |
204 EXPECT_EQ(w111.get(), w1->GetChildById(111)); | 205 EXPECT_EQ(w111.get(), w1->GetChildById(111)); |
205 } | 206 } |
206 | 207 |
207 TEST_F(WindowTest, HitTest) { | 208 TEST_F(WindowTest, HitTest) { |
208 Window w1(new ColorTestWindowDelegate(SK_ColorWHITE)); | 209 Window w1(new ColorTestWindowDelegate(SK_ColorWHITE)); |
209 w1.set_id(1); | 210 w1.set_id(1); |
210 w1.Init(ui::Layer::LAYER_HAS_TEXTURE); | 211 w1.Init(ui::Layer::LAYER_HAS_TEXTURE, Window::LAYER_INITIALLY_INVISIBLE); |
211 w1.SetBounds(gfx::Rect(10, 10, 50, 50)); | 212 w1.SetBounds(gfx::Rect(10, 10, 50, 50)); |
212 w1.Show(); | 213 w1.Show(); |
213 w1.SetParent(NULL); | 214 w1.SetParent(NULL); |
214 | 215 |
215 // Points are in the Window's coordinates. | 216 // Points are in the Window's coordinates. |
216 EXPECT_TRUE(w1.HitTest(gfx::Point(1, 1))); | 217 EXPECT_TRUE(w1.HitTest(gfx::Point(1, 1))); |
217 EXPECT_FALSE(w1.HitTest(gfx::Point(-1, -1))); | 218 EXPECT_FALSE(w1.HitTest(gfx::Point(-1, -1))); |
218 | 219 |
219 // TODO(beng): clip Window to parent. | 220 // TODO(beng): clip Window to parent. |
220 } | 221 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 // Both the parent and child should have been destroyed. | 351 // Both the parent and child should have been destroyed. |
351 EXPECT_EQ(1, parent_delegate.destroying_count()); | 352 EXPECT_EQ(1, parent_delegate.destroying_count()); |
352 EXPECT_EQ(1, parent_delegate.destroyed_count()); | 353 EXPECT_EQ(1, parent_delegate.destroyed_count()); |
353 EXPECT_EQ(1, child_delegate.destroying_count()); | 354 EXPECT_EQ(1, child_delegate.destroying_count()); |
354 EXPECT_EQ(1, child_delegate.destroyed_count()); | 355 EXPECT_EQ(1, child_delegate.destroyed_count()); |
355 } | 356 } |
356 | 357 |
357 // Make sure MoveChildToFront moves both the window and layer to the front. | 358 // Make sure MoveChildToFront moves both the window and layer to the front. |
358 TEST_F(WindowTest, MoveChildToFront) { | 359 TEST_F(WindowTest, MoveChildToFront) { |
359 Window parent(NULL); | 360 Window parent(NULL); |
360 parent.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); | 361 parent.Init(ui::Layer::LAYER_HAS_NO_TEXTURE, |
| 362 Window::LAYER_INITIALLY_INVISIBLE); |
361 Window child1(NULL); | 363 Window child1(NULL); |
362 child1.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); | 364 child1.Init(ui::Layer::LAYER_HAS_NO_TEXTURE, |
| 365 Window::LAYER_INITIALLY_INVISIBLE); |
363 Window child2(NULL); | 366 Window child2(NULL); |
364 child2.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); | 367 child2.Init(ui::Layer::LAYER_HAS_NO_TEXTURE, |
| 368 Window::LAYER_INITIALLY_INVISIBLE); |
365 | 369 |
366 child1.SetParent(&parent); | 370 child1.SetParent(&parent); |
367 child2.SetParent(&parent); | 371 child2.SetParent(&parent); |
368 ASSERT_EQ(2u, parent.children().size()); | 372 ASSERT_EQ(2u, parent.children().size()); |
369 EXPECT_EQ(&child1, parent.children()[0]); | 373 EXPECT_EQ(&child1, parent.children()[0]); |
370 EXPECT_EQ(&child2, parent.children()[1]); | 374 EXPECT_EQ(&child2, parent.children()[1]); |
371 ASSERT_EQ(2u, parent.layer()->children().size()); | 375 ASSERT_EQ(2u, parent.layer()->children().size()); |
372 EXPECT_EQ(child1.layer(), parent.layer()->children()[0]); | 376 EXPECT_EQ(child1.layer(), parent.layer()->children()[0]); |
373 EXPECT_EQ(child2.layer(), parent.layer()->children()[1]); | 377 EXPECT_EQ(child2.layer(), parent.layer()->children()[1]); |
374 | 378 |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 EXPECT_EQ(w1.get(), parent->children()[1]); | 1051 EXPECT_EQ(w1.get(), parent->children()[1]); |
1048 } | 1052 } |
1049 | 1053 |
1050 class ToplevelWindowTest : public WindowTest { | 1054 class ToplevelWindowTest : public WindowTest { |
1051 public: | 1055 public: |
1052 ToplevelWindowTest() {} | 1056 ToplevelWindowTest() {} |
1053 virtual ~ToplevelWindowTest() {} | 1057 virtual ~ToplevelWindowTest() {} |
1054 | 1058 |
1055 virtual void SetUp() OVERRIDE { | 1059 virtual void SetUp() OVERRIDE { |
1056 WindowTest::SetUp(); | 1060 WindowTest::SetUp(); |
1057 toplevel_container_.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); | 1061 toplevel_container_.Init(ui::Layer::LAYER_HAS_NO_TEXTURE, |
| 1062 Window::LAYER_INITIALLY_INVISIBLE); |
1058 toplevel_container_.SetParent(aura::Desktop::GetInstance()); | 1063 toplevel_container_.SetParent(aura::Desktop::GetInstance()); |
1059 toplevel_container_.SetBounds( | 1064 toplevel_container_.SetBounds( |
1060 aura::Desktop::GetInstance()->bounds()); | 1065 aura::Desktop::GetInstance()->bounds()); |
1061 toplevel_container_.Show(); | 1066 toplevel_container_.Show(); |
1062 } | 1067 } |
1063 | 1068 |
1064 virtual void TearDown() OVERRIDE { | 1069 virtual void TearDown() OVERRIDE { |
1065 toplevel_container_.Hide(); | 1070 toplevel_container_.Hide(); |
1066 toplevel_container_.SetParent(NULL); | 1071 toplevel_container_.SetParent(NULL); |
1067 WindowTest::TearDown(); | 1072 WindowTest::TearDown(); |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1362 | 1367 |
1363 w3->Activate(); | 1368 w3->Activate(); |
1364 EXPECT_EQ(w2.get(), active()); | 1369 EXPECT_EQ(w2.get(), active()); |
1365 | 1370 |
1366 w1->Activate(); | 1371 w1->Activate(); |
1367 EXPECT_EQ(w1.get(), active()); | 1372 EXPECT_EQ(w1.get(), active()); |
1368 } | 1373 } |
1369 | 1374 |
1370 } // namespace test | 1375 } // namespace test |
1371 } // namespace aura | 1376 } // namespace aura |
OLD | NEW |