Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 content::RenderWidgetHostView* expected_view) | 220 content::RenderWidgetHostView* expected_view) |
| 221 : TextInputManagerObserverBase(web_contents), | 221 : TextInputManagerObserverBase(web_contents), |
| 222 expected_view_(expected_view) { | 222 expected_view_(expected_view) { |
| 223 tester()->SetOnImeCompositionRangeChangedCallback( | 223 tester()->SetOnImeCompositionRangeChangedCallback( |
| 224 base::Bind(&ViewCompositionRangeChangedObserver::VerifyChange, | 224 base::Bind(&ViewCompositionRangeChangedObserver::VerifyChange, |
| 225 base::Unretained(this))); | 225 base::Unretained(this))); |
| 226 } | 226 } |
| 227 | 227 |
| 228 private: | 228 private: |
| 229 void VerifyChange() { | 229 void VerifyChange() { |
| 230 LOG(INFO) << "View: " << tester()->GetUpdatedView(); | |
|
Charlie Reis
2016/08/03 22:16:23
Did you mean to leave these in?
EhsanK
2016/08/04 18:57:58
No sorry. Removed. Thanks!
| |
| 230 if (expected_view_ == tester()->GetUpdatedView()) | 231 if (expected_view_ == tester()->GetUpdatedView()) |
| 231 OnSuccess(); | 232 OnSuccess(); |
| 232 } | 233 } |
| 233 | 234 |
| 234 const content::RenderWidgetHostView* const expected_view_; | 235 const content::RenderWidgetHostView* const expected_view_; |
| 235 | 236 |
| 236 DISALLOW_COPY_AND_ASSIGN(ViewCompositionRangeChangedObserver); | 237 DISALLOW_COPY_AND_ASSIGN(ViewCompositionRangeChangedObserver); |
| 237 }; | 238 }; |
| 238 | 239 |
| 239 // This class observes the |expected_view| for a change in the text selection | 240 // This class observes the |expected_view| for a change in the text selection |
| 240 // that has a selection length of |expected_length|. | 241 // that has a selection length of |expected_length|. |
| 241 class ViewTextSelectionObserver : public TextInputManagerObserverBase { | 242 class ViewTextSelectionObserver : public TextInputManagerObserverBase { |
| 242 public: | 243 public: |
| 243 ViewTextSelectionObserver(content::WebContents* web_contents, | 244 ViewTextSelectionObserver(content::WebContents* web_contents, |
| 244 content::RenderWidgetHostView* expected_view, | 245 content::RenderWidgetHostView* expected_view, |
| 245 size_t expected_selection_length) | 246 size_t expected_selection_length) |
| 246 : TextInputManagerObserverBase(web_contents), | 247 : TextInputManagerObserverBase(web_contents), |
| 247 expected_view_(expected_view), | 248 expected_view_(expected_view), |
| 248 expected_selection_length_(expected_selection_length) { | 249 expected_selection_length_(expected_selection_length) { |
| 249 tester()->SetOnTextSelectionChangedCallback(base::Bind( | 250 tester()->SetOnTextSelectionChangedCallback(base::Bind( |
| 250 &ViewTextSelectionObserver::VerifyChange, base::Unretained(this))); | 251 &ViewTextSelectionObserver::VerifyChange, base::Unretained(this))); |
| 251 } | 252 } |
| 252 | 253 |
| 253 private: | 254 private: |
| 254 void VerifyChange() { | 255 void VerifyChange() { |
| 255 if (expected_view_ == tester()->GetUpdatedView()) { | 256 if (expected_view_ == tester()->GetUpdatedView()) { |
| 256 size_t selection_length; | 257 size_t selection_length; |
| 257 if (tester()->GetCurrentTextSelectionLength(&selection_length) && | 258 if (tester()->GetCurrentTextSelectionLength(&selection_length) && |
| 258 expected_selection_length_ == selection_length) | 259 expected_selection_length_ == selection_length) { |
| 260 LOG(INFO) << "Observed length:" << selection_length; | |
| 259 OnSuccess(); | 261 OnSuccess(); |
| 262 } | |
| 260 } | 263 } |
| 261 } | 264 } |
| 262 | 265 |
| 263 const content::RenderWidgetHostView* const expected_view_; | 266 const content::RenderWidgetHostView* const expected_view_; |
| 264 const size_t expected_selection_length_; | 267 const size_t expected_selection_length_; |
| 265 | 268 |
| 266 DISALLOW_COPY_AND_ASSIGN(ViewTextSelectionObserver); | 269 DISALLOW_COPY_AND_ASSIGN(ViewTextSelectionObserver); |
| 267 }; | 270 }; |
| 268 | 271 |
| 269 // This class monitors all the changes in TextInputState and keeps a record of | 272 // This class monitors all the changes in TextInputState and keeps a record of |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 send_tab_insert_text_wait_for_bounds_change(view); | 610 send_tab_insert_text_wait_for_bounds_change(view); |
| 608 } | 611 } |
| 609 | 612 |
| 610 // This test creates a page with multiple child frames and adds an <input> to | 613 // This test creates a page with multiple child frames and adds an <input> to |
| 611 // each frame. Then, sequentially, each <input> is focused by sending a tab key. | 614 // each frame. Then, sequentially, each <input> is focused by sending a tab key. |
| 612 // Then, after |TextInputState.type| for a view is changed to text, the test | 615 // Then, after |TextInputState.type| for a view is changed to text, the test |
| 613 // sends a set composition IPC to the active widget and waits until the widget | 616 // sends a set composition IPC to the active widget and waits until the widget |
| 614 // updates its composition range. | 617 // updates its composition range. |
| 615 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | 618 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| 616 TrackCompositionRangeForAllFrames) { | 619 TrackCompositionRangeForAllFrames) { |
| 617 // TODO(ekaramd): After IME methods are implemented for WebFrameWidgetImpl, | 620 CreateIframePage("a(b,c(a,b),d)"); |
| 618 // change the page so that it contains child frames as well | 621 std::vector<content::RenderFrameHost*> frames{ |
| 619 // (crbug.com/626746). | 622 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), |
| 620 CreateIframePage("a()"); | 623 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), |
| 621 std::vector<content::RenderFrameHost*> frames{GetFrame(IndexVector{})}; | 624 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; |
| 622 std::vector<content::RenderWidgetHostView*> views; | 625 std::vector<content::RenderWidgetHostView*> views; |
| 623 for (auto* frame : frames) | 626 for (auto* frame : frames) |
| 624 views.push_back(frame->GetView()); | 627 views.push_back(frame->GetView()); |
| 625 for (size_t i = 0; i < frames.size(); ++i) | 628 for (size_t i = 0; i < frames.size(); ++i) |
| 626 AddInputFieldToFrame(frames[i], "text", "", true); | 629 AddInputFieldToFrame(frames[i], "text", "text", true); |
| 627 | 630 |
| 628 content::WebContents* web_contents = active_contents(); | 631 content::WebContents* web_contents = active_contents(); |
| 629 | 632 |
| 630 auto send_tab_set_composition_wait_for_bounds_change = | 633 auto send_tab_set_composition_wait_for_bounds_change = [&web_contents]( |
| 631 [&web_contents](content::RenderWidgetHostView* view) { | 634 content::RenderWidgetHostView* view) { |
| 632 ViewTextInputTypeObserver type_observer(web_contents, view, | 635 ViewTextInputTypeObserver type_observer(web_contents, view, |
| 633 ui::TEXT_INPUT_TYPE_TEXT); | 636 ui::TEXT_INPUT_TYPE_TEXT); |
| 634 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, | 637 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, |
| 635 ui::VKEY_TAB, false, false, false, false); | 638 ui::VKEY_TAB, false, false, false, false); |
| 636 type_observer.Wait(); | 639 type_observer.Wait(); |
| 637 ViewCompositionRangeChangedObserver range_observer(web_contents, view); | 640 ViewCompositionRangeChangedObserver range_observer(web_contents, view); |
| 638 content::SetCompositionForRenderWidgetHost( | 641 EXPECT_TRUE(content::RequestCompositionInfoFromActiveWidget(web_contents)); |
| 639 view->GetRenderWidgetHost(), base::ASCIIToUTF16("text"), | 642 range_observer.Wait(); |
| 640 {ui::CompositionUnderline()}, gfx::Range::InvalidRange(), 0, 0); | 643 LOG(INFO) << "Wait for view is over: " << view; |
|
Charlie Reis
2016/08/03 22:16:23
Should probably remove this as well.
EhsanK
2016/08/04 18:57:58
Done.
| |
| 641 range_observer.Wait(); | 644 }; |
| 642 }; | |
| 643 | 645 |
| 644 for (auto* view : views) | 646 for (auto* view : views) |
| 645 send_tab_set_composition_wait_for_bounds_change(view); | 647 send_tab_set_composition_wait_for_bounds_change(view); |
| 646 } | 648 } |
| 647 | 649 |
| 648 // This test creates a page with multiple child frames and adds an <input> to | 650 // This test creates a page with multiple child frames and adds an <input> to |
| 649 // each frame. Then, sequentially, each <input> is focused by sending a tab key. | 651 // each frame. Then, sequentially, each <input> is focused by sending a tab key. |
| 650 // After focusing each input, the whole text is automatically selected and a | 652 // After focusing each input, the whole text is automatically selected and a |
| 651 // ViewHostMsg_SelectionChanged IPC sent back to the browser. This test verifies | 653 // ViewHostMsg_SelectionChanged IPC sent back to the browser. This test verifies |
| 652 // that the browser tracks the text selection from all frames. | 654 // that the browser tracks the text selection from all frames. |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 841 | 843 |
| 842 // Set |TextInputState.show_ime_if_needed|. Expect IME. | 844 // Set |TextInputState.show_ime_if_needed|. Expect IME. |
| 843 sender.SetShowImeIfNeeded(true); | 845 sender.SetShowImeIfNeeded(true); |
| 844 EXPECT_TRUE(send_and_check_show_ime()); | 846 EXPECT_TRUE(send_and_check_show_ime()); |
| 845 | 847 |
| 846 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. | 848 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. |
| 847 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); | 849 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); |
| 848 EXPECT_FALSE(send_and_check_show_ime()); | 850 EXPECT_FALSE(send_and_check_show_ime()); |
| 849 } | 851 } |
| 850 #endif // USE_AURA | 852 #endif // USE_AURA |
| OLD | NEW |