summaryrefslogtreecommitdiff
path: root/Source/web/tests/WebViewTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/web/tests/WebViewTest.cpp')
-rw-r--r--Source/web/tests/WebViewTest.cpp186
1 files changed, 68 insertions, 118 deletions
diff --git a/Source/web/tests/WebViewTest.cpp b/Source/web/tests/WebViewTest.cpp
index 0631e7b8a..5e6169a87 100644
--- a/Source/web/tests/WebViewTest.cpp
+++ b/Source/web/tests/WebViewTest.cpp
@@ -52,7 +52,7 @@
#include "core/dom/Element.h"
#include "core/html/HTMLDocument.h"
#include "core/loader/FrameLoadRequest.h"
-#include "core/page/FrameView.h"
+#include "core/frame/FrameView.h"
#include "core/page/Settings.h"
#include "public/platform/Platform.h"
#include "public/platform/WebSize.h"
@@ -108,29 +108,6 @@ private:
TestData m_testData;
};
-class FormChangeWebViewClient : public WebViewClient {
-public:
- // WebViewClient methods
- virtual void didChangeFormState(const WebNode& node)
- {
- m_focused = node.focused();
- m_called = true;
- }
-
- // Local methods
- void reset()
- {
- m_called = false;
- m_focused = false;
- }
- bool called() { return m_called; }
- bool focused() { return m_focused; }
-
-private:
- bool m_called;
- bool m_focused;
-};
-
class TapHandlingWebViewClient : public WebViewClient {
public:
// WebViewClient methods
@@ -226,6 +203,7 @@ protected:
void testInputMode(const WebString& expectedInputMode, const std::string& htmlFile);
std::string m_baseURL;
+ FrameTestHelpers::WebViewHelper m_webViewHelper;
};
TEST_F(WebViewTest, SetBaseBackgroundColor)
@@ -235,7 +213,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);
@@ -256,14 +234,12 @@ TEST_F(WebViewTest, SetBaseBackgroundColor)
webView->setBaseBackgroundColor(kTranslucentPutty);
// Expected: red (50% alpha) blended atop kTranslucentPutty. Note the alpha.
EXPECT_EQ(0xBFE93B32, webView->backgroundColor());
-
- webView->close();
}
TEST_F(WebViewTest, FocusIsInactive)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), "visible_iframe.html");
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "visible_iframe.html");
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "visible_iframe.html");
webView->setFocus(true);
webView->setIsActive(true);
@@ -284,14 +260,12 @@ TEST_F(WebViewTest, FocusIsInactive)
webView->setFocus(false);
webView->setIsActive(true);
EXPECT_FALSE(document->hasFocus());
-
- webView->close();
}
TEST_F(WebViewTest, ActiveState)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), "visible_iframe.html");
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "visible_iframe.html");
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "visible_iframe.html");
ASSERT_TRUE(webView);
@@ -303,15 +277,13 @@ TEST_F(WebViewTest, ActiveState)
webView->setIsActive(true);
EXPECT_TRUE(webView->isActive());
-
- webView->close();
}
TEST_F(WebViewTest, HitTestResultAtWithPageScale)
{
std::string url = m_baseURL + "specify_size.html?" + "50px" + ":" + "50px";
URLTestHelpers::registerMockedURLLoad(toKURL(url), "specify_size.html");
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(url, true, 0);
+ WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0);
webView->resize(WebSize(100, 100));
WebPoint hitPoint(75, 75);
@@ -327,8 +299,6 @@ TEST_F(WebViewTest, HitTestResultAtWithPageScale)
ASSERT_EQ(WebNode::ElementNode, positiveResult.node().nodeType());
EXPECT_TRUE(positiveResult.node().to<WebElement>().hasTagName("img"));
positiveResult.reset();
-
- webView->close();
}
void WebViewTest::testAutoResize(const WebSize& minAutoResize, const WebSize& maxAutoResize,
@@ -339,7 +309,7 @@ void WebViewTest::testAutoResize(const WebSize& minAutoResize, const WebSize& ma
AutoResizeWebViewClient client;
std::string url = m_baseURL + "specify_size.html?" + pageWidth + ":" + pageHeight;
URLTestHelpers::registerMockedURLLoad(toKURL(url), "specify_size.html");
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(url, true, 0, &client);
+ WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0, &client);
client.testData().setWebView(webView);
WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
@@ -360,7 +330,7 @@ void WebViewTest::testAutoResize(const WebSize& minAutoResize, const WebSize& ma
EXPECT_EQ(expectedHorizontalState, client.testData().horizontalScrollbarState());
EXPECT_EQ(expectedVerticalState, client.testData().verticalScrollbarState());
- webView->close();
+ m_webViewHelper.reset(); // Explicitly reset to break dependency on locally scoped client.
}
TEST_F(WebViewTest, DISABLED_AutoResizeMinimumSize)
@@ -440,10 +410,9 @@ TEST_F(WebViewTest, DISABLED_AutoResizeMaxSize)
void WebViewTest::testTextInputType(WebTextInputType expectedType, const std::string& htmlFile)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8(htmlFile.c_str()));
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + htmlFile);
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + htmlFile);
webView->setInitialFocus(false);
EXPECT_EQ(expectedType, webView->textInputInfo().type);
- webView->close();
}
TEST_F(WebViewTest, TextInputType)
@@ -460,10 +429,9 @@ TEST_F(WebViewTest, TextInputType)
void WebViewTest::testInputMode(const WebString& expectedInputMode, const std::string& htmlFile)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8(htmlFile.c_str()));
- WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + htmlFile);
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + htmlFile);
webView->setInitialFocus(false);
EXPECT_EQ(expectedInputMode, webView->textInputInfo().inputMode);
- webView->close();
}
TEST_F(WebViewTest, InputMode)
@@ -480,7 +448,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());
@@ -491,10 +459,9 @@ TEST_F(WebViewTest, SetEditableSelectionOffsetsAndTextInputInfo)
EXPECT_EQ(13, info.selectionEnd);
EXPECT_EQ(-1, info.compositionStart);
EXPECT_EQ(-1, info.compositionEnd);
- 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");
+ webView = m_webViewHelper.initializeAndLoad(m_baseURL + "content_editable_populated.html");
webView->setInitialFocus(false);
webView->setEditableSelectionOffsets(8, 19);
frame = toWebFrameImpl(webView->mainFrame());
@@ -505,13 +472,12 @@ TEST_F(WebViewTest, SetEditableSelectionOffsetsAndTextInputInfo)
EXPECT_EQ(19, info.selectionEnd);
EXPECT_EQ(-1, info.compositionStart);
EXPECT_EQ(-1, info.compositionEnd);
- webView->close();
}
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.
@@ -548,14 +514,12 @@ TEST_F(WebViewTest, ConfirmCompositionCursorPositionChange)
EXPECT_EQ(8, info.selectionEnd);
EXPECT_EQ(-1, info.compositionStart);
EXPECT_EQ(-1, info.compositionEnd);
-
- webView->close();
}
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;
@@ -585,30 +549,12 @@ TEST_F(WebViewTest, InsertNewLinePlacementAfterConfirmComposition)
EXPECT_EQ(-1, info.compositionStart);
EXPECT_EQ(-1, info.compositionEnd);
EXPECT_EQ("0123\n456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.utf8().data()));
-
- webView->close();
-}
-
-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);
- EXPECT_TRUE(client.called());
- EXPECT_TRUE(client.focused());
- client.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);
- EXPECT_TRUE(client.called());
- EXPECT_FALSE(client.focused());
- webView->close();
}
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);
@@ -619,13 +565,12 @@ TEST_F(WebViewTest, ExtendSelectionAndDelete)
webView->extendSelectionAndDelete(10, 0);
info = webView->textInputInfo();
EXPECT_EQ("ijklmnopqrstuvwxyz", std::string(info.value.utf8().data()));
- webView->close();
}
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);
@@ -646,13 +591,12 @@ TEST_F(WebViewTest, SetCompositionFromExistingText)
EXPECT_EQ(10, info.selectionEnd);
EXPECT_EQ(-1, info.compositionStart);
EXPECT_EQ(-1, info.compositionEnd);
- webView->close();
}
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);
@@ -682,13 +626,12 @@ TEST_F(WebViewTest, SetCompositionFromExistingTextInTextArea)
EXPECT_EQ(34, info.selectionEnd);
EXPECT_EQ(-1, info.compositionStart);
EXPECT_EQ(-1, info.compositionEnd);
- webView->close();
}
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 ");
@@ -744,13 +687,12 @@ TEST_F(WebViewTest, SetEditableSelectionOffsetsKeepsComposition)
EXPECT_EQ(2, info.selectionEnd);
EXPECT_EQ(-1, info.compositionStart);
EXPECT_EQ(-1, info.compositionEnd);
- webView->close();
}
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);
@@ -761,13 +703,12 @@ TEST_F(WebViewTest, IsSelectionAnchorFirst)
webView->selectionBounds(anchor, focus);
frame->selectRange(WebPoint(focus.x, focus.y), WebPoint(anchor.x, anchor.y));
EXPECT_FALSE(webView->isSelectionAnchorFirst());
- webView->close();
}
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);
@@ -806,7 +747,6 @@ TEST_F(WebViewTest, HistoryResetScrollAndScaleState)
EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor());
EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width);
EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height);
- webViewImpl->close();
}
class EnterFullscreenWebViewClient : public WebViewClient {
@@ -821,7 +761,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();
@@ -854,7 +794,7 @@ TEST_F(WebViewTest, EnterFullscreenResetScrollAndScaleState)
EXPECT_EQ(116, webViewImpl->mainFrame()->scrollOffset().width);
EXPECT_EQ(84, webViewImpl->mainFrame()->scrollOffset().height);
- webViewImpl->close();
+ m_webViewHelper.reset(); // Explicitly reset to break dependency on locally scoped client.
}
class ContentDetectorClient : public WebViewClient {
@@ -922,7 +862,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();
@@ -964,14 +904,13 @@ TEST_F(WebViewTest, DetectContentAroundPosition)
webView->handleInputEvent(event);
runPendingTasks();
EXPECT_TRUE(client.pendingIntentsCancelled());
- webView->close();
}
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;
@@ -988,7 +927,8 @@ TEST_F(WebViewTest, ClientTapHandling)
runPendingTasks();
EXPECT_EQ(25, client.longpressX());
EXPECT_EQ(7, client.longpressY());
- webView->close();
+
+ m_webViewHelper.reset(); // Explicitly reset to break dependency on locally scoped client.
}
#if OS(ANDROID)
@@ -996,7 +936,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();
@@ -1009,14 +949,13 @@ TEST_F(WebViewTest, LongPressSelection)
EXPECT_EQ("", std::string(frame->selectionAsText().utf8().data()));
EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, target));
EXPECT_EQ("testword", std::string(frame->selectionAsText().utf8().data()));
- webView->close();
}
#endif
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();
@@ -1031,14 +970,12 @@ TEST_F(WebViewTest, SelectionOnDisabledInput)
EXPECT_TRUE(toWebViewImpl(webView)->caretOrSelectionRange(&location, &length));
EXPECT_EQ(location, 0UL);
EXPECT_EQ(length, testWord.length());
-
- webView->close();
}
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();
@@ -1053,8 +990,6 @@ TEST_F(WebViewTest, SelectionOnReadOnlyInput)
EXPECT_TRUE(toWebViewImpl(webView)->caretOrSelectionRange(&location, &length));
EXPECT_EQ(location, 0UL);
EXPECT_EQ(length, testWord.length());
-
- webView->close();
}
class MockAutofillClient : public WebAutofillClient {
@@ -1095,7 +1030,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);
@@ -1117,14 +1052,13 @@ TEST_F(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange)
EXPECT_EQ(0, client.textChangesWhileNotIgnored());
webView->setAutofillClient(0);
- webView->close();
}
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);
@@ -1146,14 +1080,13 @@ TEST_F(WebViewTest, ConfirmCompositionTriggersAutofillTextChange)
EXPECT_EQ(1, client.textChangesWhileNotIgnored());
webView->setAutofillClient(0);
- webView->close();
}
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);
@@ -1174,13 +1107,12 @@ TEST_F(WebViewTest, SetCompositionFromExistingTextTriggersAutofillTextChange)
EXPECT_EQ(WebString::fromUTF8("none"), document.getElementById("inputEvent").firstChild().nodeValue());
webView->setAutofillClient(0);
- webView->close();
}
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();
{
@@ -1195,13 +1127,12 @@ TEST_F(WebViewTest, ShadowRoot)
WebNode shadowRoot = elementWithoutShadowRoot.shadowRoot();
EXPECT_TRUE(shadowRoot.isNull());
}
- webViewImpl->close();
}
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());
@@ -1212,23 +1143,21 @@ TEST_F(WebViewTest, HelperPlugin)
webViewImpl->closeHelperPluginSoon(helperPlugin);
- webViewImpl->close();
+ m_webViewHelper.reset(); // Explicitly reset to break dependency on locally scoped client.
}
class ViewCreatingWebViewClient : public WebViewClient {
public:
ViewCreatingWebViewClient()
- : m_createdWebView(0)
- , m_didFocusCalled(false)
+ : m_didFocusCalled(false)
{
}
// WebViewClient methods
virtual WebView* createView(WebFrame*, const WebURLRequest&, const WebWindowFeatures&, const WebString& name, WebNavigationPolicy) OVERRIDE
{
- m_createdWebView = FrameTestHelpers::createWebView(true, 0, 0);
- return m_createdWebView;
+ return m_webViewHelper.initialize(true, 0, 0);
}
// WebWidgetClient methods
@@ -1237,23 +1166,19 @@ public:
m_didFocusCalled = true;
}
- void close()
- {
- if (m_createdWebView)
- m_createdWebView->close();
- }
bool didFocusCalled() const { return m_didFocusCalled; }
- WebView* createdWebView() const { return m_createdWebView; }
+ WebView* createdWebView() const { return m_webViewHelper.webView(); }
private:
- WebView* m_createdWebView;
+ FrameTestHelpers::WebViewHelper m_webViewHelper;
bool m_didFocusCalled;
};
TEST_F(WebViewTest, FocusExistingFrameOnNavigate)
{
ViewCreatingWebViewClient client;
- WebViewImpl* webViewImpl = toWebViewImpl(FrameTestHelpers::createWebView(true, 0, &client));
+ FrameTestHelpers::WebViewHelper m_webViewHelper;
+ WebViewImpl* webViewImpl = toWebViewImpl(m_webViewHelper.initialize(true, 0, &client));
webViewImpl->page()->settings().setJavaScriptCanOpenWindowsAutomatically(true);
WebFrameImpl* frame = toWebFrameImpl(webViewImpl->mainFrame());
frame->setName("_start");
@@ -1273,8 +1198,33 @@ TEST_F(WebViewTest, FocusExistingFrameOnNavigate)
toWebViewImpl(client.createdWebView())->page()->mainFrame()->loader()->load(requestWithTargetStart);
EXPECT_TRUE(client.didFocusCalled());
- client.close();
- webViewImpl->close();
+ m_webViewHelper.reset(); // Remove dependency on locally scoped client.
+}
+
+TEST_F(WebViewTest, DispatchesFocusOutFocusInOnViewToggleFocus)
+{
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), "focusout_focusin_events.html");
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "focusout_focusin_events.html", true, 0);
+
+ webView->setFocus(true);
+ webView->setFocus(false);
+ webView->setFocus(true);
+
+ WebElement element = webView->mainFrame()->document().getElementById("message");
+ EXPECT_STREQ("focusoutfocusin", element.innerText().utf8().data());
+}
+
+TEST_F(WebViewTest, DispatchesDomFocusOutDomFocusInOnViewToggleFocus)
+{
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), "domfocusout_domfocusin_events.html");
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "domfocusout_domfocusin_events.html", true, 0);
+
+ webView->setFocus(true);
+ webView->setFocus(false);
+ webView->setFocus(true);
+
+ WebElement element = webView->mainFrame()->document().getElementById("message");
+ EXPECT_STREQ("DOMFocusOutDOMFocusIn", element.innerText().utf8().data());
}
}