| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 1334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1345 int m_textChangesWhileNotIgnored; | 1345 int m_textChangesWhileNotIgnored; |
| 1346 int m_userGestureNotificationsCount; | 1346 int m_userGestureNotificationsCount; |
| 1347 }; | 1347 }; |
| 1348 | 1348 |
| 1349 | 1349 |
| 1350 TEST_F(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange) | 1350 TEST_F(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange) |
| 1351 { | 1351 { |
| 1352 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 1352 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
| 1353 MockAutofillClient client; | 1353 MockAutofillClient client; |
| 1354 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); | 1354 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); |
| 1355 webView->setAutofillClient(&client); | 1355 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); |
| 1356 frame->setAutofillClient(&client); |
| 1356 webView->setInitialFocus(false); | 1357 webView->setInitialFocus(false); |
| 1357 | 1358 |
| 1358 // Set up a composition that needs to be committed. | 1359 // Set up a composition that needs to be committed. |
| 1359 WebVector<WebCompositionUnderline> emptyUnderlines; | 1360 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 1360 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); | |
| 1361 frame->setEditableSelectionOffsets(4, 10); | 1361 frame->setEditableSelectionOffsets(4, 10); |
| 1362 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); | 1362 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); |
| 1363 WebTextInputInfo info = webView->textInputInfo(); | 1363 WebTextInputInfo info = webView->textInputInfo(); |
| 1364 EXPECT_EQ(4, info.selectionStart); | 1364 EXPECT_EQ(4, info.selectionStart); |
| 1365 EXPECT_EQ(10, info.selectionEnd); | 1365 EXPECT_EQ(10, info.selectionEnd); |
| 1366 EXPECT_EQ(8, info.compositionStart); | 1366 EXPECT_EQ(8, info.compositionStart); |
| 1367 EXPECT_EQ(12, info.compositionEnd); | 1367 EXPECT_EQ(12, info.compositionEnd); |
| 1368 | 1368 |
| 1369 // Clear the focus and track that the subsequent composition commit does not
trigger a | 1369 // Clear the focus and track that the subsequent composition commit does not
trigger a |
| 1370 // text changed notification for autofill. | 1370 // text changed notification for autofill. |
| 1371 client.clearChangeCounts(); | 1371 client.clearChangeCounts(); |
| 1372 webView->setFocus(false); | 1372 webView->setFocus(false); |
| 1373 EXPECT_EQ(1, client.textChangesWhileIgnored()); | 1373 EXPECT_EQ(1, client.textChangesWhileIgnored()); |
| 1374 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); | 1374 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); |
| 1375 | 1375 |
| 1376 webView->setAutofillClient(0); | 1376 frame->setAutofillClient(0); |
| 1377 } | 1377 } |
| 1378 | 1378 |
| 1379 TEST_F(WebViewTest, ConfirmCompositionTriggersAutofillTextChange) | 1379 TEST_F(WebViewTest, ConfirmCompositionTriggersAutofillTextChange) |
| 1380 { | 1380 { |
| 1381 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 1381 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
| 1382 MockAutofillClient client; | 1382 MockAutofillClient client; |
| 1383 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); | 1383 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); |
| 1384 webView->setAutofillClient(&client); | 1384 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); |
| 1385 frame->setAutofillClient(&client); |
| 1385 webView->setInitialFocus(false); | 1386 webView->setInitialFocus(false); |
| 1386 | 1387 |
| 1387 // Set up a composition that needs to be committed. | 1388 // Set up a composition that needs to be committed. |
| 1388 std::string compositionText("testingtext"); | 1389 std::string compositionText("testingtext"); |
| 1389 | 1390 |
| 1390 WebVector<WebCompositionUnderline> emptyUnderlines; | 1391 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 1391 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU
nderlines, 0, compositionText.length()); | 1392 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU
nderlines, 0, compositionText.length()); |
| 1392 | 1393 |
| 1393 WebTextInputInfo info = webView->textInputInfo(); | 1394 WebTextInputInfo info = webView->textInputInfo(); |
| 1394 EXPECT_EQ(0, info.selectionStart); | 1395 EXPECT_EQ(0, info.selectionStart); |
| 1395 EXPECT_EQ((int) compositionText.length(), info.selectionEnd); | 1396 EXPECT_EQ((int) compositionText.length(), info.selectionEnd); |
| 1396 EXPECT_EQ(0, info.compositionStart); | 1397 EXPECT_EQ(0, info.compositionStart); |
| 1397 EXPECT_EQ((int) compositionText.length(), info.compositionEnd); | 1398 EXPECT_EQ((int) compositionText.length(), info.compositionEnd); |
| 1398 | 1399 |
| 1399 client.clearChangeCounts(); | 1400 client.clearChangeCounts(); |
| 1400 webView->confirmComposition(); | 1401 webView->confirmComposition(); |
| 1401 EXPECT_EQ(0, client.textChangesWhileIgnored()); | 1402 EXPECT_EQ(0, client.textChangesWhileIgnored()); |
| 1402 EXPECT_EQ(1, client.textChangesWhileNotIgnored()); | 1403 EXPECT_EQ(1, client.textChangesWhileNotIgnored()); |
| 1403 | 1404 |
| 1404 webView->setAutofillClient(0); | 1405 frame->setAutofillClient(0); |
| 1405 } | 1406 } |
| 1406 | 1407 |
| 1407 TEST_F(WebViewTest, SetCompositionFromExistingTextTriggersAutofillTextChange) | 1408 TEST_F(WebViewTest, SetCompositionFromExistingTextTriggersAutofillTextChange) |
| 1408 { | 1409 { |
| 1409 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 1410 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
| 1410 MockAutofillClient client; | 1411 MockAutofillClient client; |
| 1411 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html", true); | 1412 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html", true); |
| 1412 webView->setAutofillClient(&client); | 1413 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); |
| 1414 frame->setAutofillClient(&client); |
| 1413 webView->setInitialFocus(false); | 1415 webView->setInitialFocus(false); |
| 1414 | 1416 |
| 1415 WebVector<WebCompositionUnderline> emptyUnderlines; | 1417 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 1416 | 1418 |
| 1417 client.clearChangeCounts(); | 1419 client.clearChangeCounts(); |
| 1418 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); | |
| 1419 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); | 1420 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); |
| 1420 | 1421 |
| 1421 WebTextInputInfo info = webView->textInputInfo(); | 1422 WebTextInputInfo info = webView->textInputInfo(); |
| 1422 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.utf
8().data())); | 1423 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.utf
8().data())); |
| 1423 EXPECT_EQ(8, info.compositionStart); | 1424 EXPECT_EQ(8, info.compositionStart); |
| 1424 EXPECT_EQ(12, info.compositionEnd); | 1425 EXPECT_EQ(12, info.compositionEnd); |
| 1425 | 1426 |
| 1426 EXPECT_EQ(0, client.textChangesWhileIgnored()); | 1427 EXPECT_EQ(0, client.textChangesWhileIgnored()); |
| 1427 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); | 1428 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); |
| 1428 | 1429 |
| 1429 WebDocument document = webView->mainFrame()->document(); | 1430 WebDocument document = webView->mainFrame()->document(); |
| 1430 EXPECT_EQ(WebString::fromUTF8("none"), document.getElementById("inputEvent"
).firstChild().nodeValue()); | 1431 EXPECT_EQ(WebString::fromUTF8("none"), document.getElementById("inputEvent"
).firstChild().nodeValue()); |
| 1431 | 1432 |
| 1432 webView->setAutofillClient(0); | 1433 frame->setAutofillClient(0); |
| 1433 } | 1434 } |
| 1434 | 1435 |
| 1435 TEST_F(WebViewTest, ShadowRoot) | 1436 TEST_F(WebViewTest, ShadowRoot) |
| 1436 { | 1437 { |
| 1437 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("shadow_dom_test.html")); | 1438 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("shadow_dom_test.html")); |
| 1438 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "sh
adow_dom_test.html", true); | 1439 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "sh
adow_dom_test.html", true); |
| 1439 | 1440 |
| 1440 WebDocument document = webViewImpl->mainFrame()->document(); | 1441 WebDocument document = webViewImpl->mainFrame()->document(); |
| 1441 { | 1442 { |
| 1442 WebElement elementWithShadowRoot = document.getElementById("shadowroot")
; | 1443 WebElement elementWithShadowRoot = document.getElementById("shadowroot")
; |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2137 m_webViewHelper.reset(); | 2138 m_webViewHelper.reset(); |
| 2138 } | 2139 } |
| 2139 | 2140 |
| 2140 // Check that the WebAutofillClient is correctly notified about first user | 2141 // Check that the WebAutofillClient is correctly notified about first user |
| 2141 // gestures after load, following various input events. | 2142 // gestures after load, following various input events. |
| 2142 TEST_F(WebViewTest, FirstUserGestureObservedKeyEvent) | 2143 TEST_F(WebViewTest, FirstUserGestureObservedKeyEvent) |
| 2143 { | 2144 { |
| 2144 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("form.html")); | 2145 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("form.html")); |
| 2145 MockAutofillClient client; | 2146 MockAutofillClient client; |
| 2146 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "form.html"
, true); | 2147 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "form.html"
, true); |
| 2147 webView->setAutofillClient(&client); | 2148 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); |
| 2149 frame->setAutofillClient(&client); |
| 2148 webView->setInitialFocus(false); | 2150 webView->setInitialFocus(false); |
| 2149 | 2151 |
| 2150 EXPECT_EQ(0, client.getUserGestureNotificationsCount()); | 2152 EXPECT_EQ(0, client.getUserGestureNotificationsCount()); |
| 2151 | 2153 |
| 2152 WebKeyboardEvent keyEvent; | 2154 WebKeyboardEvent keyEvent; |
| 2153 keyEvent.windowsKeyCode = VKEY_SPACE; | 2155 keyEvent.windowsKeyCode = VKEY_SPACE; |
| 2154 keyEvent.type = WebInputEvent::RawKeyDown; | 2156 keyEvent.type = WebInputEvent::RawKeyDown; |
| 2155 keyEvent.setKeyIdentifierFromWindowsKeyCode(); | 2157 keyEvent.setKeyIdentifierFromWindowsKeyCode(); |
| 2156 webView->handleInputEvent(keyEvent); | 2158 webView->handleInputEvent(keyEvent); |
| 2157 keyEvent.type = WebInputEvent::KeyUp; | 2159 keyEvent.type = WebInputEvent::KeyUp; |
| 2158 webView->handleInputEvent(keyEvent); | 2160 webView->handleInputEvent(keyEvent); |
| 2159 | 2161 |
| 2160 EXPECT_EQ(1, client.getUserGestureNotificationsCount()); | 2162 EXPECT_EQ(1, client.getUserGestureNotificationsCount()); |
| 2161 webView->setAutofillClient(0); | 2163 frame->setAutofillClient(0); |
| 2162 } | 2164 } |
| 2163 | 2165 |
| 2164 TEST_F(WebViewTest, FirstUserGestureObservedMouseEvent) | 2166 TEST_F(WebViewTest, FirstUserGestureObservedMouseEvent) |
| 2165 { | 2167 { |
| 2166 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("form.html")); | 2168 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("form.html")); |
| 2167 MockAutofillClient client; | 2169 MockAutofillClient client; |
| 2168 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "form.html"
, true); | 2170 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "form.html"
, true); |
| 2169 webView->setAutofillClient(&client); | 2171 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); |
| 2172 frame->setAutofillClient(&client); |
| 2170 webView->setInitialFocus(false); | 2173 webView->setInitialFocus(false); |
| 2171 | 2174 |
| 2172 EXPECT_EQ(0, client.getUserGestureNotificationsCount()); | 2175 EXPECT_EQ(0, client.getUserGestureNotificationsCount()); |
| 2173 | 2176 |
| 2174 WebMouseEvent mouseEvent; | 2177 WebMouseEvent mouseEvent; |
| 2175 mouseEvent.button = WebMouseEvent::ButtonLeft; | 2178 mouseEvent.button = WebMouseEvent::ButtonLeft; |
| 2176 mouseEvent.x = 1; | 2179 mouseEvent.x = 1; |
| 2177 mouseEvent.y = 1; | 2180 mouseEvent.y = 1; |
| 2178 mouseEvent.clickCount = 1; | 2181 mouseEvent.clickCount = 1; |
| 2179 mouseEvent.type = WebInputEvent::MouseDown; | 2182 mouseEvent.type = WebInputEvent::MouseDown; |
| 2180 webView->handleInputEvent(mouseEvent); | 2183 webView->handleInputEvent(mouseEvent); |
| 2181 mouseEvent.type = WebInputEvent::MouseUp; | 2184 mouseEvent.type = WebInputEvent::MouseUp; |
| 2182 webView->handleInputEvent(mouseEvent); | 2185 webView->handleInputEvent(mouseEvent); |
| 2183 | 2186 |
| 2184 EXPECT_EQ(1, client.getUserGestureNotificationsCount()); | 2187 EXPECT_EQ(1, client.getUserGestureNotificationsCount()); |
| 2185 webView->setAutofillClient(0); | 2188 frame->setAutofillClient(0); |
| 2186 } | 2189 } |
| 2187 | 2190 |
| 2188 TEST_F(WebViewTest, FirstUserGestureObservedGestureTap) | 2191 TEST_F(WebViewTest, FirstUserGestureObservedGestureTap) |
| 2189 { | 2192 { |
| 2190 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("longpress_selection.html")); | 2193 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("longpress_selection.html")); |
| 2191 MockAutofillClient client; | 2194 MockAutofillClient client; |
| 2192 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "longpress_
selection.html", true); | 2195 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "longpress_
selection.html", true); |
| 2193 webView->setAutofillClient(&client); | 2196 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); |
| 2197 frame->setAutofillClient(&client); |
| 2194 webView->setInitialFocus(false); | 2198 webView->setInitialFocus(false); |
| 2195 | 2199 |
| 2196 EXPECT_EQ(0, client.getUserGestureNotificationsCount()); | 2200 EXPECT_EQ(0, client.getUserGestureNotificationsCount()); |
| 2197 | 2201 |
| 2198 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr
omUTF8("target"))); | 2202 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr
omUTF8("target"))); |
| 2199 | 2203 |
| 2200 EXPECT_EQ(1, client.getUserGestureNotificationsCount()); | 2204 EXPECT_EQ(1, client.getUserGestureNotificationsCount()); |
| 2201 webView->setAutofillClient(0); | 2205 frame->setAutofillClient(0); |
| 2202 } | 2206 } |
| 2203 | 2207 |
| 2204 TEST_F(WebViewTest, CompareSelectAllToContentAsText) | 2208 TEST_F(WebViewTest, CompareSelectAllToContentAsText) |
| 2205 { | 2209 { |
| 2206 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("longpress_selection.html")); | 2210 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("longpress_selection.html")); |
| 2207 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "longpress_
selection.html", true); | 2211 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "longpress_
selection.html", true); |
| 2208 | 2212 |
| 2209 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); | 2213 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); |
| 2210 frame->executeScript(WebScriptSource(WebString::fromUTF8("document.execComma
nd('SelectAll', false, null)"))); | 2214 frame->executeScript(WebScriptSource(WebString::fromUTF8("document.execComma
nd('SelectAll', false, null)"))); |
| 2211 std::string actual = frame->selectionAsText().utf8(); | 2215 std::string actual = frame->selectionAsText().utf8(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2225 loadFrame(webView->mainFrame(), url); | 2229 loadFrame(webView->mainFrame(), url); |
| 2226 | 2230 |
| 2227 FrameView* frameView = m_webViewHelper.webViewImpl()->mainFrameImpl()->frame
View(); | 2231 FrameView* frameView = m_webViewHelper.webViewImpl()->mainFrameImpl()->frame
View(); |
| 2228 | 2232 |
| 2229 // Auto-resizing used to ASSERT(needsLayout()) in RenderBlockFlow::layout. T
his EXPECT is | 2233 // Auto-resizing used to ASSERT(needsLayout()) in RenderBlockFlow::layout. T
his EXPECT is |
| 2230 // merely a dummy. The real test is that we don't trigger asserts in debug b
uilds. | 2234 // merely a dummy. The real test is that we don't trigger asserts in debug b
uilds. |
| 2231 EXPECT_FALSE(frameView->needsLayout()); | 2235 EXPECT_FALSE(frameView->needsLayout()); |
| 2232 }; | 2236 }; |
| 2233 | 2237 |
| 2234 } // namespace | 2238 } // namespace |
| OLD | NEW |