Chromium Code Reviews| 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 using namespace content; | |
|
darin (slow to review)
2012/10/17 19:14:01
nit: google style forbids 'using namespace Foo'
Y
trchen
2012/10/17 22:25:08
Done.
| |
| 15 using namespace WebKit; | |
| 16 | |
| 17 // these constants are copied from the implementation class | |
| 18 namespace { | |
| 19 const float kDisambiguationPopupMaxScale = 5.0; | |
| 20 const float kDisambiguationPopupMinScale = 2.0; | |
| 21 } // unnamed namespace | |
| 22 | |
| 23 class DisambiguationPopupHelperUnittest : public testing::Test { | |
| 24 public: | |
| 25 DisambiguationPopupHelperUnittest() | |
| 26 : kViewportSize_(640, 480) { } | |
| 27 protected: | |
| 28 const gfx::Size kViewportSize_; | |
| 29 }; | |
| 30 | |
| 31 TEST_F(DisambiguationPopupHelperUnittest, ClipByViewport) { | |
| 32 gfx::Rect tap_rect(1000, 1000, 10, 10); | |
| 33 WebVector<WebRect> target_rects(static_cast<size_t>(1)); | |
| 34 target_rects[0] = gfx::Rect(-20, -20, 10, 10); | |
| 35 | |
| 36 gfx::Rect zoom_rect; | |
| 37 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor( | |
| 38 tap_rect, target_rects, kViewportSize_, &zoom_rect); | |
| 39 | |
| 40 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(zoom_rect)); | |
| 41 EXPECT_LE(kDisambiguationPopupMinScale, scale); | |
| 42 | |
| 43 gfx::Size scaled_size = ToCeiledSize(zoom_rect.size().Scale(scale)); | |
| 44 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(gfx::Rect(scaled_size))); | |
| 45 } | |
| 46 | |
| 47 TEST_F(DisambiguationPopupHelperUnittest, MiniTarget) { | |
| 48 gfx::Rect tap_rect(-5, -5, 20, 20); | |
| 49 WebVector<WebRect> target_rects(static_cast<size_t>(1)); | |
| 50 target_rects[0] = gfx::Rect(10, 10, 1, 1); | |
| 51 | |
| 52 gfx::Rect zoom_rect; | |
| 53 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor( | |
| 54 tap_rect, target_rects, kViewportSize_, &zoom_rect); | |
| 55 | |
| 56 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(zoom_rect)); | |
| 57 EXPECT_EQ(kDisambiguationPopupMaxScale, scale); | |
| 58 EXPECT_TRUE(zoom_rect.Contains(target_rects[0])); | |
| 59 | |
| 60 gfx::Size scaled_size = ToCeiledSize(zoom_rect.size().Scale(scale)); | |
| 61 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(gfx::Rect(scaled_size))); | |
| 62 } | |
| 63 | |
| 64 TEST_F(DisambiguationPopupHelperUnittest, LongLinks) { | |
| 65 gfx::Rect tap_rect(10, 10, 20, 20); | |
| 66 WebVector<WebRect> target_rects(static_cast<size_t>(2)); | |
| 67 target_rects[0] = gfx::Rect(15, 15, 1000, 5); | |
| 68 target_rects[1] = gfx::Rect(15, 25, 1000, 5); | |
| 69 | |
| 70 gfx::Rect zoom_rect; | |
| 71 float scale = DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor( | |
| 72 tap_rect, target_rects, kViewportSize_, &zoom_rect); | |
| 73 | |
| 74 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(zoom_rect)); | |
| 75 EXPECT_EQ(kDisambiguationPopupMaxScale, scale); | |
| 76 EXPECT_TRUE(zoom_rect.Contains(tap_rect)); | |
| 77 | |
| 78 gfx::Size scaled_size = ToCeiledSize(zoom_rect.size().Scale(scale)); | |
| 79 EXPECT_TRUE(gfx::Rect(kViewportSize_).Contains(gfx::Rect(scaled_size))); | |
| 80 } | |
| 81 | |
| OLD | NEW |