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

Side by Side Diff: views/view_unittest.cc

Issue 6685069: Disambiguate OnMouseCaptureLost from OnMouseReleased, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address most TODOs and sync. Created 9 years, 9 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
OLDNEW
1 // Copyright (c) 2010 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 <map> 5 #include <map>
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "ui/base/clipboard/clipboard.h" 10 #include "ui/base/clipboard/clipboard.h"
11 #include "ui/base/keycodes/keyboard_codes.h" 11 #include "ui/base/keycodes/keyboard_codes.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 #endif 150 #endif
151 last_clip_.setEmpty(); 151 last_clip_.setEmpty();
152 accelerator_count_map_.clear(); 152 accelerator_count_map_.clear();
153 } 153 }
154 154
155 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; 155 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
156 virtual void ViewHierarchyChanged( 156 virtual void ViewHierarchyChanged(
157 bool is_add, View *parent, View *child) OVERRIDE; 157 bool is_add, View *parent, View *child) OVERRIDE;
158 virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; 158 virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE;
159 virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE; 159 virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE;
160 virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE; 160 virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE;
161 #if defined(TOUCH_UI) 161 #if defined(TOUCH_UI)
162 virtual TouchStatus OnTouchEvent(const TouchEvent& event); 162 virtual TouchStatus OnTouchEvent(const TouchEvent& event);
163 #endif 163 #endif
164 virtual void Paint(gfx::Canvas* canvas) OVERRIDE; 164 virtual void Paint(gfx::Canvas* canvas) OVERRIDE;
165 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; 165 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
166 virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE; 166 virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE;
167 167
168 // OnBoundsChanged test 168 // OnBoundsChanged test
169 bool did_change_bounds_; 169 bool did_change_bounds_;
170 gfx::Rect new_bounds_; 170 gfx::Rect new_bounds_;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 location_.SetPoint(event.x(), event.y()); 350 location_.SetPoint(event.x(), event.y());
351 return true; 351 return true;
352 } 352 }
353 353
354 bool TestView::OnMouseDragged(const MouseEvent& event) { 354 bool TestView::OnMouseDragged(const MouseEvent& event) {
355 last_mouse_event_type_ = event.type(); 355 last_mouse_event_type_ = event.type();
356 location_.SetPoint(event.x(), event.y()); 356 location_.SetPoint(event.x(), event.y());
357 return true; 357 return true;
358 } 358 }
359 359
360 void TestView::OnMouseReleased(const MouseEvent& event, bool canceled) { 360 void TestView::OnMouseReleased(const MouseEvent& event) {
361 last_mouse_event_type_ = event.type(); 361 last_mouse_event_type_ = event.type();
362 location_.SetPoint(event.x(), event.y()); 362 location_.SetPoint(event.x(), event.y());
363 } 363 }
364 364
365 TEST_F(ViewTest, MouseEvent) { 365 TEST_F(ViewTest, MouseEvent) {
366 TestView* v1 = new TestView(); 366 TestView* v1 = new TestView();
367 v1->SetBounds(0, 0, 300, 300); 367 v1->SetBounds(0, 0, 300, 300);
368 368
369 TestView* v2 = new TestView(); 369 TestView* v2 = new TestView();
370 v2->SetBounds(100, 100, 100, 100); 370 v2->SetBounds(100, 100, 100, 100);
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 DISALLOW_COPY_AND_ASSIGN(ButtonDropDownTest); 1470 DISALLOW_COPY_AND_ASSIGN(ButtonDropDownTest);
1471 }; 1471 };
1472 1472
1473 // Ensure that regular clicks on the drop down button still work. (i.e. - the 1473 // Ensure that regular clicks on the drop down button still work. (i.e. - the
1474 // click events are processed and the listener gets the click) 1474 // click events are processed and the listener gets the click)
1475 TEST_F(ButtonDropDownTest, RegularClickTest) { 1475 TEST_F(ButtonDropDownTest, RegularClickTest) {
1476 MouseEvent press_event(ui::ET_MOUSE_PRESSED, 1, 1, ui::EF_LEFT_BUTTON_DOWN); 1476 MouseEvent press_event(ui::ET_MOUSE_PRESSED, 1, 1, ui::EF_LEFT_BUTTON_DOWN);
1477 MouseEvent release_event(ui::ET_MOUSE_RELEASED, 1, 1, 1477 MouseEvent release_event(ui::ET_MOUSE_RELEASED, 1, 1,
1478 ui::EF_LEFT_BUTTON_DOWN); 1478 ui::EF_LEFT_BUTTON_DOWN);
1479 button_as_view_->OnMousePressed(press_event); 1479 button_as_view_->OnMousePressed(press_event);
1480 button_as_view_->OnMouseReleased(release_event, false); 1480 button_as_view_->OnMouseReleased(release_event);
1481 EXPECT_EQ(test_dialog_->last_pressed_button_, test_dialog_->button_drop_); 1481 EXPECT_EQ(test_dialog_->last_pressed_button_, test_dialog_->button_drop_);
1482 } 1482 }
1483 1483
1484 #if defined(OS_WIN) 1484 #if defined(OS_WIN)
1485 // Ensure that dragging downwards on the button shows the menu while keeping the 1485 // Ensure that dragging downwards on the button shows the menu while keeping the
1486 // button depressed. 1486 // button depressed.
1487 TEST_F(ButtonDropDownTest, DragMenuTest) { 1487 TEST_F(ButtonDropDownTest, DragMenuTest) {
1488 test_dialog_->last_pressed_button_ = NULL; 1488 test_dialog_->last_pressed_button_ = NULL;
1489 MouseEvent press_event(ui::ET_MOUSE_PRESSED, 1, 1, ui::EF_LEFT_BUTTON_DOWN); 1489 MouseEvent press_event(ui::ET_MOUSE_PRESSED, 1, 1, ui::EF_LEFT_BUTTON_DOWN);
1490 MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, 1, 99, ui::EF_LEFT_BUTTON_DOWN); 1490 MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, 1, 99, ui::EF_LEFT_BUTTON_DOWN);
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 MouseEvent pressed(ui::ET_MOUSE_PRESSED, 1745 MouseEvent pressed(ui::ET_MOUSE_PRESSED,
1746 110, 210, 1746 110, 210,
1747 ui::EF_LEFT_BUTTON_DOWN); 1747 ui::EF_LEFT_BUTTON_DOWN);
1748 root->OnMousePressed(pressed); 1748 root->OnMousePressed(pressed);
1749 EXPECT_EQ(0, v1->last_mouse_event_type_); 1749 EXPECT_EQ(0, v1->last_mouse_event_type_);
1750 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v2->last_mouse_event_type_); 1750 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v2->last_mouse_event_type_);
1751 EXPECT_EQ(190, v2->location_.x()); 1751 EXPECT_EQ(190, v2->location_.x());
1752 EXPECT_EQ(10, v2->location_.y()); 1752 EXPECT_EQ(10, v2->location_.y());
1753 1753
1754 MouseEvent released(ui::ET_MOUSE_RELEASED, 0, 0, 0); 1754 MouseEvent released(ui::ET_MOUSE_RELEASED, 0, 0, 0);
1755 root->OnMouseReleased(released, false); 1755 root->OnMouseReleased(released);
1756 1756
1757 // Now rotate |v2| inside |v1| clockwise. 1757 // Now rotate |v2| inside |v1| clockwise.
1758 v2->SetRotation(90.0); 1758 v2->SetRotation(90.0);
1759 v2->SetTranslateX(100); 1759 v2->SetTranslateX(100);
1760 1760
1761 // Now, |v2| occupies (100, 100) to (200, 300) in |v1|, and (100, 300) to 1761 // Now, |v2| occupies (100, 100) to (200, 300) in |v1|, and (100, 300) to
1762 // (300, 400) in |root|. 1762 // (300, 400) in |root|.
1763 1763
1764 v1->Reset(); 1764 v1->Reset();
1765 v2->Reset(); 1765 v2->Reset();
1766 1766
1767 MouseEvent p2(ui::ET_MOUSE_PRESSED, 1767 MouseEvent p2(ui::ET_MOUSE_PRESSED,
1768 110, 320, 1768 110, 320,
1769 ui::EF_LEFT_BUTTON_DOWN); 1769 ui::EF_LEFT_BUTTON_DOWN);
1770 root->OnMousePressed(p2); 1770 root->OnMousePressed(p2);
1771 EXPECT_EQ(0, v1->last_mouse_event_type_); 1771 EXPECT_EQ(0, v1->last_mouse_event_type_);
1772 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v2->last_mouse_event_type_); 1772 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v2->last_mouse_event_type_);
1773 EXPECT_EQ(10, v2->location_.x()); 1773 EXPECT_EQ(10, v2->location_.x());
1774 EXPECT_EQ(20, v2->location_.y()); 1774 EXPECT_EQ(20, v2->location_.y());
1775 1775
1776 root->OnMouseReleased(released, false); 1776 root->OnMouseReleased(released);
1777 1777
1778 v1->ResetTransform(); 1778 v1->ResetTransform();
1779 v2->ResetTransform(); 1779 v2->ResetTransform();
1780 1780
1781 TestView* v3 = new TestView(); 1781 TestView* v3 = new TestView();
1782 v3->SetBounds(10, 10, 20, 30); 1782 v3->SetBounds(10, 10, 20, 30);
1783 v2->AddChildView(v3); 1783 v2->AddChildView(v3);
1784 1784
1785 // Rotate |v3| clockwise with respect to |v2|. 1785 // Rotate |v3| clockwise with respect to |v2|.
1786 v3->SetRotation(90.0); 1786 v3->SetRotation(90.0);
(...skipping 10 matching lines...) Expand all
1797 1797
1798 MouseEvent p3(ui::ET_MOUSE_PRESSED, 1798 MouseEvent p3(ui::ET_MOUSE_PRESSED,
1799 112, 110, 1799 112, 110,
1800 ui::EF_LEFT_BUTTON_DOWN); 1800 ui::EF_LEFT_BUTTON_DOWN);
1801 root->OnMousePressed(p3); 1801 root->OnMousePressed(p3);
1802 1802
1803 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v3->last_mouse_event_type_); 1803 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v3->last_mouse_event_type_);
1804 EXPECT_EQ(10, v3->location_.x()); 1804 EXPECT_EQ(10, v3->location_.x());
1805 EXPECT_EQ(25, v3->location_.y()); 1805 EXPECT_EQ(25, v3->location_.y());
1806 1806
1807 root->OnMouseReleased(released, false); 1807 root->OnMouseReleased(released);
1808 1808
1809 v1->ResetTransform(); 1809 v1->ResetTransform();
1810 v2->ResetTransform(); 1810 v2->ResetTransform();
1811 v3->ResetTransform(); 1811 v3->ResetTransform();
1812 1812
1813 v1->Reset(); 1813 v1->Reset();
1814 v2->Reset(); 1814 v2->Reset();
1815 v3->Reset(); 1815 v3->Reset();
1816 1816
1817 // Rotate |v3| clockwise with respect to |v2|, and scale it along both axis. 1817 // Rotate |v3| clockwise with respect to |v2|, and scale it along both axis.
(...skipping 11 matching lines...) Expand all
1829 1829
1830 MouseEvent p4(ui::ET_MOUSE_PRESSED, 1830 MouseEvent p4(ui::ET_MOUSE_PRESSED,
1831 124, 125, 1831 124, 125,
1832 ui::EF_LEFT_BUTTON_DOWN); 1832 ui::EF_LEFT_BUTTON_DOWN);
1833 root->OnMousePressed(p4); 1833 root->OnMousePressed(p4);
1834 1834
1835 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v3->last_mouse_event_type_); 1835 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v3->last_mouse_event_type_);
1836 EXPECT_EQ(10, v3->location_.x()); 1836 EXPECT_EQ(10, v3->location_.x());
1837 EXPECT_EQ(25, v3->location_.y()); 1837 EXPECT_EQ(25, v3->location_.y());
1838 1838
1839 root->OnMouseReleased(released, false); 1839 root->OnMouseReleased(released);
1840 1840
1841 widget->CloseNow(); 1841 widget->CloseNow();
1842 } 1842 }
1843 1843
1844 //////////////////////////////////////////////////////////////////////////////// 1844 ////////////////////////////////////////////////////////////////////////////////
1845 // OnVisibleBoundsChanged() 1845 // OnVisibleBoundsChanged()
1846 1846
1847 class VisibleBoundsView : public View { 1847 class VisibleBoundsView : public View {
1848 public: 1848 public:
1849 VisibleBoundsView() : received_notification_(false) {} 1849 VisibleBoundsView() : received_notification_(false) {}
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 top_view->scheduled_paint_rects_.clear(); 1932 top_view->scheduled_paint_rects_.clear();
1933 child_view->SetBounds(30, 30, 20, 20); 1933 child_view->SetBounds(30, 30, 20, 20);
1934 EXPECT_EQ(2U, top_view->scheduled_paint_rects_.size()); 1934 EXPECT_EQ(2U, top_view->scheduled_paint_rects_.size());
1935 1935
1936 // There should be 2 rects, spanning from (10, 10) to (50, 50). 1936 // There should be 2 rects, spanning from (10, 10) to (50, 50).
1937 gfx::Rect paint_rect = 1937 gfx::Rect paint_rect =
1938 top_view->scheduled_paint_rects_[0].Union( 1938 top_view->scheduled_paint_rects_[0].Union(
1939 top_view->scheduled_paint_rects_[1]); 1939 top_view->scheduled_paint_rects_[1]);
1940 EXPECT_EQ(gfx::Rect(10, 10, 40, 40), paint_rect); 1940 EXPECT_EQ(gfx::Rect(10, 10, 40, 40), paint_rect);
1941 } 1941 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698