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/chrome_content_browser_client.h" | 9 #include "chrome/browser/chrome_content_browser_client.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 OnSuccess(); | 264 OnSuccess(); |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 | 267 |
| 268 const content::RenderWidgetHostView* const expected_view_; | 268 const content::RenderWidgetHostView* const expected_view_; |
| 269 const size_t expected_length_; | 269 const size_t expected_length_; |
| 270 | 270 |
| 271 DISALLOW_COPY_AND_ASSIGN(ViewTextSelectionObserver); | 271 DISALLOW_COPY_AND_ASSIGN(ViewTextSelectionObserver); |
| 272 }; | 272 }; |
| 273 | 273 |
| 274 // This class observes all the text selection updates within a WebContents. | |
| 275 class TextSelectionObserver : public TextInputManagerObserverBase { | |
| 276 public: | |
| 277 explicit TextSelectionObserver(content::WebContents* web_contents) | |
| 278 : TextInputManagerObserverBase(web_contents) { | |
| 279 tester()->SetOnTextSelectionChangedCallback(base::Bind( | |
| 280 &TextSelectionObserver::VerifyChange, base::Unretained(this))); | |
| 281 } | |
| 282 | |
| 283 void WaitForSelectedText(const std::string& text) { | |
| 284 selected_text_ = text; | |
| 285 Wait(); | |
| 286 } | |
| 287 | |
| 288 private: | |
| 289 void VerifyChange() { | |
| 290 if (base::UTF16ToUTF8(tester()->GetUpdatedView()->GetSelectedText()) == | |
| 291 selected_text_) | |
|
sky
2017/02/09 17:18:37
{} (as conditional spans multiple-lines)
EhsanK
2017/02/09 22:03:48
Done.
| |
| 292 OnSuccess(); | |
| 293 } | |
| 294 | |
| 295 std::string selected_text_; | |
| 296 | |
| 297 DISALLOW_COPY_AND_ASSIGN(TextSelectionObserver); | |
| 298 }; | |
| 299 | |
| 274 // This class is used to verify the result of form field data requests. | 300 // This class is used to verify the result of form field data requests. |
| 275 class FormFieldDataVerifier { | 301 class FormFieldDataVerifier { |
| 276 public: | 302 public: |
| 277 FormFieldDataVerifier(const std::string& text, const std::string& placeholder) | 303 FormFieldDataVerifier(const std::string& text, const std::string& placeholder) |
| 278 : text_(text), placeholder_(placeholder), success_(false) {} | 304 : text_(text), placeholder_(placeholder), success_(false) {} |
| 279 | 305 |
| 280 void Verify(const content::FormFieldData& field) { | 306 void Verify(const content::FormFieldData& field) { |
| 281 ASSERT_EQ(field.text, text_); | 307 ASSERT_EQ(field.text, text_); |
| 282 ASSERT_EQ(field.placeholder, placeholder_); | 308 ASSERT_EQ(field.placeholder, placeholder_); |
| 283 OnSuccess(); | 309 OnSuccess(); |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 785 for (size_t i = 0; i < views.size(); ++i) { | 811 for (size_t i = 0; i < views.size(); ++i) { |
| 786 // First focus the <input>. | 812 // First focus the <input>. |
| 787 send_tab_and_wait_for_value(values[i]); | 813 send_tab_and_wait_for_value(values[i]); |
| 788 | 814 |
| 789 // Send a sequence of |count| 'E' keys and wait until the view receives a | 815 // Send a sequence of |count| 'E' keys and wait until the view receives a |
| 790 // selection change update for a text of the corresponding size, |count|. | 816 // selection change update for a text of the corresponding size, |count|. |
| 791 send_keys_select_all_wait_for_selection_change(views[i], count++); | 817 send_keys_select_all_wait_for_selection_change(views[i], count++); |
| 792 } | 818 } |
| 793 } | 819 } |
| 794 | 820 |
| 821 // This test verifies that committing text works as expected for all the frames | |
| 822 // on the page. Specifically, the test sends an IPC to the RenderWidget | |
| 823 // corresponding to a focused frame with a focused <input> to commit some text. | |
| 824 // Then, it verifies that the <input>'s value matches the committed text | |
| 825 // (https://crbug.com/688842). | |
| 826 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | |
| 827 ImeCommitTextForAllFrames) { | |
| 828 CreateIframePage("a(b,c(a))"); | |
| 829 std::vector<content::RenderFrameHost*> frames{ | |
| 830 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), | |
| 831 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0})}; | |
| 832 for (size_t i = 0; i < frames.size(); ++i) | |
| 833 AddInputFieldToFrame(frames[i], "text", "", true); | |
| 834 | |
| 835 std::vector<std::string> sample_text{"main", "child_b", "child_c", "child_a"}; | |
| 836 ASSERT_EQ(frames.size(), sample_text.size()); | |
| 837 | |
| 838 // An observer of all text selection updates within a WebContents. | |
| 839 TextSelectionObserver observer(active_contents()); | |
| 840 for (size_t index = 0; index < frames.size(); ++index) { | |
| 841 // Focus the input and listen to 'input' event inside the frame. When the | |
| 842 // event fires, select all the text inside the input. This will trigger a | |
| 843 // selection update on the browser side. | |
| 844 ASSERT_TRUE(ExecuteScript(frames[index], | |
| 845 "window.focus();" | |
| 846 "var input = document.querySelector('input');" | |
| 847 "input.focus();" | |
| 848 "window.addEventListener('input', function(e) {" | |
| 849 " input.select();" | |
| 850 "});")) | |
| 851 << "Could not run script in frame with index:" << index; | |
| 852 | |
| 853 // Commit some text for this frame. | |
| 854 content::SendImeCommitTextToWidget( | |
| 855 frames[index]->GetView()->GetRenderWidgetHost(), | |
| 856 base::UTF8ToUTF16(sample_text[index]), | |
| 857 std::vector<ui::CompositionUnderline>(), gfx::Range(), 0); | |
| 858 | |
| 859 // Verify that the text we committed is now selected by listening to a | |
| 860 // selection update from a RenderWidgetHostView which has the expected | |
| 861 // selected text. | |
| 862 observer.WaitForSelectedText(sample_text[index]); | |
| 863 } | |
| 864 } | |
| 865 | |
| 795 // TODO(ekaramad): Some of the following tests should be active on Android as | 866 // TODO(ekaramad): Some of the following tests should be active on Android as |
| 796 // well. Enable them when the corresponding feature is implemented for Android | 867 // well. Enable them when the corresponding feature is implemented for Android |
| 797 // (https://crbug.com/602723). | 868 // (https://crbug.com/602723). |
| 798 #if !defined(OS_ANDROID) | 869 #if !defined(OS_ANDROID) |
| 799 // This test creates a page with multiple child frames and adds an <input> to | 870 // This test creates a page with multiple child frames and adds an <input> to |
| 800 // each frame. Then, sequentially, each <input> is focused by sending a tab key. | 871 // each frame. Then, sequentially, each <input> is focused by sending a tab key. |
| 801 // Then, after |TextInputState.type| for a view is changed to text, another key | 872 // Then, after |TextInputState.type| for a view is changed to text, another key |
| 802 // is pressed (a character) and then the test verifies that TextInputManager | 873 // is pressed (a character) and then the test verifies that TextInputManager |
| 803 // receives the corresponding update on the change in selection bounds on the | 874 // receives the corresponding update on the change in selection bounds on the |
| 804 // browser side. | 875 // browser side. |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1354 | 1425 |
| 1355 // Closing this WebContents while we still hold on to our TestBrowserClient. | 1426 // Closing this WebContents while we still hold on to our TestBrowserClient. |
| 1356 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt( | 1427 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt( |
| 1357 1, TabStripModel::CLOSE_USER_GESTURE)); | 1428 1, TabStripModel::CLOSE_USER_GESTURE)); |
| 1358 | 1429 |
| 1359 // For the cleanup of the original WebContents in tab index 0. | 1430 // For the cleanup of the original WebContents in tab index 0. |
| 1360 content::SetBrowserClientForTesting(old_browser_client); | 1431 content::SetBrowserClientForTesting(old_browser_client); |
| 1361 } | 1432 } |
| 1362 #endif // defined(MAC_OSX) | 1433 #endif // defined(MAC_OSX) |
| 1363 #endif // !defined(OS_ANDROID) | 1434 #endif // !defined(OS_ANDROID) |
| OLD | NEW |