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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 public: | 140 public: |
| 141 explicit TextInputManagerChangeObserver(content::WebContents* web_contents) | 141 explicit TextInputManagerChangeObserver(content::WebContents* web_contents) |
| 142 : TextInputManagerObserverBase(web_contents) { | 142 : TextInputManagerObserverBase(web_contents) { |
| 143 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( | 143 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( |
| 144 &TextInputManagerChangeObserver::VerifyChange, base::Unretained(this))); | 144 &TextInputManagerChangeObserver::VerifyChange, base::Unretained(this))); |
| 145 } | 145 } |
| 146 | 146 |
| 147 private: | 147 private: |
| 148 void VerifyChange( | 148 void VerifyChange( |
| 149 content::TextInputManagerTester* text_input_manager_tester) { | 149 content::TextInputManagerTester* text_input_manager_tester) { |
| 150 ASSERT_EQ(tester(), text_input_manager_tester); | 150 ASSERT_EQ(tester(), text_input_manager_tester); |
|
Charlie Reis
2016/06/29 20:18:37
Should we have this check in the classes below?
EhsanK
2016/06/30 00:24:45
I don't think this check can even hit.
1- tester(
| |
| 151 if (tester()->IsTextInputStateChanged()) | 151 if (tester()->IsTextInputStateChanged()) |
| 152 OnSuccess(); | 152 OnSuccess(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 DISALLOW_COPY_AND_ASSIGN(TextInputManagerChangeObserver); | 155 DISALLOW_COPY_AND_ASSIGN(TextInputManagerChangeObserver); |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 // This class observes |TextInputState.type| for a specific RWHV. | 158 // This class observes |TextInputState.type| for a specific RWHV. |
| 159 class ViewTextInputTypeObserver : public TextInputManagerObserverBase { | 159 class ViewTextInputTypeObserver : public TextInputManagerObserverBase { |
| 160 public: | 160 public: |
| 161 explicit ViewTextInputTypeObserver(content::WebContents* web_contents, | 161 explicit ViewTextInputTypeObserver(content::WebContents* web_contents, |
| 162 content::RenderWidgetHostView* rwhv, | 162 content::RenderWidgetHostView* rwhv, |
| 163 ui::TextInputType expected_type) | 163 ui::TextInputType expected_type) |
| 164 : TextInputManagerObserverBase(web_contents), | 164 : TextInputManagerObserverBase(web_contents), |
| 165 web_contents_(web_contents), | 165 web_contents_(web_contents), |
| 166 view_(rwhv), | 166 view_(rwhv), |
| 167 expected_type_(expected_type) { | 167 expected_type_(expected_type) { |
| 168 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( | 168 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( |
| 169 &ViewTextInputTypeObserver::VerifyType, base::Unretained(this))); | 169 &ViewTextInputTypeObserver::VerifyType, base::Unretained(this))); |
| 170 } | 170 } |
| 171 | 171 |
| 172 private: | 172 private: |
| 173 void VerifyType(content::TextInputManagerTester* tester) { | 173 void VerifyType(content::TextInputManagerTester* text_input_manager_tester) { |
| 174 ui::TextInputType type; | 174 ui::TextInputType type; |
| 175 if (!content::GetTextInputTypeForView(web_contents_, view_, &type)) | 175 if (!content::GetTextInputTypeForView(web_contents_, view_, &type)) |
| 176 return; | 176 return; |
| 177 if (expected_type_ == type) | 177 if (expected_type_ == type) |
| 178 OnSuccess(); | 178 OnSuccess(); |
| 179 } | 179 } |
| 180 | 180 |
| 181 content::WebContents* web_contents_; | 181 content::WebContents* web_contents_; |
| 182 content::RenderWidgetHostView* view_; | 182 content::RenderWidgetHostView* view_; |
| 183 const ui::TextInputType expected_type_; | 183 const ui::TextInputType expected_type_; |
| 184 | 184 |
| 185 DISALLOW_COPY_AND_ASSIGN(ViewTextInputTypeObserver); | 185 DISALLOW_COPY_AND_ASSIGN(ViewTextInputTypeObserver); |
| 186 }; | 186 }; |
| 187 | 187 |
| 188 // This class observes the |expected_view| for the first change in its | |
| 189 // selection bounds. | |
| 190 class ViewSelectionBoundsChangedObserver : public TextInputManagerObserverBase { | |
| 191 public: | |
| 192 explicit ViewSelectionBoundsChangedObserver( | |
| 193 content::WebContents* web_contents, | |
| 194 content::RenderWidgetHostView* expected_view) | |
| 195 : TextInputManagerObserverBase(web_contents), | |
| 196 expected_view_(expected_view) { | |
| 197 tester()->SetOnSelectionBoundsChangedCallback( | |
| 198 base::Bind(&ViewSelectionBoundsChangedObserver::VerifyChange, | |
| 199 base::Unretained(this))); | |
| 200 } | |
| 201 | |
| 202 private: | |
| 203 void VerifyChange( | |
| 204 content::TextInputManagerTester* text_input_manager_tester) { | |
| 205 if (expected_view_ == tester()->GetUpdatedView()) | |
| 206 OnSuccess(); | |
| 207 } | |
| 208 | |
| 209 const content::RenderWidgetHostView* const expected_view_; | |
| 210 | |
| 211 DISALLOW_COPY_AND_ASSIGN(ViewSelectionBoundsChangedObserver); | |
| 212 }; | |
| 213 | |
| 188 } // namespace | 214 } // namespace |
| 189 | 215 |
| 190 // Main class for all TextInputState and IME related tests. | 216 // Main class for all TextInputState and IME related tests. |
| 191 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest { | 217 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest { |
| 192 public: | 218 public: |
| 193 SitePerProcessTextInputManagerTest() {} | 219 SitePerProcessTextInputManagerTest() {} |
| 194 ~SitePerProcessTextInputManagerTest() override {} | 220 ~SitePerProcessTextInputManagerTest() override {} |
| 195 | 221 |
| 196 void SetUpCommandLine(base::CommandLine* command_line) override { | 222 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 197 content::IsolateAllSitesForTesting(command_line); | 223 content::IsolateAllSitesForTesting(command_line); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, | 475 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, |
| 450 ui::VKEY_TAB, false, false, false, false); | 476 ui::VKEY_TAB, false, false, false, false); |
| 451 set_state_observer.Wait(); | 477 set_state_observer.Wait(); |
| 452 | 478 |
| 453 TextInputManagerTypeObserver reset_state_observer(active_contents(), | 479 TextInputManagerTypeObserver reset_state_observer(active_contents(), |
| 454 ui::TEXT_INPUT_TYPE_NONE); | 480 ui::TEXT_INPUT_TYPE_NONE); |
| 455 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 481 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 456 reset_state_observer.Wait(); | 482 reset_state_observer.Wait(); |
| 457 } | 483 } |
| 458 | 484 |
| 485 // This test creates a page with multiple child frames and adds an <input> to | |
| 486 // each frame. Then, sequentially, each <input> is focused by sending a tab key. | |
| 487 // Then, after |TextInputState.type| for a view is changed to text, another key | |
| 488 // is pressed (a character) and then the test verifies that TextInputManager | |
| 489 // receives the corresponding update on the change in selection bounds on the | |
| 490 // browser side. | |
| 491 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | |
| 492 TrackSelectionBoundsForChildFrames) { | |
| 493 CreateIframePage("a(b,c(a,b),d)"); | |
| 494 std::vector<content::RenderFrameHost*> frames{ | |
| 495 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), | |
| 496 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), | |
| 497 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; | |
| 498 std::vector<content::RenderWidgetHostView*> views; | |
| 499 for (auto frame : frames) | |
| 500 views.push_back(frame->GetView()); | |
| 501 for (size_t i = 0; i < frames.size(); ++i) | |
| 502 AddInputFieldToFrame(frames[i], "text", "", true); | |
| 503 | |
| 504 content::WebContents* web_contents = active_contents(); | |
| 505 | |
| 506 auto send_tab_insert_text_wait_for_bounds_change = [&web_contents]( | |
| 507 content::RenderWidgetHostView* view) { | |
| 508 ViewTextInputTypeObserver type_observer(web_contents, view, | |
| 509 ui::TEXT_INPUT_TYPE_TEXT); | |
| 510 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, | |
| 511 ui::VKEY_TAB, false, false, false, false); | |
| 512 type_observer.Wait(); | |
| 513 ViewSelectionBoundsChangedObserver bounds_observer(web_contents, view); | |
| 514 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('E'), | |
| 515 ui::DomCode::US_E, ui::VKEY_E, false, false, false, false); | |
| 516 bounds_observer.Wait(); | |
| 517 }; | |
| 518 | |
| 519 for (auto view : views) | |
| 520 send_tab_insert_text_wait_for_bounds_change(view); | |
| 521 } | |
| 522 | |
| 459 // TODO(ekaramad): The following tests are specifically written for Aura and are | 523 // TODO(ekaramad): The following tests are specifically written for Aura and are |
| 460 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus | 524 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus |
| 461 // (crbug.com/602723). | 525 // (crbug.com/602723). |
| 462 | 526 |
| 463 // Observes current input method for state changes. | 527 // Observes current input method for state changes. |
| 464 class InputMethodObserverBase { | 528 class InputMethodObserverBase { |
| 465 public: | 529 public: |
| 466 explicit InputMethodObserverBase(content::WebContents* web_contents) | 530 explicit InputMethodObserverBase(content::WebContents* web_contents) |
| 467 : success_(false), | 531 : success_(false), |
| 468 test_observer_(content::TestInputMethodObserver::Create(web_contents)) { | 532 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()); | 622 EXPECT_FALSE(send_and_check_show_ime()); |
| 559 | 623 |
| 560 // Set |TextInputState.show_ime_if_needed|. Expect IME. | 624 // Set |TextInputState.show_ime_if_needed|. Expect IME. |
| 561 sender.SetShowImeIfNeeded(true); | 625 sender.SetShowImeIfNeeded(true); |
| 562 EXPECT_TRUE(send_and_check_show_ime()); | 626 EXPECT_TRUE(send_and_check_show_ime()); |
| 563 | 627 |
| 564 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. | 628 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. |
| 565 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); | 629 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); |
| 566 EXPECT_FALSE(send_and_check_show_ime()); | 630 EXPECT_FALSE(send_and_check_show_ime()); |
| 567 } | 631 } |
| OLD | NEW |