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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 widget->OnGestureEvent(&end); 1403 widget->OnGestureEvent(&end);
1404 1404
1405 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_BEGIN)); 1405 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_BEGIN));
1406 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE)); 1406 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
1407 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_END)); 1407 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_END));
1408 } 1408 }
1409 1409
1410 widget->CloseNow(); 1410 widget->CloseNow();
1411 } 1411 }
1412 1412
1413 // Used by SingleWindowClosing to count number of times WindowClosing() has
1414 // been invoked.
1415 class ClosingDelegate : public WidgetDelegate {
1416 public:
1417 ClosingDelegate() : count_(0), widget_(NULL) {}
1418
1419 int count() const { return count_; }
1420
1421 void set_widget(views::Widget* widget) { widget_ = widget; }
1422
1423 // WidgetDelegate overrides:
1424 virtual Widget* GetWidget() OVERRIDE { return widget_; }
1425 virtual const Widget* GetWidget() const OVERRIDE { return widget_; }
1426 virtual void WindowClosing() OVERRIDE {
1427 count_++;
1428 }
1429
1430 private:
1431 int count_;
1432 views::Widget* widget_;
1433
1434 DISALLOW_COPY_AND_ASSIGN(ClosingDelegate);
1435 };
1436
1437 // Verifies WindowClosing() is invoked correctly on the delegate when a Widget
1438 // is closed.
1439 TEST_F(WidgetTest, SingleWindowClosing) {
1440 scoped_ptr<ClosingDelegate> delegate(new ClosingDelegate());
1441 Widget* widget = new Widget(); // Destroyed by CloseNow() below.
1442 Widget::InitParams init_params =
1443 CreateParams(Widget::InitParams::TYPE_WINDOW);
1444 init_params.bounds = gfx::Rect(0, 0, 200, 200);
1445 init_params.delegate = delegate.get();
1446 #if defined(USE_AURA) && !defined(OS_CHROMEOS)
1447 init_params.native_widget = new DesktopNativeWidgetAura(widget);
1448 #endif
1449 widget->Init(init_params);
1450 EXPECT_EQ(0, delegate->count());
1451 widget->CloseNow();
1452 EXPECT_EQ(1, delegate->count());
1453 }
1454
1413 } // namespace 1455 } // namespace
1414 } // namespace views 1456 } // namespace views
OLDNEW
« 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