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 "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 10 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 public: | 91 public: |
| 92 TextInputManagerValueObserver(content::WebContents* web_contents, | 92 TextInputManagerValueObserver(content::WebContents* web_contents, |
| 93 const std::string& expected_value) | 93 const std::string& expected_value) |
| 94 : TextInputManagerObserverBase(web_contents), | 94 : TextInputManagerObserverBase(web_contents), |
| 95 expected_value_(expected_value) { | 95 expected_value_(expected_value) { |
| 96 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( | 96 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( |
| 97 &TextInputManagerValueObserver::VerifyValue, base::Unretained(this))); | 97 &TextInputManagerValueObserver::VerifyValue, base::Unretained(this))); |
| 98 } | 98 } |
| 99 | 99 |
| 100 private: | 100 private: |
| 101 void VerifyValue(content::TextInputManagerTester* text_input_manager_tester) { | 101 void VerifyValue() { |
| 102 ASSERT_EQ(tester(), text_input_manager_tester); | |
| 103 std::string value; | 102 std::string value; |
| 104 if (tester()->GetTextInputValue(&value) && expected_value_ == value) | 103 if (tester()->GetTextInputValue(&value) && expected_value_ == value) |
| 105 OnSuccess(); | 104 OnSuccess(); |
| 106 } | 105 } |
| 107 | 106 |
| 108 const std::string expected_value_; | 107 const std::string expected_value_; |
| 109 | 108 |
| 110 DISALLOW_COPY_AND_ASSIGN(TextInputManagerValueObserver); | 109 DISALLOW_COPY_AND_ASSIGN(TextInputManagerValueObserver); |
| 111 }; | 110 }; |
| 112 | 111 |
| 113 // This class observes TextInputManager for changes in |TextInputState.type|. | 112 // This class observes TextInputManager for changes in |TextInputState.type|. |
| 114 class TextInputManagerTypeObserver : public TextInputManagerObserverBase { | 113 class TextInputManagerTypeObserver : public TextInputManagerObserverBase { |
| 115 public: | 114 public: |
| 116 TextInputManagerTypeObserver(content::WebContents* web_contents, | 115 TextInputManagerTypeObserver(content::WebContents* web_contents, |
| 117 ui::TextInputType expected_type) | 116 ui::TextInputType expected_type) |
| 118 : TextInputManagerObserverBase(web_contents), | 117 : TextInputManagerObserverBase(web_contents), |
| 119 expected_type_(expected_type) { | 118 expected_type_(expected_type) { |
| 120 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( | 119 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( |
| 121 &TextInputManagerTypeObserver::VerifyType, base::Unretained(this))); | 120 &TextInputManagerTypeObserver::VerifyType, base::Unretained(this))); |
| 122 } | 121 } |
| 123 | 122 |
| 124 private: | 123 private: |
| 125 void VerifyType(content::TextInputManagerTester* text_input_manager_tester) { | 124 void VerifyType() { |
| 126 ASSERT_EQ(tester(), text_input_manager_tester); | |
| 127 ui::TextInputType type = | 125 ui::TextInputType type = |
| 128 tester()->GetTextInputType(&type) ? type : ui::TEXT_INPUT_TYPE_NONE; | 126 tester()->GetTextInputType(&type) ? type : ui::TEXT_INPUT_TYPE_NONE; |
| 129 if (expected_type_ == type) | 127 if (expected_type_ == type) |
| 130 OnSuccess(); | 128 OnSuccess(); |
| 131 } | 129 } |
| 132 | 130 |
| 133 const ui::TextInputType expected_type_; | 131 const ui::TextInputType expected_type_; |
| 134 | 132 |
| 135 DISALLOW_COPY_AND_ASSIGN(TextInputManagerTypeObserver); | 133 DISALLOW_COPY_AND_ASSIGN(TextInputManagerTypeObserver); |
| 136 }; | 134 }; |
| 137 | 135 |
| 138 // This class observes TextInputManager for the first change in TextInputState. | 136 // This class observes TextInputManager for the first change in TextInputState. |
| 139 class TextInputManagerChangeObserver : public TextInputManagerObserverBase { | 137 class TextInputManagerChangeObserver : public TextInputManagerObserverBase { |
| 140 public: | 138 public: |
| 141 explicit TextInputManagerChangeObserver(content::WebContents* web_contents) | 139 explicit TextInputManagerChangeObserver(content::WebContents* web_contents) |
| 142 : TextInputManagerObserverBase(web_contents) { | 140 : TextInputManagerObserverBase(web_contents) { |
| 143 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( | 141 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( |
| 144 &TextInputManagerChangeObserver::VerifyChange, base::Unretained(this))); | 142 &TextInputManagerChangeObserver::VerifyChange, base::Unretained(this))); |
| 145 } | 143 } |
| 146 | 144 |
| 147 private: | 145 private: |
| 148 void VerifyChange( | 146 void VerifyChange() { |
| 149 content::TextInputManagerTester* text_input_manager_tester) { | |
| 150 ASSERT_EQ(tester(), text_input_manager_tester); | |
| 151 if (tester()->IsTextInputStateChanged()) | 147 if (tester()->IsTextInputStateChanged()) |
| 152 OnSuccess(); | 148 OnSuccess(); |
| 153 } | 149 } |
| 154 | 150 |
| 155 DISALLOW_COPY_AND_ASSIGN(TextInputManagerChangeObserver); | 151 DISALLOW_COPY_AND_ASSIGN(TextInputManagerChangeObserver); |
| 156 }; | 152 }; |
| 157 | 153 |
| 158 // This class observes |TextInputState.type| for a specific RWHV. | 154 // This class observes |TextInputState.type| for a specific RWHV. |
| 159 class ViewTextInputTypeObserver : public TextInputManagerObserverBase { | 155 class ViewTextInputTypeObserver : public TextInputManagerObserverBase { |
| 160 public: | 156 public: |
| 161 explicit ViewTextInputTypeObserver(content::WebContents* web_contents, | 157 explicit ViewTextInputTypeObserver(content::WebContents* web_contents, |
| 162 content::RenderWidgetHostView* rwhv, | 158 content::RenderWidgetHostView* rwhv, |
| 163 ui::TextInputType expected_type) | 159 ui::TextInputType expected_type) |
| 164 : TextInputManagerObserverBase(web_contents), | 160 : TextInputManagerObserverBase(web_contents), |
| 165 web_contents_(web_contents), | 161 web_contents_(web_contents), |
| 166 view_(rwhv), | 162 view_(rwhv), |
| 167 expected_type_(expected_type) { | 163 expected_type_(expected_type) { |
| 168 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( | 164 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( |
| 169 &ViewTextInputTypeObserver::VerifyType, base::Unretained(this))); | 165 &ViewTextInputTypeObserver::VerifyType, base::Unretained(this))); |
| 170 } | 166 } |
| 171 | 167 |
| 172 private: | 168 private: |
| 173 void VerifyType(content::TextInputManagerTester* tester) { | 169 void VerifyType() { |
| 174 ui::TextInputType type; | 170 ui::TextInputType type; |
| 175 if (!content::GetTextInputTypeForView(web_contents_, view_, &type)) | 171 if (!content::GetTextInputTypeForView(web_contents_, view_, &type)) |
| 176 return; | 172 return; |
| 177 if (expected_type_ == type) | 173 if (expected_type_ == type) |
| 178 OnSuccess(); | 174 OnSuccess(); |
| 179 } | 175 } |
| 180 | 176 |
| 181 content::WebContents* web_contents_; | 177 content::WebContents* web_contents_; |
| 182 content::RenderWidgetHostView* view_; | 178 content::RenderWidgetHostView* view_; |
| 183 const ui::TextInputType expected_type_; | 179 const ui::TextInputType expected_type_; |
| 184 | 180 |
| 185 DISALLOW_COPY_AND_ASSIGN(ViewTextInputTypeObserver); | 181 DISALLOW_COPY_AND_ASSIGN(ViewTextInputTypeObserver); |
| 186 }; | 182 }; |
| 187 | 183 |
| 184 // This class observes the |expected_view| for the first change in its | |
| 185 // selection bounds. | |
| 186 class ViewSelectionBoundsChangedObserver : public TextInputManagerObserverBase { | |
| 187 public: | |
| 188 explicit ViewSelectionBoundsChangedObserver( | |
| 189 content::WebContents* web_contents, | |
| 190 content::RenderWidgetHostView* expected_view) | |
| 191 : TextInputManagerObserverBase(web_contents), | |
| 192 expected_view_(expected_view) { | |
| 193 tester()->SetOnSelectionBoundsChangedCallback( | |
| 194 base::Bind(&ViewSelectionBoundsChangedObserver::VerifyChange, | |
| 195 base::Unretained(this))); | |
| 196 } | |
| 197 | |
| 198 private: | |
| 199 void VerifyChange() { | |
| 200 if (expected_view_ == tester()->GetUpdatedView()) | |
| 201 OnSuccess(); | |
| 202 } | |
| 203 | |
| 204 const content::RenderWidgetHostView* const expected_view_; | |
| 205 | |
| 206 DISALLOW_COPY_AND_ASSIGN(ViewSelectionBoundsChangedObserver); | |
| 207 }; | |
| 208 | |
| 188 } // namespace | 209 } // namespace |
| 189 | 210 |
| 190 // Main class for all TextInputState and IME related tests. | 211 // Main class for all TextInputState and IME related tests. |
| 191 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest { | 212 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest { |
| 192 public: | 213 public: |
| 193 SitePerProcessTextInputManagerTest() {} | 214 SitePerProcessTextInputManagerTest() {} |
| 194 ~SitePerProcessTextInputManagerTest() override {} | 215 ~SitePerProcessTextInputManagerTest() override {} |
| 195 | 216 |
| 196 void SetUpCommandLine(base::CommandLine* command_line) override { | 217 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 197 content::IsolateAllSitesForTesting(command_line); | 218 content::IsolateAllSitesForTesting(command_line); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 | 333 |
| 313 for (size_t i = 0; i < frames.size(); ++i) { | 334 for (size_t i = 0; i < frames.size(); ++i) { |
| 314 TextInputManagerValueObserver observer(active_contents(), values[i]); | 335 TextInputManagerValueObserver observer(active_contents(), values[i]); |
| 315 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, | 336 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, |
| 316 ui::VKEY_TAB, false, false, false, false); | 337 ui::VKEY_TAB, false, false, false, false); |
| 317 observer.Wait(); | 338 observer.Wait(); |
| 318 } | 339 } |
| 319 | 340 |
| 320 // Make sure that the first view has set its TextInputState.type to NONE. | 341 // Make sure that the first view has set its TextInputState.type to NONE. |
| 321 view_type_observer.Wait(); | 342 view_type_observer.Wait(); |
| 322 | |
|
Charlie Reis
2016/06/30 21:16:13
nit: Better to leave this blank line in place.
| |
| 323 // Verify that we are tracking the TextInputState from the first frame. | 343 // Verify that we are tracking the TextInputState from the first frame. |
| 324 content::RenderWidgetHostView* first_view = frames[0]->GetView(); | 344 content::RenderWidgetHostView* first_view = frames[0]->GetView(); |
| 325 ui::TextInputType first_view_type; | 345 ui::TextInputType first_view_type; |
| 326 EXPECT_TRUE(content::GetTextInputTypeForView(active_contents(), first_view, | 346 EXPECT_TRUE(content::GetTextInputTypeForView(active_contents(), first_view, |
| 327 &first_view_type)); | 347 &first_view_type)); |
| 328 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, first_view_type); | 348 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, first_view_type); |
| 329 | 349 |
| 330 size_t registered_views_count = | 350 size_t registered_views_count = |
| 331 content::GetRegisteredViewsCountFromTextInputManager(active_contents()); | 351 content::GetRegisteredViewsCountFromTextInputManager(active_contents()); |
| 332 | 352 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, | 469 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, |
| 450 ui::VKEY_TAB, false, false, false, false); | 470 ui::VKEY_TAB, false, false, false, false); |
| 451 set_state_observer.Wait(); | 471 set_state_observer.Wait(); |
| 452 | 472 |
| 453 TextInputManagerTypeObserver reset_state_observer(active_contents(), | 473 TextInputManagerTypeObserver reset_state_observer(active_contents(), |
| 454 ui::TEXT_INPUT_TYPE_NONE); | 474 ui::TEXT_INPUT_TYPE_NONE); |
| 455 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 475 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 456 reset_state_observer.Wait(); | 476 reset_state_observer.Wait(); |
| 457 } | 477 } |
| 458 | 478 |
| 479 // This test creates a page with multiple child frames and adds an <input> to | |
| 480 // each frame. Then, sequentially, each <input> is focused by sending a tab key. | |
| 481 // Then, after |TextInputState.type| for a view is changed to text, another key | |
| 482 // is pressed (a character) and then the test verifies that TextInputManager | |
| 483 // receives the corresponding update on the change in selection bounds on the | |
| 484 // browser side. | |
| 485 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | |
| 486 TrackSelectionBoundsForChildFrames) { | |
| 487 CreateIframePage("a(b,c(a,b),d)"); | |
| 488 std::vector<content::RenderFrameHost*> frames{ | |
| 489 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), | |
| 490 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), | |
| 491 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; | |
| 492 std::vector<content::RenderWidgetHostView*> views; | |
| 493 for (auto frame : frames) | |
| 494 views.push_back(frame->GetView()); | |
| 495 for (size_t i = 0; i < frames.size(); ++i) | |
| 496 AddInputFieldToFrame(frames[i], "text", "", true); | |
| 497 | |
| 498 content::WebContents* web_contents = active_contents(); | |
| 499 | |
| 500 auto send_tab_insert_text_wait_for_bounds_change = [&web_contents]( | |
| 501 content::RenderWidgetHostView* view) { | |
| 502 ViewTextInputTypeObserver type_observer(web_contents, view, | |
| 503 ui::TEXT_INPUT_TYPE_TEXT); | |
| 504 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, | |
| 505 ui::VKEY_TAB, false, false, false, false); | |
| 506 type_observer.Wait(); | |
| 507 ViewSelectionBoundsChangedObserver bounds_observer(web_contents, view); | |
| 508 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('E'), | |
| 509 ui::DomCode::US_E, ui::VKEY_E, false, false, false, false); | |
| 510 bounds_observer.Wait(); | |
| 511 }; | |
| 512 | |
| 513 for (auto view : views) | |
| 514 send_tab_insert_text_wait_for_bounds_change(view); | |
| 515 } | |
| 516 | |
| 459 // TODO(ekaramad): The following tests are specifically written for Aura and are | 517 // TODO(ekaramad): The following tests are specifically written for Aura and are |
| 460 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus | 518 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus |
| 461 // (crbug.com/602723). | 519 // (crbug.com/602723). |
| 462 | 520 |
| 463 // Observes current input method for state changes. | 521 // Observes current input method for state changes. |
| 464 class InputMethodObserverBase { | 522 class InputMethodObserverBase { |
| 465 public: | 523 public: |
| 466 explicit InputMethodObserverBase(content::WebContents* web_contents) | 524 explicit InputMethodObserverBase(content::WebContents* web_contents) |
| 467 : success_(false), | 525 : success_(false), |
| 468 test_observer_(content::TestInputMethodObserver::Create(web_contents)) { | 526 test_observer_(content::TestInputMethodObserver::Create(web_contents)) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 558 EXPECT_FALSE(send_and_check_show_ime()); | 616 EXPECT_FALSE(send_and_check_show_ime()); |
| 559 | 617 |
| 560 // Set |TextInputState.show_ime_if_needed|. Expect IME. | 618 // Set |TextInputState.show_ime_if_needed|. Expect IME. |
| 561 sender.SetShowImeIfNeeded(true); | 619 sender.SetShowImeIfNeeded(true); |
| 562 EXPECT_TRUE(send_and_check_show_ime()); | 620 EXPECT_TRUE(send_and_check_show_ime()); |
| 563 | 621 |
| 564 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. | 622 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. |
| 565 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); | 623 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); |
| 566 EXPECT_FALSE(send_and_check_show_ime()); | 624 EXPECT_FALSE(send_and_check_show_ime()); |
| 567 } | 625 } |
| OLD | NEW |