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_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <tuple> | 10 #include <tuple> |
(...skipping 5437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5448 | 5448 |
5449 // This test is for selected text. | 5449 // This test is for selected text. |
5450 TEST_F(InputMethodStateAuraTest, GetSelectedText) { | 5450 TEST_F(InputMethodStateAuraTest, GetSelectedText) { |
5451 base::string16 text = base::ASCIIToUTF16("some text of length 22"); | 5451 base::string16 text = base::ASCIIToUTF16("some text of length 22"); |
5452 size_t offset = 0U; | 5452 size_t offset = 0U; |
5453 gfx::Range selection_range(20, 21); | 5453 gfx::Range selection_range(20, 21); |
5454 | 5454 |
5455 for (auto index : active_view_sequence_) { | 5455 for (auto index : active_view_sequence_) { |
5456 render_widget_host_delegate()->set_focused_widget( | 5456 render_widget_host_delegate()->set_focused_widget( |
5457 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); | 5457 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); |
5458 views_[index]->SelectionChanged(text, offset, selection_range, true); | 5458 views_[index]->SelectionChanged(text, offset, selection_range); |
5459 base::string16 expected_text = text.substr( | 5459 base::string16 expected_text = text.substr( |
5460 selection_range.GetMin() - offset, selection_range.length()); | 5460 selection_range.GetMin() - offset, selection_range.length()); |
5461 | 5461 |
5462 EXPECT_EQ(expected_text, views_[index]->GetSelectedText()); | 5462 EXPECT_EQ(expected_text, views_[index]->GetSelectedText()); |
5463 | 5463 |
5464 // Changing offset to make sure that the next view has a different text | 5464 // Changing offset to make sure that the next view has a different text |
5465 // selection. | 5465 // selection. |
5466 offset++; | 5466 offset++; |
5467 } | 5467 } |
5468 } | 5468 } |
5469 | 5469 |
5470 // This test is for text range. | 5470 // This test is for text range. |
5471 TEST_F(InputMethodStateAuraTest, GetTextRange) { | 5471 TEST_F(InputMethodStateAuraTest, GetTextRange) { |
5472 base::string16 text = base::ASCIIToUTF16("some text of length 22"); | 5472 base::string16 text = base::ASCIIToUTF16("some text of length 22"); |
5473 size_t offset = 0U; | 5473 size_t offset = 0U; |
5474 gfx::Range selection_range; | 5474 gfx::Range selection_range; |
5475 | 5475 |
5476 for (auto index : active_view_sequence_) { | 5476 for (auto index : active_view_sequence_) { |
5477 render_widget_host_delegate()->set_focused_widget( | 5477 render_widget_host_delegate()->set_focused_widget( |
5478 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); | 5478 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); |
5479 gfx::Range expected_range(offset, offset + text.length()); | 5479 gfx::Range expected_range(offset, offset + text.length()); |
5480 views_[index]->SelectionChanged(text, offset, selection_range, true); | 5480 views_[index]->SelectionChanged(text, offset, selection_range); |
5481 gfx::Range range_from_client; | 5481 gfx::Range range_from_client; |
5482 | 5482 |
5483 // For aura this always returns true. | 5483 // For aura this always returns true. |
5484 EXPECT_TRUE(text_input_client()->GetTextRange(&range_from_client)); | 5484 EXPECT_TRUE(text_input_client()->GetTextRange(&range_from_client)); |
5485 EXPECT_EQ(expected_range, range_from_client); | 5485 EXPECT_EQ(expected_range, range_from_client); |
5486 | 5486 |
5487 // Changing offset to make sure that the next view has a different text | 5487 // Changing offset to make sure that the next view has a different text |
5488 // selection. | 5488 // selection. |
5489 offset++; | 5489 offset++; |
5490 } | 5490 } |
5491 } | 5491 } |
5492 | 5492 |
5493 // This test is for selection range. | 5493 // This test is for selection range. |
5494 TEST_F(InputMethodStateAuraTest, GetSelectionRange) { | 5494 TEST_F(InputMethodStateAuraTest, GetSelectionRange) { |
5495 base::string16 text; | 5495 base::string16 text; |
5496 gfx::Range expected_range(0U, 1U); | 5496 gfx::Range expected_range(0U, 1U); |
5497 | 5497 |
5498 for (auto index : active_view_sequence_) { | 5498 for (auto index : active_view_sequence_) { |
5499 render_widget_host_delegate()->set_focused_widget( | 5499 render_widget_host_delegate()->set_focused_widget( |
5500 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); | 5500 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); |
5501 views_[index]->SelectionChanged(text, 0U, expected_range, true); | 5501 views_[index]->SelectionChanged(text, 0U, expected_range); |
5502 gfx::Range range_from_client; | 5502 gfx::Range range_from_client; |
5503 | 5503 |
5504 // This method always returns true. | 5504 // This method always returns true. |
5505 EXPECT_TRUE(text_input_client()->GetSelectionRange(&range_from_client)); | 5505 EXPECT_TRUE(text_input_client()->GetSelectionRange(&range_from_client)); |
5506 EXPECT_EQ(expected_range, range_from_client); | 5506 EXPECT_EQ(expected_range, range_from_client); |
5507 | 5507 |
5508 // Changing range to make sure that the next view has a different text | 5508 // Changing range to make sure that the next view has a different text |
5509 // selection. | 5509 // selection. |
5510 expected_range.set_end(expected_range.end() + 1U); | 5510 expected_range.set_end(expected_range.end() + 1U); |
5511 } | 5511 } |
5512 } | 5512 } |
5513 | 5513 |
5514 #if defined(USE_X11) && !defined(OS_CHROMEOS) | 5514 #if defined(USE_X11) && !defined(OS_CHROMEOS) |
5515 // This test will verify that after selection, the selected text is written to | 5515 // This test will verify that after selection, the selected text is written to |
5516 // the clipboard from the focused widget. | 5516 // the clipboard from the focused widget. |
5517 TEST_F(InputMethodStateAuraTest, SelectedTextCopiedToClipboard) { | 5517 TEST_F(InputMethodStateAuraTest, SelectedTextCopiedToClipboard) { |
5518 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); | 5518 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); |
5519 EXPECT_TRUE(!!clipboard); | 5519 EXPECT_TRUE(!!clipboard); |
5520 std::vector<std::string> texts = {"text0", "text1", "text2", "text3"}; | 5520 std::vector<std::string> texts = {"text0", "text1", "text2", "text3"}; |
5521 for (auto index : active_view_sequence_) { | 5521 for (auto index : active_view_sequence_) { |
5522 clipboard->Clear(ui::CLIPBOARD_TYPE_SELECTION); | 5522 clipboard->Clear(ui::CLIPBOARD_TYPE_SELECTION); |
5523 | 5523 |
5524 // Focus the corresponding widget. | 5524 // Focus the corresponding widget. |
5525 render_widget_host_delegate()->set_focused_widget( | 5525 render_widget_host_delegate()->set_focused_widget( |
5526 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); | 5526 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost())); |
5527 | 5527 |
5528 // Change the selection of the currently focused widget. It suffices to just | 5528 // Change the selection of the currently focused widget. It suffices to just |
5529 // call the method on the view. | 5529 // call the method on the view. |
5530 base::string16 expected_text = base::ASCIIToUTF16(texts[index]); | 5530 base::string16 expected_text = base::ASCIIToUTF16(texts[index]); |
5531 views_[index]->SelectionChanged(expected_text, 0U, gfx::Range(0, 5), true); | 5531 views_[index]->SelectionChanged(expected_text, 0U, gfx::Range(0, 5)); |
5532 | 5532 |
5533 // Retrieve the selected text from clipboard and verify it is as expected. | 5533 // Retrieve the selected text from clipboard and verify it is as expected. |
5534 base::string16 result_text; | 5534 base::string16 result_text; |
5535 clipboard->ReadText(ui::CLIPBOARD_TYPE_SELECTION, &result_text); | 5535 clipboard->ReadText(ui::CLIPBOARD_TYPE_SELECTION, &result_text); |
5536 EXPECT_EQ(expected_text, result_text); | 5536 EXPECT_EQ(expected_text, result_text); |
5537 } | 5537 } |
5538 } | 5538 } |
5539 #endif | 5539 #endif |
5540 | 5540 |
5541 // This test verifies that when any view on the page cancels an ongoing | 5541 // This test verifies that when any view on the page cancels an ongoing |
5542 // composition, the RenderWidgetHostViewAura will receive the notification and | 5542 // composition, the RenderWidgetHostViewAura will receive the notification and |
5543 // the current composition is canceled. | 5543 // the current composition is canceled. |
5544 TEST_F(InputMethodStateAuraTest, ImeCancelCompositionForAllViews) { | 5544 TEST_F(InputMethodStateAuraTest, ImeCancelCompositionForAllViews) { |
5545 for (auto* view : views_) { | 5545 for (auto* view : views_) { |
5546 ActivateViewForTextInputManager(view, ui::TEXT_INPUT_TYPE_TEXT); | 5546 ActivateViewForTextInputManager(view, ui::TEXT_INPUT_TYPE_TEXT); |
5547 // There is no composition in the beginning. | 5547 // There is no composition in the beginning. |
5548 EXPECT_FALSE(has_composition_text()); | 5548 EXPECT_FALSE(has_composition_text()); |
5549 SetHasCompositionTextToTrue(); | 5549 SetHasCompositionTextToTrue(); |
5550 view->ImeCancelComposition(); | 5550 view->ImeCancelComposition(); |
5551 // The composition must have been canceled. | 5551 // The composition must have been canceled. |
5552 EXPECT_FALSE(has_composition_text()); | 5552 EXPECT_FALSE(has_composition_text()); |
5553 } | 5553 } |
5554 } | 5554 } |
5555 | 5555 |
5556 } // namespace content | 5556 } // namespace content |
OLD | NEW |