| 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/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/gfx/native_widget_types.h" | 9 #include "ui/gfx/native_widget_types.h" |
| 10 #include "ui/gfx/point.h" | 10 #include "ui/gfx/point.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 #endif | 165 #endif |
| 166 Widget* child = CreateChildPlatformWidget(parent); | 166 Widget* child = CreateChildPlatformWidget(parent); |
| 167 | 167 |
| 168 EXPECT_EQ(toplevel, toplevel->GetTopLevelWidget()); | 168 EXPECT_EQ(toplevel, toplevel->GetTopLevelWidget()); |
| 169 EXPECT_EQ(toplevel, child->GetTopLevelWidget()); | 169 EXPECT_EQ(toplevel, child->GetTopLevelWidget()); |
| 170 | 170 |
| 171 toplevel->CloseNow(); | 171 toplevel->CloseNow(); |
| 172 // |child| should be automatically destroyed with |toplevel|. | 172 // |child| should be automatically destroyed with |toplevel|. |
| 173 } | 173 } |
| 174 | 174 |
| 175 TEST_F(WidgetTest, GetTopLevelWidget_Synthetic) { | |
| 176 // Create a hierarchy consisting of a top level platform native widget and a | |
| 177 // child NativeWidget. | |
| 178 Widget* toplevel = CreateTopLevelPlatformWidget(); | |
| 179 Widget* child = CreateTopLevelNativeWidget(); | |
| 180 | |
| 181 EXPECT_EQ(toplevel, toplevel->GetTopLevelWidget()); | |
| 182 EXPECT_EQ(child, child->GetTopLevelWidget()); | |
| 183 | |
| 184 toplevel->CloseNow(); | |
| 185 // |child| should be automatically destroyed with |toplevel|. | |
| 186 } | |
| 187 | |
| 188 // Creates a hierarchy consisting of a desktop platform native widget, a | |
| 189 // toplevel NativeWidget, and a child of that toplevel, another NativeWidget. | |
| 190 TEST_F(WidgetTest, GetTopLevelWidget_SyntheticDesktop) { | |
| 191 // Create a hierarchy consisting of a desktop platform native widget, | |
| 192 // a toplevel NativeWidget and a chlid NativeWidget. | |
| 193 Widget* desktop = CreateTopLevelPlatformWidget(); | |
| 194 Widget* toplevel = CreateTopLevelNativeWidget(); // Will be parented | |
| 195 // automatically to | |
| 196 // |toplevel|. | |
| 197 | |
| 198 Widget* child = CreateChildNativeWidgetWithParent(toplevel); | |
| 199 | |
| 200 EXPECT_EQ(desktop, desktop->GetTopLevelWidget()); | |
| 201 EXPECT_EQ(toplevel, toplevel->GetTopLevelWidget()); | |
| 202 EXPECT_EQ(toplevel, child->GetTopLevelWidget()); | |
| 203 | |
| 204 desktop->CloseNow(); | |
| 205 // |toplevel|, |child| should be automatically destroyed with |toplevel|. | |
| 206 } | |
| 207 | |
| 208 // Tests some grab/ungrab events. | 175 // Tests some grab/ungrab events. |
| 209 TEST_F(WidgetTest, DISABLED_GrabUngrab) { | 176 TEST_F(WidgetTest, DISABLED_GrabUngrab) { |
| 210 Widget* toplevel = CreateTopLevelPlatformWidget(); | 177 Widget* toplevel = CreateTopLevelPlatformWidget(); |
| 211 Widget* child1 = CreateChildNativeWidgetWithParent(toplevel); | 178 Widget* child1 = CreateChildNativeWidgetWithParent(toplevel); |
| 212 Widget* child2 = CreateChildNativeWidgetWithParent(toplevel); | 179 Widget* child2 = CreateChildNativeWidgetWithParent(toplevel); |
| 213 | 180 |
| 214 toplevel->SetBounds(gfx::Rect(0, 0, 500, 500)); | 181 toplevel->SetBounds(gfx::Rect(0, 0, 500, 500)); |
| 215 | 182 |
| 216 child1->SetBounds(gfx::Rect(10, 10, 300, 300)); | 183 child1->SetBounds(gfx::Rect(10, 10, 300, 300)); |
| 217 View* view = new MouseView(); | 184 View* view = new MouseView(); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 | 302 |
| 336 child_popup->Show(); | 303 child_popup->Show(); |
| 337 | 304 |
| 338 EXPECT_TRUE(child_popup->IsVisible()); | 305 EXPECT_TRUE(child_popup->IsVisible()); |
| 339 | 306 |
| 340 toplevel->CloseNow(); | 307 toplevel->CloseNow(); |
| 341 // |child_popup| should be automatically destroyed with |toplevel|. | 308 // |child_popup| should be automatically destroyed with |toplevel|. |
| 342 } | 309 } |
| 343 #endif | 310 #endif |
| 344 | 311 |
| 345 // Tests visibility of synthetic child widgets. | |
| 346 TEST_F(WidgetTest, Visibility_Synthetic) { | |
| 347 // Create a hierarchy consisting of a desktop platform native widget, | |
| 348 // a toplevel NativeWidget and a chlid NativeWidget. | |
| 349 Widget* desktop = CreateTopLevelPlatformWidget(); | |
| 350 desktop->Show(); | |
| 351 | |
| 352 Widget* toplevel = CreateTopLevelNativeWidget(); // Will be parented | |
| 353 // automatically to | |
| 354 // |toplevel|. | |
| 355 | |
| 356 Widget* child = CreateChildNativeWidgetWithParent(toplevel); | |
| 357 | |
| 358 EXPECT_FALSE(toplevel->IsVisible()); | |
| 359 EXPECT_FALSE(child->IsVisible()); | |
| 360 | |
| 361 child->Show(); | |
| 362 | |
| 363 EXPECT_FALSE(toplevel->IsVisible()); | |
| 364 EXPECT_FALSE(child->IsVisible()); | |
| 365 | |
| 366 toplevel->Show(); | |
| 367 | |
| 368 EXPECT_TRUE(toplevel->IsVisible()); | |
| 369 EXPECT_TRUE(child->IsVisible()); | |
| 370 | |
| 371 desktop->CloseNow(); | |
| 372 } | |
| 373 | |
| 374 //////////////////////////////////////////////////////////////////////////////// | 312 //////////////////////////////////////////////////////////////////////////////// |
| 375 // Widget ownership tests. | 313 // Widget ownership tests. |
| 376 // | 314 // |
| 377 // Tests various permutations of Widget ownership specified in the | 315 // Tests various permutations of Widget ownership specified in the |
| 378 // InitParams::Ownership param. | 316 // InitParams::Ownership param. |
| 379 | 317 |
| 380 // A WidgetTest that supplies a toplevel widget for NativeWidget to parent to. | 318 // A WidgetTest that supplies a toplevel widget for NativeWidget to parent to. |
| 381 class WidgetOwnershipTest : public WidgetTest { | 319 class WidgetOwnershipTest : public WidgetTest { |
| 382 public: | 320 public: |
| 383 WidgetOwnershipTest() {} | 321 WidgetOwnershipTest() {} |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 RunPendingMessages(); | 758 RunPendingMessages(); |
| 821 EXPECT_NE(toplevel->GetWindowScreenBounds().ToString(), | 759 EXPECT_NE(toplevel->GetWindowScreenBounds().ToString(), |
| 822 toplevel->GetRestoredBounds().ToString()); | 760 toplevel->GetRestoredBounds().ToString()); |
| 823 EXPECT_GT(toplevel->GetRestoredBounds().width(), 0); | 761 EXPECT_GT(toplevel->GetRestoredBounds().width(), 0); |
| 824 EXPECT_GT(toplevel->GetRestoredBounds().height(), 0); | 762 EXPECT_GT(toplevel->GetRestoredBounds().height(), 0); |
| 825 } | 763 } |
| 826 #endif | 764 #endif |
| 827 | 765 |
| 828 } // namespace | 766 } // namespace |
| 829 } // namespace views | 767 } // namespace views |
| OLD | NEW |