OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/renderer/disambiguation_popup_helper.h" | |
6 | |
7 #include <stddef.h> | |
8 | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 #include "third_party/WebKit/public/platform/WebRect.h" | |
11 #include "third_party/WebKit/public/platform/WebVector.h" | |
12 #include "ui/gfx/geometry/rect.h" | |
13 #include "ui/gfx/geometry/size.h" | |
14 #include "ui/gfx/geometry/size_conversions.h" | |
15 | |
16 // these constants are copied from the implementation class | |
17 namespace { | |
18 const float kDisambiguationPopupMaxScale = 5.0; | |
19 const float kDisambiguationPopupMinScale = 2.0; | |
20 } // unnamed namespace | |
21 | |
22 namespace content { | |
23 | |
24 class DisambiguationPopupHelperUnittest : public testing::Test { | |
25 public: | |
26 DisambiguationPopupHelperUnittest() | |
27 : kScreenSize_(640, 480) | |
28 , kVisibleContentSize_(640, 480) | |
29 , kImplScale_(1) { } | |
30 protected: | |
31 const gfx::Size kScreenSize_; | |
32 const gfx::Size kVisibleContentSize_; | |
33 const float kImplScale_; | |
34 }; | |
35 | |
36 TEST_F(DisambiguationPopupHelperUnittest, ClipByViewport) { | |
37 gfx::Rect tap_rect(1000, 1000, 10, 10); | |
38 blink::WebVector<blink::WebRect> target_rects(static_cast<size_t>(1)); | |
39 target_rects[0] = gfx::Rect(-20, -20, 10, 10); | |
40 | |
41 gfx::Rect zoom_rect; | |
42 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor( | |
43 tap_rect, target_rects, kScreenSize_, kVisibleContentSize_, kImplScale_, | |
44 &zoom_rect); | |
45 | |
46 EXPECT_TRUE(gfx::Rect(kVisibleContentSize_).Contains(zoom_rect)); | |
47 EXPECT_LE(kDisambiguationPopupMinScale, scale); | |
48 | |
49 gfx::Size scaled_size = gfx::ScaleToCeiledSize(zoom_rect.size(), scale); | |
50 EXPECT_TRUE(gfx::Rect(kScreenSize_).Contains(gfx::Rect(scaled_size))); | |
51 } | |
52 | |
53 TEST_F(DisambiguationPopupHelperUnittest, MiniTarget) { | |
54 gfx::Rect tap_rect(-5, -5, 20, 20); | |
55 blink::WebVector<blink::WebRect> target_rects(static_cast<size_t>(1)); | |
56 target_rects[0] = gfx::Rect(10, 10, 1, 1); | |
57 | |
58 gfx::Rect zoom_rect; | |
59 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor( | |
60 tap_rect, target_rects, kScreenSize_, kVisibleContentSize_, kImplScale_, | |
61 &zoom_rect); | |
62 | |
63 EXPECT_TRUE(gfx::Rect(kVisibleContentSize_).Contains(zoom_rect)); | |
64 EXPECT_EQ(kDisambiguationPopupMaxScale, scale); | |
65 EXPECT_TRUE(zoom_rect.Contains(target_rects[0])); | |
66 | |
67 gfx::Size scaled_size = gfx::ScaleToCeiledSize(zoom_rect.size(), scale); | |
68 EXPECT_TRUE(gfx::Rect(kScreenSize_).Contains(gfx::Rect(scaled_size))); | |
69 } | |
70 | |
71 TEST_F(DisambiguationPopupHelperUnittest, LongLinks) { | |
72 gfx::Rect tap_rect(10, 10, 20, 20); | |
73 blink::WebVector<blink::WebRect> target_rects(static_cast<size_t>(2)); | |
74 target_rects[0] = gfx::Rect(15, 15, 1000, 5); | |
75 target_rects[1] = gfx::Rect(15, 25, 1000, 5); | |
76 | |
77 gfx::Rect zoom_rect; | |
78 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor( | |
79 tap_rect, target_rects, kScreenSize_, kVisibleContentSize_, kImplScale_, | |
80 &zoom_rect); | |
81 | |
82 EXPECT_TRUE(gfx::Rect(kVisibleContentSize_).Contains(zoom_rect)); | |
83 EXPECT_EQ(kDisambiguationPopupMaxScale, scale); | |
84 EXPECT_TRUE(zoom_rect.Contains(tap_rect)); | |
85 | |
86 gfx::Size scaled_size = gfx::ScaleToCeiledSize(zoom_rect.size(), scale); | |
87 EXPECT_TRUE(gfx::Rect(kScreenSize_).Contains(gfx::Rect(scaled_size))); | |
88 } | |
89 | |
90 } // namespace content | |
OLD | NEW |