15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2010 Google Inc. All rights reserved.
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions are
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * met:
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Redistributions of source code must retain the above copyright
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer.
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Redistributions in binary form must reproduce the above
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * in the documentation and/or other materials provided with the
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * distribution.
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Neither the name of Google Inc. nor the names of its
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * contributors may be used to endorse or promote products derived from
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * this software without specific prior written permission.
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "config.h"
325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
33f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebFrame.h"
345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
35926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#include "SkBitmap.h"
36926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#include "SkCanvas.h"
377242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#include "bindings/core/v8/V8Node.h"
3876c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles)#include "core/UserAgentStyleSheets.h"
39197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/clipboard/DataTransfer.h"
40aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch#include "core/css/StyleSheetContents.h"
41197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/css/resolver/StyleResolver.h"
42aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch#include "core/css/resolver/ViewportStyleResolver.h"
4353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/dom/DocumentMarkerController.h"
449e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)#include "core/dom/Fullscreen.h"
45c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)#include "core/dom/NodeRenderStyle.h"
4653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/dom/Range.h"
470019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch#include "core/editing/Editor.h"
4853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/editing/FrameSelection.h"
491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "core/editing/SpellChecker.h"
50f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles)#include "core/editing/VisiblePosition.h"
5109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/events/MouseEvent.h"
529e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)#include "core/fetch/MemoryCache.h"
537242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#include "core/frame/FrameHost.h"
54d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/frame/FrameView.h"
55d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/frame/LocalFrame.h"
567242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#include "core/frame/PinchViewport.h"
57d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/frame/Settings.h"
58197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/html/HTMLDocument.h"
59e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/html/HTMLFormElement.h"
60197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/loader/DocumentThreadableLoader.h"
61197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/loader/DocumentThreadableLoaderClient.h"
62e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/loader/FrameLoadRequest.h"
63197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/loader/ThreadableLoader.h"
6453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/page/EventHandler.h"
65197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/page/Page.h"
6653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/HitTestResult.h"
6753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/RenderView.h"
68d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/rendering/compositing/RenderLayerCompositor.h"
699e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)#include "core/testing/URLTestHelpers.h"
70f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)#include "platform/DragImage.h"
7176c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles)#include "platform/RuntimeEnabledFeatures.h"
72d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "platform/UserGestureIndicator.h"
731e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/geometry/FloatRect.h"
741e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/network/ResourceError.h"
75a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/scroll/ScrollbarTheme.h"
76197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "platform/weborigin/SchemeRegistry.h"
775267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "public/platform/Platform.h"
785267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "public/platform/WebFloatRect.h"
79197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "public/platform/WebSelectionBound.h"
805267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "public/platform/WebThread.h"
81bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#include "public/platform/WebURL.h"
825267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "public/platform/WebURLResponse.h"
83bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#include "public/platform/WebUnitTestSupport.h"
849e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)#include "public/web/WebCache.h"
85f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebDataSource.h"
86f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebDocument.h"
87f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebFindOptions.h"
88f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebFormElement.h"
89f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebFrameClient.h"
90f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebHistoryItem.h"
91e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)#include "public/web/WebPrintParams.h"
92f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebRange.h"
93197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "public/web/WebRemoteFrame.h"
94f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebScriptSource.h"
95f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebSearchableFormData.h"
96f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebSecurityOrigin.h"
97f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebSecurityPolicy.h"
98f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebSettings.h"
99f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebSpellCheckClient.h"
100f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebTextCheckingCompletion.h"
101f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebTextCheckingResult.h"
102f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebViewClient.h"
103f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "web/WebLocalFrameImpl.h"
1047242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#include "web/WebRemoteFrameImpl.h"
105f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "web/WebViewImpl.h"
106f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "web/tests/FrameTestHelpers.h"
107591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "wtf/Forward.h"
108d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "wtf/dtoa/utils.h"
109f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include <gmock/gmock.h>
110f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include <gtest/gtest.h>
1111e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include <map>
112f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include <v8.h>
1135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1147242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tuccinamespace {
1157242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
11651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)using blink::URLTestHelpers::toKURL;
11751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)using blink::FrameTestHelpers::runPendingTasks;
1187242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucciusing namespace blink;
1195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
120f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles)const int touchPointPadding = 32;
121f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles)
1227242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#define EXPECT_RECT_EQ(a, b) \
1237242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    do {                                   \
1247242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        EXPECT_EQ(a.x(), b.x());           \
1257242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        EXPECT_EQ(a.y(), b.y());           \
1267242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        EXPECT_EQ(a.width(), b.width());   \
1277242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        EXPECT_EQ(a.height(), b.height()); \
1287242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    } while (false)
1297242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
1307242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#define EXPECT_POINT_EQ(expected, actual) \
1317242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    do { \
1327242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        EXPECT_EQ((expected).x(), (actual).x()); \
1337242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        EXPECT_EQ((expected).y(), (actual).y()); \
1347242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    } while (false)
1357242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
1367242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#define EXPECT_FLOAT_POINT_EQ(expected, actual) \
1377242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    do { \
1387242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        EXPECT_FLOAT_EQ((expected).x(), (actual).x()); \
1397242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        EXPECT_FLOAT_EQ((expected).y(), (actual).y()); \
1407242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    } while (false)
1417242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
1427242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#define EXPECT_EQ_POINT(a, b) \
143926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    EXPECT_EQ(a.x(), b.x()); \
1447242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    EXPECT_EQ(a.y(), b.y());
145926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
146f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liuclass FakeCompositingWebViewClient : public FrameTestHelpers::TestWebViewClient {
14753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)public:
14843e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)    virtual bool enterFullScreen() OVERRIDE { return true; }
14953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)};
15053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
1515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class WebFrameTest : public testing::Test {
1521e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)protected:
1535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    WebFrameTest()
154926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        : m_baseURL("http://www.test.com/")
155926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        , m_chromeURL("chrome://")
156926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    {
157926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    }
158926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
159926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    virtual ~WebFrameTest()
1605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
161926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
1625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
1635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void registerMockedHttpURLLoad(const std::string& fileName)
1655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
1665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8(fileName.c_str()));
1675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
1685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void registerMockedChromeURLLoad(const std::string& fileName)
1705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
1715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_chromeURL.c_str()), WebString::fromUTF8(fileName.c_str()));
1725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
1735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
174aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    void applyViewportStyleOverride(FrameTestHelpers::WebViewHelper* webViewHelper)
175aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    {
1767242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        RefPtrWillBeRawPtr<StyleSheetContents> styleSheet = StyleSheetContents::create(CSSParserContext(UASheetMode, 0));
177c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)        styleSheet->parseString(String(blink::viewportAndroidCss, sizeof(blink::viewportAndroidCss)));
1787242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        OwnPtrWillBeRawPtr<RuleSet> ruleSet = RuleSet::create();
1797242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        ruleSet->addRulesFromSheet(styleSheet.get(), MediaQueryEvaluator("screen"));
180aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch
1815d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        Document* document = toLocalFrame(webViewHelper->webViewImpl()->page()->mainFrame())->document();
1827242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        document->ensureStyleResolver().viewportStyleResolver()->collectViewportRules(ruleSet.get(), ViewportStyleResolver::UserAgentOrigin);
183aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch        document->ensureStyleResolver().viewportStyleResolver()->resolve();
184aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    }
185aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch
1861e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static void configueCompositingWebView(WebSettings* settings)
18753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    {
1881e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        settings->setAcceleratedCompositingEnabled(true);
1899e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        settings->setPreferCompositingToLCDTextEnabled(true);
1909e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    }
1919e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)
1929e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    static void configureLoadsImagesAutomatically(WebSettings* settings)
1939e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    {
1949e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        settings->setLoadsImagesAutomatically(true);
19553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    }
19653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
1971e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    void initializeTextSelectionWebView(const std::string& url, FrameTestHelpers::WebViewHelper* webViewHelper)
1981e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {
1991e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        webViewHelper->initializeAndLoad(url, true);
2001e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        webViewHelper->webView()->settings()->setDefaultFontSize(12);
2011e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        webViewHelper->webView()->resize(WebSize(640, 480));
2021e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
203c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)
2047242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    PassOwnPtr<DragImage> nodeImageTestSetup(FrameTestHelpers::WebViewHelper* webViewHelper, const std::string& testcase)
205f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    {
206f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        registerMockedHttpURLLoad("nodeimage.html");
207f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        webViewHelper->initializeAndLoad(m_baseURL + "nodeimage.html");
208f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        webViewHelper->webView()->resize(WebSize(640, 480));
209f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        webViewHelper->webView()->layout();
2107242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        RefPtrWillBeRawPtr<LocalFrame> frame = toLocalFrame(webViewHelper->webViewImpl()->page()->mainFrame());
2117242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        ASSERT(frame);
2127242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        Element* element = frame->document()->getElementById(testcase.c_str());
213f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)        return frame->nodeImage(*element);
214f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    }
215f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
2165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    std::string m_baseURL;
2175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    std::string m_chromeURL;
2185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)};
2195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2208abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)class UseMockScrollbarSettings {
2218abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)public:
2228abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    UseMockScrollbarSettings()
2238abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    {
2247242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        Settings::setMockScrollbarsEnabled(true);
2257242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true);
2267242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        EXPECT_TRUE(ScrollbarTheme::theme()->usesOverlayScrollbars());
2278abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    }
2288abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
2298abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    ~UseMockScrollbarSettings()
2308abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    {
2317242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        Settings::setMockScrollbarsEnabled(false);
2327242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(false);
2338abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    }
2348abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)};
2358abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
2365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)TEST_F(WebFrameTest, ContentText)
2375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    registerMockedHttpURLLoad("iframes_test.html");
2395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    registerMockedHttpURLLoad("visible_iframe.html");
2405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    registerMockedHttpURLLoad("invisible_iframe.html");
2415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    registerMockedHttpURLLoad("zero_sized_iframe.html");
2425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2431e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
2441e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "iframes_test.html");
2455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Now retrieve the frames text and test it only includes visible elements.
2471e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    std::string content = webViewHelper.webView()->mainFrame()->contentAsText(1024).utf8();
2485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    EXPECT_NE(std::string::npos, content.find(" visible paragraph"));
2495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    EXPECT_NE(std::string::npos, content.find(" visible iframe"));
2505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    EXPECT_EQ(std::string::npos, content.find(" invisible pararaph"));
2515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    EXPECT_EQ(std::string::npos, content.find(" invisible iframe"));
2525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    EXPECT_EQ(std::string::npos, content.find("iframe with zero size"));
2535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)TEST_F(WebFrameTest, FrameForEnteredContext)
2565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    registerMockedHttpURLLoad("iframes_test.html");
2585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    registerMockedHttpURLLoad("visible_iframe.html");
2595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    registerMockedHttpURLLoad("invisible_iframe.html");
2605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    registerMockedHttpURLLoad("zero_sized_iframe.html");
2615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2621e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
2631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "iframes_test.html", true);
2645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2658abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    v8::HandleScope scope(v8::Isolate::GetCurrent());
2666f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    EXPECT_EQ(webViewHelper.webView()->mainFrame(), WebLocalFrame::frameForContext(webViewHelper.webView()->mainFrame()->mainWorldScriptContext()));
2676f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    EXPECT_EQ(webViewHelper.webView()->mainFrame()->firstChild(), WebLocalFrame::frameForContext(webViewHelper.webView()->mainFrame()->firstChild()->mainWorldScriptContext()));
2685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)TEST_F(WebFrameTest, FormWithNullFrame)
2715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    registerMockedHttpURLLoad("form.html");
2735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2741e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
2751e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "form.html");
2765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    WebVector<WebFormElement> forms;
2781e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->mainFrame()->document().forms(forms);
2791e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.reset();
2805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    EXPECT_EQ(forms.size(), 1U);
2825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // This test passes if this doesn't crash.
2845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    WebSearchableFormData searchableDataForm(forms[0]);
2855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)TEST_F(WebFrameTest, ChromePageJavascript)
2885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    registerMockedChromeURLLoad("history.html");
29002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
2915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Pass true to enable JavaScript.
2921e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
2931e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.initializeAndLoad(m_chromeURL + "history.html", true);
2945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Try to run JS against the chrome-style URL.
2961e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascript:document.body.appendChild(document.createTextNode('Clobbered'))");
2975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Required to see any updates in contentAsText.
2991e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
3005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Now retrieve the frame's text and ensure it was modified by running javascript.
3021e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    std::string content = webViewHelper.webView()->mainFrame()->contentAsText(1024).utf8();
3035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    EXPECT_NE(std::string::npos, content.find("Clobbered"));
3045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
3055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)TEST_F(WebFrameTest, ChromePageNoJavascript)
3075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
3085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    registerMockedChromeURLLoad("history.html");
3095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    /// Pass true to enable JavaScript.
3111e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
3121e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.initializeAndLoad(m_chromeURL + "history.html", true);
3135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Try to run JS against the chrome-style URL after prohibiting it.
3155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs("chrome");
3161e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascript:document.body.appendChild(document.createTextNode('Clobbered'))");
3175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Required to see any updates in contentAsText.
3191e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
3205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Now retrieve the frame's text and ensure it wasn't modified by running javascript.
3221e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    std::string content = webViewHelper.webView()->mainFrame()->contentAsText(1024).utf8();
3235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    EXPECT_EQ(std::string::npos, content.find("Clobbered"));
3245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
3255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
326bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)TEST_F(WebFrameTest, LocationSetHostWithMissingPort)
327bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){
328bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    std::string fileName = "print-location-href.html";
329bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    registerMockedHttpURLLoad(fileName);
330bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    URLTestHelpers::registerMockedURLLoad(toKURL("http://www.test.com:0/" + fileName), WebString::fromUTF8(fileName));
331bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
332bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
333bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
334bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    /// Pass true to enable JavaScript.
335bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + fileName, true);
336bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
337bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    // Setting host to "hostname:" should be treated as "hostname:0".
338bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascript:location.host = 'www.test.com:'; void 0;");
339bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
340bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascript:document.body.textContent = location.href; void 0;");
341bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
342bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    std::string content = webViewHelper.webView()->mainFrame()->contentAsText(1024).utf8();
343bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    EXPECT_EQ("http://www.test.com:0/" + fileName, content);
344bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)}
345bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
346bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)TEST_F(WebFrameTest, LocationSetEmptyPort)
347bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles){
348bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    std::string fileName = "print-location-href.html";
349bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    registerMockedHttpURLLoad(fileName);
350bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    URLTestHelpers::registerMockedURLLoad(toKURL("http://www.test.com:0/" + fileName), WebString::fromUTF8(fileName));
351bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
352bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
353bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
354bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    /// Pass true to enable JavaScript.
355bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + fileName, true);
356bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
357bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascript:location.port = ''; void 0;");
358bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
359bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascript:document.body.textContent = location.href; void 0;");
360bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
361bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    std::string content = webViewHelper.webView()->mainFrame()->contentAsText(1024).utf8();
362bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    EXPECT_EQ("http://www.test.com:0/" + fileName, content);
363bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)}
364bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
365d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)class CSSCallbackWebFrameClient : public FrameTestHelpers::TestWebFrameClient {
3661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)public:
3671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    CSSCallbackWebFrameClient() : m_updateCount(0) { }
368a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    virtual void didMatchCSS(WebLocalFrame*, const WebVector<WebString>& newlyMatchingSelectors, const WebVector<WebString>& stoppedMatchingSelectors) OVERRIDE;
3691e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
370a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    std::map<WebLocalFrame*, std::set<std::string> > m_matchedSelectors;
3711e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int m_updateCount;
3721e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)};
3731e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
374a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdochvoid CSSCallbackWebFrameClient::didMatchCSS(WebLocalFrame* frame, const WebVector<WebString>& newlyMatchingSelectors, const WebVector<WebString>& stoppedMatchingSelectors)
3751e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
3761e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ++m_updateCount;
3771e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    std::set<std::string>& frameSelectors = m_matchedSelectors[frame];
3781e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    for (size_t i = 0; i < newlyMatchingSelectors.size(); ++i) {
3791e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        std::string selector = newlyMatchingSelectors[i].utf8();
3801e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        EXPECT_EQ(0U, frameSelectors.count(selector)) << selector;
3811e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        frameSelectors.insert(selector);
3821e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
3831e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    for (size_t i = 0; i < stoppedMatchingSelectors.size(); ++i) {
3841e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        std::string selector = stoppedMatchingSelectors[i].utf8();
3851e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        EXPECT_EQ(1U, frameSelectors.count(selector)) << selector;
3861e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        frameSelectors.erase(selector);
3871e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
3881e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
3891e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
3901e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)class WebFrameCSSCallbackTest : public testing::Test {
3911e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)protected:
3921e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    WebFrameCSSCallbackTest()
3931e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {
3941e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
395a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch        m_frame = m_helper.initializeAndLoad("about:blank", true, &m_client)->mainFrame()->toWebLocalFrame();
3961e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
3971e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
3981e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ~WebFrameCSSCallbackTest()
3991e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {
4001e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        EXPECT_EQ(1U, m_client.m_matchedSelectors.size());
4011e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
4021e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4031e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    WebDocument doc() const
4041e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {
4051e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return m_frame->document();
4061e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
4071e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4081e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int updateCount() const
4091e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {
4101e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return m_client.m_updateCount;
4111e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
4121e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4131e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    const std::set<std::string>& matchedSelectors()
4141e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {
4151e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return m_client.m_matchedSelectors[m_frame];
4161e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
4171e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
418d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    void loadHTML(const std::string& html)
4191e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {
420d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)        FrameTestHelpers::loadHTMLString(m_frame, html, toKURL("about:blank"));
4211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
4221e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4231e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    void executeScript(const WebString& code)
4241e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {
4251e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        m_frame->executeScript(WebScriptSource(code));
42609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        m_frame->view()->layout();
4271e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        runPendingTasks();
4281e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
4291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    CSSCallbackWebFrameClient m_client;
4311e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper m_helper;
432a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    WebLocalFrame* m_frame;
4331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)};
4341e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
43551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)TEST_F(WebFrameCSSCallbackTest, AuthorStyleSheet)
4361e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
4371e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    loadHTML(
4381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "<style>"
4391e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        // This stylesheet checks that the internal property and value can't be
4401e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        // set by a stylesheet, only WebDocument::watchCSSSelectors().
4411e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "div.initial_on { -internal-callback: none; }"
4421e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "div.initial_off { -internal-callback: -internal-presence; }"
4431e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "</style>"
4441e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "<div class=\"initial_on\"></div>"
4451e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "<div class=\"initial_off\"></div>");
4461e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4471e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    std::vector<WebString> selectors;
4481e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    selectors.push_back(WebString::fromUTF8("div.initial_on"));
4491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    m_frame->document().watchCSSSelectors(WebVector<WebString>(selectors));
45009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_frame->view()->layout();
4511e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    runPendingTasks();
4521e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(1, updateCount());
4531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_THAT(matchedSelectors(), testing::ElementsAre("div.initial_on"));
4541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Check that adding a watched selector calls back for already-present nodes.
4561e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    selectors.push_back(WebString::fromUTF8("div.initial_off"));
4571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    doc().watchCSSSelectors(WebVector<WebString>(selectors));
45809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_frame->view()->layout();
4591e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    runPendingTasks();
4601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(2, updateCount());
4611e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_THAT(matchedSelectors(), testing::ElementsAre("div.initial_off", "div.initial_on"));
4621e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Check that we can turn off callbacks for certain selectors.
4641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    doc().watchCSSSelectors(WebVector<WebString>());
46509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_frame->view()->layout();
4661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    runPendingTasks();
4671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(3, updateCount());
4681e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_THAT(matchedSelectors(), testing::ElementsAre());
4691e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
4701e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4711e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)TEST_F(WebFrameCSSCallbackTest, SharedRenderStyle)
4721e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
4731e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Check that adding an element calls back when it matches an existing rule.
4741e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    std::vector<WebString> selectors;
4751e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    selectors.push_back(WebString::fromUTF8("span"));
4761e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    doc().watchCSSSelectors(WebVector<WebString>(selectors));
4771e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4781e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    executeScript(
4791e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "i1 = document.createElement('span');"
4801e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "i1.id = 'first_span';"
4811e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "document.body.appendChild(i1)");
4821e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(1, updateCount());
4831e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span"));
4841e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4851e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Adding a second element that shares a RenderStyle shouldn't call back.
4861e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // We use <span>s to avoid default style rules that can set
4871e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // RenderStyle::unique().
4881e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    executeScript(
4891e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "i2 = document.createElement('span');"
4901e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "i2.id = 'second_span';"
4911e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "i1 = document.getElementById('first_span');"
4921e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "i1.parentNode.insertBefore(i2, i1.nextSibling);");
4931e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(1, updateCount());
4941e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span"));
4951e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4961e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Removing the first element shouldn't call back.
4971e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    executeScript(
4981e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "i1 = document.getElementById('first_span');"
4991e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "i1.parentNode.removeChild(i1);");
5001e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(1, updateCount());
5011e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span"));
5021e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5031e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // But removing the second element *should* call back.
5041e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    executeScript(
5051e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "i2 = document.getElementById('second_span');"
5061e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "i2.parentNode.removeChild(i2);");
5071e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(2, updateCount());
5081e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_THAT(matchedSelectors(), testing::ElementsAre());
5091e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
5101e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
51151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)TEST_F(WebFrameCSSCallbackTest, CatchesAttributeChange)
5121e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
5131e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    loadHTML("<span></span>");
5141e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5151e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    std::vector<WebString> selectors;
5161e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    selectors.push_back(WebString::fromUTF8("span[attr=\"value\"]"));
5171e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    doc().watchCSSSelectors(WebVector<WebString>(selectors));
5181e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    runPendingTasks();
5191e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5201e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(0, updateCount());
5211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_THAT(matchedSelectors(), testing::ElementsAre());
5221e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5231e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    executeScript(
5241e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "document.querySelector('span').setAttribute('attr', 'value');");
5251e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(1, updateCount());
5261e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span[attr=\"value\"]"));
5271e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
5281e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
52951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)TEST_F(WebFrameCSSCallbackTest, DisplayNone)
5301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
5311e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    loadHTML("<div style='display:none'><span></span></div>");
5321e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    std::vector<WebString> selectors;
5341e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    selectors.push_back(WebString::fromUTF8("span"));
5351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    doc().watchCSSSelectors(WebVector<WebString>(selectors));
5361e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    runPendingTasks();
5371e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(0, updateCount()) << "Don't match elements in display:none trees.";
5391e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5401e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    executeScript(
5411e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "d = document.querySelector('div');"
5421e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "d.style.display = 'block';");
5431e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(1, updateCount()) << "Match elements when they become displayed.";
5441e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span"));
5451e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5461e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    executeScript(
5471e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "d = document.querySelector('div');"
5481e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "d.style.display = 'none';");
5491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(2, updateCount()) << "Unmatch elements when they become undisplayed.";
5501e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_THAT(matchedSelectors(), testing::ElementsAre());
5511e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5521e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    executeScript(
5531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "s = document.querySelector('span');"
5541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "s.style.display = 'none';");
5551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(2, updateCount()) << "No effect from no-display'ing a span that's already undisplayed.";
5561e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    executeScript(
5581e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "d = document.querySelector('div');"
5591e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "d.style.display = 'block';");
5601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(2, updateCount()) << "No effect from displaying a div whose span is display:none.";
5611e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5621e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    executeScript(
5631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "s = document.querySelector('span');"
5641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "s.style.display = 'inline';");
5651e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(3, updateCount()) << "Now the span is visible and produces a callback.";
5661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span"));
5671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5681e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    executeScript(
5691e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "s = document.querySelector('span');"
5701e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "s.style.display = 'none';");
5711e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(4, updateCount()) << "Undisplaying the span directly should produce another callback.";
5721e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_THAT(matchedSelectors(), testing::ElementsAre());
5731e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
5741e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5751e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)TEST_F(WebFrameCSSCallbackTest, Reparenting)
5761e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
5771e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    loadHTML(
5781e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "<div id='d1'><span></span></div>"
5791e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "<div id='d2'></div>");
5801e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5811e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    std::vector<WebString> selectors;
5821e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    selectors.push_back(WebString::fromUTF8("span"));
5831e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    doc().watchCSSSelectors(WebVector<WebString>(selectors));
58409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_frame->view()->layout();
5851e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    runPendingTasks();
5861e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5871e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(1, updateCount());
5881e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span"));
5891e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5901e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    executeScript(
5911e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "s = document.querySelector('span');"
5921e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "d2 = document.getElementById('d2');"
5931e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        "d2.appendChild(s);");
5941e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(1, updateCount()) << "Just moving an element that continues to match shouldn't send a spurious callback.";
5951e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span"));
5961e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
5971e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
59851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)TEST_F(WebFrameCSSCallbackTest, MultiSelector)
5991e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
6001e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    loadHTML("<span></span>");
6011e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
6021e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Check that selector lists match as the whole list, not as each element
6031e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // independently.
6041e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    std::vector<WebString> selectors;
6051e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    selectors.push_back(WebString::fromUTF8("span"));
6061e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    selectors.push_back(WebString::fromUTF8("span,p"));
6071e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    doc().watchCSSSelectors(WebVector<WebString>(selectors));
60809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_frame->view()->layout();
6091e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    runPendingTasks();
61009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
6111e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(1, updateCount());
6121e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span", "span, p"));
6131e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
6141e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
6151e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)TEST_F(WebFrameCSSCallbackTest, InvalidSelector)
6161e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
6171e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    loadHTML("<p><span></span></p>");
6181e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
6191e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Build a list with one valid selector and one invalid.
6201e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    std::vector<WebString> selectors;
6211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    selectors.push_back(WebString::fromUTF8("span"));
6221e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    selectors.push_back(WebString::fromUTF8("[")); // Invalid.
6231e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    selectors.push_back(WebString::fromUTF8("p span")); // Not compound.
6241e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    doc().watchCSSSelectors(WebVector<WebString>(selectors));
62509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_frame->view()->layout();
6261e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    runPendingTasks();
62709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
6281e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(1, updateCount());
6291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span"))
6301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        << "An invalid selector shouldn't prevent other selectors from matching.";
6311e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
6321e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
6335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)TEST_F(WebFrameTest, DispatchMessageEventWithOriginCheck)
6345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    registerMockedHttpURLLoad("postmessage_test.html");
6365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Pass true to enable JavaScript.
6381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
6391e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "postmessage_test.html", true);
64002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
6415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Send a message with the correct origin.
6425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    WebSecurityOrigin correctOrigin(WebSecurityOrigin::create(toKURL(m_baseURL)));
6431e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    WebDOMEvent event = webViewHelper.webView()->mainFrame()->document().createEvent("MessageEvent");
6445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    WebDOMMessageEvent message = event.to<WebDOMMessageEvent>();
6455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    WebSerializedScriptValue data(WebSerializedScriptValue::fromString("foo"));
6465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    message.initMessageEvent("message", false, false, data, "http://origin.com", 0, "");
6471e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->mainFrame()->dispatchMessageEventWithOriginCheck(correctOrigin, message);
6485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Send another message with incorrect origin.
6505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    WebSecurityOrigin incorrectOrigin(WebSecurityOrigin::create(toKURL(m_chromeURL)));
6511e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->mainFrame()->dispatchMessageEventWithOriginCheck(incorrectOrigin, message);
6525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Required to see any updates in contentAsText.
6541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
6555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Verify that only the first addition is in the body of the page.
6571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    std::string content = webViewHelper.webView()->mainFrame()->contentAsText(1024).utf8();
6585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    EXPECT_NE(std::string::npos, content.find("Message 1."));
6595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    EXPECT_EQ(std::string::npos, content.find("Message 2."));
6605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
66209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)TEST_F(WebFrameTest, PostMessageThenDetach)
66309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
66409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
66509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    webViewHelper.initializeAndLoad("about:blank");
66609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
6677242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    RefPtrWillBeRawPtr<LocalFrame> frame = toLocalFrame(webViewHelper.webViewImpl()->page()->mainFrame());
6687242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    NonThrowableExceptionState exceptionState;
6697242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    frame->domWindow()->postMessage(SerializedScriptValue::create("message"), 0, "*", frame->domWindow(), exceptionState);
67009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    webViewHelper.reset();
67109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    EXPECT_FALSE(exceptionState.hadException());
67209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
67309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // Success is not crashing.
67409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    runPendingTasks();
67509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
67609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
677f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liuclass FixedLayoutTestWebViewClient : public FrameTestHelpers::TestWebViewClient {
6785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) public:
6795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    virtual WebScreenInfo screenInfo() OVERRIDE { return m_screenInfo; }
6805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    WebScreenInfo m_screenInfo;
6825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)};
6835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
684a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)// Viewport settings need to be set before the page gets loaded
685a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)static void enableViewportSettings(WebSettings* settings)
686a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles){
687a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    settings->setViewportMetaEnabled(true);
688a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    settings->setViewportEnabled(true);
689a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    settings->setMainFrameResizesAreOrientationChanges(true);
690a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    settings->setShrinksViewportContentToFit(true);
691a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)}
692a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)
69307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch// Helper function to check or set text autosizing multipliers on a document.
69407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdochstatic bool checkOrSetTextAutosizingMultiplier(Document* document, float multiplier, bool setMultiplier)
69507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch{
69607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    bool multiplierCheckedOrSetAtLeastOnce = false;
6977242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    for (RenderObject* renderer = document->renderView(); renderer; renderer = renderer->nextInPreOrder()) {
69807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        if (renderer->style()) {
69907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch            if (setMultiplier)
70007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch                renderer->style()->setTextAutosizingMultiplier(multiplier);
70107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch            EXPECT_EQ(multiplier, renderer->style()->textAutosizingMultiplier());
70207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch            multiplierCheckedOrSetAtLeastOnce = true;
70307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        }
70407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    }
70507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    return multiplierCheckedOrSetAtLeastOnce;
70607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
70707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch}
70807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
70907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdochstatic bool setTextAutosizingMultiplier(Document* document, float multiplier)
71007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch{
71107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    return checkOrSetTextAutosizingMultiplier(document, multiplier, true);
71207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch}
71307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
71407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdochstatic bool checkTextAutosizingMultiplier(Document* document, float multiplier)
71507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch{
71607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    return checkOrSetTextAutosizingMultiplier(document, multiplier, false);
71707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch}
71807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
71907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben MurdochTEST_F(WebFrameTest, ChangeInFixedLayoutResetsTextAutosizingMultipliers)
7205267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles){
721bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
7225267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    registerMockedHttpURLLoad("fixed_layout.html");
7235267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
7245267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
7255267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    int viewportWidth = 640;
7265267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    int viewportHeight = 480;
7275267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
7281e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
729a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &client, enableViewportSettings);
7305267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
7317242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    Document* document = toLocalFrame(webViewHelper.webViewImpl()->page()->mainFrame())->document();
7325267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    document->settings()->setTextAutosizingEnabled(true);
7335267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    EXPECT_TRUE(document->settings()->textAutosizingEnabled());
7341e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webViewImpl()->resize(WebSize(viewportWidth, viewportHeight));
7351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webViewImpl()->layout();
7365267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
73707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    EXPECT_TRUE(setTextAutosizingMultiplier(document, 2));
7385267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
7397242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    ViewportDescription description = document->viewportDescription();
7408abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    // Choose a width that's not going match the viewport width of the loaded document.
7417242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    description.minWidth = Length(100, blink::Fixed);
7427242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    description.maxWidth = Length(100, blink::Fixed);
743bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    webViewHelper.webViewImpl()->updatePageDefinedViewportConstraints(description);
7445267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
74507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    EXPECT_TRUE(checkTextAutosizingMultiplier(document, 1));
74607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch}
74707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
748f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo LiuTEST_F(WebFrameTest, SetFrameRectInvalidatesTextAutosizingMultipliers)
74907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch{
75007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    UseMockScrollbarSettings mockScrollbarSettings;
75107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    registerMockedHttpURLLoad("iframe_reload.html");
75207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    registerMockedHttpURLLoad("visible_iframe.html");
75307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
75407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    FixedLayoutTestWebViewClient client;
75507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    int viewportWidth = 640;
75607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    int viewportHeight = 480;
75707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
75807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    FrameTestHelpers::WebViewHelper webViewHelper;
75907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    webViewHelper.initializeAndLoad(m_baseURL + "iframe_reload.html", true, 0, &client, enableViewportSettings);
76007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
7617242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    LocalFrame* mainFrame = toLocalFrame(webViewHelper.webViewImpl()->page()->mainFrame());
7627242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    Document* document = mainFrame->document();
7637242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    FrameView* frameView = webViewHelper.webViewImpl()->mainFrameImpl()->frameView();
76407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    document->settings()->setTextAutosizingEnabled(true);
76507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    EXPECT_TRUE(document->settings()->textAutosizingEnabled());
76607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    webViewHelper.webViewImpl()->resize(WebSize(viewportWidth, viewportHeight));
76707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    webViewHelper.webViewImpl()->layout();
76807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
7697242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    for (Frame* frame = mainFrame; frame; frame = frame->tree().traverseNext()) {
7705d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        if (!frame->isLocalFrame())
7715d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)            continue;
7725d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        EXPECT_TRUE(setTextAutosizingMultiplier(toLocalFrame(frame)->document(), 2));
7737242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        for (RenderObject* renderer = toLocalFrame(frame)->document()->renderView(); renderer; renderer = renderer->nextInPreOrder()) {
774f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu            if (renderer->isText())
775f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu                EXPECT_FALSE(renderer->needsLayout());
776f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu        }
777f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    }
77807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
7797242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    frameView->setFrameRect(IntRect(0, 0, 200, 200));
7807242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    for (Frame* frame = mainFrame; frame; frame = frame->tree().traverseNext()) {
7815d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        if (!frame->isLocalFrame())
7825d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)            continue;
7837242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        for (RenderObject* renderer = toLocalFrame(frame)->document()->renderView(); renderer; renderer = renderer->nextInPreOrder()) {
784f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu            if (renderer->isText())
785f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu                EXPECT_TRUE(renderer->needsLayout());
786f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu        }
787f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    }
7885267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)}
7895267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
790d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)TEST_F(WebFrameTest, ZeroHeightPositiveWidthNotIgnored)
791d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
792d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
793d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
794d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    FixedLayoutTestWebViewClient client;
795d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
796d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    int viewportWidth = 1280;
797d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    int viewportHeight = 0;
798d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
799d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
800d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    webViewHelper.initialize(true, 0, &client, enableViewportSettings);
801d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
802d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
803d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    EXPECT_EQ(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().width());
804d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    EXPECT_EQ(viewportHeight, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height());
805d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
806d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
8075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)TEST_F(WebFrameTest, DeviceScaleFactorUsesDefaultWithoutViewportTag)
8085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
809bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
8105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    registerMockedHttpURLLoad("no_viewport_tag.html");
8115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    int viewportWidth = 640;
8135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    int viewportHeight = 480;
8145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    FixedLayoutTestWebViewClient client;
816926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 2;
8175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8181e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
819a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "no_viewport_tag.html", true, 0, &client, enableViewportSettings);
8205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
8221e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
8235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8241e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(2, webViewHelper.webView()->deviceScaleFactor());
8255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
826926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    // Device scale factor should be independent of page scale.
8271e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->setPageScaleFactorLimits(1, 2);
82810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    webViewHelper.webView()->setPageScaleFactor(0.5);
8291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
8301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(1, webViewHelper.webView()->pageScaleFactor());
8315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Force the layout to happen before leaving the test.
8331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->mainFrame()->contentAsText(1024).utf8();
8345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
8355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
83693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)TEST_F(WebFrameTest, FixedLayoutInitializeAtMinimumScale)
8375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
8388abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
83993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
8405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    registerMockedHttpURLLoad("fixed_layout.html");
8415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    FixedLayoutTestWebViewClient client;
843926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
8445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    int viewportWidth = 640;
8455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    int viewportHeight = 480;
8465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Make sure we initialize to minimum scale, even if the window size
8485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // only becomes available after the load begins.
8491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
850a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &client, enableViewportSettings);
8511e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
8525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    int defaultFixedLayoutWidth = 980;
8545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    float minimumPageScaleFactor = viewportWidth / (float) defaultFixedLayoutWidth;
8551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(minimumPageScaleFactor, webViewHelper.webView()->pageScaleFactor());
8561e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(minimumPageScaleFactor, webViewHelper.webView()->minimumPageScaleFactor());
85793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
85893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Assume the user has pinch zoomed to page scale factor 2.
85993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    float userPinchPageScaleFactor = 2;
86010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    webViewHelper.webView()->setPageScaleFactor(userPinchPageScaleFactor);
8611e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
86293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
86393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Make sure we don't reset to initial scale if the page continues to load.
864bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    webViewHelper.webViewImpl()->didCommitLoad(false, false);
8651e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webViewImpl()->didChangeContentsSize();
8661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(userPinchPageScaleFactor, webViewHelper.webView()->pageScaleFactor());
86793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
86893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Make sure we don't reset to initial scale if the viewport size changes.
8691e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight + 100));
8701e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(userPinchPageScaleFactor, webViewHelper.webView()->pageScaleFactor());
87193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)}
87293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
87393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)TEST_F(WebFrameTest, WideDocumentInitializeAtMinimumScale)
87493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){
8758abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
87693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
87793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    registerMockedHttpURLLoad("wide_document.html");
87893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
87993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    FixedLayoutTestWebViewClient client;
88093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
88193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    int viewportWidth = 640;
88293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    int viewportHeight = 480;
88393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
88493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Make sure we initialize to minimum scale, even if the window size
88593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // only becomes available after the load begins.
8861e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
887a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "wide_document.html", true, 0, &client, enableViewportSettings);
8881e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
88993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
89093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    int wideDocumentWidth = 1500;
89193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    float minimumPageScaleFactor = viewportWidth / (float) wideDocumentWidth;
8921e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(minimumPageScaleFactor, webViewHelper.webView()->pageScaleFactor());
8931e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(minimumPageScaleFactor, webViewHelper.webView()->minimumPageScaleFactor());
8945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Assume the user has pinch zoomed to page scale factor 2.
8965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    float userPinchPageScaleFactor = 2;
89710f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    webViewHelper.webView()->setPageScaleFactor(userPinchPageScaleFactor);
8981e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
8995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Make sure we don't reset to initial scale if the page continues to load.
901bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    webViewHelper.webViewImpl()->didCommitLoad(false, false);
9021e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webViewImpl()->didChangeContentsSize();
9031e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(userPinchPageScaleFactor, webViewHelper.webView()->pageScaleFactor());
9045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Make sure we don't reset to initial scale if the viewport size changes.
9061e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight + 100));
9071e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(userPinchPageScaleFactor, webViewHelper.webView()->pageScaleFactor());
908926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
909926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
91051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)TEST_F(WebFrameTest, DelayedViewportInitialScale)
91151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){
91251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
91351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    registerMockedHttpURLLoad("viewport-auto-initial-scale.html");
91451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
91551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
91651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
91751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int viewportWidth = 640;
91851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int viewportHeight = 480;
91951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
92051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
921a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "viewport-auto-initial-scale.html", true, 0, &client, enableViewportSettings);
92251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
92351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
92451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_EQ(0.25f, webViewHelper.webView()->pageScaleFactor());
92551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
9267242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    Document* document = toLocalFrame(webViewHelper.webViewImpl()->page()->mainFrame())->document();
9277242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    ViewportDescription description = document->viewportDescription();
92851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    description.zoom = 2;
92951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    document->setViewportDescription(description);
93051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->layout();
93151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_EQ(2, webViewHelper.webView()->pageScaleFactor());
93251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}
93351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
93493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)TEST_F(WebFrameTest, setLoadWithOverviewModeToFalse)
935926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
936bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
937926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    registerMockedHttpURLLoad("viewport-auto-initial-scale.html");
938926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
939926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
940926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
941926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    int viewportWidth = 640;
942926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    int viewportHeight = 480;
943926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
9441e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
945a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "viewport-auto-initial-scale.html", true, 0, &client, enableViewportSettings);
9461e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
9471e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setLoadWithOverviewMode(false);
9481e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
949926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
950926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    // The page must be displayed at 100% zoom.
9511e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(1.0f, webViewHelper.webView()->pageScaleFactor());
952926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
953926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
95493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)TEST_F(WebFrameTest, SetLoadWithOverviewModeToFalseAndNoWideViewport)
95553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles){
956bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
95753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    registerMockedHttpURLLoad("large-div.html");
95853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
95953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
96053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
96153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    int viewportWidth = 640;
96253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    int viewportHeight = 480;
96353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
9641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
965a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "large-div.html", true, 0, &client, enableViewportSettings);
9661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setLoadWithOverviewMode(false);
9671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
9681e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(false);
9691e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
97053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
97153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    // The page must be displayed at 100% zoom, despite that it hosts a wide div element.
9721e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(1.0f, webViewHelper.webView()->pageScaleFactor());
97353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)}
97453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
97553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)TEST_F(WebFrameTest, NoWideViewportIgnoresPageViewportWidth)
97653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles){
977bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
97853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    registerMockedHttpURLLoad("viewport-auto-initial-scale.html");
97953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
98053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
98153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
98253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    int viewportWidth = 640;
98353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    int viewportHeight = 480;
98453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
9851e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
986a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "viewport-auto-initial-scale.html", true, 0, &client, enableViewportSettings);
9871e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
9881e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(false);
9891e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
99053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
99153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    // The page sets viewport width to 3000, but with UseWideViewport == false is must be ignored.
9921e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->contentsSize().width());
9931e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(viewportHeight, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->contentsSize().height());
99453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)}
99553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
99653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)TEST_F(WebFrameTest, NoWideViewportIgnoresPageViewportWidthButAccountsScale)
99753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles){
998bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
99953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    registerMockedHttpURLLoad("viewport-wide-2x-initial-scale.html");
100053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
100153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
100253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
100353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    int viewportWidth = 640;
100453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    int viewportHeight = 480;
100553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
10061e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
100751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "viewport-wide-2x-initial-scale.html", true, 0, &client, enableViewportSettings);
10081e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
10091e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(false);
10101e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
101153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
1012bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    // The page sets viewport width to 3000, but with UseWideViewport == false it must be ignored.
101353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    // While the initial scale specified by the page must be accounted.
10141e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(viewportWidth / 2, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->contentsSize().width());
10151e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(viewportHeight / 2, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->contentsSize().height());
101653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)}
101753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
10188abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)TEST_F(WebFrameTest, WideViewportSetsTo980WithoutViewportTag)
10198abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){
1020bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
10218abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    registerMockedHttpURLLoad("no_viewport_tag.html");
10228abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
10238abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    FixedLayoutTestWebViewClient client;
10248abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
10258abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    int viewportWidth = 640;
10268abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    int viewportHeight = 480;
10278abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
10281e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1029a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "no_viewport_tag.html", true, 0, &client, enableViewportSettings);
1030aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    applyViewportStyleOverride(&webViewHelper);
10311e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
10321e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(true);
10331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
10348abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
10351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(980, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->contentsSize().width());
10361e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(980.0 / viewportWidth * viewportHeight, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->contentsSize().height());
10378abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)}
10388abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
10398abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)TEST_F(WebFrameTest, NoWideViewportAndHeightInMeta)
10408abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){
1041bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
10428abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    registerMockedHttpURLLoad("viewport-height-1000.html");
10438abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
10448abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    FixedLayoutTestWebViewClient client;
10458abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
10468abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    int viewportWidth = 640;
10478abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    int viewportHeight = 480;
10488abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
10491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1050a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "viewport-height-1000.html", true, 0, &client, enableViewportSettings);
10511e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
10521e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(false);
10531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
10548abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
10551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->contentsSize().width());
10568abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)}
10578abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
105853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)TEST_F(WebFrameTest, WideViewportSetsTo980WithAutoWidth)
1059926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
1060bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
1061926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    registerMockedHttpURLLoad("viewport-2x-initial-scale.html");
1062926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1063926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
1064926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
1065926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    int viewportWidth = 640;
1066926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    int viewportHeight = 480;
1067926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
10681e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1069a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "viewport-2x-initial-scale.html", true, 0, &client, enableViewportSettings);
1070aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    applyViewportStyleOverride(&webViewHelper);
10711e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
10721e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(true);
10731e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
107453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
10751e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(980, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->contentsSize().width());
10761e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(980.0 / viewportWidth * viewportHeight, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->contentsSize().height());
107753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)}
107853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
107993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)TEST_F(WebFrameTest, PageViewportInitialScaleOverridesLoadWithOverviewMode)
108053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles){
1081bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
108253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    registerMockedHttpURLLoad("viewport-wide-2x-initial-scale.html");
108353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
108453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
108553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
108653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    int viewportWidth = 640;
108753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    int viewportHeight = 480;
108853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
10891e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
109051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "viewport-wide-2x-initial-scale.html", true, 0, &client, enableViewportSettings);
10911e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setLoadWithOverviewMode(false);
10921e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1093926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1094926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    // The page must be displayed at 200% zoom, as specified in its viewport meta tag.
10951e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(2.0f, webViewHelper.webView()->pageScaleFactor());
1096926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
1097926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1098926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)TEST_F(WebFrameTest, setInitialPageScaleFactorPermanently)
1099926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
11008abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
110193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
1102926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    registerMockedHttpURLLoad("fixed_layout.html");
1103926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1104926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
1105926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
110693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    float enforcedPageScaleFactor = 2.0f;
1107926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
11081e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1109a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &client, enableViewportSettings);
1110aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    applyViewportStyleOverride(&webViewHelper);
11111e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
11121e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setLoadWithOverviewMode(false);
11131e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->setInitialPageScaleOverride(enforcedPageScaleFactor);
11141e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
1115926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
11161e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(enforcedPageScaleFactor, webViewHelper.webView()->pageScaleFactor());
1117926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
111893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    int viewportWidth = 640;
111993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    int viewportHeight = 480;
11201e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
11211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
1122926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
11231e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(enforcedPageScaleFactor, webViewHelper.webView()->pageScaleFactor());
1124926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
11251e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->setInitialPageScaleOverride(-1);
11261e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
11271e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(1.0, webViewHelper.webView()->pageScaleFactor());
1128926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
1129926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
113093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)TEST_F(WebFrameTest, PermanentInitialPageScaleFactorOverridesLoadWithOverviewMode)
1131926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
1132bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
1133926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    registerMockedHttpURLLoad("viewport-auto-initial-scale.html");
1134926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1135926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
1136926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
1137926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    int viewportWidth = 640;
1138926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    int viewportHeight = 480;
113951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    float enforcedPageScaleFactor = 0.5f;
1140926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
11411e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
114251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "viewport-auto-initial-scale.html", true, 0, &client, enableViewportSettings);
11431e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setLoadWithOverviewMode(false);
114451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->setInitialPageScaleOverride(enforcedPageScaleFactor);
11451e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1146926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
114751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_EQ(enforcedPageScaleFactor, webViewHelper.webView()->pageScaleFactor());
1148926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
1149926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1150926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)TEST_F(WebFrameTest, PermanentInitialPageScaleFactorOverridesPageViewportInitialScale)
1151926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
1152bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
115353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    registerMockedHttpURLLoad("viewport-wide-2x-initial-scale.html");
1154926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1155926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
1156926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
1157926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    int viewportWidth = 640;
1158926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    int viewportHeight = 480;
115951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    float enforcedPageScaleFactor = 0.5f;
116051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
116151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
116251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "viewport-wide-2x-initial-scale.html", true, 0, &client, enableViewportSettings);
116351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->setInitialPageScaleOverride(enforcedPageScaleFactor);
116451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
116551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
116651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_EQ(enforcedPageScaleFactor, webViewHelper.webView()->pageScaleFactor());
116751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}
116851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
116951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)TEST_F(WebFrameTest, SmallPermanentInitialPageScaleFactorIsClobbered)
117051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){
117151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
117251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    const char* pages[] = {
117351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        // These pages trigger the clobbering condition. There must be a matching item in "pageScaleFactors" array.
117451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        "viewport-device-0.5x-initial-scale.html",
117551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        "viewport-initial-scale-1.html",
117651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        // These ones do not.
117751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        "viewport-auto-initial-scale.html",
117851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        "viewport-target-densitydpi-device-and-fixed-width.html"
117951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    };
118051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    float pageScaleFactors[] = { 0.5f, 1.0f };
118151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    for (size_t i = 0; i < ARRAY_SIZE(pages); ++i)
118251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        registerMockedHttpURLLoad(pages[i]);
118351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
118451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
118551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
118651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int viewportWidth = 400;
118751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int viewportHeight = 300;
118851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    float enforcedPageScaleFactor = 0.75f;
118951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
119051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    for (size_t i = 0; i < ARRAY_SIZE(pages); ++i) {
119151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        for (int quirkEnabled = 0; quirkEnabled <= 1; ++quirkEnabled) {
119251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)            FrameTestHelpers::WebViewHelper webViewHelper;
1193a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)            webViewHelper.initializeAndLoad(m_baseURL + pages[i], true, 0, &client, enableViewportSettings);
1194aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch            applyViewportStyleOverride(&webViewHelper);
119551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)            webViewHelper.webView()->settings()->setClobberUserAgentInitialScaleQuirk(quirkEnabled);
119651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)            webViewHelper.webView()->setInitialPageScaleOverride(enforcedPageScaleFactor);
119751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)            webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
119851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
119951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)            float expectedPageScaleFactor = quirkEnabled && i < ARRAY_SIZE(pageScaleFactors) ? pageScaleFactors[i] : enforcedPageScaleFactor;
120051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)            EXPECT_EQ(expectedPageScaleFactor, webViewHelper.webView()->pageScaleFactor());
120151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        }
120251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    }
120351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}
120451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
120551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)TEST_F(WebFrameTest, PermanentInitialPageScaleFactorAffectsLayoutWidth)
120651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){
120751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
120851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
120951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
121051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
121151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int viewportWidth = 640;
121251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int viewportHeight = 480;
121351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    float enforcedPageScaleFactor = 0.5;
1214926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
12151e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1216a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad("about:blank", true, 0, &client, enableViewportSettings);
121751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
121851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(false);
121951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setLoadWithOverviewMode(false);
122051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->setInitialPageScaleOverride(enforcedPageScaleFactor);
12211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1222926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
122351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_EQ(viewportWidth / enforcedPageScaleFactor, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->contentsSize().width());
122451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_EQ(enforcedPageScaleFactor, webViewHelper.webView()->pageScaleFactor());
1225926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
1226926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1227e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)TEST_F(WebFrameTest, SetForceZeroLayoutHeight)
1228e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles){
1229e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
1230e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    registerMockedHttpURLLoad("200-by-300.html");
1231e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1232e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
1233e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
1234e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    int viewportWidth = 640;
1235e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    int viewportHeight = 480;
1236e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1237e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1238e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1239e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html", true, 0, &client, enableViewportSettings);
1240e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1241e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.webView()->layout();
1242e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1243e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    EXPECT_LE(viewportHeight, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height());
1244e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.webView()->settings()->setForceZeroLayoutHeight(true);
1245e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    EXPECT_TRUE(webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->needsLayout());
1246e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1247e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    EXPECT_EQ(0, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height());
1248e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1249e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight * 2));
1250e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    EXPECT_FALSE(webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->needsLayout());
1251e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    EXPECT_EQ(0, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height());
1252e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1253e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth * 2, viewportHeight));
1254e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.webView()->layout();
1255e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    EXPECT_EQ(0, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height());
1256e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1257e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.webView()->settings()->setForceZeroLayoutHeight(false);
1258e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    EXPECT_LE(viewportHeight, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height());
1259e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)}
1260e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1261e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)TEST_F(WebFrameTest, SetForceZeroLayoutHeightWorksAcrossNavigations)
1262e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles){
1263e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
1264e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    registerMockedHttpURLLoad("200-by-300.html");
1265e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    registerMockedHttpURLLoad("large-div.html");
1266e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1267e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
1268e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
1269e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    int viewportWidth = 640;
1270e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    int viewportHeight = 480;
1271e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1272e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1273e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1274e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html", true, 0, &client, enableViewportSettings);
1275e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.webView()->settings()->setForceZeroLayoutHeight(true);
1276e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1277e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.webView()->layout();
1278e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1279e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL + "large-div.html");
1280e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.webView()->layout();
1281e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1282e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    EXPECT_EQ(0, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height());
1283e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)}
1284e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1285e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)TEST_F(WebFrameTest, SetForceZeroLayoutHeightWithWideViewportQuirk)
1286e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles){
1287e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
1288e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    registerMockedHttpURLLoad("200-by-300.html");
1289e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1290e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
1291e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
1292e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    int viewportWidth = 640;
1293e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    int viewportHeight = 480;
1294e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1295e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1296e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1297e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html", true, 0, &client, enableViewportSettings);
1298e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
1299e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(true);
1300e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.webView()->settings()->setForceZeroLayoutHeight(true);
1301e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1302e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    webViewHelper.webView()->layout();
1303e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
1304e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    EXPECT_EQ(0, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height());
1305e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)}
1306e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)
13071e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)TEST_F(WebFrameTest, WideViewportAndWideContentWithInitialScale)
13081e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
1309bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
13101e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    registerMockedHttpURLLoad("wide_document_width_viewport.html");
13111e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
13121e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
13131e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
13141e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int viewportWidth = 600;
13151e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int viewportHeight = 800;
13161e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
13171e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
131851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.initializeAndLoad("about:blank", true, 0, &client, enableViewportSettings);
13191e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
13201e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(true);
13211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setViewportMetaLayoutSizeQuirk(true);
13221e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
13231e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
13241e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL + "wide_document_width_viewport.html");
13251e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
13261e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
13271e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int wideDocumentWidth = 800;
13281e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    float minimumPageScaleFactor = viewportWidth / (float) wideDocumentWidth;
13291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(minimumPageScaleFactor, webViewHelper.webView()->pageScaleFactor());
13301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(minimumPageScaleFactor, webViewHelper.webView()->minimumPageScaleFactor());
13318abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)}
13328abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
133351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)TEST_F(WebFrameTest, WideViewportQuirkClobbersHeight)
133451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){
133551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
133651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    registerMockedHttpURLLoad("viewport-height-1000.html");
133751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
133851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
133951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
134051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int viewportWidth = 600;
134151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int viewportHeight = 800;
134251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
134351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1344a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad("about:blank", true, 0, &client, enableViewportSettings);
134551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
134651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(false);
134751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setViewportMetaLayoutSizeQuirk(true);
134851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
134951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
135051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL + "viewport-height-1000.html");
135151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
135251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
135351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_EQ(800, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height());
135451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_EQ(1, webViewHelper.webView()->pageScaleFactor());
135551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}
135651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
135751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)TEST_F(WebFrameTest, LayoutSize320Quirk)
135851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){
135951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
136051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    registerMockedHttpURLLoad("viewport/viewport-30.html");
136151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
136251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
136351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
136451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int viewportWidth = 600;
136551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int viewportHeight = 800;
136651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
136751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1368a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad("about:blank", true, 0, &client, enableViewportSettings);
136951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
137051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(true);
137151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setViewportMetaLayoutSizeQuirk(true);
137251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
137351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
137451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL + "viewport/viewport-30.html");
137551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
137651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
137751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_EQ(600, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().width());
137851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_EQ(800, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height());
137951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_EQ(1, webViewHelper.webView()->pageScaleFactor());
138051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
138151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    // The magic number to snap to device-width is 320, so test that 321 is
138251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    // respected.
13837242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    Document* document = toLocalFrame(webViewHelper.webViewImpl()->page()->mainFrame())->document();
13847242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    ViewportDescription description = document->viewportDescription();
13857242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    description.minWidth = Length(321, blink::Fixed);
13867242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    description.maxWidth = Length(321, blink::Fixed);
138751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    document->setViewportDescription(description);
138851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->layout();
138951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_EQ(321, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().width());
139051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
13917242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    description.minWidth = Length(320, blink::Fixed);
13927242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    description.maxWidth = Length(320, blink::Fixed);
139351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    document->setViewportDescription(description);
139451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->layout();
139551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_EQ(600, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().width());
1396d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
1397d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    description = document->viewportDescription();
13987242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    description.maxHeight = Length(1000, blink::Fixed);
1399d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    document->setViewportDescription(description);
1400d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    webViewHelper.webView()->layout();
1401d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    EXPECT_EQ(1000, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height());
1402d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
14037242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    description.maxHeight = Length(320, blink::Fixed);
1404d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    document->setViewportDescription(description);
1405d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    webViewHelper.webView()->layout();
1406d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    EXPECT_EQ(800, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height());
140751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}
140851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
14098abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)TEST_F(WebFrameTest, ZeroValuesQuirk)
14108abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){
1411bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
14128abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    registerMockedHttpURLLoad("viewport-zero-values.html");
14138abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
14148abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    FixedLayoutTestWebViewClient client;
14158abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
14168abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    int viewportWidth = 640;
14178abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    int viewportHeight = 480;
14188abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
14191e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
142051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.initialize(true, 0, &client, enableViewportSettings);
14211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setViewportMetaZeroValuesQuirk(true);
14221e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
142351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setViewportMetaLayoutSizeQuirk(true);
14241e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL + "viewport-zero-values.html");
14251e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
14268abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
1427bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    EXPECT_EQ(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().width());
14281e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(1.0f, webViewHelper.webView()->pageScaleFactor());
14298abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
14301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(true);
14311e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
1432bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    EXPECT_EQ(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().width());
14331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(1.0f, webViewHelper.webView()->pageScaleFactor());
14348abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)}
14358abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)
143606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)TEST_F(WebFrameTest, OverflowHiddenDisablesScrolling)
143706f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles){
143806f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    registerMockedHttpURLLoad("body-overflow-hidden.html");
143906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)
144006f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    FixedLayoutTestWebViewClient client;
144106f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
144206f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    int viewportWidth = 640;
144306f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    int viewportHeight = 480;
144406f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)
14451e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
14461e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.initialize(true, 0, &client);
14471e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL + "body-overflow-hidden.html");
14481e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
144906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)
14507242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    FrameView* view = webViewHelper.webViewImpl()->mainFrameImpl()->frameView();
14517242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    EXPECT_FALSE(view->userInputScrollable(VerticalScrollbar));
145206f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)}
145306f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)
145406f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)TEST_F(WebFrameTest, IgnoreOverflowHiddenQuirk)
145506f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles){
145606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    registerMockedHttpURLLoad("body-overflow-hidden.html");
145706f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)
145806f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    FixedLayoutTestWebViewClient client;
145906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
146006f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    int viewportWidth = 640;
146106f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    int viewportHeight = 480;
146206f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)
14631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
14641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.initialize(true, 0, &client);
14651e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setIgnoreMainFrameOverflowHiddenQuirk(true);
14661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL + "body-overflow-hidden.html");
14671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
146806f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)
14697242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    FrameView* view = webViewHelper.webViewImpl()->mainFrameImpl()->frameView();
14707242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    EXPECT_TRUE(view->userInputScrollable(VerticalScrollbar));
147106f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)}
147206f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)
147306f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)TEST_F(WebFrameTest, NonZeroValuesNoQuirk)
147406f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles){
1475bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
147606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    registerMockedHttpURLLoad("viewport-nonzero-values.html");
147706f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)
147806f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    FixedLayoutTestWebViewClient client;
147906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
148006f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    int viewportWidth = 640;
148106f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    int viewportHeight = 480;
148206f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    float expectedPageScaleFactor = 0.5f;
148306f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)
14841e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
148551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.initialize(true, 0, &client, enableViewportSettings);
14861e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setViewportMetaZeroValuesQuirk(true);
14871e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
14881e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL + "viewport-nonzero-values.html");
14891e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
149006f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)
1491bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    EXPECT_EQ(viewportWidth / expectedPageScaleFactor, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().width());
14921e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(expectedPageScaleFactor, webViewHelper.webView()->pageScaleFactor());
149306f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)
14941e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(true);
14951e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
1496bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    EXPECT_EQ(viewportWidth / expectedPageScaleFactor, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().width());
14971e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(expectedPageScaleFactor, webViewHelper.webView()->pageScaleFactor());
149806f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)}
149906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)
1500926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)TEST_F(WebFrameTest, setPageScaleFactorDoesNotLayout)
1501926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
1502bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
1503926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    registerMockedHttpURLLoad("fixed_layout.html");
1504926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1505926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
1506926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
150753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    // Small viewport to ensure there are always scrollbars.
150853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    int viewportWidth = 64;
150953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    int viewportHeight = 48;
151053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
15111e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1512a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &client, enableViewportSettings);
15131e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
15141e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
15151e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
15161e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int prevLayoutCount = webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutCount();
151710f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    webViewHelper.webViewImpl()->setPageScaleFactor(3);
15181e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_FALSE(webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->needsLayout());
15191e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(prevLayoutCount, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutCount());
152053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)}
152153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
152253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)TEST_F(WebFrameTest, setPageScaleFactorWithOverlayScrollbarsDoesNotLayout)
152353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles){
15248abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
152553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
152653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    registerMockedHttpURLLoad("fixed_layout.html");
152753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
152853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
152953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
1530926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    int viewportWidth = 640;
1531926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    int viewportHeight = 480;
1532926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
15331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1534a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &client, enableViewportSettings);
15351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
15361e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
1537926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
15381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int prevLayoutCount = webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutCount();
153910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    webViewHelper.webViewImpl()->setPageScaleFactor(30);
15401e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_FALSE(webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->needsLayout());
15411e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(prevLayoutCount, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutCount());
154253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
154353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)}
154453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
1545926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)TEST_F(WebFrameTest, pageScaleFactorWrittenToHistoryItem)
1546926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
1547bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
1548926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    registerMockedHttpURLLoad("fixed_layout.html");
1549926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1550926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
1551926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
1552926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    int viewportWidth = 640;
1553926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    int viewportHeight = 480;
1554926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
15551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1556a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &client, enableViewportSettings);
15571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
15581e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
15591e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
156010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    webViewHelper.webView()->setPageScaleFactor(3);
15615d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    EXPECT_EQ(3, toLocalFrame(webViewHelper.webViewImpl()->page()->mainFrame())->loader().currentItem()->pageScaleFactor());
1562d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}
1563d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
1564d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)TEST_F(WebFrameTest, initialScaleWrittenToHistoryItem)
1565d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){
1566d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
1567d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    registerMockedHttpURLLoad("fixed_layout.html");
1568d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
1569d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    FixedLayoutTestWebViewClient client;
1570d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
1571d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    int viewportWidth = 640;
1572d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    int viewportHeight = 480;
1573d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
1574d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1575d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &client, enableViewportSettings);
1576d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
1577d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    webViewHelper.webView()->layout();
1578d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
1579d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    int defaultFixedLayoutWidth = 980;
1580d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    float minimumPageScaleFactor = viewportWidth / (float) defaultFixedLayoutWidth;
15815d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    EXPECT_EQ(minimumPageScaleFactor, toLocalFrame(webViewHelper.webViewImpl()->page()->mainFrame())->loader().currentItem()->pageScaleFactor());
1582926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
1583926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1584926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)TEST_F(WebFrameTest, pageScaleFactorShrinksViewport)
1585926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
1586bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
15878abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    registerMockedHttpURLLoad("large-div.html");
1588926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1589926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
1590926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
159153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    // Small viewport to ensure there are always scrollbars.
159253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    int viewportWidth = 64;
159353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    int viewportHeight = 48;
1594926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
15951e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1596a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "large-div.html", true, 0, &client, enableViewportSettings);
15971e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
15981e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
1599926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
16007242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    FrameView* view = webViewHelper.webViewImpl()->mainFrameImpl()->frameView();
160153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    int viewportWidthMinusScrollbar = viewportWidth - (view->verticalScrollbar()->isOverlayScrollbar() ? 0 : 15);
160253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    int viewportHeightMinusScrollbar = viewportHeight - (view->horizontalScrollbar()->isOverlayScrollbar() ? 0 : 15);
1603926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
160410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    webViewHelper.webView()->setPageScaleFactor(2);
1605926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
16067242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    IntSize unscaledSize = view->unscaledVisibleContentSize(IncludeScrollbars);
1607926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    EXPECT_EQ(viewportWidth, unscaledSize.width());
1608926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    EXPECT_EQ(viewportHeight, unscaledSize.height());
1609926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
16107242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    IntSize unscaledSizeMinusScrollbar = view->unscaledVisibleContentSize(ExcludeScrollbars);
1611926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    EXPECT_EQ(viewportWidthMinusScrollbar, unscaledSizeMinusScrollbar.width());
1612926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    EXPECT_EQ(viewportHeightMinusScrollbar, unscaledSizeMinusScrollbar.height());
1613926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
16147242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    IntSize scaledSize = view->visibleContentRect().size();
1615926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    EXPECT_EQ(ceil(viewportWidthMinusScrollbar / 2.0), scaledSize.width());
1616926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    EXPECT_EQ(ceil(viewportHeightMinusScrollbar / 2.0), scaledSize.height());
1617926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
1618926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1619926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)TEST_F(WebFrameTest, pageScaleFactorDoesNotApplyCssTransform)
1620926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
1621bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
1622926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    registerMockedHttpURLLoad("fixed_layout.html");
1623926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1624926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
1625926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1;
1626926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    int viewportWidth = 640;
1627926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    int viewportHeight = 480;
1628926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
16291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1630a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &client, enableViewportSettings);
16311e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
16321e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
1633926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
163410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    webViewHelper.webView()->setPageScaleFactor(2);
1635926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
16365d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    EXPECT_EQ(980, toLocalFrame(webViewHelper.webViewImpl()->page()->mainFrame())->contentRenderer()->unscaledDocumentRect().width());
16371e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_EQ(980, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->contentsSize().width());
16385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
163953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
164053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)TEST_F(WebFrameTest, targetDensityDpiHigh)
164153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles){
16428abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
164353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    registerMockedHttpURLLoad("viewport-target-densitydpi-high.html");
164453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
164553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
16463c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    // high-dpi = 240
16473c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    float targetDpi = 240.0f;
16483c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    float deviceScaleFactors[] = { 1.0f, 4.0f / 3.0f, 2.0f };
164953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    int viewportWidth = 640;
165053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    int viewportHeight = 480;
165153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
16523c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    for (size_t i = 0; i < ARRAY_SIZE(deviceScaleFactors); ++i) {
16533c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch        float deviceScaleFactor = deviceScaleFactors[i];
16543c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch        float deviceDpi = deviceScaleFactor * 160.0f;
16553c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch        client.m_screenInfo.deviceScaleFactor = deviceScaleFactor;
16563c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch
16571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        FrameTestHelpers::WebViewHelper webViewHelper;
165851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        webViewHelper.initializeAndLoad(m_baseURL + "viewport-target-densitydpi-high.html", true, 0, &client, enableViewportSettings);
16591e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
16601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        webViewHelper.webView()->settings()->setSupportDeprecatedTargetDensityDPI(true);
16611e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
166253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
16633c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch        // We need to account for the fact that logical pixels are unconditionally multiplied by deviceScaleFactor to produce
16643c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch        // physical pixels.
16653c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch        float densityDpiScaleRatio = deviceScaleFactor * targetDpi / deviceDpi;
1666bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        EXPECT_NEAR(viewportWidth * densityDpiScaleRatio, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().width(), 1.0f);
1667bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        EXPECT_NEAR(viewportHeight * densityDpiScaleRatio, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height(), 1.0f);
16681e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        EXPECT_NEAR(1.0f / densityDpiScaleRatio, webViewHelper.webView()->pageScaleFactor(), 0.01f);
16693c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    }
167053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)}
167153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
167253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)TEST_F(WebFrameTest, targetDensityDpiDevice)
167353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles){
16748abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
167553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    registerMockedHttpURLLoad("viewport-target-densitydpi-device.html");
167653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
167753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    float deviceScaleFactors[] = { 1.0f, 4.0f / 3.0f, 2.0f };
167853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
167953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
168053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    int viewportWidth = 640;
168153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    int viewportHeight = 480;
168253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
168353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    for (size_t i = 0; i < ARRAY_SIZE(deviceScaleFactors); ++i) {
168453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        client.m_screenInfo.deviceScaleFactor = deviceScaleFactors[i];
168553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
16861e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        FrameTestHelpers::WebViewHelper webViewHelper;
168751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        webViewHelper.initializeAndLoad(m_baseURL + "viewport-target-densitydpi-device.html", true, 0, &client, enableViewportSettings);
16881e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
16891e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        webViewHelper.webView()->settings()->setSupportDeprecatedTargetDensityDPI(true);
16901e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
16911e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1692bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        EXPECT_NEAR(viewportWidth * client.m_screenInfo.deviceScaleFactor, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().width(), 1.0f);
1693bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        EXPECT_NEAR(viewportHeight * client.m_screenInfo.deviceScaleFactor, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height(), 1.0f);
16941e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        EXPECT_NEAR(1.0f / client.m_screenInfo.deviceScaleFactor, webViewHelper.webView()->pageScaleFactor(), 0.01f);
16951e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
16961e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
16971e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
16981e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)TEST_F(WebFrameTest, targetDensityDpiDeviceAndFixedWidth)
16991e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
17001e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
17011e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    registerMockedHttpURLLoad("viewport-target-densitydpi-device-and-fixed-width.html");
170253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
17031e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    float deviceScaleFactors[] = { 1.0f, 4.0f / 3.0f, 2.0f };
170453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
17051e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
17061e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int viewportWidth = 640;
17071e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int viewportHeight = 480;
17081e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
17091e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    for (size_t i = 0; i < ARRAY_SIZE(deviceScaleFactors); ++i) {
17101e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        client.m_screenInfo.deviceScaleFactor = deviceScaleFactors[i];
17111e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
17121e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        FrameTestHelpers::WebViewHelper webViewHelper;
171351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        webViewHelper.initializeAndLoad(m_baseURL + "viewport-target-densitydpi-device-and-fixed-width.html", true, 0, &client, enableViewportSettings);
17141e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
17151e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        webViewHelper.webView()->settings()->setSupportDeprecatedTargetDensityDPI(true);
17161e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        webViewHelper.webView()->settings()->setUseWideViewport(true);
17171e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
17181e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1719bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        EXPECT_NEAR(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().width(), 1.0f);
1720bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        EXPECT_NEAR(viewportHeight, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height(), 1.0f);
17211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        EXPECT_NEAR(1.0f, webViewHelper.webView()->pageScaleFactor(), 0.01f);
172253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    }
172353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)}
172453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
17251e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)TEST_F(WebFrameTest, NoWideViewportAndScaleLessThanOne)
17261e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
17271e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
17281e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    registerMockedHttpURLLoad("viewport-initial-scale-less-than-1.html");
17291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
17301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
17311e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1.33f;
17321e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int viewportWidth = 640;
17331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int viewportHeight = 480;
17341e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
17351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
173651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "viewport-initial-scale-less-than-1.html", true, 0, &client, enableViewportSettings);
17371e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setSupportDeprecatedTargetDensityDPI(true);
17381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
17391e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(false);
17401e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
17411e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
17421e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1743bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    EXPECT_NEAR(viewportWidth * client.m_screenInfo.deviceScaleFactor, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().width(), 1.0f);
1744bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    EXPECT_NEAR(viewportHeight * client.m_screenInfo.deviceScaleFactor, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height(), 1.0f);
17451e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_NEAR(1.0f / client.m_screenInfo.deviceScaleFactor, webViewHelper.webView()->pageScaleFactor(), 0.01f);
17461e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
17471e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
17481e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)TEST_F(WebFrameTest, NoWideViewportAndScaleLessThanOneWithDeviceWidth)
17491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
17501e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
17511e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    registerMockedHttpURLLoad("viewport-initial-scale-less-than-1-device-width.html");
17521e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
17531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
17541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1.33f;
17551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int viewportWidth = 640;
17561e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    int viewportHeight = 480;
17571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
17581e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
175951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "viewport-initial-scale-less-than-1-device-width.html", true, 0, &client, enableViewportSettings);
17601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setSupportDeprecatedTargetDensityDPI(true);
17611e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
17621e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(false);
17631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
17641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    webViewHelper.webView()->layout();
17651e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
17661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    const float pageZoom = 0.25f;
1767bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    EXPECT_NEAR(viewportWidth * client.m_screenInfo.deviceScaleFactor / pageZoom, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().width(), 1.0f);
1768bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    EXPECT_NEAR(viewportHeight * client.m_screenInfo.deviceScaleFactor / pageZoom, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height(), 1.0f);
17691e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EXPECT_NEAR(1.0f / client.m_screenInfo.deviceScaleFactor, webViewHelper.webView()->pageScaleFactor(), 0.01f);
17701e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
17711e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
177251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)TEST_F(WebFrameTest, NoWideViewportAndNoViewportWithInitialPageScaleOverride)
177351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){
177451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
177551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    registerMockedHttpURLLoad("large-div.html");
177651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
177751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
177851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int viewportWidth = 640;
177951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int viewportHeight = 480;
178051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    float enforcedPageScaleFactor = 5.0f;
178151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
178251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
178351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "large-div.html", true, 0, &client, enableViewportSettings);
178451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
178551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(false);
178651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->setInitialPageScaleOverride(enforcedPageScaleFactor);
178751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
178851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->layout();
178951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
179051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_NEAR(viewportWidth / enforcedPageScaleFactor, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().width(), 1.0f);
179151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_NEAR(viewportHeight / enforcedPageScaleFactor, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height(), 1.0f);
179251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_NEAR(enforcedPageScaleFactor, webViewHelper.webView()->pageScaleFactor(), 0.01f);
179351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}
179451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
179551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)TEST_F(WebFrameTest, NoUserScalableQuirkIgnoresViewportScale)
179651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){
179751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
179851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    registerMockedHttpURLLoad("viewport-initial-scale-and-user-scalable-no.html");
179951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
180051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
180151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int viewportWidth = 640;
180251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int viewportHeight = 480;
180351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
180451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1805a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "viewport-initial-scale-and-user-scalable-no.html", true, 0, &client, enableViewportSettings);
180651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setViewportMetaNonUserScalableQuirk(true);
180751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
180851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->layout();
180951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
181051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_NEAR(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().width(), 1.0f);
181151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_NEAR(viewportHeight, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height(), 1.0f);
181251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_NEAR(1.0f, webViewHelper.webView()->pageScaleFactor(), 0.01f);
181351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}
181451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
181551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)TEST_F(WebFrameTest, NoUserScalableQuirkIgnoresViewportScaleForNonWideViewport)
181651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){
181751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
181851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    registerMockedHttpURLLoad("viewport-initial-scale-and-user-scalable-no.html");
181951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
182051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
182151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    client.m_screenInfo.deviceScaleFactor = 1.33f;
182251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int viewportWidth = 640;
182351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int viewportHeight = 480;
182451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
182551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1826a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "viewport-initial-scale-and-user-scalable-no.html", true, 0, &client, enableViewportSettings);
182751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setSupportDeprecatedTargetDensityDPI(true);
182851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setViewportMetaNonUserScalableQuirk(true);
182951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
183051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(false);
183151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
183251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->layout();
183351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
183451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_NEAR(viewportWidth * client.m_screenInfo.deviceScaleFactor, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().width(), 1.0f);
183551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_NEAR(viewportHeight * client.m_screenInfo.deviceScaleFactor, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height(), 1.0f);
183651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_NEAR(1.0f / client.m_screenInfo.deviceScaleFactor, webViewHelper.webView()->pageScaleFactor(), 0.01f);
183751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}
183851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
183951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)TEST_F(WebFrameTest, NoUserScalableQuirkIgnoresViewportScaleForWideViewport)
184051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){
184151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
184251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    registerMockedHttpURLLoad("viewport-2x-initial-scale-non-user-scalable.html");
184351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
184451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FixedLayoutTestWebViewClient client;
184551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int viewportWidth = 640;
184651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int viewportHeight = 480;
184751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
184851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
1849a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "viewport-2x-initial-scale-non-user-scalable.html", true, 0, &client, enableViewportSettings);
185051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setViewportMetaNonUserScalableQuirk(true);
185151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
185251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(true);
185351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
185451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
185551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_NEAR(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().width(), 1.0f);
185651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_NEAR(viewportHeight, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height(), 1.0f);
185751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    EXPECT_NEAR(1.0f, webViewHelper.webView()->pageScaleFactor(), 0.01f);
185851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}
185951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
186009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)TEST_F(WebFrameTest, DesktopPageCanBeZoomedInWhenWideViewportIsTurnedOff)
186109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
186209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    UseMockScrollbarSettings mockScrollbarSettings;
186309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    registerMockedHttpURLLoad("no_viewport_tag.html");
186409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
186509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    FixedLayoutTestWebViewClient client;
186609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    int viewportWidth = 640;
186709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    int viewportHeight = 480;
186809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
186909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    FrameTestHelpers::WebViewHelper webViewHelper;
187009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    webViewHelper.initializeAndLoad(m_baseURL + "no_viewport_tag.html", true, 0, &client, enableViewportSettings);
187109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true);
187209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    webViewHelper.webView()->settings()->setUseWideViewport(false);
187309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
187409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
187509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    EXPECT_NEAR(1.0f, webViewHelper.webView()->pageScaleFactor(), 0.01f);
187609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    EXPECT_NEAR(1.0f, webViewHelper.webView()->minimumPageScaleFactor(), 0.01f);
187709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    EXPECT_NEAR(5.0f, webViewHelper.webView()->maximumPageScaleFactor(), 0.01f);
187809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
187909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
188053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)class WebFrameResizeTest : public WebFrameTest {
188153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)protected:
188253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
18837242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    static FloatSize computeRelativeOffset(const IntPoint& absoluteOffset, const LayoutRect& rect)
188453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    {
18857242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        FloatSize relativeOffset = FloatPoint(absoluteOffset) - rect.location();
188653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        relativeOffset.scale(1.f / rect.width(), 1.f / rect.height());
188753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        return relativeOffset;
188853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    }
188953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
189053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    void testResizeYieldsCorrectScrollAndScale(const char* url,
189153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)                                               const float initialPageScaleFactor,
189253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)                                               const WebSize scrollOffset,
189353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)                                               const WebSize viewportSize,
189453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)                                               const bool shouldScaleRelativeToViewportWidth) {
1895bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        UseMockScrollbarSettings mockScrollbarSettings;
189653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        registerMockedHttpURLLoad(url);
189753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
189853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        const float aspectRatio = static_cast<float>(viewportSize.width) / viewportSize.height;
189953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
19001e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        FrameTestHelpers::WebViewHelper webViewHelper;
190151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        webViewHelper.initializeAndLoad(m_baseURL + url, true, 0, 0, enableViewportSettings);
190253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
190353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        // Origin scrollOffsets preserved under resize.
190453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        {
19051e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            webViewHelper.webViewImpl()->resize(WebSize(viewportSize.width, viewportSize.height));
190610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch            webViewHelper.webViewImpl()->setPageScaleFactor(initialPageScaleFactor);
19071e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            ASSERT_EQ(viewportSize, webViewHelper.webViewImpl()->size());
19081e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            ASSERT_EQ(initialPageScaleFactor, webViewHelper.webViewImpl()->pageScaleFactor());
19091e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            webViewHelper.webViewImpl()->resize(WebSize(viewportSize.height, viewportSize.width));
191053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)            float expectedPageScaleFactor = initialPageScaleFactor * (shouldScaleRelativeToViewportWidth ? 1 / aspectRatio : 1);
19111e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            EXPECT_NEAR(expectedPageScaleFactor, webViewHelper.webViewImpl()->pageScaleFactor(), 0.05f);
19121e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            EXPECT_EQ(WebSize(), webViewHelper.webViewImpl()->mainFrame()->scrollOffset());
191353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        }
191453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
19158abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)        // Resizing just the height should not affect pageScaleFactor or scrollOffset.
191653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        {
19171e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            webViewHelper.webViewImpl()->resize(WebSize(viewportSize.width, viewportSize.height));
191810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch            webViewHelper.webViewImpl()->setPageScaleFactor(initialPageScaleFactor);
191910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch            webViewHelper.webViewImpl()->setMainFrameScrollOffset(WebPoint(scrollOffset.width, scrollOffset.height));
19201e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            webViewHelper.webViewImpl()->layout();
19211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            const WebSize expectedScrollOffset = webViewHelper.webViewImpl()->mainFrame()->scrollOffset();
19221e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            webViewHelper.webViewImpl()->resize(WebSize(viewportSize.width, viewportSize.height * 0.8f));
19231e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            EXPECT_EQ(initialPageScaleFactor, webViewHelper.webViewImpl()->pageScaleFactor());
19241e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            EXPECT_EQ(expectedScrollOffset, webViewHelper.webViewImpl()->mainFrame()->scrollOffset());
19251e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            webViewHelper.webViewImpl()->resize(WebSize(viewportSize.width, viewportSize.height * 0.8f));
19261e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            EXPECT_EQ(initialPageScaleFactor, webViewHelper.webViewImpl()->pageScaleFactor());
19271e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            EXPECT_EQ(expectedScrollOffset, webViewHelper.webViewImpl()->mainFrame()->scrollOffset());
192853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        }
192953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
193053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        // Generic resize preserves scrollOffset relative to anchor node located
193153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        // the top center of the screen.
193253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)        {
19331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            webViewHelper.webViewImpl()->resize(WebSize(viewportSize.height, viewportSize.