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

Side by Side Diff: Source/web/tests/PinchViewportTest.cpp

Issue 268363013: Text selection handles now take into account pinch viewport's offset. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 7 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 | « Source/web/WebViewImpl.cpp ('k') | Source/web/tests/data/pinch-viewport-input-field.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 6
7 #include "core/frame/PinchViewport.h" 7 #include "core/frame/PinchViewport.h"
8 8
9 #include "core/frame/FrameHost.h" 9 #include "core/frame/FrameHost.h"
10 #include "core/frame/LocalFrame.h" 10 #include "core/frame/LocalFrame.h"
11 #include "core/rendering/RenderView.h" 11 #include "core/rendering/RenderView.h"
12 #include "core/rendering/compositing/CompositedLayerMapping.h" 12 #include "core/rendering/compositing/CompositedLayerMapping.h"
13 #include "core/rendering/compositing/RenderLayerCompositor.h" 13 #include "core/rendering/compositing/RenderLayerCompositor.h"
14 #include "public/platform/Platform.h" 14 #include "public/platform/Platform.h"
15 #include "public/platform/WebLayerTreeView.h" 15 #include "public/platform/WebLayerTreeView.h"
16 #include "public/platform/WebUnitTestSupport.h" 16 #include "public/platform/WebUnitTestSupport.h"
17 #include "public/web/WebScriptSource.h"
17 #include "public/web/WebSettings.h" 18 #include "public/web/WebSettings.h"
18 #include "public/web/WebViewClient.h" 19 #include "public/web/WebViewClient.h"
19 #include "web/WebLocalFrameImpl.h" 20 #include "web/WebLocalFrameImpl.h"
20 #include "web/tests/FrameTestHelpers.h" 21 #include "web/tests/FrameTestHelpers.h"
21 #include "web/tests/URLTestHelpers.h" 22 #include "web/tests/URLTestHelpers.h"
22 #include <gmock/gmock.h> 23 #include <gmock/gmock.h>
23 #include <gtest/gtest.h> 24 #include <gtest/gtest.h>
24 25
25 #define EXPECT_FLOAT_POINT_EQ(expected, actual) \ 26 #define EXPECT_FLOAT_POINT_EQ(expected, actual) \
26 do { \ 27 do { \
27 EXPECT_FLOAT_EQ((expected).x(), (actual).x()); \ 28 EXPECT_FLOAT_EQ((expected).x(), (actual).x()); \
28 EXPECT_FLOAT_EQ((expected).y(), (actual).y()); \ 29 EXPECT_FLOAT_EQ((expected).y(), (actual).y()); \
29 } while (false) 30 } while (false)
30 31
32 #define EXPECT_POINT_EQ(expected, actual) \
33 do { \
34 EXPECT_EQ((expected).x(), (actual).x()); \
35 EXPECT_EQ((expected).y(), (actual).y()); \
36 } while (false)
37
31 #define EXPECT_SIZE_EQ(expected, actual) \ 38 #define EXPECT_SIZE_EQ(expected, actual) \
32 do { \ 39 do { \
33 EXPECT_EQ((expected).width(), (actual).width()); \ 40 EXPECT_EQ((expected).width(), (actual).width()); \
34 EXPECT_EQ((expected).height(), (actual).height()); \ 41 EXPECT_EQ((expected).height(), (actual).height()); \
35 } while (false) 42 } while (false)
36 43
37 #define EXPECT_FLOAT_RECT_EQ(expected, actual) \ 44 #define EXPECT_FLOAT_RECT_EQ(expected, actual) \
38 do { \ 45 do { \
39 EXPECT_FLOAT_EQ((expected).x(), (actual).x()); \ 46 EXPECT_FLOAT_EQ((expected).x(), (actual).x()); \
40 EXPECT_FLOAT_EQ((expected).y(), (actual).y()); \ 47 EXPECT_FLOAT_EQ((expected).y(), (actual).y()); \
41 EXPECT_FLOAT_EQ((expected).width(), (actual).width()); \ 48 EXPECT_FLOAT_EQ((expected).width(), (actual).width()); \
42 EXPECT_FLOAT_EQ((expected).height(), (actual).height()); \ 49 EXPECT_FLOAT_EQ((expected).height(), (actual).height()); \
43 } while (false) 50 } while (false)
44 51
45 52
46 using namespace WebCore; 53 using namespace WebCore;
47 using namespace blink; 54 using namespace blink;
55 using blink::FrameTestHelpers::runPendingTasks;
48 56
49 namespace { 57 namespace {
50 58
51 class PinchViewportTest : public testing::Test { 59 class PinchViewportTest : public testing::Test {
52 public: 60 public:
53 PinchViewportTest() 61 PinchViewportTest()
54 : m_baseURL("http://www.test.com/") 62 : m_baseURL("http://www.test.com/")
55 { 63 {
56 } 64 }
57 65
(...skipping 23 matching lines...) Expand all
81 void forceFullCompositingUpdate() 89 void forceFullCompositingUpdate()
82 { 90 {
83 webViewImpl()->layout(); 91 webViewImpl()->layout();
84 } 92 }
85 93
86 void registerMockedHttpURLLoad(const std::string& fileName) 94 void registerMockedHttpURLLoad(const std::string& fileName)
87 { 95 {
88 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseU RL.c_str()), WebString::fromUTF8(fileName.c_str())); 96 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseU RL.c_str()), WebString::fromUTF8(fileName.c_str()));
89 } 97 }
90 98
99 void executeScript(const WebString& code)
100 {
101 webViewImpl()->mainFrame()->executeScript(WebScriptSource(code));
102 runPendingTasks();
103 }
104
91 WebLayer* getRootScrollLayer() 105 WebLayer* getRootScrollLayer()
92 { 106 {
93 RenderLayerCompositor* compositor = frame()->contentRenderer()->composit or(); 107 RenderLayerCompositor* compositor = frame()->contentRenderer()->composit or();
94 ASSERT(compositor); 108 ASSERT(compositor);
95 ASSERT(compositor->scrollLayer()); 109 ASSERT(compositor->scrollLayer());
96 110
97 WebLayer* webScrollLayer = compositor->scrollLayer()->platformLayer(); 111 WebLayer* webScrollLayer = compositor->scrollLayer()->platformLayer();
98 return webScrollLayer; 112 return webScrollLayer;
99 } 113 }
100 114
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 EXPECT_SIZE_EQ(IntSize(0, 0), frame()->page()->frameHost().pinchViewport().s ize()); 437 EXPECT_SIZE_EQ(IntSize(0, 0), frame()->page()->frameHost().pinchViewport().s ize());
424 438
425 webViewImpl()->enableAutoResizeMode(WebSize(10, 10), WebSize(1000, 1000)); 439 webViewImpl()->enableAutoResizeMode(WebSize(10, 10), WebSize(1000, 1000));
426 440
427 registerMockedHttpURLLoad("200-by-300.html"); 441 registerMockedHttpURLLoad("200-by-300.html");
428 navigateTo(m_baseURL + "200-by-300.html"); 442 navigateTo(m_baseURL + "200-by-300.html");
429 443
430 EXPECT_SIZE_EQ(IntSize(200, 300), frame()->page()->frameHost().pinchViewport ().size()); 444 EXPECT_SIZE_EQ(IntSize(200, 300), frame()->page()->frameHost().pinchViewport ().size());
431 } 445 }
432 446
447 // Test that the text selection handle's position accounts for the pinch viewpor t.
448 TEST_F(PinchViewportTest, TestTextSelectionHandles)
449 {
450 initializeWithDesktopSettings();
451 webViewImpl()->resize(IntSize(500, 800));
452
453 registerMockedHttpURLLoad("pinch-viewport-input-field.html");
454 navigateTo(m_baseURL + "pinch-viewport-input-field.html");
455
456 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport();
457 webViewImpl()->setInitialFocus(false);
458
459 WebRect originalAnchor;
460 WebRect originalFocus;
461 webViewImpl()->selectionBounds(originalAnchor, originalFocus);
462
463 webViewImpl()->setPageScaleFactor(2);
464 pinchViewport.setLocation(FloatPoint(100, 400));
465
466 WebRect anchor;
467 WebRect focus;
468 webViewImpl()->selectionBounds(anchor, focus);
469
470 IntPoint expected(IntRect(originalAnchor).location());
471 expected.moveBy(-flooredIntPoint(pinchViewport.visibleRect().location()));
472 expected.scale(pinchViewport.scale(), pinchViewport.scale());
473
474 EXPECT_POINT_EQ(expected, IntRect(anchor).location());
475 EXPECT_POINT_EQ(expected, IntRect(focus).location());
476
477 // FIXME(bokan) - http://crbug.com/364154 - Figure out how to test text sele ction
478 // as well rather than just carret.
479 }
480
433 } // namespace 481 } // namespace
OLDNEW
« no previous file with comments | « Source/web/WebViewImpl.cpp ('k') | Source/web/tests/data/pinch-viewport-input-field.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698