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

Unified Diff: Source/web/tests/WebViewTest.cpp

Issue 23506013: Make the embedder responsible for creating the WebFrame (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add WebViewHelper for unittests. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/web/tests/WebViewTest.cpp
diff --git a/Source/web/tests/WebViewTest.cpp b/Source/web/tests/WebViewTest.cpp
index 42df88b64e280a01737ead4376dcd39b0c633883..beaf3b0cc8f3977c59d3410303afd2db3b61f21e 100644
--- a/Source/web/tests/WebViewTest.cpp
+++ b/Source/web/tests/WebViewTest.cpp
@@ -224,6 +224,7 @@ protected:
void testInputMode(const WebString& expectedInputMode, const std::string& htmlFile);
std::string m_baseURL;
+ FrameTestHelpers::WebViewHelper m_webViewHelper;
};
TEST_F(WebViewTest, SetBaseBackgroundColor)
@@ -233,7 +234,7 @@ TEST_F(WebViewTest, SetBaseBackgroundColor)
const WebColor kDarkCyan = 0xFF227788;
const WebColor kTranslucentPutty = 0x80BFB196;
- WebView* webView = FrameTestHelpers::createWebView();
+ WebView* webView = m_webViewHelper.initialize();
EXPECT_EQ(kWhite, webView->backgroundColor());
webView->setBaseBackgroundColor(kBlue);
@@ -478,7 +479,7 @@ TEST_F(WebViewTest, InputMode)
TEST_F(WebViewTest, SetEditableSelectionOffsetsAndTextInputInfo)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_populated.html");
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_field_populated.html");
webView->setInitialFocus(false);
webView->setEditableSelectionOffsets(5, 13);
WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
@@ -492,7 +493,8 @@ TEST_F(WebViewTest, SetEditableSelectionOffsetsAndTextInputInfo)
webView->close();
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("content_editable_populated.html"));
- webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "content_editable_populated.html");
+ m_webViewHelper.reset();
+ webView = m_webViewHelper.initializeAndLoad(m_baseURL + "content_editable_populated.html");
webView->setInitialFocus(false);
webView->setEditableSelectionOffsets(8, 19);
frame = toWebFrameImpl(webView->mainFrame());
@@ -509,7 +511,7 @@ TEST_F(WebViewTest, SetEditableSelectionOffsetsAndTextInputInfo)
TEST_F(WebViewTest, ConfirmCompositionCursorPositionChange)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_populated.html");
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_field_populated.html");
webView->setInitialFocus(false);
// Set up a composition that needs to be committed.
@@ -553,7 +555,7 @@ TEST_F(WebViewTest, ConfirmCompositionCursorPositionChange)
TEST_F(WebViewTest, InsertNewLinePlacementAfterConfirmComposition)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("text_area_populated.html"));
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "text_area_populated.html");
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "text_area_populated.html");
webView->setInitialFocus(false);
WebVector<WebCompositionUnderline> emptyUnderlines;
@@ -592,12 +594,13 @@ TEST_F(WebViewTest, FormChange)
FormChangeWebViewClient client;
client.reset();
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_set_value_while_focused.html"));
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_set_value_while_focused.html", true, 0, &client);
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_field_set_value_while_focused.html", true, 0, &client);
EXPECT_TRUE(client.called());
EXPECT_TRUE(client.focused());
client.reset();
+ m_webViewHelper.reset();
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_set_value_while_not_focused.html"));
- webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_set_value_while_not_focused.html", true, 0, &client);
+ webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_field_set_value_while_not_focused.html", true, 0, &client);
EXPECT_TRUE(client.called());
EXPECT_FALSE(client.focused());
webView->close();
@@ -606,7 +609,7 @@ TEST_F(WebViewTest, FormChange)
TEST_F(WebViewTest, ExtendSelectionAndDelete)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_populated.html");
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_field_populated.html");
webView->setInitialFocus(false);
webView->setEditableSelectionOffsets(10, 10);
webView->extendSelectionAndDelete(5, 8);
@@ -623,7 +626,7 @@ TEST_F(WebViewTest, ExtendSelectionAndDelete)
TEST_F(WebViewTest, SetCompositionFromExistingText)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_populated.html");
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_field_populated.html");
webView->setInitialFocus(false);
WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1));
underlines[0] = WebKit::WebCompositionUnderline(0, 4, 0, false);
@@ -650,7 +653,7 @@ TEST_F(WebViewTest, SetCompositionFromExistingText)
TEST_F(WebViewTest, SetCompositionFromExistingTextInTextArea)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("text_area_populated.html"));
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "text_area_populated.html");
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "text_area_populated.html");
webView->setInitialFocus(false);
WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1));
underlines[0] = WebKit::WebCompositionUnderline(0, 4, 0, false);
@@ -686,7 +689,7 @@ TEST_F(WebViewTest, SetCompositionFromExistingTextInTextArea)
TEST_F(WebViewTest, SetEditableSelectionOffsetsKeepsComposition)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_populated.html");
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_field_populated.html");
webView->setInitialFocus(false);
std::string compositionTextFirst("hello ");
@@ -748,7 +751,7 @@ TEST_F(WebViewTest, SetEditableSelectionOffsetsKeepsComposition)
TEST_F(WebViewTest, IsSelectionAnchorFirst)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_populated.html");
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_field_populated.html");
WebFrame* frame = webView->mainFrame();
webView->setInitialFocus(false);
@@ -765,7 +768,7 @@ TEST_F(WebViewTest, IsSelectionAnchorFirst)
TEST_F(WebViewTest, HistoryResetScrollAndScaleState)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("hello_world.html"));
- WebViewImpl* webViewImpl = toWebViewImpl(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "hello_world.html"));
+ WebViewImpl* webViewImpl = toWebViewImpl(m_webViewHelper.initializeAndLoad(m_baseURL + "hello_world.html"));
webViewImpl->resize(WebSize(640, 480));
webViewImpl->layout();
EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width);
@@ -819,7 +822,7 @@ TEST_F(WebViewTest, EnterFullscreenResetScrollAndScaleState)
{
EnterFullscreenWebViewClient client;
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("hello_world.html"));
- WebViewImpl* webViewImpl = toWebViewImpl(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "hello_world.html", true, 0, &client));
+ WebViewImpl* webViewImpl = toWebViewImpl(m_webViewHelper.initializeAndLoad(m_baseURL + "hello_world.html", true, 0, &client));
webViewImpl->settings()->setFullScreenEnabled(true);
webViewImpl->resize(WebSize(640, 480));
webViewImpl->layout();
@@ -920,7 +923,7 @@ TEST_F(WebViewTest, DetectContentAroundPosition)
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("content_listeners.html"));
ContentDetectorClient client;
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "content_listeners.html", true, 0, &client);
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "content_listeners.html", true, 0, &client);
webView->resize(WebSize(500, 300));
webView->layout();
runPendingTasks();
@@ -969,7 +972,7 @@ TEST_F(WebViewTest, ClientTapHandling)
{
TapHandlingWebViewClient client;
client.reset();
- WebView* webView = FrameTestHelpers::createWebViewAndLoad("about:blank", true, 0, &client);
+ WebView* webView = m_webViewHelper.initializeAndLoad("about:blank", true, 0, &client);
WebGestureEvent event;
event.type = WebInputEvent::GestureTap;
event.x = 3;
@@ -994,7 +997,7 @@ TEST_F(WebViewTest, LongPressSelection)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("longpress_selection.html"));
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "longpress_selection.html", true);
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "longpress_selection.html", true);
webView->resize(WebSize(500, 300));
webView->layout();
runPendingTasks();
@@ -1014,7 +1017,7 @@ TEST_F(WebViewTest, LongPressSelection)
TEST_F(WebViewTest, SelectionOnDisabledInput)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("selection_disabled.html"));
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "selection_disabled.html", true);
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "selection_disabled.html", true);
webView->resize(WebSize(640, 480));
webView->layout();
runPendingTasks();
@@ -1036,7 +1039,7 @@ TEST_F(WebViewTest, SelectionOnDisabledInput)
TEST_F(WebViewTest, SelectionOnReadOnlyInput)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("selection_readonly.html"));
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "selection_readonly.html", true);
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "selection_readonly.html", true);
webView->resize(WebSize(640, 480));
webView->layout();
runPendingTasks();
@@ -1093,7 +1096,7 @@ TEST_F(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
MockAutofillClient client;
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_populated.html");
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_field_populated.html");
webView->setAutofillClient(&client);
webView->setInitialFocus(false);
@@ -1122,7 +1125,7 @@ TEST_F(WebViewTest, ConfirmCompositionTriggersAutofillTextChange)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
MockAutofillClient client;
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_populated.html");
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_field_populated.html");
webView->setAutofillClient(&client);
webView->setInitialFocus(false);
@@ -1151,7 +1154,7 @@ TEST_F(WebViewTest, SetCompositionFromExistingTextTriggersAutofillTextChange)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
MockAutofillClient client;
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_populated.html", true);
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_field_populated.html", true);
webView->setAutofillClient(&client);
webView->setInitialFocus(false);
@@ -1178,7 +1181,7 @@ TEST_F(WebViewTest, SetCompositionFromExistingTextTriggersAutofillTextChange)
TEST_F(WebViewTest, ShadowRoot)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("shadow_dom_test.html"));
- WebViewImpl* webViewImpl = toWebViewImpl(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "shadow_dom_test.html", true));
+ WebViewImpl* webViewImpl = toWebViewImpl(m_webViewHelper.initializeAndLoad(m_baseURL + "shadow_dom_test.html", true));
WebDocument document = webViewImpl->mainFrame()->document();
{
@@ -1199,7 +1202,7 @@ TEST_F(WebViewTest, ShadowRoot)
TEST_F(WebViewTest, HelperPlugin)
{
HelperPluginCreatingWebViewClient client;
- WebViewImpl* webViewImpl = toWebViewImpl(FrameTestHelpers::createWebView(true, 0, &client));
+ WebViewImpl* webViewImpl = toWebViewImpl(m_webViewHelper.initialize(true, 0, &client));
WebFrameImpl* frame = toWebFrameImpl(webViewImpl->mainFrame());
client.setWebFrameClient(frame->client());

Powered by Google App Engine
This is Rietveld 408576698