Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: chrome/browser/renderer_host/site_per_process_text_input_browsertest.cc

Issue 2681473002: Fix a recent regression in IME inside OOPIFs (Closed)
Patch Set: Resolved Merge Conflict Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/public/test/text_input_test_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_) {
292 OnSuccess();
293 }
294 }
295
296 std::string selected_text_;
297
298 DISALLOW_COPY_AND_ASSIGN(TextSelectionObserver);
299 };
300
274 // This class is used to verify the result of form field data requests. 301 // This class is used to verify the result of form field data requests.
275 class FormFieldDataVerifier { 302 class FormFieldDataVerifier {
276 public: 303 public:
277 FormFieldDataVerifier(const std::string& text, const std::string& placeholder) 304 FormFieldDataVerifier(const std::string& text, const std::string& placeholder)
278 : text_(text), placeholder_(placeholder), success_(false) {} 305 : text_(text), placeholder_(placeholder), success_(false) {}
279 306
280 void Verify(const content::FormFieldData& field) { 307 void Verify(const content::FormFieldData& field) {
281 ASSERT_EQ(field.text, text_); 308 ASSERT_EQ(field.text, text_);
282 ASSERT_EQ(field.placeholder, placeholder_); 309 ASSERT_EQ(field.placeholder, placeholder_);
283 OnSuccess(); 310 OnSuccess();
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 for (size_t i = 0; i < views.size(); ++i) { 812 for (size_t i = 0; i < views.size(); ++i) {
786 // First focus the <input>. 813 // First focus the <input>.
787 send_tab_and_wait_for_value(values[i]); 814 send_tab_and_wait_for_value(values[i]);
788 815
789 // Send a sequence of |count| 'E' keys and wait until the view receives a 816 // 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|. 817 // selection change update for a text of the corresponding size, |count|.
791 send_keys_select_all_wait_for_selection_change(views[i], count++); 818 send_keys_select_all_wait_for_selection_change(views[i], count++);
792 } 819 }
793 } 820 }
794 821
822 // This test verifies that committing text works as expected for all the frames
823 // on the page. Specifically, the test sends an IPC to the RenderWidget
824 // corresponding to a focused frame with a focused <input> to commit some text.
825 // Then, it verifies that the <input>'s value matches the committed text
826 // (https://crbug.com/688842).
827 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
828 ImeCommitTextForAllFrames) {
829 CreateIframePage("a(b,c(a))");
830 std::vector<content::RenderFrameHost*> frames{
831 GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
832 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0})};
833 for (size_t i = 0; i < frames.size(); ++i)
834 AddInputFieldToFrame(frames[i], "text", "", true);
835
836 std::vector<std::string> sample_text{"main", "child_b", "child_c", "child_a"};
837 ASSERT_EQ(frames.size(), sample_text.size());
838
839 // An observer of all text selection updates within a WebContents.
840 TextSelectionObserver observer(active_contents());
841 for (size_t index = 0; index < frames.size(); ++index) {
842 // Focus the input and listen to 'input' event inside the frame. When the
843 // event fires, select all the text inside the input. This will trigger a
844 // selection update on the browser side.
845 ASSERT_TRUE(ExecuteScript(frames[index],
846 "window.focus();"
847 "var input = document.querySelector('input');"
848 "input.focus();"
849 "window.addEventListener('input', function(e) {"
850 " input.select();"
851 "});"))
852 << "Could not run script in frame with index:" << index;
853
854 // Commit some text for this frame.
855 content::SendImeCommitTextToWidget(
856 frames[index]->GetView()->GetRenderWidgetHost(),
857 base::UTF8ToUTF16(sample_text[index]),
858 std::vector<ui::CompositionUnderline>(), gfx::Range(), 0);
859
860 // Verify that the text we committed is now selected by listening to a
861 // selection update from a RenderWidgetHostView which has the expected
862 // selected text.
863 observer.WaitForSelectedText(sample_text[index]);
864 }
865 }
866
795 // TODO(ekaramad): Some of the following tests should be active on Android as 867 // 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 868 // well. Enable them when the corresponding feature is implemented for Android
797 // (https://crbug.com/602723). 869 // (https://crbug.com/602723).
798 #if !defined(OS_ANDROID) 870 #if !defined(OS_ANDROID)
799 // This test creates a page with multiple child frames and adds an <input> to 871 // 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. 872 // 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 873 // 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 874 // is pressed (a character) and then the test verifies that TextInputManager
803 // receives the corresponding update on the change in selection bounds on the 875 // receives the corresponding update on the change in selection bounds on the
804 // browser side. 876 // browser side.
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 1426
1355 // Closing this WebContents while we still hold on to our TestBrowserClient. 1427 // Closing this WebContents while we still hold on to our TestBrowserClient.
1356 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt( 1428 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1357 1, TabStripModel::CLOSE_USER_GESTURE)); 1429 1, TabStripModel::CLOSE_USER_GESTURE));
1358 1430
1359 // For the cleanup of the original WebContents in tab index 0. 1431 // For the cleanup of the original WebContents in tab index 0.
1360 content::SetBrowserClientForTesting(old_browser_client); 1432 content::SetBrowserClientForTesting(old_browser_client);
1361 } 1433 }
1362 #endif // defined(MAC_OSX) 1434 #endif // defined(MAC_OSX)
1363 #endif // !defined(OS_ANDROID) 1435 #endif // !defined(OS_ANDROID)
OLDNEW
« no previous file with comments | « no previous file | content/public/test/text_input_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698