OLD | NEW |
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 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1315 | 1315 |
1316 private: | 1316 private: |
1317 TestBrowserContext browser_context_; | 1317 TestBrowserContext browser_context_; |
1318 TextInputManager* text_input_manager_; | 1318 TextInputManager* text_input_manager_; |
1319 RenderWidgetHostImpl* tab_widget_; | 1319 RenderWidgetHostImpl* tab_widget_; |
1320 | 1320 |
1321 DISALLOW_COPY_AND_ASSIGN(InputMethodMacTest); | 1321 DISALLOW_COPY_AND_ASSIGN(InputMethodMacTest); |
1322 }; | 1322 }; |
1323 | 1323 |
1324 // This test will verify that calling unmarkText on the cocoa view will lead to | 1324 // This test will verify that calling unmarkText on the cocoa view will lead to |
1325 // a confirm composition IPC for the corresponding active widget. | 1325 // a finish composing text IPC for the corresponding active widget. |
1326 TEST_F(InputMethodMacTest, UnmarkText) { | 1326 TEST_F(InputMethodMacTest, UnmarkText) { |
1327 // Make the child view active and then call unmarkText on the view (Note that | 1327 // Make the child view active and then call unmarkText on the view (Note that |
1328 // |RenderWidgetHostViewCocoa::handlingKeyDown_| is false so calling | 1328 // |RenderWidgetHostViewCocoa::handlingKeyDown_| is false so calling |
1329 // unmarkText would lead to an IPC. This assumption is made in other similar | 1329 // unmarkText would lead to an IPC. This assumption is made in other similar |
1330 // tests as well). We should observe an IPC being sent to the |child_widget_|. | 1330 // tests as well). We should observe an IPC being sent to the |child_widget_|. |
1331 SetTextInputType(child_view_, ui::TEXT_INPUT_TYPE_TEXT); | 1331 SetTextInputType(child_view_, ui::TEXT_INPUT_TYPE_TEXT); |
1332 EXPECT_EQ(child_widget_, text_input_manager()->GetActiveWidget()); | 1332 EXPECT_EQ(child_widget_, text_input_manager()->GetActiveWidget()); |
1333 child_sink().ClearMessages(); | 1333 child_sink().ClearMessages(); |
1334 [rwhv_cocoa_ unmarkText]; | 1334 [rwhv_cocoa_ unmarkText]; |
1335 EXPECT_TRUE(!!child_sink().GetFirstMessageMatching( | 1335 EXPECT_TRUE(!!child_sink().GetFirstMessageMatching( |
1336 InputMsg_ImeConfirmComposition::ID)); | 1336 InputMsg_ImeFinishComposingText::ID)); |
1337 | 1337 |
1338 // Repeat the same steps for the tab's view . | 1338 // Repeat the same steps for the tab's view . |
1339 SetTextInputType(tab_view(), ui::TEXT_INPUT_TYPE_TEXT); | 1339 SetTextInputType(tab_view(), ui::TEXT_INPUT_TYPE_TEXT); |
1340 EXPECT_EQ(tab_widget(), text_input_manager()->GetActiveWidget()); | 1340 EXPECT_EQ(tab_widget(), text_input_manager()->GetActiveWidget()); |
1341 tab_sink().ClearMessages(); | 1341 tab_sink().ClearMessages(); |
1342 [rwhv_cocoa_ unmarkText]; | 1342 [rwhv_cocoa_ unmarkText]; |
1343 EXPECT_TRUE( | 1343 EXPECT_TRUE(!!tab_sink().GetFirstMessageMatching( |
1344 !!tab_sink().GetFirstMessageMatching(InputMsg_ImeConfirmComposition::ID)); | 1344 InputMsg_ImeFinishComposingText::ID)); |
1345 } | 1345 } |
1346 | 1346 |
1347 // This test makes sure that calling setMarkedText on the cocoa view will lead | 1347 // This test makes sure that calling setMarkedText on the cocoa view will lead |
1348 // to a set composition IPC for the corresponding active widget. | 1348 // to a set composition IPC for the corresponding active widget. |
1349 TEST_F(InputMethodMacTest, SetMarkedText) { | 1349 TEST_F(InputMethodMacTest, SetMarkedText) { |
1350 // Some values for the call to setMarkedText. | 1350 // Some values for the call to setMarkedText. |
1351 base::scoped_nsobject<NSString> text( | 1351 base::scoped_nsobject<NSString> text( |
1352 [[NSString alloc] initWithString:@"sample text"]); | 1352 [[NSString alloc] initWithString:@"sample text"]); |
1353 NSRange selectedRange = NSMakeRange(0, 4); | 1353 NSRange selectedRange = NSMakeRange(0, 4); |
1354 NSRange replacementRange = NSMakeRange(0, 1); | 1354 NSRange replacementRange = NSMakeRange(0, 1); |
(...skipping 14 matching lines...) Expand all Loading... |
1369 EXPECT_EQ(tab_widget(), text_input_manager()->GetActiveWidget()); | 1369 EXPECT_EQ(tab_widget(), text_input_manager()->GetActiveWidget()); |
1370 tab_sink().ClearMessages(); | 1370 tab_sink().ClearMessages(); |
1371 [rwhv_cocoa_ setMarkedText:text | 1371 [rwhv_cocoa_ setMarkedText:text |
1372 selectedRange:selectedRange | 1372 selectedRange:selectedRange |
1373 replacementRange:replacementRange]; | 1373 replacementRange:replacementRange]; |
1374 EXPECT_TRUE( | 1374 EXPECT_TRUE( |
1375 !!tab_sink().GetFirstMessageMatching(InputMsg_ImeSetComposition::ID)); | 1375 !!tab_sink().GetFirstMessageMatching(InputMsg_ImeSetComposition::ID)); |
1376 } | 1376 } |
1377 | 1377 |
1378 // This test verifies that calling insertText on the cocoa view will lead to a | 1378 // This test verifies that calling insertText on the cocoa view will lead to a |
1379 // confirm composition IPC sent to the active widget. | 1379 // commit text IPC sent to the active widget. |
1380 TEST_F(InputMethodMacTest, InsetText) { | 1380 TEST_F(InputMethodMacTest, InsertText) { |
1381 // Some values for the call to insertText. | 1381 // Some values for the call to insertText. |
1382 base::scoped_nsobject<NSString> text( | 1382 base::scoped_nsobject<NSString> text( |
1383 [[NSString alloc] initWithString:@"sample text"]); | 1383 [[NSString alloc] initWithString:@"sample text"]); |
1384 NSRange replacementRange = NSMakeRange(0, 1); | 1384 NSRange replacementRange = NSMakeRange(0, 1); |
1385 | 1385 |
1386 // Make the child view active and then call insertText with some values. We | 1386 // Make the child view active and then call insertText with some values. We |
1387 // should observe an IPC being sent to the |child_widget_|. | 1387 // should observe an IPC being sent to the |child_widget_|. |
1388 SetTextInputType(child_view_, ui::TEXT_INPUT_TYPE_TEXT); | 1388 SetTextInputType(child_view_, ui::TEXT_INPUT_TYPE_TEXT); |
1389 EXPECT_EQ(child_widget_, text_input_manager()->GetActiveWidget()); | 1389 EXPECT_EQ(child_widget_, text_input_manager()->GetActiveWidget()); |
1390 child_sink().ClearMessages(); | 1390 child_sink().ClearMessages(); |
1391 [rwhv_cocoa_ insertText:text replacementRange:replacementRange]; | 1391 [rwhv_cocoa_ insertText:text replacementRange:replacementRange]; |
1392 EXPECT_TRUE(!!child_sink().GetFirstMessageMatching( | 1392 EXPECT_TRUE( |
1393 InputMsg_ImeConfirmComposition::ID)); | 1393 !!child_sink().GetFirstMessageMatching(InputMsg_ImeCommitText::ID)); |
1394 | 1394 |
1395 // Repeat the same steps for the tab's view. | 1395 // Repeat the same steps for the tab's view. |
1396 SetTextInputType(tab_view(), ui::TEXT_INPUT_TYPE_TEXT); | 1396 SetTextInputType(tab_view(), ui::TEXT_INPUT_TYPE_TEXT); |
1397 EXPECT_EQ(tab_widget(), text_input_manager()->GetActiveWidget()); | 1397 EXPECT_EQ(tab_widget(), text_input_manager()->GetActiveWidget()); |
1398 [rwhv_cocoa_ insertText:text replacementRange:replacementRange]; | 1398 [rwhv_cocoa_ insertText:text replacementRange:replacementRange]; |
1399 EXPECT_TRUE( | 1399 EXPECT_TRUE(!!tab_sink().GetFirstMessageMatching(InputMsg_ImeCommitText::ID)); |
1400 !!tab_sink().GetFirstMessageMatching(InputMsg_ImeConfirmComposition::ID)); | |
1401 } | 1400 } |
1402 | 1401 |
1403 // This test makes sure that calling confirmComposition on the cocoa view will | 1402 // This test makes sure that calling finishComposingText on the cocoa view will |
1404 // lead to a confirm composition IPC for a the corresponding active widget. | 1403 // lead to a finish composing text IPC for a the corresponding active widget. |
1405 TEST_F(InputMethodMacTest, ConfirmComposition) { | 1404 TEST_F(InputMethodMacTest, FinishComposingText) { |
1406 // Some values for the call to setMarkedText. | 1405 // Some values for the call to setMarkedText. |
1407 base::scoped_nsobject<NSString> text( | 1406 base::scoped_nsobject<NSString> text( |
1408 [[NSString alloc] initWithString:@"sample text"]); | 1407 [[NSString alloc] initWithString:@"sample text"]); |
1409 NSRange selectedRange = NSMakeRange(0, 4); | 1408 NSRange selectedRange = NSMakeRange(0, 4); |
1410 NSRange replacementRange = NSMakeRange(0, 1); | 1409 NSRange replacementRange = NSMakeRange(0, 1); |
1411 | 1410 |
1412 // Make child view active and then call confirmComposition. We should observe | 1411 // Make child view active and then call finishComposingText. We should observe |
1413 // an IPC being sent to the |child_widget_|. | 1412 // an IPC being sent to the |child_widget_|. |
1414 SetTextInputType(child_view_, ui::TEXT_INPUT_TYPE_TEXT); | 1413 SetTextInputType(child_view_, ui::TEXT_INPUT_TYPE_TEXT); |
1415 EXPECT_EQ(child_widget_, text_input_manager()->GetActiveWidget()); | 1414 EXPECT_EQ(child_widget_, text_input_manager()->GetActiveWidget()); |
1416 child_sink().ClearMessages(); | 1415 child_sink().ClearMessages(); |
1417 // In order to confirm composition, we must first have some marked text. So, | 1416 // In order to finish composing text, we must first have some marked text. So, |
1418 // we will first call setMarkedText on cocoa view. This would lead to a set | 1417 // we will first call setMarkedText on cocoa view. This would lead to a set |
1419 // composition IPC in the sink, but it doesn't matter since we will be looking | 1418 // composition IPC in the sink, but it doesn't matter since we will be looking |
1420 // for a confirm composition IPC for this test. | 1419 // for a finish composing text IPC for this test. |
1421 [rwhv_cocoa_ setMarkedText:text | 1420 [rwhv_cocoa_ setMarkedText:text |
1422 selectedRange:selectedRange | 1421 selectedRange:selectedRange |
1423 replacementRange:replacementRange]; | 1422 replacementRange:replacementRange]; |
1424 [rwhv_cocoa_ confirmComposition]; | 1423 [rwhv_cocoa_ finishComposingText]; |
1425 EXPECT_TRUE(!!child_sink().GetFirstMessageMatching( | 1424 EXPECT_TRUE(!!child_sink().GetFirstMessageMatching( |
1426 InputMsg_ImeConfirmComposition::ID)); | 1425 InputMsg_ImeFinishComposingText::ID)); |
1427 | 1426 |
1428 // Repeat the same steps for the tab's view. | 1427 // Repeat the same steps for the tab's view. |
1429 SetTextInputType(tab_view(), ui::TEXT_INPUT_TYPE_TEXT); | 1428 SetTextInputType(tab_view(), ui::TEXT_INPUT_TYPE_TEXT); |
1430 EXPECT_EQ(tab_widget(), text_input_manager()->GetActiveWidget()); | 1429 EXPECT_EQ(tab_widget(), text_input_manager()->GetActiveWidget()); |
1431 tab_sink().ClearMessages(); | 1430 tab_sink().ClearMessages(); |
1432 [rwhv_cocoa_ setMarkedText:text | 1431 [rwhv_cocoa_ setMarkedText:text |
1433 selectedRange:selectedRange | 1432 selectedRange:selectedRange |
1434 replacementRange:replacementRange]; | 1433 replacementRange:replacementRange]; |
1435 [rwhv_cocoa_ confirmComposition]; | 1434 [rwhv_cocoa_ finishComposingText]; |
1436 EXPECT_TRUE( | 1435 EXPECT_TRUE(!!tab_sink().GetFirstMessageMatching( |
1437 !!tab_sink().GetFirstMessageMatching(InputMsg_ImeConfirmComposition::ID)); | 1436 InputMsg_ImeFinishComposingText::ID)); |
1438 } | 1437 } |
1439 | 1438 |
1440 // This test creates a test view to mimic a child frame's view and verifies that | 1439 // This test creates a test view to mimic a child frame's view and verifies that |
1441 // calling ImeCancelComposition on either the child view or the tab's view will | 1440 // calling ImeCancelComposition on either the child view or the tab's view will |
1442 // always lead to a call to cancelComposition on the cocoa view. | 1441 // always lead to a call to cancelComposition on the cocoa view. |
1443 TEST_F(InputMethodMacTest, ImeCancelCompositionForAllViews) { | 1442 TEST_F(InputMethodMacTest, ImeCancelCompositionForAllViews) { |
1444 // Some values for the call to setMarkedText. | 1443 // Some values for the call to setMarkedText. |
1445 base::scoped_nsobject<NSString> text( | 1444 base::scoped_nsobject<NSString> text( |
1446 [[NSString alloc] initWithString:@"sample text"]); | 1445 [[NSString alloc] initWithString:@"sample text"]); |
1447 NSRange selectedRange = NSMakeRange(0, 1); | 1446 NSRange selectedRange = NSMakeRange(0, 1); |
(...skipping 10 matching lines...) Expand all Loading... |
1458 // Repeat for the tab's view. | 1457 // Repeat for the tab's view. |
1459 [rwhv_cocoa_ setMarkedText:text | 1458 [rwhv_cocoa_ setMarkedText:text |
1460 selectedRange:selectedRange | 1459 selectedRange:selectedRange |
1461 replacementRange:replacementRange]; | 1460 replacementRange:replacementRange]; |
1462 EXPECT_TRUE([rwhv_cocoa_ hasMarkedText]); | 1461 EXPECT_TRUE([rwhv_cocoa_ hasMarkedText]); |
1463 rwhv_mac_->ImeCancelComposition(); | 1462 rwhv_mac_->ImeCancelComposition(); |
1464 EXPECT_FALSE([rwhv_cocoa_ hasMarkedText]); | 1463 EXPECT_FALSE([rwhv_cocoa_ hasMarkedText]); |
1465 } | 1464 } |
1466 | 1465 |
1467 } // namespace content | 1466 } // namespace content |
OLD | NEW |