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

Side by Side Diff: content/renderer/disambiguation_popup_helper_unittest.cc

Issue 11377068: ui: Make gfx::Size::Scale() mutate the class. Add gfx::ScaleSize() similar to Rect/Point. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebaseTOGO Created 8 years, 1 month 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 | « content/renderer/disambiguation_popup_helper.cc ('k') | content/renderer/render_view_impl.cc » ('j') | 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 "content/renderer/disambiguation_popup_helper.h" 5 #include "content/renderer/disambiguation_popup_helper.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" 8 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" 9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
10 #include "ui/gfx/rect.h" 10 #include "ui/gfx/rect.h"
(...skipping 21 matching lines...) Expand all
32 WebKit::WebVector<WebKit::WebRect> target_rects(static_cast<size_t>(1)); 32 WebKit::WebVector<WebKit::WebRect> target_rects(static_cast<size_t>(1));
33 target_rects[0] = gfx::Rect(-20, -20, 10, 10); 33 target_rects[0] = gfx::Rect(-20, -20, 10, 10);
34 34
35 gfx::Rect zoom_rect; 35 gfx::Rect zoom_rect;
36 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor( 36 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
37 tap_rect, target_rects, kViewportSize_, &zoom_rect); 37 tap_rect, target_rects, kViewportSize_, &zoom_rect);
38 38
39 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(zoom_rect)); 39 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(zoom_rect));
40 EXPECT_LE(kDisambiguationPopupMinScale, scale); 40 EXPECT_LE(kDisambiguationPopupMinScale, scale);
41 41
42 gfx::Size scaled_size = ToCeiledSize(zoom_rect.size().Scale(scale)); 42 gfx::Size scaled_size = ToCeiledSize(ScaleSize(zoom_rect.size(), scale));
43 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(gfx::Rect(scaled_size))); 43 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(gfx::Rect(scaled_size)));
44 } 44 }
45 45
46 TEST_F(DisambiguationPopupHelperUnittest, MiniTarget) { 46 TEST_F(DisambiguationPopupHelperUnittest, MiniTarget) {
47 gfx::Rect tap_rect(-5, -5, 20, 20); 47 gfx::Rect tap_rect(-5, -5, 20, 20);
48 WebKit::WebVector<WebKit::WebRect> target_rects(static_cast<size_t>(1)); 48 WebKit::WebVector<WebKit::WebRect> target_rects(static_cast<size_t>(1));
49 target_rects[0] = gfx::Rect(10, 10, 1, 1); 49 target_rects[0] = gfx::Rect(10, 10, 1, 1);
50 50
51 gfx::Rect zoom_rect; 51 gfx::Rect zoom_rect;
52 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor( 52 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
53 tap_rect, target_rects, kViewportSize_, &zoom_rect); 53 tap_rect, target_rects, kViewportSize_, &zoom_rect);
54 54
55 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(zoom_rect)); 55 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(zoom_rect));
56 EXPECT_EQ(kDisambiguationPopupMaxScale, scale); 56 EXPECT_EQ(kDisambiguationPopupMaxScale, scale);
57 EXPECT_TRUE(zoom_rect.Contains(target_rects[0])); 57 EXPECT_TRUE(zoom_rect.Contains(target_rects[0]));
58 58
59 gfx::Size scaled_size = ToCeiledSize(zoom_rect.size().Scale(scale)); 59 gfx::Size scaled_size = ToCeiledSize(ScaleSize(zoom_rect.size(), scale));
60 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(gfx::Rect(scaled_size))); 60 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(gfx::Rect(scaled_size)));
61 } 61 }
62 62
63 TEST_F(DisambiguationPopupHelperUnittest, LongLinks) { 63 TEST_F(DisambiguationPopupHelperUnittest, LongLinks) {
64 gfx::Rect tap_rect(10, 10, 20, 20); 64 gfx::Rect tap_rect(10, 10, 20, 20);
65 WebKit::WebVector<WebKit::WebRect> target_rects(static_cast<size_t>(2)); 65 WebKit::WebVector<WebKit::WebRect> target_rects(static_cast<size_t>(2));
66 target_rects[0] = gfx::Rect(15, 15, 1000, 5); 66 target_rects[0] = gfx::Rect(15, 15, 1000, 5);
67 target_rects[1] = gfx::Rect(15, 25, 1000, 5); 67 target_rects[1] = gfx::Rect(15, 25, 1000, 5);
68 68
69 gfx::Rect zoom_rect; 69 gfx::Rect zoom_rect;
70 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor( 70 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
71 tap_rect, target_rects, kViewportSize_, &zoom_rect); 71 tap_rect, target_rects, kViewportSize_, &zoom_rect);
72 72
73 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(zoom_rect)); 73 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(zoom_rect));
74 EXPECT_EQ(kDisambiguationPopupMaxScale, scale); 74 EXPECT_EQ(kDisambiguationPopupMaxScale, scale);
75 EXPECT_TRUE(zoom_rect.Contains(tap_rect)); 75 EXPECT_TRUE(zoom_rect.Contains(tap_rect));
76 76
77 gfx::Size scaled_size = ToCeiledSize(zoom_rect.size().Scale(scale)); 77 gfx::Size scaled_size = ToCeiledSize(ScaleSize(zoom_rect.size(), scale));
78 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(gfx::Rect(scaled_size))); 78 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(gfx::Rect(scaled_size)));
79 } 79 }
80 80
81 } // namespace content 81 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/disambiguation_popup_helper.cc ('k') | content/renderer/render_view_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698