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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac_unittest.mm

Issue 2373243005: Request composition info from the focused RenderWidget (Closed)
Patch Set: Added a unit test Created 4 years, 2 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 // 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 "content/browser/renderer_host/render_widget_host_view_mac.h" 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h"
6 6
7 #include <Cocoa/Cocoa.h> 7 #include <Cocoa/Cocoa.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <tuple> 10 #include <tuple>
(...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1482 1482
1483 // Repeat for the tab's view. 1483 // Repeat for the tab's view.
1484 [rwhv_cocoa_ setMarkedText:text 1484 [rwhv_cocoa_ setMarkedText:text
1485 selectedRange:selectedRange 1485 selectedRange:selectedRange
1486 replacementRange:replacementRange]; 1486 replacementRange:replacementRange];
1487 EXPECT_TRUE([rwhv_cocoa_ hasMarkedText]); 1487 EXPECT_TRUE([rwhv_cocoa_ hasMarkedText]);
1488 rwhv_mac_->ImeCancelComposition(); 1488 rwhv_mac_->ImeCancelComposition();
1489 EXPECT_FALSE([rwhv_cocoa_ hasMarkedText]); 1489 EXPECT_FALSE([rwhv_cocoa_ hasMarkedText]);
1490 } 1490 }
1491 1491
1492 // This test verifies than when a RenderWidgetHostView changes its
Charlie Reis 2016/09/30 22:39:16 nit: s/than/that/
EhsanK 2016/10/05 16:39:02 Done.
1493 // TextInputState to NONE we send the IPC to stop monitor composition info and,
1494 // conversely, when its state is set to non-NONE, we start monitoring the
1495 // composition info.
1496 TEST_F(InputMethodMacTest, MonitorCompositionRangeForActiveWidget) {
1497 // First, we need to make the cocoa view the first responder so that the
1498 // method RWHVMac::HasFocus() returns true. Then we can make sure that as long
1499 // as there is some TextInputState of non-NONE, the corresponding widget will
1500 // be asked to start monitoring composition info.
1501 base::scoped_nsobject<CocoaTestHelperWindow> window(
1502 [[CocoaTestHelperWindow alloc] init]);
1503 [[window contentView] addSubview:rwhv_cocoa_];
1504 [window makeFirstResponder:rwhv_cocoa_];
1505 EXPECT_TRUE(rwhv_mac_->HasFocus());
1506
1507 TextInputState state;
1508 state.type = ui::TEXT_INPUT_TYPE_TEXT;
1509 tab_sink().ClearMessages();
1510
1511 // Make the tab's widget active.
1512 rwhv_mac_->TextInputStateChanged(state);
1513
1514 // The tab's widget must have received an IPC regarding composition updates.
1515 const IPC::Message* composition_request_msg_for_tab =
1516 tab_sink().GetUniqueMessageMatching(
1517 InputMsg_RequestCompositionUpdate::ID);
1518 EXPECT_TRUE(composition_request_msg_for_tab);
1519
1520 // The message should ask for monitoring updates, but no immediate update.
1521 InputMsg_RequestCompositionUpdate::Param tab_msg_params;
1522 InputMsg_RequestCompositionUpdate::Read(composition_request_msg_for_tab,
1523 &tab_msg_params);
1524 bool is_tab_msg_for_immediate_request = std::get<0>(tab_msg_params);
1525 bool is_tab_msg_for_monitor_request = std::get<1>(tab_msg_params);
1526 EXPECT_FALSE(is_tab_msg_for_immediate_request);
1527 EXPECT_TRUE(is_tab_msg_for_monitor_request);
1528 tab_sink().ClearMessages();
1529 child_sink().ClearMessages();
1530
1531 // Now make the child view active.
1532 child_view_->TextInputStateChanged(state);
1533
1534 // The tab should receive another IPC for composition updates.
1535 composition_request_msg_for_tab = tab_sink().GetUniqueMessageMatching(
1536 InputMsg_RequestCompositionUpdate::ID);
1537 EXPECT_TRUE(composition_request_msg_for_tab);
1538
1539 // This time, the tab should have been asked to stop monitoring (and no
1540 // immediate updates).
1541 InputMsg_RequestCompositionUpdate::Read(composition_request_msg_for_tab,
1542 &tab_msg_params);
1543 is_tab_msg_for_immediate_request = std::get<0>(tab_msg_params);
1544 is_tab_msg_for_monitor_request = std::get<1>(tab_msg_params);
1545 EXPECT_FALSE(is_tab_msg_for_immediate_request);
1546 EXPECT_FALSE(is_tab_msg_for_monitor_request);
1547 tab_sink().ClearMessages();
1548
1549 // The child too must have received an IPC for composition updates.
1550 const IPC::Message* composition_request_msg_for_child =
1551 child_sink().GetUniqueMessageMatching(
1552 InputMsg_RequestCompositionUpdate::ID);
1553 EXPECT_TRUE(composition_request_msg_for_child);
1554
1555 // Verify that the message is asking for monitoring to start; but no immediate
1556 // updates.
1557 InputMsg_RequestCompositionUpdate::Param child_msg_params;
1558 InputMsg_RequestCompositionUpdate::Read(composition_request_msg_for_child,
1559 &child_msg_params);
1560 bool is_child_msg_for_immediate_request = std::get<0>(child_msg_params);
1561 bool is_child_msg_for_monitor_request = std::get<1>(child_msg_params);
1562 EXPECT_FALSE(is_child_msg_for_immediate_request);
1563 EXPECT_TRUE(is_child_msg_for_monitor_request);
1564 child_sink().ClearMessages();
1565
1566 // Make the tab view active again.
1567 rwhv_mac_->TextInputStateChanged(state);
1568
1569 // Verify that the child received another IPC for composition updates.
1570 composition_request_msg_for_child = child_sink().GetUniqueMessageMatching(
1571 InputMsg_RequestCompositionUpdate::ID);
1572 EXPECT_TRUE(composition_request_msg_for_child);
1573
1574 // Verify that this IPC is asking for no monitoring or immediate updates.
1575 InputMsg_RequestCompositionUpdate::Read(composition_request_msg_for_child,
1576 &child_msg_params);
1577 is_child_msg_for_immediate_request = std::get<0>(child_msg_params);
1578 is_child_msg_for_monitor_request = std::get<1>(child_msg_params);
1579 EXPECT_FALSE(is_child_msg_for_immediate_request);
1580 EXPECT_FALSE(is_child_msg_for_monitor_request);
1581 }
1582
1492 } // namespace content 1583 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698