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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/message_loop.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/aura/aura_test_base.h" |
9 #include "ui/aura/desktop.h" | 9 #include "ui/aura/desktop.h" |
10 #include "ui/aura/event.h" | 10 #include "ui/aura/event.h" |
11 #include "ui/aura/focus_manager.h" | 11 #include "ui/aura/focus_manager.h" |
12 #include "ui/aura/root_window.h" | 12 #include "ui/aura/root_window.h" |
13 #include "ui/aura/window_delegate.h" | 13 #include "ui/aura/window_delegate.h" |
14 #include "ui/gfx/canvas_skia.h" | 14 #include "ui/gfx/canvas_skia.h" |
15 #include "ui/gfx/compositor/layer.h" | 15 #include "ui/gfx/compositor/layer.h" |
16 #include "ui/base/keycodes/keyboard_codes.h" | 16 #include "ui/base/keycodes/keyboard_codes.h" |
17 | 17 |
18 #if !defined(OS_WIN) | 18 #if !defined(OS_WIN) |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 canvas->GetSkCanvas()->drawColor(color_, SkXfermode::kSrc_Mode); | 165 canvas->GetSkCanvas()->drawColor(color_, SkXfermode::kSrc_Mode); |
166 } | 166 } |
167 | 167 |
168 private: | 168 private: |
169 SkColor color_; | 169 SkColor color_; |
170 ui::KeyboardCode last_key_code_; | 170 ui::KeyboardCode last_key_code_; |
171 | 171 |
172 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate); | 172 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate); |
173 }; | 173 }; |
174 | 174 |
175 class WindowTest : public testing::Test { | 175 class WindowTest : public AuraTestBase { |
176 public: | 176 public: |
177 WindowTest() : main_message_loop(MessageLoop::TYPE_UI) { | 177 WindowTest() {} |
178 Desktop::GetInstance()->Show(); | |
179 Desktop::GetInstance()->SetSize(gfx::Size(500, 500)); | |
180 if (!Desktop::GetInstance()->default_parent()) | |
181 Desktop::GetInstance()->CreateDefaultParentForTesting(); | |
182 } | |
183 virtual ~WindowTest() {} | 178 virtual ~WindowTest() {} |
184 | 179 |
185 // Overridden from testing::Test: | |
186 virtual void SetUp() OVERRIDE { | |
187 } | |
188 | |
189 virtual void TearDown() OVERRIDE { | |
190 } | |
191 | |
192 Window* CreateTestWindowWithId(int id, Window* parent) { | 180 Window* CreateTestWindowWithId(int id, Window* parent) { |
193 return CreateTestWindowWithDelegate(NULL, id, gfx::Rect(), parent); | 181 return CreateTestWindowWithDelegate(NULL, id, gfx::Rect(), parent); |
194 } | 182 } |
195 | 183 |
196 Window* CreateTestWindow(SkColor color, | 184 Window* CreateTestWindow(SkColor color, |
197 int id, | 185 int id, |
198 const gfx::Rect& bounds, | 186 const gfx::Rect& bounds, |
199 Window* parent) { | 187 Window* parent) { |
200 return CreateTestWindowWithDelegate(new TestWindowDelegate(color), | 188 return CreateTestWindowWithDelegate(new TestWindowDelegate(color), |
201 id, bounds, parent); | 189 id, bounds, parent); |
202 } | 190 } |
203 | 191 |
204 Window* CreateTestWindowWithDelegate(WindowDelegate* delegate, | 192 Window* CreateTestWindowWithDelegate(WindowDelegate* delegate, |
205 int id, | 193 int id, |
206 const gfx::Rect& bounds, | 194 const gfx::Rect& bounds, |
207 Window* parent) { | 195 Window* parent) { |
208 Window* window = new Window(delegate); | 196 Window* window = new Window(delegate); |
209 window->set_id(id); | 197 window->set_id(id); |
210 window->Init(); | 198 window->Init(); |
211 window->SetBounds(bounds); | 199 window->SetBounds(bounds); |
212 window->Show(); | 200 window->Show(); |
213 window->SetParent(parent); | 201 window->SetParent(parent); |
214 return window; | 202 return window; |
215 } | 203 } |
216 | 204 |
217 private: | 205 private: |
218 MessageLoop main_message_loop; | |
219 | |
220 DISALLOW_COPY_AND_ASSIGN(WindowTest); | 206 DISALLOW_COPY_AND_ASSIGN(WindowTest); |
221 }; | 207 }; |
222 | 208 |
223 } // namespace | 209 } // namespace |
224 | 210 |
225 TEST_F(WindowTest, GetChildById) { | 211 TEST_F(WindowTest, GetChildById) { |
226 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); | 212 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); |
227 scoped_ptr<Window> w11(CreateTestWindowWithId(11, w1.get())); | 213 scoped_ptr<Window> w11(CreateTestWindowWithId(11, w1.get())); |
228 scoped_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); | 214 scoped_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); |
229 scoped_ptr<Window> w12(CreateTestWindowWithId(12, w1.get())); | 215 scoped_ptr<Window> w12(CreateTestWindowWithId(12, w1.get())); |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 | 746 |
761 // Dectivate w1 and make sure w2 becomes active and frontmost. | 747 // Dectivate w1 and make sure w2 becomes active and frontmost. |
762 w1->Deactivate(); | 748 w1->Deactivate(); |
763 EXPECT_FALSE(w1->IsActive()); | 749 EXPECT_FALSE(w1->IsActive()); |
764 EXPECT_TRUE(w2->IsActive()); | 750 EXPECT_TRUE(w2->IsActive()); |
765 EXPECT_EQ(w2.get(), parent->children()[1]); | 751 EXPECT_EQ(w2.get(), parent->children()[1]); |
766 } | 752 } |
767 | 753 |
768 } // namespace internal | 754 } // namespace internal |
769 } // namespace aura | 755 } // namespace aura |
OLD | NEW |