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

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

Issue 10885004: Implement disambiguation popup (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixing visibility Created 8 years, 2 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
« no previous file with comments | « content/renderer/disambiguation_popup_helper.cc ('k') | content/renderer/render_view_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "testing/gtest/include/gtest/gtest.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"
10 #include "ui/gfx/rect.h"
11 #include "ui/gfx/size.h"
12 #include "ui/gfx/size_conversions.h"
13
14 // these constants are copied from the implementation class
15 namespace {
16 const float kDisambiguationPopupMaxScale = 5.0;
17 const float kDisambiguationPopupMinScale = 2.0;
18 } // unnamed namespace
19
20 namespace content {
21
22 class DisambiguationPopupHelperUnittest : public testing::Test {
23 public:
24 DisambiguationPopupHelperUnittest()
25 : kViewportSize_(640, 480) { }
26 protected:
27 const gfx::Size kViewportSize_;
28 };
29
30 TEST_F(DisambiguationPopupHelperUnittest, ClipByViewport) {
31 gfx::Rect tap_rect(1000, 1000, 10, 10);
32 WebKit::WebVector<WebKit::WebRect> target_rects(static_cast<size_t>(1));
33 target_rects[0] = gfx::Rect(-20, -20, 10, 10);
34
35 gfx::Rect zoom_rect;
36 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
37 tap_rect, target_rects, kViewportSize_, &zoom_rect);
38
39 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(zoom_rect));
40 EXPECT_LE(kDisambiguationPopupMinScale, scale);
41
42 gfx::Size scaled_size = ToCeiledSize(zoom_rect.size().Scale(scale));
43 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(gfx::Rect(scaled_size)));
44 }
45
46 TEST_F(DisambiguationPopupHelperUnittest, MiniTarget) {
47 gfx::Rect tap_rect(-5, -5, 20, 20);
48 WebKit::WebVector<WebKit::WebRect> target_rects(static_cast<size_t>(1));
49 target_rects[0] = gfx::Rect(10, 10, 1, 1);
50
51 gfx::Rect zoom_rect;
52 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
53 tap_rect, target_rects, kViewportSize_, &zoom_rect);
54
55 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(zoom_rect));
56 EXPECT_EQ(kDisambiguationPopupMaxScale, scale);
57 EXPECT_TRUE(zoom_rect.Contains(target_rects[0]));
58
59 gfx::Size scaled_size = ToCeiledSize(zoom_rect.size().Scale(scale));
60 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(gfx::Rect(scaled_size)));
61 }
62
63 TEST_F(DisambiguationPopupHelperUnittest, LongLinks) {
64 gfx::Rect tap_rect(10, 10, 20, 20);
65 WebKit::WebVector<WebKit::WebRect> target_rects(static_cast<size_t>(2));
66 target_rects[0] = gfx::Rect(15, 15, 1000, 5);
67 target_rects[1] = gfx::Rect(15, 25, 1000, 5);
68
69 gfx::Rect zoom_rect;
70 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
71 tap_rect, target_rects, kViewportSize_, &zoom_rect);
72
73 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(zoom_rect));
74 EXPECT_EQ(kDisambiguationPopupMaxScale, scale);
75 EXPECT_TRUE(zoom_rect.Contains(tap_rect));
76
77 gfx::Size scaled_size = ToCeiledSize(zoom_rect.size().Scale(scale));
78 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(gfx::Rect(scaled_size)));
79 }
80
81 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/disambiguation_popup_helper.cc ('k') | content/renderer/render_view_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698