Chromium Code Reviews| 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 "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 "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/base/events/event_utils.h" | 10 #include "ui/base/events/event_utils.h" |
| (...skipping 1697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1708 set_views_delegate(delegate); // ViewsTestBase takes ownership. | 1708 set_views_delegate(delegate); // ViewsTestBase takes ownership. |
| 1709 scoped_ptr<Widget> widget(new Widget); | 1709 scoped_ptr<Widget> widget(new Widget); |
| 1710 Widget::InitParams params = | 1710 Widget::InitParams params = |
| 1711 CreateParams(views::Widget::InitParams::TYPE_POPUP); | 1711 CreateParams(views::Widget::InitParams::TYPE_POPUP); |
| 1712 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 1712 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 1713 widget->Init(params); | 1713 widget->Init(params); |
| 1714 EXPECT_TRUE(delegate->on_before_init_called()); | 1714 EXPECT_TRUE(delegate->on_before_init_called()); |
| 1715 EXPECT_TRUE(delegate->is_top_level()); | 1715 EXPECT_TRUE(delegate->is_top_level()); |
| 1716 } | 1716 } |
| 1717 | 1717 |
| 1718 // A scumbag View that deletes its owning widget OnMousePressed. | |
| 1719 class WidgetDeleterView : public View { | |
| 1720 public: | |
| 1721 WidgetDeleterView() : View() { } | |
|
sky
2013/04/04 20:36:04
nit: { } -> {}
varunjain
2013/04/04 21:02:08
Done.
| |
| 1722 | |
| 1723 // Overridden from View. | |
| 1724 bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE { | |
| 1725 delete GetWidget(); | |
| 1726 return true; | |
| 1727 } | |
| 1728 | |
| 1729 private: | |
| 1730 DISALLOW_COPY_AND_ASSIGN(WidgetDeleterView); | |
| 1731 }; | |
| 1732 | |
| 1733 TEST_F(WidgetTest, TestWidgetDeletedInOnMousePressed) { | |
| 1734 Widget* widget = new Widget; | |
| 1735 Widget::InitParams params = | |
| 1736 CreateParams(views::Widget::InitParams::TYPE_POPUP); | |
| 1737 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 1738 widget->Init(params); | |
| 1739 | |
| 1740 widget->SetContentsView(new WidgetDeleterView); | |
| 1741 | |
| 1742 widget->SetSize(gfx::Size(100, 100)); | |
| 1743 widget->Show(); | |
| 1744 | |
| 1745 gfx::Point click_location(45, 15); | |
| 1746 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, click_location, click_location, | |
| 1747 ui::EF_LEFT_MOUSE_BUTTON); | |
| 1748 widget->OnMouseEvent(&press); | |
| 1749 | |
| 1750 // Yay we did not crash! | |
| 1751 } | |
| 1752 | |
| 1718 } // namespace | 1753 } // namespace |
| 1719 } // namespace views | 1754 } // namespace views |
| OLD | NEW |