Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: ui/views/widget/widget_unittest.cc

Issue 12225122: Verifies WindowClosing() is invoked only once when a window is (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/widget/desktop_aura/desktop_root_window_host_linux.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/widget/widget_unittest.cc
diff --git a/ui/views/widget/widget_unittest.cc b/ui/views/widget/widget_unittest.cc
index ffac6175560b2b46fd5784ffd661e0516887fa99..55ae459e3c0170be2f84f4aee6408e791fc1aa0f 100644
--- a/ui/views/widget/widget_unittest.cc
+++ b/ui/views/widget/widget_unittest.cc
@@ -1410,5 +1410,47 @@ TEST_F(WidgetTest, GestureScrollEventDispatching) {
widget->CloseNow();
}
+// Used by SingleWindowClosing to count number of times WindowClosing() has
+// been invoked.
+class ClosingDelegate : public WidgetDelegate {
+ public:
+ ClosingDelegate() : count_(0), widget_(NULL) {}
+
+ int count() const { return count_; }
+
+ void set_widget(views::Widget* widget) { widget_ = widget; }
+
+ // WidgetDelegate overrides:
+ virtual Widget* GetWidget() OVERRIDE { return widget_; }
+ virtual const Widget* GetWidget() const OVERRIDE { return widget_; }
+ virtual void WindowClosing() OVERRIDE {
+ count_++;
+ }
+
+ private:
+ int count_;
+ views::Widget* widget_;
+
+ DISALLOW_COPY_AND_ASSIGN(ClosingDelegate);
+};
+
+// Verifies WindowClosing() is invoked correctly on the delegate when a Widget
+// is closed.
+TEST_F(WidgetTest, SingleWindowClosing) {
+ scoped_ptr<ClosingDelegate> delegate(new ClosingDelegate());
+ Widget* widget = new Widget(); // Destroyed by CloseNow() below.
+ Widget::InitParams init_params =
+ CreateParams(Widget::InitParams::TYPE_WINDOW);
+ init_params.bounds = gfx::Rect(0, 0, 200, 200);
+ init_params.delegate = delegate.get();
+#if defined(USE_AURA) && !defined(OS_CHROMEOS)
+ init_params.native_widget = new DesktopNativeWidgetAura(widget);
+#endif
+ widget->Init(init_params);
+ EXPECT_EQ(0, delegate->count());
+ widget->CloseNow();
+ EXPECT_EQ(1, delegate->count());
+}
+
} // namespace
} // namespace views
« no previous file with comments | « ui/views/widget/desktop_aura/desktop_root_window_host_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698