Commit 9c772586 authored by pdr's avatar pdr Committed by Commit Bot

Give RenderViewTest a non-zero initial size for scrolling

This patch sets RenderViewTest's initial size to be 400x300 instead of
0x0 so scrolling can work. This is in preparation for a future patch
that asserts scroll layers have non-zero dimensions.

The following test changes were required:
1) RenderViewTest.MacTestCmdUp: removed a TODO hack that made the document
non-empty for scrolling.
2) PasswordGenerationAgentTest.FillTest previously used a gesture to focus
an initial element but this gesture event failed because the window size
was empty. This patch removes the gesture event so the test still has no
initial focused element.
3) RenderViewImplTest.NavigateSubframe no longer wraps "hello world".
4) RenderFrameImplTest.FrameResize has been changed so it does change the
viewport instead of leaving it with a 0,0 size, and a new test proves it.

Bug: 723263
Change-Id: Ie1d56dcbf09ddf6250011a8a59e6c07fafd60346
Reviewed-on: https://chromium-review.googlesource.com/541982Reviewed-by: default avatarCharlie Reis <creis@chromium.org>
Reviewed-by: default avatarVaclav Brozek <vabr@chromium.org>
Reviewed-by: default avatarenne <enne@chromium.org>
Commit-Queue: Philip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#481668}
parent 31e3bc75
......@@ -318,12 +318,13 @@ TEST_F(PasswordGenerationAgentTest, FillTest) {
// Make sure that we are enabled before loading HTML.
std::string html =
std::string(kAccountCreationFormHTML) + events_registration_script;
LoadHTMLWithUserGesture(html.c_str());
// Begin with no gesture and therefore no focused element.
LoadHTML(html.c_str());
WebDocument document = GetMainFrame()->GetDocument();
ASSERT_TRUE(document.FocusedElement().IsNull());
SetNotBlacklistedMessage(password_generation_, html.c_str());
SetAccountCreationFormsDetectedMessage(password_generation_,
GetMainFrame()->GetDocument(), 0, 1);
SetAccountCreationFormsDetectedMessage(password_generation_, document, 0, 1);
WebDocument document = GetMainFrame()->GetDocument();
WebElement element =
document.GetElementById(WebString::FromUTF8("first_password"));
ASSERT_FALSE(element.IsNull());
......
......@@ -637,7 +637,11 @@ ContentRendererClient* RenderViewTest::CreateContentRendererClient() {
}
std::unique_ptr<ResizeParams> RenderViewTest::InitialSizeParams() {
return base::MakeUnique<ResizeParams>();
auto initial_size = base::MakeUnique<ResizeParams>();
// Ensure the view has some size so tests involving scrolling bounds work.
initial_size->new_size = gfx::Size(400, 300);
initial_size->visible_viewport_size = gfx::Size(400, 300);
return initial_size;
}
void RenderViewTest::GoToOffset(int offset,
......
......@@ -25,12 +25,14 @@
#include "content/test/fake_compositor_dependencies.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/platform/WebEffectiveConnectionType.h"
#include "third_party/WebKit/public/platform/WebRuntimeFeatures.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURL.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h"
#include "third_party/WebKit/public/web/WebHistoryItem.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebView.h"
#include "ui/native_theme/native_theme_features.h"
using blink::WebString;
using blink::WebURLRequest;
......@@ -51,6 +53,8 @@ class RenderFrameImplTest : public RenderViewTest {
~RenderFrameImplTest() override {}
void SetUp() override {
blink::WebRuntimeFeatures::EnableOverlayScrollbars(
ui::IsOverlayScrollbarEnabled());
RenderViewTest::SetUp();
EXPECT_TRUE(GetMainRenderFrame()->is_main_frame_);
......@@ -153,6 +157,7 @@ TEST_F(RenderFrameImplTest, FrameResize) {
resize_params.screen_info = ScreenInfo();
resize_params.new_size = size;
resize_params.physical_backing_size = size;
resize_params.visible_viewport_size = size;
resize_params.top_controls_height = 0.f;
resize_params.browser_controls_shrink_blink_size = false;
resize_params.is_fullscreen_granted = false;
......@@ -161,6 +166,7 @@ TEST_F(RenderFrameImplTest, FrameResize) {
frame_widget()->OnMessageReceived(resize_message);
EXPECT_EQ(frame_widget()->GetWebWidget()->Size(), blink::WebSize(size));
EXPECT_EQ(view_->GetWebView()->Size(), blink::WebSize(size));
}
// Verify a subframe RenderWidget properly processes a WasShown message.
......
......@@ -1729,7 +1729,7 @@ TEST_F(RenderViewImplTest, NavigateSubframe) {
std::string output = WebFrameContentDumper::DumpWebViewAsText(
view()->GetWebView(), kMaxOutputCharacters)
.Utf8();
EXPECT_EQ(output, "hello \n\nworld");
EXPECT_EQ(output, "hello \n\nworld");
}
// This test ensures that a RenderFrame object is created for the top level
......
......@@ -56,40 +56,28 @@ NSEvent* CmdDeadKeyEvent(NSEventType type, unsigned short code) {
// Test that cmd-up/down scrolls the page exactly if it is not intercepted by
// javascript.
TEST_F(RenderViewTest, MacTestCmdUp) {
// Some preprocessor trickery so that we can have literal html in our source,
// makes it easier to copy html to and from an html file for testing (the
// preprocessor will remove the newlines at the line ends, turning this into
// a single long line).
#define HTML(s) #s
const char* kRawHtml = HTML(
<!DOCTYPE html>
<style>
/* Add a vertical scrollbar */
body { height: 10128px; }
</style>
<div id='keydown'></div>
<div id='scroll'></div>
<script>
var allowKeyEvents = true;
var scroll = document.getElementById('scroll');
var result = document.getElementById('keydown');
onkeydown = function(event) {
result.textContent =
event.keyCode + ',' +
event.shiftKey + ',' +
event.ctrlKey + ',' +
event.metaKey + ',' +
event.altKey;
return allowKeyEvents;
}
</script>
<!--
TODO(esprehn): For some strange reason we need a non-empty document for
scrolling to work. This is not the case in a real browser only in the test.
-->
<p>p1
);
#undef HTML
const char* kRawHtml =
"<!DOCTYPE html>"
"<style>"
" /* Add a vertical scrollbar */"
" body { height: 10128px; }"
"</style>"
"<div id='keydown'></div>"
"<div id='scroll'></div>"
"<script>"
" var allowKeyEvents = true;"
" var scroll = document.getElementById('scroll');"
" var result = document.getElementById('keydown');"
" onkeydown = function(event) {"
" result.textContent ="
" event.keyCode + ',' +"
" event.shiftKey + ',' +"
" event.ctrlKey + ',' +"
" event.metaKey + ',' +"
" event.altKey;"
" return allowKeyEvents;"
" }"
"</script>";
WebPreferences prefs;
prefs.enable_scroll_animator = false;
......@@ -108,7 +96,7 @@ TEST_F(RenderViewTest, MacTestCmdUp) {
LoadHTML(kRawHtml);
render_thread_->sink().ClearMessages();
const char* kArrowDownScrollDown = "40,false,false,true,false\n10144\np1";
const char* kArrowDownScrollDown = "40,false,false,true,false\n9844";
view->OnSetEditCommandsForNextKeyEvent(
EditCommands(1, EditCommand("moveToEndOfDocument", "")));
SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown));
......@@ -119,7 +107,7 @@ TEST_F(RenderViewTest, MacTestCmdUp) {
.Ascii();
EXPECT_EQ(kArrowDownScrollDown, output);
const char* kArrowUpScrollUp = "38,false,false,true,false\n0\np1";
const char* kArrowUpScrollUp = "38,false,false,true,false\n0";
view->OnSetEditCommandsForNextKeyEvent(
EditCommands(1, EditCommand("moveToBeginningOfDocument", "")));
SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown));
......@@ -135,7 +123,7 @@ TEST_F(RenderViewTest, MacTestCmdUp) {
// move.
ExecuteJavaScriptForTests("allowKeyEvents = false; window.scrollTo(0, 100)");
const char* kArrowDownNoScroll = "40,false,false,true,false\n100\np1";
const char* kArrowDownNoScroll = "40,false,false,true,false\n100";
view->OnSetEditCommandsForNextKeyEvent(
EditCommands(1, EditCommand("moveToEndOfDocument", "")));
SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown));
......@@ -146,7 +134,7 @@ TEST_F(RenderViewTest, MacTestCmdUp) {
.Ascii();
EXPECT_EQ(kArrowDownNoScroll, output);
const char* kArrowUpNoScroll = "38,false,false,true,false\n100\np1";
const char* kArrowUpNoScroll = "38,false,false,true,false\n100";
view->OnSetEditCommandsForNextKeyEvent(
EditCommands(1, EditCommand("moveToBeginningOfDocument", "")));
SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown));
......
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