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

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

Issue 970743002: [IME] Fix s_suppressNextKeypressEvent logic in WebViewImpl::setComposition(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Cleaning up logic. Created 5 years, 9 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 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 // Clear the focus and track that the subsequent composition commit does not trigger a 1425 // Clear the focus and track that the subsequent composition commit does not trigger a
1426 // text changed notification for autofill. 1426 // text changed notification for autofill.
1427 client.clearChangeCounts(); 1427 client.clearChangeCounts();
1428 webView->setFocus(false); 1428 webView->setFocus(false);
1429 EXPECT_EQ(1, client.textChangesWhileIgnored()); 1429 EXPECT_EQ(1, client.textChangesWhileIgnored());
1430 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); 1430 EXPECT_EQ(0, client.textChangesWhileNotIgnored());
1431 1431
1432 frame->setAutofillClient(0); 1432 frame->setAutofillClient(0);
1433 } 1433 }
1434 1434
1435 static void verifySelectionAndComposition(WebView* webView, int selectionStart, int selectionEnd, int compositionStart, int compositionEnd, const char* failMess age)
1436 {
1437 WebTextInputInfo info = webView->textInputInfo();
1438 EXPECT_EQ(selectionStart, info.selectionStart) << failMessage;
1439 EXPECT_EQ(selectionEnd, info.selectionEnd) << failMessage;
1440 EXPECT_EQ(compositionStart, info.compositionStart) << failMessage;
1441 EXPECT_EQ(compositionEnd, info.compositionEnd) << failMessage;
1442 }
1443
1444 TEST_F(WebViewTest, CompositionNotCancelledByBackspace)
1445 {
1446 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("composition_not_cancelled_by_backspace.html"));
1447 MockAutofillClient client;
1448 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "compositio n_not_cancelled_by_backspace.html");
1449 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
1450 frame->setAutofillClient(&client);
1451 webView->setInitialFocus(false);
1452
1453 // Test both input elements.
1454 for (int i = 0; i < 2; ++i) {
1455 // Select composition and do sanity check.
1456 WebVector<WebCompositionUnderline> emptyUnderlines;
1457 frame->setEditableSelectionOffsets(6, 6);
1458 EXPECT_TRUE(webView->setComposition("fghij", emptyUnderlines, 0, 5));
1459 frame->setEditableSelectionOffsets(11, 11);
1460 verifySelectionAndComposition(webView, 11, 11, 6, 11, "initial case");
1461
1462 // Press Backspace and verify composition didn't get cancelled. This is to verify the fix
1463 // for crbug.com/429916.
1464 WebKeyboardEvent keyEvent;
1465 keyEvent.windowsKeyCode = VKEY_BACK;
1466 keyEvent.setKeyIdentifierFromWindowsKeyCode();
1467 keyEvent.type = WebInputEvent::RawKeyDown;
1468 webView->handleInputEvent(keyEvent);
1469
1470 frame->setEditableSelectionOffsets(6, 6);
1471 EXPECT_TRUE(webView->setComposition("fghi", emptyUnderlines, 0, 4));
1472 frame->setEditableSelectionOffsets(10, 10);
1473 verifySelectionAndComposition(webView, 10, 10, 6, 10, "after pressing Ba ckspace");
1474
1475 keyEvent.type = WebInputEvent::KeyUp;
1476 webView->handleInputEvent(keyEvent);
1477
1478 webView->advanceFocus(false);
1479 }
1480
1481 frame->setAutofillClient(0);
1482 }
1483
1435 TEST_F(WebViewTest, ConfirmCompositionTriggersAutofillTextChange) 1484 TEST_F(WebViewTest, ConfirmCompositionTriggersAutofillTextChange)
1436 { 1485 {
1437 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html")); 1486 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
1438 MockAutofillClient client; 1487 MockAutofillClient client;
1439 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html"); 1488 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html");
1440 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); 1489 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
1441 frame->setAutofillClient(&client); 1490 frame->setAutofillClient(&client);
1442 webView->setInitialFocus(false); 1491 webView->setInitialFocus(false);
1443 1492
1444 // Set up a composition that needs to be committed. 1493 // Set up a composition that needs to be committed.
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after
2389 // Test without any preventDefault. 2438 // Test without any preventDefault.
2390 client.reset(); 2439 client.reset();
2391 frame->executeScript(WebScriptSource("setTest('none');")); 2440 frame->executeScript(WebScriptSource("setTest('none');"));
2392 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr omUTF8("target"))); 2441 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr omUTF8("target")));
2393 EXPECT_TRUE(client.getWasCalled()); 2442 EXPECT_TRUE(client.getWasCalled());
2394 2443
2395 m_webViewHelper.reset(); // Remove dependency on locally scoped client. 2444 m_webViewHelper.reset(); // Remove dependency on locally scoped client.
2396 } 2445 }
2397 2446
2398 } // namespace 2447 } // namespace
OLDNEW
« no previous file with comments | « Source/web/WebViewImpl.cpp ('k') | Source/web/tests/data/composition_not_cancelled_by_backspace.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698