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 1423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 // Clear the focus and track that the subsequent composition commit does not
trigger a | 1434 // Clear the focus and track that the subsequent composition commit does not
trigger a |
1435 // text changed notification for autofill. | 1435 // text changed notification for autofill. |
1436 client.clearChangeCounts(); | 1436 client.clearChangeCounts(); |
1437 webView->setFocus(false); | 1437 webView->setFocus(false); |
1438 EXPECT_EQ(1, client.textChangesWhileIgnored()); | 1438 EXPECT_EQ(1, client.textChangesWhileIgnored()); |
1439 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); | 1439 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); |
1440 | 1440 |
1441 frame->setAutofillClient(0); | 1441 frame->setAutofillClient(0); |
1442 } | 1442 } |
1443 | 1443 |
| 1444 static void verifySelectionAndComposition(WebView* webView, int selectionStart,
int selectionEnd, int compositionStart, int compositionEnd, const char* failMess
age) |
| 1445 { |
| 1446 WebTextInputInfo info = webView->textInputInfo(); |
| 1447 EXPECT_EQ(selectionStart, info.selectionStart) << failMessage; |
| 1448 EXPECT_EQ(selectionEnd, info.selectionEnd) << failMessage; |
| 1449 EXPECT_EQ(compositionStart, info.compositionStart) << failMessage; |
| 1450 EXPECT_EQ(compositionEnd, info.compositionEnd) << failMessage; |
| 1451 } |
| 1452 |
| 1453 TEST_F(WebViewTest, CompositionNotCancelledByBackspace) |
| 1454 { |
| 1455 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("composition_not_cancelled_by_backspace.html")); |
| 1456 MockAutofillClient client; |
| 1457 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "compositio
n_not_cancelled_by_backspace.html"); |
| 1458 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); |
| 1459 frame->setAutofillClient(&client); |
| 1460 webView->setInitialFocus(false); |
| 1461 |
| 1462 // Test both input elements. |
| 1463 for (int i = 0; i < 2; ++i) { |
| 1464 // Select composition and do sanity check. |
| 1465 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 1466 frame->setEditableSelectionOffsets(6, 6); |
| 1467 webView->setComposition("fghij", emptyUnderlines, 0, 5); |
| 1468 frame->setEditableSelectionOffsets(11, 11); |
| 1469 verifySelectionAndComposition(webView, 11, 11, 6, 11, "initial case"); |
| 1470 |
| 1471 // Press Backspace and verify composition didn't get cancelled. This is
to verify the fix |
| 1472 // for crbug.com/429916. |
| 1473 WebKeyboardEvent keyEvent; |
| 1474 keyEvent.windowsKeyCode = VKEY_BACK; |
| 1475 keyEvent.setKeyIdentifierFromWindowsKeyCode(); |
| 1476 keyEvent.type = WebInputEvent::RawKeyDown; |
| 1477 webView->handleInputEvent(keyEvent); |
| 1478 |
| 1479 frame->setEditableSelectionOffsets(6, 6); |
| 1480 webView->setComposition("fghi", emptyUnderlines, 0, 4); |
| 1481 frame->setEditableSelectionOffsets(10, 10); |
| 1482 verifySelectionAndComposition(webView, 10, 10, 6, 10, "after pressing Ba
ckspace"); |
| 1483 |
| 1484 keyEvent.type = WebInputEvent::KeyUp; |
| 1485 webView->handleInputEvent(keyEvent); |
| 1486 |
| 1487 webView->advanceFocus(false); |
| 1488 } |
| 1489 |
| 1490 frame->setAutofillClient(0); |
| 1491 } |
| 1492 |
1444 TEST_F(WebViewTest, ConfirmCompositionTriggersAutofillTextChange) | 1493 TEST_F(WebViewTest, ConfirmCompositionTriggersAutofillTextChange) |
1445 { | 1494 { |
1446 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 1495 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
1447 MockAutofillClient client; | 1496 MockAutofillClient client; |
1448 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); | 1497 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); |
1449 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); | 1498 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); |
1450 frame->setAutofillClient(&client); | 1499 frame->setAutofillClient(&client); |
1451 webView->setInitialFocus(false); | 1500 webView->setInitialFocus(false); |
1452 | 1501 |
1453 // Set up a composition that needs to be committed. | 1502 // Set up a composition that needs to be committed. |
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2438 // Test without any preventDefault. | 2487 // Test without any preventDefault. |
2439 client.reset(); | 2488 client.reset(); |
2440 frame->executeScript(WebScriptSource("setTest('none');")); | 2489 frame->executeScript(WebScriptSource("setTest('none');")); |
2441 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr
omUTF8("target"))); | 2490 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr
omUTF8("target"))); |
2442 EXPECT_TRUE(client.getWasCalled()); | 2491 EXPECT_TRUE(client.getWasCalled()); |
2443 | 2492 |
2444 m_webViewHelper.reset(); // Remove dependency on locally scoped client. | 2493 m_webViewHelper.reset(); // Remove dependency on locally scoped client. |
2445 } | 2494 } |
2446 | 2495 |
2447 } // namespace | 2496 } // namespace |
OLD | NEW |