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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 | 65 |
| 66 bool success() const { return success_; } | 66 bool success() const { return success_; } |
| 67 | 67 |
| 68 protected: | 68 protected: |
| 69 content::TextInputManagerTester* tester() { return tester_.get(); } | 69 content::TextInputManagerTester* tester() { return tester_.get(); } |
| 70 | 70 |
| 71 void OnSuccess() { | 71 void OnSuccess() { |
| 72 success_ = true; | 72 success_ = true; |
| 73 if (message_loop_runner_) | 73 if (message_loop_runner_) |
| 74 message_loop_runner_->Quit(); | 74 message_loop_runner_->Quit(); |
| 75 | |
| 76 // By deleting |tester_| we make sure that the internal observer used in | |
| 77 // content/ is removed from the observer list of TextInputManager. | |
| 78 tester_.reset(nullptr); | |
|
EhsanK
2016/06/25 00:10:35
This is the public API's helper, which owns an int
Charlie Reis
2016/06/28 18:12:41
Acknowledged.
| |
| 75 } | 79 } |
| 76 | 80 |
| 77 private: | 81 private: |
| 78 std::unique_ptr<content::TextInputManagerTester> tester_; | 82 std::unique_ptr<content::TextInputManagerTester> tester_; |
| 79 bool success_; | 83 bool success_; |
| 80 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 84 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 81 | 85 |
| 82 DISALLOW_COPY_AND_ASSIGN(TextInputManagerObserverBase); | 86 DISALLOW_COPY_AND_ASSIGN(TextInputManagerObserverBase); |
| 83 }; | 87 }; |
| 84 | 88 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 // Make sure that the first view has set its TextInputState.type to NONE. | 320 // Make sure that the first view has set its TextInputState.type to NONE. |
| 317 view_type_observer.Wait(); | 321 view_type_observer.Wait(); |
| 318 | 322 |
| 319 // Verify that we are tracking the TextInputState from the first frame. | 323 // Verify that we are tracking the TextInputState from the first frame. |
| 320 content::RenderWidgetHostView* first_view = frames[0]->GetView(); | 324 content::RenderWidgetHostView* first_view = frames[0]->GetView(); |
| 321 ui::TextInputType first_view_type; | 325 ui::TextInputType first_view_type; |
| 322 EXPECT_TRUE(content::GetTextInputTypeForView(active_contents(), first_view, | 326 EXPECT_TRUE(content::GetTextInputTypeForView(active_contents(), first_view, |
| 323 &first_view_type)); | 327 &first_view_type)); |
| 324 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, first_view_type); | 328 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, first_view_type); |
| 325 | 329 |
| 330 size_t registered_views_count = | |
| 331 content::GetRegisteredViewsCountFromTextInputManager(active_contents()); | |
| 332 | |
| 333 DCHECK_LT(2U, registered_views_count); | |
|
Charlie Reis
2016/06/28 18:12:41
This is probably easier to read as:
// There are
EhsanK
2016/06/28 18:56:53
Acknowledged.
| |
| 334 | |
| 326 // Now that the second frame's <input> is focused, we crash the first frame | 335 // Now that the second frame's <input> is focused, we crash the first frame |
| 327 // and observe that text input state is updated for the view. | 336 // and observe that text input state is updated for the view. |
| 328 std::unique_ptr<content::TestRenderWidgetHostViewDestructionObserver> | 337 std::unique_ptr<content::TestRenderWidgetHostViewDestructionObserver> |
| 329 destruction_observer( | 338 destruction_observer( |
| 330 new content::TestRenderWidgetHostViewDestructionObserver(first_view)); | 339 new content::TestRenderWidgetHostViewDestructionObserver(first_view)); |
| 331 frames[0]->GetProcess()->Shutdown(0, false); | 340 frames[0]->GetProcess()->Shutdown(0, false); |
| 332 destruction_observer->Wait(); | 341 destruction_observer->Wait(); |
| 333 | 342 |
| 334 // Verifying that the TextInputManager is no longer tracking TextInputState | 343 // Verifying that the TextInputManager is no longer tracking TextInputState |
|
Charlie Reis
2016/06/28 18:12:41
nit: Verify
EhsanK
2016/06/28 18:56:53
Done.
| |
| 335 // for |first_view|. Note that |first_view| is now a dangling pointer. | 344 // for |first_view|. |
| 336 EXPECT_FALSE(content::GetTextInputTypeForView(active_contents(), first_view, | 345 EXPECT_EQ( |
| 337 &first_view_type)); | 346 registered_views_count - 1U, |
| 347 content::GetRegisteredViewsCountFromTextInputManager(active_contents())); | |
| 348 // Now crash the second <iframe> which has an active view. | |
|
Charlie Reis
2016/06/28 18:12:41
nit: Add blank line before.
EhsanK
2016/06/28 18:56:53
Done.
| |
| 349 destruction_observer.reset( | |
| 350 new content::TestRenderWidgetHostViewDestructionObserver( | |
| 351 frames[1]->GetView())); | |
| 352 frames[1]->GetProcess()->Shutdown(0, false); | |
| 353 destruction_observer->Wait(); | |
| 338 | 354 |
| 339 // Now crash the second <iframe> which has an active view. | 355 EXPECT_EQ( |
| 340 content::RenderWidgetHostView* second_view = frames[1]->GetView(); | 356 registered_views_count - 2U, |
| 341 TextInputManagerChangeObserver change_observer(active_contents()); | 357 content::GetRegisteredViewsCountFromTextInputManager(active_contents())); |
| 342 frames[1]->GetProcess()->Shutdown(0, false); | |
| 343 change_observer.Wait(); | |
| 344 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, | |
| 345 content::GetTextInputTypeFromWebContents(active_contents())); | |
| 346 EXPECT_FALSE(!!content::GetActiveViewFromWebContents(active_contents())); | |
| 347 ui::TextInputType second_view_type; | |
| 348 EXPECT_FALSE(content::GetTextInputTypeForView(active_contents(), second_view, | |
| 349 &second_view_type)); | |
| 350 } | 358 } |
| 351 | 359 |
| 352 // The following test loads a page with two child frames: one in process and one | 360 // The following test loads a page with two child frames: one in process and one |
| 353 // out of process with main frame. The test inserts an <input> inside each frame | 361 // out of process with main frame. The test inserts an <input> inside each frame |
| 354 // and focuses the first frame and observes the TextInputManager setting the | 362 // and focuses the first frame and observes the TextInputManager setting the |
| 355 // state to ui::TEXT_INPUT_TYPE_TEXT. Then, the frame is detached and the test | 363 // state to ui::TEXT_INPUT_TYPE_TEXT. Then, the frame is detached and the test |
| 356 // observes that the state type is reset to ui::TEXT_INPUT_TYPE_NONE. The same | 364 // observes that the state type is reset to ui::TEXT_INPUT_TYPE_NONE. The same |
| 357 // sequence of actions is then performed on the out of process frame. | 365 // sequence of actions is then performed on the out of process frame. |
| 358 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | 366 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| 359 ResetStateAfterFrameDetached) { | 367 ResetStateAfterFrameDetached) { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 EXPECT_FALSE(send_and_check_show_ime()); | 556 EXPECT_FALSE(send_and_check_show_ime()); |
| 549 | 557 |
| 550 // Set |TextInputState.show_ime_if_needed|. Expect IME. | 558 // Set |TextInputState.show_ime_if_needed|. Expect IME. |
| 551 sender.SetShowImeIfNeeded(true); | 559 sender.SetShowImeIfNeeded(true); |
| 552 EXPECT_TRUE(send_and_check_show_ime()); | 560 EXPECT_TRUE(send_and_check_show_ime()); |
| 553 | 561 |
| 554 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. | 562 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. |
| 555 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); | 563 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); |
| 556 EXPECT_FALSE(send_and_check_show_ime()); | 564 EXPECT_FALSE(send_and_check_show_ime()); |
| 557 } | 565 } |
| OLD | NEW |