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 "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 |
OLD | NEW |