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

Side by Side Diff: Source/web/tests/WebViewTest.cpp

Issue 956133002: [IME] Differentiate s_suppressNextKeypressEvent in WebViewImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add unit tests; breaking fix on purpose for testing. Created 5 years, 10 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 unified diff | Download patch
OLDNEW
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 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 event.x = 25; 1275 event.x = 25;
1276 event.y = 7; 1276 event.y = 7;
1277 webView->handleInputEvent(event); 1277 webView->handleInputEvent(event);
1278 runPendingTasks(); 1278 runPendingTasks();
1279 EXPECT_EQ(25, client.longpressX()); 1279 EXPECT_EQ(25, client.longpressX());
1280 EXPECT_EQ(7, client.longpressY()); 1280 EXPECT_EQ(7, client.longpressY());
1281 1281
1282 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally scoped client. 1282 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally scoped client.
1283 } 1283 }
1284 1284
1285 static void simulateKeyPress(WebView* webView, int windowsKeyCode)
1286 {
1287 WebKeyboardEvent keyEvent;
1288 if (windowsKeyCode != VK_UNKNOWN) {
1289 keyEvent.windowsKeyCode = windowsKeyCode;
1290 keyEvent.setKeyIdentifierFromWindowsKeyCode();
1291 }
1292 keyEvent.type = WebInputEvent::RawKeyDown;
1293 webView->handleInputEvent(keyEvent);
1294
1295 keyEvent.type = WebInputEvent::KeyUp;
1296 webView->handleInputEvent(keyEvent);
1297 }
1298
1285 #if OS(ANDROID) 1299 #if OS(ANDROID)
1286 TEST_F(WebViewTest, LongPressSelection) 1300 TEST_F(WebViewTest, LongPressSelection)
1287 { 1301 {
1288 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("longpress_selection.html")); 1302 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("longpress_selection.html"));
1289 1303
1290 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "longpress_ selection.html", true); 1304 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "longpress_ selection.html", true);
1291 webView->resize(WebSize(500, 300)); 1305 webView->resize(WebSize(500, 300));
1292 webView->layout(); 1306 webView->layout();
1293 runPendingTasks(); 1307 runPendingTasks();
1294 1308
(...skipping 15 matching lines...) Expand all
1310 webView->resize(WebSize(640, 480)); 1324 webView->resize(WebSize(640, 480));
1311 webView->layout(); 1325 webView->layout();
1312 runPendingTasks(); 1326 runPendingTasks();
1313 1327
1314 WebString target = WebString::fromUTF8("target"); 1328 WebString target = WebString::fromUTF8("target");
1315 WebLocalFrameImpl* mainFrame = toWebLocalFrameImpl(webView->mainFrame()); 1329 WebLocalFrameImpl* mainFrame = toWebLocalFrameImpl(webView->mainFrame());
1316 1330
1317 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, target) ); 1331 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, target) );
1318 EXPECT_TRUE(mainFrame->frame()->selection().isCaretBlinkingSuspended()); 1332 EXPECT_TRUE(mainFrame->frame()->selection().isCaretBlinkingSuspended());
1319 1333
1320 WebKeyboardEvent keyEvent; 1334 simulateKeyPress(webView, VK_UNKNOWN);
1321 keyEvent.type = WebInputEvent::RawKeyDown;
1322 webView->handleInputEvent(keyEvent);
1323 keyEvent.type = WebInputEvent::KeyUp;
1324 webView->handleInputEvent(keyEvent);
1325 EXPECT_FALSE(mainFrame->frame()->selection().isCaretBlinkingSuspended()); 1335 EXPECT_FALSE(mainFrame->frame()->selection().isCaretBlinkingSuspended());
1326 } 1336 }
1327 #endif 1337 #endif
1328 1338
1329 TEST_F(WebViewTest, SelectionOnReadOnlyInput) 1339 TEST_F(WebViewTest, SelectionOnReadOnlyInput)
1330 { 1340 {
1331 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("selection_readonly.html")); 1341 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("selection_readonly.html"));
1332 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "selection_ readonly.html", true); 1342 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "selection_ readonly.html", true);
1333 webView->resize(WebSize(640, 480)); 1343 webView->resize(WebSize(640, 480));
1334 webView->layout(); 1344 webView->layout();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 int getUserGestureNotificationsCount() { return m_userGestureNotificationsCo unt; } 1415 int getUserGestureNotificationsCount() { return m_userGestureNotificationsCo unt; }
1406 1416
1407 private: 1417 private:
1408 bool m_ignoreTextChanges; 1418 bool m_ignoreTextChanges;
1409 int m_textChangesWhileIgnored; 1419 int m_textChangesWhileIgnored;
1410 int m_textChangesWhileNotIgnored; 1420 int m_textChangesWhileNotIgnored;
1411 int m_userGestureNotificationsCount; 1421 int m_userGestureNotificationsCount;
1412 }; 1422 };
1413 1423
1414 1424
1425 static void verifySelectionAndComposition(WebView* webView, const char* value, i nt selectionStart, int selectionEnd, int compositionStart, int compositionEnd, c onst char* failMessage)
1426 {
1427 WebTextInputInfo info = webView->textInputInfo();
1428 if (value) {
1429 EXPECT_EQ(std::string(value), std::string(info.value.utf8().data())) << failMessage;
1430 }
1431 EXPECT_EQ(selectionStart, info.selectionStart) << failMessage;
1432 EXPECT_EQ(selectionEnd, info.selectionEnd) << failMessage;
1433 EXPECT_EQ(compositionStart, info.compositionStart) << failMessage;
1434 EXPECT_EQ(compositionEnd, info.compositionEnd) << failMessage;
1435 }
1436
1415 TEST_F(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange) 1437 TEST_F(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange)
1416 { 1438 {
1417 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html")); 1439 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
1418 MockAutofillClient client; 1440 MockAutofillClient client;
1419 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html"); 1441 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html");
1420 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); 1442 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
1421 frame->setAutofillClient(&client); 1443 frame->setAutofillClient(&client);
1422 webView->setInitialFocus(false); 1444 webView->setInitialFocus(false);
1423 1445
1424 // Set up a composition that needs to be committed. 1446 // Set up a composition that needs to be committed.
1425 WebVector<WebCompositionUnderline> emptyUnderlines; 1447 WebVector<WebCompositionUnderline> emptyUnderlines;
1426 frame->setEditableSelectionOffsets(4, 10); 1448 frame->setEditableSelectionOffsets(4, 10);
1427 frame->setCompositionFromExistingText(8, 12, emptyUnderlines); 1449 frame->setCompositionFromExistingText(8, 12, emptyUnderlines);
1428 WebTextInputInfo info = webView->textInputInfo(); 1450 verifySelectionAndComposition(webView, nullptr, 4, 10, 8, 12, "base case");
1429 EXPECT_EQ(4, info.selectionStart);
1430 EXPECT_EQ(10, info.selectionEnd);
1431 EXPECT_EQ(8, info.compositionStart);
1432 EXPECT_EQ(12, info.compositionEnd);
1433 1451
1434 // Clear the focus and track that the subsequent composition commit does not trigger a 1452 // Clear the focus and track that the subsequent composition commit does not trigger a
1435 // text changed notification for autofill. 1453 // text changed notification for autofill.
1436 client.clearChangeCounts(); 1454 client.clearChangeCounts();
1437 webView->setFocus(false); 1455 webView->setFocus(false);
1438 EXPECT_EQ(1, client.textChangesWhileIgnored()); 1456 EXPECT_EQ(1, client.textChangesWhileIgnored());
1439 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); 1457 EXPECT_EQ(0, client.textChangesWhileNotIgnored());
1440 1458
1441 frame->setAutofillClient(0); 1459 frame->setAutofillClient(0);
1442 } 1460 }
1443 1461
1462 TEST_F(WebViewTest, CompositionChangeWithKeyEvents)
1463 {
1464 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("composition_with_key_events.html"));
1465 MockAutofillClient client;
1466 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "compositio n_with_key_events.html");
1467 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
1468 frame->setAutofillClient(&client);
1469 webView->setInitialFocus(false);
1470
1471 // Test both input elements.
1472 for (int i = 0; i < 2; ++i) {
1473 // Select composition and do sanity check.
1474 WebVector<WebCompositionUnderline> emptyUnderlines;
1475 frame->setEditableSelectionOffsets(2, 15);
1476 frame->setCompositionFromExistingText(6, 11, emptyUnderlines);
1477 verifySelectionAndComposition(webView, nullptr, 2, 15, 6, 11, "initial c ase");
1478
1479 // Press 'A' and verify that the composition grew.
1480 simulateKeyPress(webView, VKEY_A);
1481 verifySelectionAndComposition(webView, nullptr, 2, 16, 6, 12, "after pre ssing 'A'");
1482
1483 // Press Backspace and verify that the composition shrunk (and is not ca ncelled).
1484 simulateKeyPress(webView, VKEY_BACK);
1485 verifySelectionAndComposition(webView, nullptr, 2, 15, 6, 11, "after pre ssing Backspace");
1486
1487 webView->advanceFocus(false);
1488 }
1489 }
1490
1444 TEST_F(WebViewTest, ConfirmCompositionTriggersAutofillTextChange) 1491 TEST_F(WebViewTest, ConfirmCompositionTriggersAutofillTextChange)
1445 { 1492 {
1446 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html")); 1493 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
1447 MockAutofillClient client; 1494 MockAutofillClient client;
1448 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html"); 1495 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html");
1449 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); 1496 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
1450 frame->setAutofillClient(&client); 1497 frame->setAutofillClient(&client);
1451 webView->setInitialFocus(false); 1498 webView->setInitialFocus(false);
1452 1499
1453 // Set up a composition that needs to be committed. 1500 // Set up a composition that needs to be committed.
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 webView->setFocus(true); 1642 webView->setFocus(true);
1596 1643
1597 WebElement element = webView->mainFrame()->document().getElementById("messag e"); 1644 WebElement element = webView->mainFrame()->document().getElementById("messag e");
1598 EXPECT_STREQ("DOMFocusOutDOMFocusIn", element.innerText().utf8().data()); 1645 EXPECT_STREQ("DOMFocusOutDOMFocusIn", element.innerText().utf8().data());
1599 } 1646 }
1600 1647
1601 #if !ENABLE(INPUT_MULTIPLE_FIELDS_UI) 1648 #if !ENABLE(INPUT_MULTIPLE_FIELDS_UI)
1602 static void openDateTimeChooser(WebView* webView, HTMLInputElement* inputElement ) 1649 static void openDateTimeChooser(WebView* webView, HTMLInputElement* inputElement )
1603 { 1650 {
1604 inputElement->focus(); 1651 inputElement->focus();
1605 1652 simulateKeyPress(webView, VKEY_SPACE);
1606 WebKeyboardEvent keyEvent;
1607 keyEvent.windowsKeyCode = VKEY_SPACE;
1608 keyEvent.type = WebInputEvent::RawKeyDown;
1609 keyEvent.setKeyIdentifierFromWindowsKeyCode();
1610 webView->handleInputEvent(keyEvent);
1611
1612 keyEvent.type = WebInputEvent::KeyUp;
1613 webView->handleInputEvent(keyEvent);
1614 } 1653 }
1615 1654
1616 TEST_F(WebViewTest, ChooseValueFromDateTimeChooser) 1655 TEST_F(WebViewTest, ChooseValueFromDateTimeChooser)
1617 { 1656 {
1618 DateTimeChooserWebViewClient client; 1657 DateTimeChooserWebViewClient client;
1619 std::string url = m_baseURL + "date_time_chooser.html"; 1658 std::string url = m_baseURL + "date_time_chooser.html";
1620 URLTestHelpers::registerMockedURLLoad(toKURL(url), "date_time_chooser.html") ; 1659 URLTestHelpers::registerMockedURLLoad(toKURL(url), "date_time_chooser.html") ;
1621 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, & client); 1660 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, & client);
1622 1661
1623 Document* document = webViewImpl->mainFrameImpl()->frame()->document(); 1662 Document* document = webViewImpl->mainFrameImpl()->frame()->document();
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
2193 { 2232 {
2194 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("form.html")); 2233 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("form.html"));
2195 MockAutofillClient client; 2234 MockAutofillClient client;
2196 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "form.html" , true); 2235 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "form.html" , true);
2197 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); 2236 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
2198 frame->setAutofillClient(&client); 2237 frame->setAutofillClient(&client);
2199 webView->setInitialFocus(false); 2238 webView->setInitialFocus(false);
2200 2239
2201 EXPECT_EQ(0, client.getUserGestureNotificationsCount()); 2240 EXPECT_EQ(0, client.getUserGestureNotificationsCount());
2202 2241
2203 WebKeyboardEvent keyEvent; 2242 simulateKeyPress(webView, VKEY_SPACE);
2204 keyEvent.windowsKeyCode = VKEY_SPACE;
2205 keyEvent.type = WebInputEvent::RawKeyDown;
2206 keyEvent.setKeyIdentifierFromWindowsKeyCode();
2207 webView->handleInputEvent(keyEvent);
2208 keyEvent.type = WebInputEvent::KeyUp;
2209 webView->handleInputEvent(keyEvent);
2210 2243
2211 EXPECT_EQ(1, client.getUserGestureNotificationsCount()); 2244 EXPECT_EQ(1, client.getUserGestureNotificationsCount());
2212 frame->setAutofillClient(0); 2245 frame->setAutofillClient(0);
2213 } 2246 }
2214 2247
2215 TEST_F(WebViewTest, FirstUserGestureObservedMouseEvent) 2248 TEST_F(WebViewTest, FirstUserGestureObservedMouseEvent)
2216 { 2249 {
2217 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("form.html")); 2250 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("form.html"));
2218 MockAutofillClient client; 2251 MockAutofillClient client;
2219 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "form.html" , true); 2252 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "form.html" , true);
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
2438 // Test without any preventDefault. 2471 // Test without any preventDefault.
2439 client.reset(); 2472 client.reset();
2440 frame->executeScript(WebScriptSource("setTest('none');")); 2473 frame->executeScript(WebScriptSource("setTest('none');"));
2441 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr omUTF8("target"))); 2474 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr omUTF8("target")));
2442 EXPECT_TRUE(client.getWasCalled()); 2475 EXPECT_TRUE(client.getWasCalled());
2443 2476
2444 m_webViewHelper.reset(); // Remove dependency on locally scoped client. 2477 m_webViewHelper.reset(); // Remove dependency on locally scoped client.
2445 } 2478 }
2446 2479
2447 } // namespace 2480 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698