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

Side by Side Diff: ui/views/view_unittest.cc

Issue 10830101: Cleanup: Fix a few compiler warnings by changing EXPECT_EQ(false, ...) to EXPECT_FALSE(...). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 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/base/ime/input_method_ibus_unittest.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 <map> 5 #include <map>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 938
939 DISALLOW_COPY_AND_ASSIGN(HitTestView); 939 DISALLOW_COPY_AND_ASSIGN(HitTestView);
940 }; 940 };
941 941
942 gfx::Point ConvertPointToView(View* view, const gfx::Point& p) { 942 gfx::Point ConvertPointToView(View* view, const gfx::Point& p) {
943 gfx::Point tmp(p); 943 gfx::Point tmp(p);
944 View::ConvertPointToView(view->GetWidget()->GetRootView(), view, &tmp); 944 View::ConvertPointToView(view->GetWidget()->GetRootView(), view, &tmp);
945 return tmp; 945 return tmp;
946 } 946 }
947 947
948 void RotateCounterclockwise(ui::Transform& transform) { 948 void RotateCounterclockwise(ui::Transform* transform) {
949 transform.matrix().set3x3(0, -1, 0, 949 transform->matrix().set3x3(0, -1, 0,
950 1, 0, 0, 950 1, 0, 0,
951 0, 0, 1); 951 0, 0, 1);
952 } 952 }
953 953
954 void RotateClockwise(ui::Transform& transform) { 954 void RotateClockwise(ui::Transform* transform) {
955 transform.matrix().set3x3( 0, 1, 0, 955 transform->matrix().set3x3( 0, 1, 0,
956 -1, 0, 0, 956 -1, 0, 0,
957 0, 0, 1); 957 0, 0, 1);
958 } 958 }
959 959
960 } // namespace 960 } // namespace
961 961
962 TEST_F(ViewTest, HitTestMasks) { 962 TEST_F(ViewTest, HitTestMasks) {
963 Widget* widget = new Widget; 963 Widget* widget = new Widget;
964 widget->Init(Widget::InitParams(Widget::InitParams::TYPE_POPUP)); 964 widget->Init(Widget::InitParams(Widget::InitParams::TYPE_POPUP));
965 View* root_view = widget->GetRootView(); 965 View* root_view = widget->GetRootView();
966 root_view->SetBoundsRect(gfx::Rect(0, 0, 500, 500)); 966 root_view->SetBoundsRect(gfx::Rect(0, 0, 500, 500));
967 967
(...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after
1999 v1->AddChildView(v2); 1999 v1->AddChildView(v2);
2000 2000
2001 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|. 2001 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|.
2002 v1->ClearScheduledPaintRect(); 2002 v1->ClearScheduledPaintRect();
2003 v2->SchedulePaint(); 2003 v2->SchedulePaint();
2004 2004
2005 EXPECT_EQ(gfx::Rect(100, 100, 200, 100), v1->scheduled_paint_rect()); 2005 EXPECT_EQ(gfx::Rect(100, 100, 200, 100), v1->scheduled_paint_rect());
2006 2006
2007 // Rotate |v1| counter-clockwise. 2007 // Rotate |v1| counter-clockwise.
2008 ui::Transform transform; 2008 ui::Transform transform;
2009 RotateCounterclockwise(transform); 2009 RotateCounterclockwise(&transform);
2010 transform.SetTranslateY(500.0f); 2010 transform.SetTranslateY(500.0f);
2011 v1->SetTransform(transform); 2011 v1->SetTransform(transform);
2012 2012
2013 // |v2| now occupies (100, 200) to (200, 400) in |root|. 2013 // |v2| now occupies (100, 200) to (200, 400) in |root|.
2014 2014
2015 v1->ClearScheduledPaintRect(); 2015 v1->ClearScheduledPaintRect();
2016 v2->SchedulePaint(); 2016 v2->SchedulePaint();
2017 2017
2018 EXPECT_EQ(gfx::Rect(100, 200, 100, 200), v1->scheduled_paint_rect()); 2018 EXPECT_EQ(gfx::Rect(100, 200, 100, 200), v1->scheduled_paint_rect());
2019 2019
(...skipping 13 matching lines...) Expand all
2033 widget->Init(params); 2033 widget->Init(params);
2034 View* root = widget->GetRootView(); 2034 View* root = widget->GetRootView();
2035 2035
2036 root->AddChildView(v1); 2036 root->AddChildView(v1);
2037 v1->AddChildView(v2); 2037 v1->AddChildView(v2);
2038 2038
2039 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|. 2039 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|.
2040 2040
2041 // Rotate |v1| counter-clockwise. 2041 // Rotate |v1| counter-clockwise.
2042 ui::Transform transform(v1->GetTransform()); 2042 ui::Transform transform(v1->GetTransform());
2043 RotateCounterclockwise(transform); 2043 RotateCounterclockwise(&transform);
2044 transform.SetTranslateY(500.0f); 2044 transform.SetTranslateY(500.0f);
2045 v1->SetTransform(transform); 2045 v1->SetTransform(transform);
2046 2046
2047 // |v2| now occupies (100, 200) to (200, 400) in |root|. 2047 // |v2| now occupies (100, 200) to (200, 400) in |root|.
2048 v1->Reset(); 2048 v1->Reset();
2049 v2->Reset(); 2049 v2->Reset();
2050 2050
2051 MouseEvent pressed(ui::ET_MOUSE_PRESSED, 2051 MouseEvent pressed(ui::ET_MOUSE_PRESSED,
2052 110, 210, 2052 110, 210,
2053 ui::EF_LEFT_MOUSE_BUTTON); 2053 ui::EF_LEFT_MOUSE_BUTTON);
2054 root->OnMousePressed(pressed); 2054 root->OnMousePressed(pressed);
2055 EXPECT_EQ(0, v1->last_mouse_event_type_); 2055 EXPECT_EQ(0, v1->last_mouse_event_type_);
2056 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v2->last_mouse_event_type_); 2056 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v2->last_mouse_event_type_);
2057 EXPECT_EQ(190, v2->location_.x()); 2057 EXPECT_EQ(190, v2->location_.x());
2058 EXPECT_EQ(10, v2->location_.y()); 2058 EXPECT_EQ(10, v2->location_.y());
2059 2059
2060 MouseEvent released(ui::ET_MOUSE_RELEASED, 0, 0, 0); 2060 MouseEvent released(ui::ET_MOUSE_RELEASED, 0, 0, 0);
2061 root->OnMouseReleased(released); 2061 root->OnMouseReleased(released);
2062 2062
2063 // Now rotate |v2| inside |v1| clockwise. 2063 // Now rotate |v2| inside |v1| clockwise.
2064 transform = v2->GetTransform(); 2064 transform = v2->GetTransform();
2065 RotateClockwise(transform); 2065 RotateClockwise(&transform);
2066 transform.SetTranslateX(100.0f); 2066 transform.SetTranslateX(100.0f);
2067 v2->SetTransform(transform); 2067 v2->SetTransform(transform);
2068 2068
2069 // Now, |v2| occupies (100, 100) to (200, 300) in |v1|, and (100, 300) to 2069 // Now, |v2| occupies (100, 100) to (200, 300) in |v1|, and (100, 300) to
2070 // (300, 400) in |root|. 2070 // (300, 400) in |root|.
2071 2071
2072 v1->Reset(); 2072 v1->Reset();
2073 v2->Reset(); 2073 v2->Reset();
2074 2074
2075 MouseEvent p2(ui::ET_MOUSE_PRESSED, 2075 MouseEvent p2(ui::ET_MOUSE_PRESSED,
2076 110, 320, 2076 110, 320,
2077 ui::EF_LEFT_MOUSE_BUTTON); 2077 ui::EF_LEFT_MOUSE_BUTTON);
2078 root->OnMousePressed(p2); 2078 root->OnMousePressed(p2);
2079 EXPECT_EQ(0, v1->last_mouse_event_type_); 2079 EXPECT_EQ(0, v1->last_mouse_event_type_);
2080 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v2->last_mouse_event_type_); 2080 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v2->last_mouse_event_type_);
2081 EXPECT_EQ(10, v2->location_.x()); 2081 EXPECT_EQ(10, v2->location_.x());
2082 EXPECT_EQ(20, v2->location_.y()); 2082 EXPECT_EQ(20, v2->location_.y());
2083 2083
2084 root->OnMouseReleased(released); 2084 root->OnMouseReleased(released);
2085 2085
2086 v1->SetTransform(ui::Transform()); 2086 v1->SetTransform(ui::Transform());
2087 v2->SetTransform(ui::Transform()); 2087 v2->SetTransform(ui::Transform());
2088 2088
2089 TestView* v3 = new TestView(); 2089 TestView* v3 = new TestView();
2090 v3->SetBoundsRect(gfx::Rect(10, 10, 20, 30)); 2090 v3->SetBoundsRect(gfx::Rect(10, 10, 20, 30));
2091 v2->AddChildView(v3); 2091 v2->AddChildView(v3);
2092 2092
2093 // Rotate |v3| clockwise with respect to |v2|. 2093 // Rotate |v3| clockwise with respect to |v2|.
2094 transform = v1->GetTransform(); 2094 transform = v1->GetTransform();
2095 RotateClockwise(transform); 2095 RotateClockwise(&transform);
2096 transform.SetTranslateX(30.0f); 2096 transform.SetTranslateX(30.0f);
2097 v3->SetTransform(transform); 2097 v3->SetTransform(transform);
2098 2098
2099 // Scale |v2| with respect to |v1| along both axis. 2099 // Scale |v2| with respect to |v1| along both axis.
2100 transform = v2->GetTransform(); 2100 transform = v2->GetTransform();
2101 transform.SetScale(0.8f, 0.5f); 2101 transform.SetScale(0.8f, 0.5f);
2102 v2->SetTransform(transform); 2102 v2->SetTransform(transform);
2103 2103
2104 // |v3| occupies (108, 105) to (132, 115) in |root|. 2104 // |v3| occupies (108, 105) to (132, 115) in |root|.
2105 2105
(...skipping 15 matching lines...) Expand all
2121 v1->SetTransform(ui::Transform()); 2121 v1->SetTransform(ui::Transform());
2122 v2->SetTransform(ui::Transform()); 2122 v2->SetTransform(ui::Transform());
2123 v3->SetTransform(ui::Transform()); 2123 v3->SetTransform(ui::Transform());
2124 2124
2125 v1->Reset(); 2125 v1->Reset();
2126 v2->Reset(); 2126 v2->Reset();
2127 v3->Reset(); 2127 v3->Reset();
2128 2128
2129 // Rotate |v3| clockwise with respect to |v2|, and scale it along both axis. 2129 // Rotate |v3| clockwise with respect to |v2|, and scale it along both axis.
2130 transform = v3->GetTransform(); 2130 transform = v3->GetTransform();
2131 RotateClockwise(transform); 2131 RotateClockwise(&transform);
2132 transform.SetTranslateX(30.0f); 2132 transform.SetTranslateX(30.0f);
2133 // Rotation sets some scaling transformation. Using SetScale would overwrite 2133 // Rotation sets some scaling transformation. Using SetScale would overwrite
2134 // that and pollute the rotation. So combine the scaling with the existing 2134 // that and pollute the rotation. So combine the scaling with the existing
2135 // transforamtion. 2135 // transforamtion.
2136 transform.ConcatScale(0.8f, 0.5f); 2136 transform.ConcatScale(0.8f, 0.5f);
2137 v3->SetTransform(transform); 2137 v3->SetTransform(transform);
2138 2138
2139 // Translate |v2| with respect to |v1|. 2139 // Translate |v2| with respect to |v1|.
2140 transform = v2->GetTransform(); 2140 transform = v2->GetTransform();
2141 transform.SetTranslate(10, 10); 2141 transform.SetTranslate(10, 10);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2174 viewport->SetBoundsRect(viewport_bounds); 2174 viewport->SetBoundsRect(viewport_bounds);
2175 contents->SetBoundsRect(gfx::Rect(0, 0, 100, 200)); 2175 contents->SetBoundsRect(gfx::Rect(0, 0, 100, 200));
2176 2176
2177 View* child = new View; 2177 View* child = new View;
2178 contents->AddChildView(child); 2178 contents->AddChildView(child);
2179 child->SetBoundsRect(gfx::Rect(10, 90, 50, 50)); 2179 child->SetBoundsRect(gfx::Rect(10, 90, 50, 50));
2180 EXPECT_EQ(gfx::Rect(0, 0, 50, 10), child->GetVisibleBounds()); 2180 EXPECT_EQ(gfx::Rect(0, 0, 50, 10), child->GetVisibleBounds());
2181 2181
2182 // Rotate |child| counter-clockwise 2182 // Rotate |child| counter-clockwise
2183 ui::Transform transform; 2183 ui::Transform transform;
2184 RotateCounterclockwise(transform); 2184 RotateCounterclockwise(&transform);
2185 transform.SetTranslateY(50.0f); 2185 transform.SetTranslateY(50.0f);
2186 child->SetTransform(transform); 2186 child->SetTransform(transform);
2187 EXPECT_EQ(gfx::Rect(40, 0, 10, 50), child->GetVisibleBounds()); 2187 EXPECT_EQ(gfx::Rect(40, 0, 10, 50), child->GetVisibleBounds());
2188 2188
2189 widget->CloseNow(); 2189 widget->CloseNow();
2190 } 2190 }
2191 2191
2192 //////////////////////////////////////////////////////////////////////////////// 2192 ////////////////////////////////////////////////////////////////////////////////
2193 // OnVisibleBoundsChanged() 2193 // OnVisibleBoundsChanged()
2194 2194
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 v1->SetBoundsRect(gfx::Rect(10, 10, 500, 500)); 2410 v1->SetBoundsRect(gfx::Rect(10, 10, 500, 500));
2411 v2->SetBoundsRect(gfx::Rect(20, 20, 100, 200)); 2411 v2->SetBoundsRect(gfx::Rect(20, 20, 100, 200));
2412 2412
2413 // |v2| now occupies (30, 30) to (130, 230) in |widget| 2413 // |v2| now occupies (30, 30) to (130, 230) in |widget|
2414 gfx::Rect rect(5, 5, 15, 40); 2414 gfx::Rect rect(5, 5, 15, 40);
2415 EXPECT_EQ(gfx::Rect(25, 25, 15, 40), v2->ConvertRectToParent(rect)); 2415 EXPECT_EQ(gfx::Rect(25, 25, 15, 40), v2->ConvertRectToParent(rect));
2416 EXPECT_EQ(gfx::Rect(35, 35, 15, 40), v2->ConvertRectToWidget(rect)); 2416 EXPECT_EQ(gfx::Rect(35, 35, 15, 40), v2->ConvertRectToWidget(rect));
2417 2417
2418 // Rotate |v2| 2418 // Rotate |v2|
2419 ui::Transform t2; 2419 ui::Transform t2;
2420 RotateCounterclockwise(t2); 2420 RotateCounterclockwise(&t2);
2421 t2.SetTranslateY(100.0f); 2421 t2.SetTranslateY(100.0f);
2422 v2->SetTransform(t2); 2422 v2->SetTransform(t2);
2423 2423
2424 // |v2| now occupies (30, 30) to (230, 130) in |widget| 2424 // |v2| now occupies (30, 30) to (230, 130) in |widget|
2425 EXPECT_EQ(gfx::Rect(25, 100, 40, 15), v2->ConvertRectToParent(rect)); 2425 EXPECT_EQ(gfx::Rect(25, 100, 40, 15), v2->ConvertRectToParent(rect));
2426 EXPECT_EQ(gfx::Rect(35, 110, 40, 15), v2->ConvertRectToWidget(rect)); 2426 EXPECT_EQ(gfx::Rect(35, 110, 40, 15), v2->ConvertRectToWidget(rect));
2427 2427
2428 // Scale down |v1| 2428 // Scale down |v1|
2429 ui::Transform t1; 2429 ui::Transform t1;
2430 t1.SetScale(0.5, 0.5); 2430 t1.SetScale(0.5, 0.5);
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after
3337 // Set to non default value. 3337 // Set to non default value.
3338 v->layer()->set_scale_content(false); 3338 v->layer()->set_scale_content(false);
3339 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); 3339 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer());
3340 ui::Layer* new_layer = v->layer(); 3340 ui::Layer* new_layer = v->layer();
3341 EXPECT_FALSE(new_layer->scale_content()); 3341 EXPECT_FALSE(new_layer->scale_content());
3342 } 3342 }
3343 3343
3344 #endif // USE_AURA 3344 #endif // USE_AURA
3345 3345
3346 } // namespace views 3346 } // namespace views
OLDNEW
« no previous file with comments | « ui/base/ime/input_method_ibus_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698