Source/web/tests/WebViewTest.cpp
// This test verifies that WebWidgetClient::didUpdateTextOfFocusedElementByNonUserInput is
// called iff value of a focused element is modified via script.
This test verifies that WebWidgetClient::didUpdateTextOfFocusedElementByNonUserInput is
called iff value of a focused element is modified via script.
This test verifies that WebWidgetClient :: didUpdateTextOfFocusedElementByNonUserInput is called iff value of a focused element is modified via script .
TEST_F(WebViewTest, NonUserInputTextUpdate)
{
    NonUserInputTextUpdateWebViewClient client;
    std::string url = m_baseURL + "non_user_input_text_update.html";
    URLTestHelpers::registerMockedURLLoad(toKURL(url), "non_user_input_text_update.html");
    WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &client);
    webViewImpl->setInitialFocus(false);
    WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame());
    WebCore::HTMLDocument* document = WebCore::toHTMLDocument(frame->frame()->document());
    client.reset();
    EXPECT_FALSE(client.textIsUpdated());
    WebCore::HTMLInputElement* inputElement = toHTMLInputElement(document->getElementById("input"));
    document->setFocusedElement(inputElement);
    webViewImpl->setFocus(true);
    EXPECT_EQ(document->focusedElement(), static_cast<WebCore::Element*>(inputElement));
    inputElement->setValue("testA");
    EXPECT_TRUE(client.textIsUpdated());
    WebTextInputInfo info = webViewImpl->textInputInfo();
    EXPECT_EQ("testA", std::string(info.value.utf8().data()));
    client.reset();
    EXPECT_FALSE(client.textIsUpdated());
    WebVector<WebCompositionUnderline> emptyUnderlines;
    webViewImpl->setComposition(WebString::fromUTF8("2"), emptyUnderlines, 1, 1);
    webViewImpl->confirmComposition(WebWidget::KeepSelection);
    EXPECT_FALSE(client.textIsUpdated());
    info = webViewImpl->textInputInfo();
    EXPECT_EQ("testA2", std::string(info.value.utf8().data()));
    client.reset();
    EXPECT_FALSE(client.textIsUpdated());
    document->setFocusedElement(nullptr);
    webViewImpl->setFocus(false);
    EXPECT_NE(document->focusedElement(), static_cast<WebCore::Element*>(inputElement));
    inputElement->setValue("testA3");
    EXPECT_FALSE(client.textIsUpdated());
    client.reset();
    EXPECT_FALSE(client.textIsUpdated());
    WebCore::HTMLTextAreaElement* textAreaElement = toHTMLTextAreaElement(document->getElementById("textarea"));
    document->setFocusedElement(textAreaElement);
    webViewImpl->setFocus(true);
    EXPECT_EQ(document->focusedElement(), static_cast<WebCore::Element*>(textAreaElement));
    textAreaElement->setValue("testB");
    EXPECT_TRUE(client.textIsUpdated());
    info = webViewImpl->textInputInfo();
    EXPECT_EQ("testB", std::string(info.value.utf8().data()));
    client.reset();
    EXPECT_FALSE(client.textIsUpdated());
    webViewImpl->setComposition(WebString::fromUTF8("2"), emptyUnderlines, 1, 1);
    webViewImpl->confirmComposition(WebWidget::KeepSelection);
    info = webViewImpl->textInputInfo();
    EXPECT_EQ("testB2", std::string(info.value.utf8().data()));
    client.reset();
    EXPECT_FALSE(client.textIsUpdated());
    document->setFocusedElement(nullptr);
    webViewImpl->setFocus(false);
    EXPECT_NE(document->focusedElement(), static_cast<WebCore::Element*>(textAreaElement));
    inputElement->setValue("testB3");
    EXPECT_FALSE(client.textIsUpdated());
    m_webViewHelper.reset();
}
TEST_F ( WebViewTest , NonUserInputTextUpdate ) { NonUserInputTextUpdateWebViewClient client ; std :: string url = m_baseURL + " " ; URLTestHelpers :: registerMockedURLLoad ( toKURL ( url ) , " " ) ; WebViewImpl * webViewImpl = m_webViewHelper . initializeAndLoad ( url , true , 0 , & client ) ; webViewImpl -> setInitialFocus ( false ) ; WebLocalFrameImpl * frame = toWebLocalFrameImpl ( webViewImpl -> mainFrame ( ) ) ; WebCore :: HTMLDocument * document = WebCore :: toHTMLDocument ( frame -> frame ( ) -> document ( ) ) ; client . reset ( ) ; EXPECT_FALSE ( client . textIsUpdated ( ) ) ; WebCore :: HTMLInputElement * inputElement = toHTMLInputElement ( document -> getElementById ( " " ) ) ; document -> setFocusedElement ( inputElement ) ; webViewImpl -> setFocus ( true ) ; EXPECT_EQ ( document -> focusedElement ( ) , static_cast < WebCore :: Element * > ( inputElement ) ) ; inputElement -> setValue ( " " ) ; EXPECT_TRUE ( client . textIsUpdated ( ) ) ; WebTextInputInfo info = webViewImpl -> textInputInfo ( ) ; EXPECT_EQ ( " " , std :: string ( info . value . utf8 ( ) . data ( ) ) ) ; client . reset ( ) ; EXPECT_FALSE ( client . textIsUpdated ( ) ) ; WebVector < WebCompositionUnderline > emptyUnderlines ; webViewImpl -> setComposition ( WebString :: fromUTF8 ( " " ) , emptyUnderlines , 1 , 1 ) ; webViewImpl -> confirmComposition ( WebWidget :: KeepSelection ) ; EXPECT_FALSE ( client . textIsUpdated ( ) ) ; info = webViewImpl -> textInputInfo ( ) ; EXPECT_EQ ( " " , std :: string ( info . value . utf8 ( ) . data ( ) ) ) ; client . reset ( ) ; EXPECT_FALSE ( client . textIsUpdated ( ) ) ; document -> setFocusedElement ( nullptr ) ; webViewImpl -> setFocus ( false ) ; EXPECT_NE ( document -> focusedElement ( ) , static_cast < WebCore :: Element * > ( inputElement ) ) ; inputElement -> setValue ( " " ) ; EXPECT_FALSE ( client . textIsUpdated ( ) ) ; client . reset ( ) ; EXPECT_FALSE ( client . textIsUpdated ( ) ) ; WebCore :: HTMLTextAreaElement * textAreaElement = toHTMLTextAreaElement ( document -> getElementById ( " " ) ) ; document -> setFocusedElement ( textAreaElement ) ; webViewImpl -> setFocus ( true ) ; EXPECT_EQ ( document -> focusedElement ( ) , static_cast < WebCore :: Element * > ( textAreaElement ) ) ; textAreaElement -> setValue ( " " ) ; EXPECT_TRUE ( client . textIsUpdated ( ) ) ; info = webViewImpl -> textInputInfo ( ) ; EXPECT_EQ ( " " , std :: string ( info . value . utf8 ( ) . data ( ) ) ) ; client . reset ( ) ; EXPECT_FALSE ( client . textIsUpdated ( ) ) ; webViewImpl -> setComposition ( WebString :: fromUTF8 ( " " ) , emptyUnderlines , 1 , 1 ) ; webViewImpl -> confirmComposition ( WebWidget :: KeepSelection ) ; info = webViewImpl -> textInputInfo ( ) ; EXPECT_EQ ( " " , std :: string ( info . value . utf8 ( ) . data ( ) ) ) ; client . reset ( ) ; EXPECT_FALSE ( client . textIsUpdated ( ) ) ; document -> setFocusedElement ( nullptr ) ; webViewImpl -> setFocus ( false ) ; EXPECT_NE ( document -> focusedElement ( ) , static_cast < WebCore :: Element * > ( textAreaElement ) ) ; inputElement -> setValue ( " " ) ; EXPECT_FALSE ( client . textIsUpdated ( ) ) ; m_webViewHelper . reset ( ) ; }
This test verifies that WebWidgetClient::didUpdateTextOfFocusedElementByNonUserInput is
called iff value of a focused element is modified via script.
This test verifies that WebWidgetClient :: didUpdateTextOfFocusedElementByNonUserInput is called iff value of a focused element is modified via script .
// (A) <input> // (A.1) Focused and value is changed by script. // Emulate value change from script. // (A.2) Focused and user input modifies value. // (A.3) Unfocused and value is changed by script. // (B) <textarea> // (B.1) Focused and value is changed by script. // (B.2) Focused and user input modifies value. // (B.3) Unfocused and value is changed by script. // Free the webView before freeing the NonUserInputTextUpdateWebViewClient.