Commit e5022c8d authored by dgozman@chromium.org's avatar dgozman@chromium.org

[DevTools] Add test for viewport invalidation on resize with emulation enabled.

BUG=386142

Review URL: https://codereview.chromium.org/1314903010

git-svn-id: svn://svn.chromium.org/blink/trunk@201761 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent d1d1f49e
...@@ -97,6 +97,7 @@ ...@@ -97,6 +97,7 @@
#include "public/web/WebCache.h" #include "public/web/WebCache.h"
#include "public/web/WebConsoleMessage.h" #include "public/web/WebConsoleMessage.h"
#include "public/web/WebDataSource.h" #include "public/web/WebDataSource.h"
#include "public/web/WebDeviceEmulationParams.h"
#include "public/web/WebDocument.h" #include "public/web/WebDocument.h"
#include "public/web/WebFindOptions.h" #include "public/web/WebFindOptions.h"
#include "public/web/WebFormElement.h" #include "public/web/WebFormElement.h"
...@@ -7732,6 +7733,57 @@ TEST_P(ParameterizedWebFrameTest, CrossDomainAccessErrorsUseCallingWindow) ...@@ -7732,6 +7733,57 @@ TEST_P(ParameterizedWebFrameTest, CrossDomainAccessErrorsUseCallingWindow)
popupWebViewHelper.reset(); popupWebViewHelper.reset();
} }
class ViewportOnResizeTest : public ParameterizedWebFrameTest {
protected:
ViewportOnResizeTest()
: m_webViewHelper(this)
{
registerMockedHttpURLLoad("viewport_emulation.html");
m_client.m_screenInfo.deviceScaleFactor = 1;
m_webViewHelper.initializeAndLoad(m_baseURL + "viewport_emulation.html", true, 0, &m_client);
}
void testResize(const WebSize size, const String& expectedSize)
{
m_client.m_screenInfo.rect = WebRect(0, 0, size.width, size.height);
m_client.m_screenInfo.availableRect = m_client.m_screenInfo.rect;
m_webViewHelper.webView()->resize(size);
m_webViewHelper.webView()->layout();
v8::HandleScope scope(v8::Isolate::GetCurrent());
ScriptExecutionCallbackHelper callbackHelper(m_webViewHelper.webView()->mainFrame()->mainWorldScriptContext());
m_webViewHelper.webView()->mainFrame()->toWebLocalFrame()->requestExecuteScriptAndReturnValue(WebScriptSource(WebString("dumpSize()")), false, &callbackHelper);
runPendingTasks();
EXPECT_TRUE(callbackHelper.didComplete());
EXPECT_EQ(expectedSize, callbackHelper.stringValue());
}
FixedLayoutTestWebViewClient m_client;
FrameTestHelpers::WebViewHelper m_webViewHelper;
};
INSTANTIATE_TEST_CASE_P(All, ViewportOnResizeTest, ::testing::Values(
ParameterizedWebFrameTestConfig::Default,
ParameterizedWebFrameTestConfig::RootLayerScrolls));
TEST_P(ViewportOnResizeTest, ViewportInvalidatedOnResizeWithEmulation)
{
WebDeviceEmulationParams params;
params.screenPosition = WebDeviceEmulationParams::Mobile;
m_webViewHelper.webView()->enableDeviceEmulation(params);
testResize(WebSize(700, 500), "300x300");
testResize(WebSize(710, 500), "400x300");
testResize(WebSize(690, 500), "200x300");
testResize(WebSize(700, 510), "300x400");
testResize(WebSize(700, 490), "300x200");
testResize(WebSize(710, 510), "400x400");
testResize(WebSize(690, 490), "200x200");
testResize(WebSize(800, 600), "400x400");
m_webViewHelper.webView()->disableDeviceEmulation();
}
class WebLocalFrameScope final { class WebLocalFrameScope final {
public: public:
WebLocalFrameScope(WebLocalFrame* localFrame) WebLocalFrameScope(WebLocalFrame* localFrame)
......
<html>
<head>
<style>
body {
margin: 0;
min-height: 1000px;
}
#test {
width: 100px;
height: 100px;
}
@media all and (device-width:700px)
{
#test { width: 300px; }
}
@media all and (max-device-width:699px)
{
#test { width: 200px; }
}
@media all and (min-device-width:701px)
{
#test { width: 400px; }
}
@media all and (device-height:500px)
{
#test { height: 300px; }
}
@media all and (max-device-height:499px)
{
#test { height: 200px; }
}
@media all and (min-device-height:501px)
{
#test { height: 400px; }
}
</style>
<script>
function dumpSize()
{
var div = document.querySelector("#test");
return div.offsetWidth + "x" + div.offsetHeight;
}
</script>
</head>
<body>
<div id="test"></div>
</body>
</html>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment