summaryrefslogtreecommitdiffstats
path: root/content/renderer/disambiguation_popup_helper_unittest.cc
diff options
context:
space:
mode:
authortrchen@chromium.org <trchen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-18 01:55:03 +0000
committertrchen@chromium.org <trchen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-18 01:55:03 +0000
commitf9526d17e1eb2ae23c805c3dbe1ee5d489cc01f2 (patch)
tree09db5bb4f5c163cd2aca14a082ed7986496f9ec2 /content/renderer/disambiguation_popup_helper_unittest.cc
parent5fcbd95d392220159dda31f9de049f792cbc20d5 (diff)
downloadchromium_src-f9526d17e1eb2ae23c805c3dbe1ee5d489cc01f2.zip
chromium_src-f9526d17e1eb2ae23c805c3dbe1ee5d489cc01f2.tar.gz
chromium_src-f9526d17e1eb2ae23c805c3dbe1ee5d489cc01f2.tar.bz2
Implement disambiguation popup
This patch implements the renderer-process side of disambiguation popup. Individual platforms shall provide its own browser-side handling. Correspoding WebKit CL: https://bugs.webkit.org/show_bug.cgi?id=94182 BUG=100752 Review URL: https://chromiumcodereview.appspot.com/10885004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162612 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer/disambiguation_popup_helper_unittest.cc')
-rw-r--r--content/renderer/disambiguation_popup_helper_unittest.cc81
1 files changed, 81 insertions, 0 deletions
diff --git a/content/renderer/disambiguation_popup_helper_unittest.cc b/content/renderer/disambiguation_popup_helper_unittest.cc
new file mode 100644
index 0000000..2aaeb84
--- /dev/null
+++ b/content/renderer/disambiguation_popup_helper_unittest.cc
@@ -0,0 +1,81 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/disambiguation_popup_helper.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/size.h"
+#include "ui/gfx/size_conversions.h"
+
+// these constants are copied from the implementation class
+namespace {
+const float kDisambiguationPopupMaxScale = 5.0;
+const float kDisambiguationPopupMinScale = 2.0;
+} // unnamed namespace
+
+namespace content {
+
+class DisambiguationPopupHelperUnittest : public testing::Test {
+ public:
+ DisambiguationPopupHelperUnittest()
+ : kViewportSize_(640, 480) { }
+ protected:
+ const gfx::Size kViewportSize_;
+};
+
+TEST_F(DisambiguationPopupHelperUnittest, ClipByViewport) {
+ gfx::Rect tap_rect(1000, 1000, 10, 10);
+ WebKit::WebVector<WebKit::WebRect> target_rects(static_cast<size_t>(1));
+ target_rects[0] = gfx::Rect(-20, -20, 10, 10);
+
+ gfx::Rect zoom_rect;
+ float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
+ tap_rect, target_rects, kViewportSize_, &zoom_rect);
+
+ EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(zoom_rect));
+ EXPECT_LE(kDisambiguationPopupMinScale, scale);
+
+ gfx::Size scaled_size = ToCeiledSize(zoom_rect.size().Scale(scale));
+ EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(gfx::Rect(scaled_size)));
+}
+
+TEST_F(DisambiguationPopupHelperUnittest, MiniTarget) {
+ gfx::Rect tap_rect(-5, -5, 20, 20);
+ WebKit::WebVector<WebKit::WebRect> target_rects(static_cast<size_t>(1));
+ target_rects[0] = gfx::Rect(10, 10, 1, 1);
+
+ gfx::Rect zoom_rect;
+ float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
+ tap_rect, target_rects, kViewportSize_, &zoom_rect);
+
+ EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(zoom_rect));
+ EXPECT_EQ(kDisambiguationPopupMaxScale, scale);
+ EXPECT_TRUE(zoom_rect.Contains(target_rects[0]));
+
+ gfx::Size scaled_size = ToCeiledSize(zoom_rect.size().Scale(scale));
+ EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(gfx::Rect(scaled_size)));
+}
+
+TEST_F(DisambiguationPopupHelperUnittest, LongLinks) {
+ gfx::Rect tap_rect(10, 10, 20, 20);
+ WebKit::WebVector<WebKit::WebRect> target_rects(static_cast<size_t>(2));
+ target_rects[0] = gfx::Rect(15, 15, 1000, 5);
+ target_rects[1] = gfx::Rect(15, 25, 1000, 5);
+
+ gfx::Rect zoom_rect;
+ float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
+ tap_rect, target_rects, kViewportSize_, &zoom_rect);
+
+ EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(zoom_rect));
+ EXPECT_EQ(kDisambiguationPopupMaxScale, scale);
+ EXPECT_TRUE(zoom_rect.Contains(tap_rect));
+
+ gfx::Size scaled_size = ToCeiledSize(zoom_rect.size().Scale(scale));
+ EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(gfx::Rect(scaled_size)));
+}
+
+} // namespace content