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

Side by Side Diff: content/renderer/render_view_browsertest.cc

Issue 2508363003: [refactor] - Move textInputInfo() and textInputType() from WebWidget to WebInputMethodController (Closed)
Patch Set: 'controller' may be nullptr. Created 4 years, 1 month 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <tuple> 7 #include <tuple>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 #include "testing/gtest/include/gtest/gtest.h" 66 #include "testing/gtest/include/gtest/gtest.h"
67 #include "third_party/WebKit/public/platform/WebData.h" 67 #include "third_party/WebKit/public/platform/WebData.h"
68 #include "third_party/WebKit/public/platform/WebHTTPBody.h" 68 #include "third_party/WebKit/public/platform/WebHTTPBody.h"
69 #include "third_party/WebKit/public/platform/WebString.h" 69 #include "third_party/WebKit/public/platform/WebString.h"
70 #include "third_party/WebKit/public/platform/WebURLResponse.h" 70 #include "third_party/WebKit/public/platform/WebURLResponse.h"
71 #include "third_party/WebKit/public/web/WebDataSource.h" 71 #include "third_party/WebKit/public/web/WebDataSource.h"
72 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" 72 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
73 #include "third_party/WebKit/public/web/WebFrameContentDumper.h" 73 #include "third_party/WebKit/public/web/WebFrameContentDumper.h"
74 #include "third_party/WebKit/public/web/WebHistoryCommitType.h" 74 #include "third_party/WebKit/public/web/WebHistoryCommitType.h"
75 #include "third_party/WebKit/public/web/WebHistoryItem.h" 75 #include "third_party/WebKit/public/web/WebHistoryItem.h"
76 #include "third_party/WebKit/public/web/WebInputMethodController.h"
76 #include "third_party/WebKit/public/web/WebLocalFrame.h" 77 #include "third_party/WebKit/public/web/WebLocalFrame.h"
77 #include "third_party/WebKit/public/web/WebPerformance.h" 78 #include "third_party/WebKit/public/web/WebPerformance.h"
78 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 79 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
79 #include "third_party/WebKit/public/web/WebScriptSource.h" 80 #include "third_party/WebKit/public/web/WebScriptSource.h"
80 #include "third_party/WebKit/public/web/WebSettings.h" 81 #include "third_party/WebKit/public/web/WebSettings.h"
81 #include "third_party/WebKit/public/web/WebView.h" 82 #include "third_party/WebKit/public/web/WebView.h"
82 #include "third_party/WebKit/public/web/WebWindowFeatures.h" 83 #include "third_party/WebKit/public/web/WebWindowFeatures.h"
83 #include "ui/events/event.h" 84 #include "ui/events/event.h"
84 #include "ui/events/keycodes/keyboard_codes.h" 85 #include "ui/events/keycodes/keyboard_codes.h"
85 #include "ui/gfx/codec/jpeg_codec.h" 86 #include "ui/gfx/codec/jpeg_codec.h"
(...skipping 1488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1574 "<head>" 1575 "<head>"
1575 "</head>" 1576 "</head>"
1576 "<body>" 1577 "<body>"
1577 "<input id=\"test1\" value=\"some test text hello\"></input>" 1578 "<input id=\"test1\" value=\"some test text hello\"></input>"
1578 "</body>" 1579 "</body>"
1579 "</html>"); 1580 "</html>");
1580 ExecuteJavaScriptForTests("document.getElementById('test1').focus();"); 1581 ExecuteJavaScriptForTests("document.getElementById('test1').focus();");
1581 frame()->SetEditableSelectionOffsets(4, 8); 1582 frame()->SetEditableSelectionOffsets(4, 8);
1582 const std::vector<blink::WebCompositionUnderline> empty_underline; 1583 const std::vector<blink::WebCompositionUnderline> empty_underline;
1583 frame()->SetCompositionFromExistingText(7, 10, empty_underline); 1584 frame()->SetCompositionFromExistingText(7, 10, empty_underline);
1584 blink::WebTextInputInfo info = view()->webview()->textInputInfo(); 1585 blink::WebInputMethodController* controller =
1586 frame()->GetWebFrame()->inputMethodController();
1587 blink::WebTextInputInfo info = controller->textInputInfo();
1585 EXPECT_EQ(4, info.selectionStart); 1588 EXPECT_EQ(4, info.selectionStart);
1586 EXPECT_EQ(8, info.selectionEnd); 1589 EXPECT_EQ(8, info.selectionEnd);
1587 EXPECT_EQ(7, info.compositionStart); 1590 EXPECT_EQ(7, info.compositionStart);
1588 EXPECT_EQ(10, info.compositionEnd); 1591 EXPECT_EQ(10, info.compositionEnd);
1589 frame()->Unselect(); 1592 frame()->Unselect();
1590 info = view()->webview()->textInputInfo(); 1593 info = controller->textInputInfo();
1591 EXPECT_EQ(0, info.selectionStart); 1594 EXPECT_EQ(0, info.selectionStart);
1592 EXPECT_EQ(0, info.selectionEnd); 1595 EXPECT_EQ(0, info.selectionEnd);
1593 } 1596 }
1594 1597
1595 TEST_F(RenderViewImplTest, OnExtendSelectionAndDelete) { 1598 TEST_F(RenderViewImplTest, OnExtendSelectionAndDelete) {
1596 // Load an HTML page consisting of an input field. 1599 // Load an HTML page consisting of an input field.
1597 LoadHTML("<html>" 1600 LoadHTML("<html>"
1598 "<head>" 1601 "<head>"
1599 "</head>" 1602 "</head>"
1600 "<body>" 1603 "<body>"
1601 "<input id=\"test1\" value=\"abcdefghijklmnopqrstuvwxyz\"></input>" 1604 "<input id=\"test1\" value=\"abcdefghijklmnopqrstuvwxyz\"></input>"
1602 "</body>" 1605 "</body>"
1603 "</html>"); 1606 "</html>");
1604 ExecuteJavaScriptForTests("document.getElementById('test1').focus();"); 1607 ExecuteJavaScriptForTests("document.getElementById('test1').focus();");
1605 frame()->SetEditableSelectionOffsets(10, 10); 1608 frame()->SetEditableSelectionOffsets(10, 10);
1606 frame()->ExtendSelectionAndDelete(3, 4); 1609 frame()->ExtendSelectionAndDelete(3, 4);
1607 blink::WebTextInputInfo info = view()->webview()->textInputInfo(); 1610 blink::WebInputMethodController* controller =
1611 frame()->GetWebFrame()->inputMethodController();
1612 blink::WebTextInputInfo info = controller->textInputInfo();
1608 EXPECT_EQ("abcdefgopqrstuvwxyz", info.value); 1613 EXPECT_EQ("abcdefgopqrstuvwxyz", info.value);
1609 EXPECT_EQ(7, info.selectionStart); 1614 EXPECT_EQ(7, info.selectionStart);
1610 EXPECT_EQ(7, info.selectionEnd); 1615 EXPECT_EQ(7, info.selectionEnd);
1611 frame()->SetEditableSelectionOffsets(4, 8); 1616 frame()->SetEditableSelectionOffsets(4, 8);
1612 frame()->ExtendSelectionAndDelete(2, 5); 1617 frame()->ExtendSelectionAndDelete(2, 5);
1613 info = view()->webview()->textInputInfo(); 1618 info = controller->textInputInfo();
1614 EXPECT_EQ("abuvwxyz", info.value); 1619 EXPECT_EQ("abuvwxyz", info.value);
1615 EXPECT_EQ(2, info.selectionStart); 1620 EXPECT_EQ(2, info.selectionStart);
1616 EXPECT_EQ(2, info.selectionEnd); 1621 EXPECT_EQ(2, info.selectionEnd);
1617 } 1622 }
1618 1623
1619 TEST_F(RenderViewImplTest, OnDeleteSurroundingText) { 1624 TEST_F(RenderViewImplTest, OnDeleteSurroundingText) {
1620 // Load an HTML page consisting of an input field. 1625 // Load an HTML page consisting of an input field.
1621 LoadHTML( 1626 LoadHTML(
1622 "<html>" 1627 "<html>"
1623 "<head>" 1628 "<head>"
1624 "</head>" 1629 "</head>"
1625 "<body>" 1630 "<body>"
1626 "<input id=\"test1\" value=\"abcdefghijklmnopqrstuvwxyz\"></input>" 1631 "<input id=\"test1\" value=\"abcdefghijklmnopqrstuvwxyz\"></input>"
1627 "</body>" 1632 "</body>"
1628 "</html>"); 1633 "</html>");
1629 ExecuteJavaScriptForTests("document.getElementById('test1').focus();"); 1634 ExecuteJavaScriptForTests("document.getElementById('test1').focus();");
1630 1635
1631 frame()->SetEditableSelectionOffsets(10, 10); 1636 frame()->SetEditableSelectionOffsets(10, 10);
1632 frame()->DeleteSurroundingText(3, 4); 1637 frame()->DeleteSurroundingText(3, 4);
1633 blink::WebTextInputInfo info = view()->webview()->textInputInfo(); 1638 blink::WebInputMethodController* controller =
1639 frame()->GetWebFrame()->inputMethodController();
1640 blink::WebTextInputInfo info = controller->textInputInfo();
1634 EXPECT_EQ("abcdefgopqrstuvwxyz", info.value); 1641 EXPECT_EQ("abcdefgopqrstuvwxyz", info.value);
1635 EXPECT_EQ(7, info.selectionStart); 1642 EXPECT_EQ(7, info.selectionStart);
1636 EXPECT_EQ(7, info.selectionEnd); 1643 EXPECT_EQ(7, info.selectionEnd);
1637 1644
1638 frame()->SetEditableSelectionOffsets(4, 8); 1645 frame()->SetEditableSelectionOffsets(4, 8);
1639 frame()->DeleteSurroundingText(2, 5); 1646 frame()->DeleteSurroundingText(2, 5);
1640 info = view()->webview()->textInputInfo(); 1647 info = controller->textInputInfo();
1641 EXPECT_EQ("abefgouvwxyz", info.value); 1648 EXPECT_EQ("abefgouvwxyz", info.value);
1642 EXPECT_EQ(2, info.selectionStart); 1649 EXPECT_EQ(2, info.selectionStart);
1643 EXPECT_EQ(6, info.selectionEnd); 1650 EXPECT_EQ(6, info.selectionEnd);
1644 1651
1645 frame()->SetEditableSelectionOffsets(5, 5); 1652 frame()->SetEditableSelectionOffsets(5, 5);
1646 frame()->DeleteSurroundingText(10, 0); 1653 frame()->DeleteSurroundingText(10, 0);
1647 info = view()->webview()->textInputInfo(); 1654 info = controller->textInputInfo();
1648 EXPECT_EQ("ouvwxyz", info.value); 1655 EXPECT_EQ("ouvwxyz", info.value);
1649 EXPECT_EQ(0, info.selectionStart); 1656 EXPECT_EQ(0, info.selectionStart);
1650 EXPECT_EQ(0, info.selectionEnd); 1657 EXPECT_EQ(0, info.selectionEnd);
1651 1658
1652 frame()->DeleteSurroundingText(0, 10); 1659 frame()->DeleteSurroundingText(0, 10);
1653 info = view()->webview()->textInputInfo(); 1660 info = controller->textInputInfo();
1654 EXPECT_EQ("", info.value); 1661 EXPECT_EQ("", info.value);
1655 EXPECT_EQ(0, info.selectionStart); 1662 EXPECT_EQ(0, info.selectionStart);
1656 EXPECT_EQ(0, info.selectionEnd); 1663 EXPECT_EQ(0, info.selectionEnd);
1657 1664
1658 frame()->DeleteSurroundingText(10, 10); 1665 frame()->DeleteSurroundingText(10, 10);
1659 info = view()->webview()->textInputInfo(); 1666 info = controller->textInputInfo();
1660 EXPECT_EQ("", info.value); 1667 EXPECT_EQ("", info.value);
1661 1668
1662 EXPECT_EQ(0, info.selectionStart); 1669 EXPECT_EQ(0, info.selectionStart);
1663 EXPECT_EQ(0, info.selectionEnd); 1670 EXPECT_EQ(0, info.selectionEnd);
1664 } 1671 }
1665 1672
1666 // Test that the navigating specific frames works correctly. 1673 // Test that the navigating specific frames works correctly.
1667 TEST_F(RenderViewImplTest, NavigateSubframe) { 1674 TEST_F(RenderViewImplTest, NavigateSubframe) {
1668 // Load page A. 1675 // Load page A.
1669 LoadHTML("hello <iframe srcdoc='fail' name='frame'></iframe>"); 1676 LoadHTML("hello <iframe srcdoc='fail' name='frame'></iframe>");
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
2492 ExpectPauseAndResume(3); 2499 ExpectPauseAndResume(3);
2493 blink::WebScriptSource source2( 2500 blink::WebScriptSource source2(
2494 WebString::fromUTF8("function func2() { func1(); }; func2();")); 2501 WebString::fromUTF8("function func2() { func1(); }; func2();"));
2495 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1); 2502 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1);
2496 2503
2497 EXPECT_FALSE(IsPaused()); 2504 EXPECT_FALSE(IsPaused());
2498 Detach(); 2505 Detach();
2499 } 2506 }
2500 2507
2501 } // namespace content 2508 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698