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

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

Issue 2696883002: Fix a recent regression in IME inside OOPIFs (Merge to M-57) (Closed)
Patch Set: 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 OnSuccess(); 265 OnSuccess();
266 } 266 }
267 } 267 }
268 268
269 const content::RenderWidgetHostView* const expected_view_; 269 const content::RenderWidgetHostView* const expected_view_;
270 const size_t expected_length_; 270 const size_t expected_length_;
271 271
272 DISALLOW_COPY_AND_ASSIGN(ViewTextSelectionObserver); 272 DISALLOW_COPY_AND_ASSIGN(ViewTextSelectionObserver);
273 }; 273 };
274 274
275 // This class observes all the text selection updates within a WebContents.
276 class TextSelectionObserver : public TextInputManagerObserverBase {
277 public:
278 explicit TextSelectionObserver(content::WebContents* web_contents)
279 : TextInputManagerObserverBase(web_contents) {
280 tester()->SetOnTextSelectionChangedCallback(base::Bind(
281 &TextSelectionObserver::VerifyChange, base::Unretained(this)));
282 }
283
284 void WaitForSelectedText(const std::string& text) {
285 selected_text_ = text;
286 Wait();
287 }
288
289 private:
290 void VerifyChange() {
291 if (base::UTF16ToUTF8(tester()->GetUpdatedView()->GetSelectedText()) ==
292 selected_text_) {
293 OnSuccess();
294 }
295 }
296
297 std::string selected_text_;
298
299 DISALLOW_COPY_AND_ASSIGN(TextSelectionObserver);
300 };
301
275 // This class is used to verify the result of form field data requests. 302 // This class is used to verify the result of form field data requests.
276 class FormFieldDataVerifier { 303 class FormFieldDataVerifier {
277 public: 304 public:
278 FormFieldDataVerifier(const std::string& text, const std::string& placeholder) 305 FormFieldDataVerifier(const std::string& text, const std::string& placeholder)
279 : text_(text), placeholder_(placeholder), success_(false) {} 306 : text_(text), placeholder_(placeholder), success_(false) {}
280 307
281 void Verify(const content::FormFieldData& field) { 308 void Verify(const content::FormFieldData& field) {
282 ASSERT_EQ(field.text, text_); 309 ASSERT_EQ(field.text, text_);
283 ASSERT_EQ(field.placeholder, placeholder_); 310 ASSERT_EQ(field.placeholder, placeholder_);
284 OnSuccess(); 311 OnSuccess();
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 767
741 ViewCompositionRangeChangedObserver range_observer(web_contents, view); 768 ViewCompositionRangeChangedObserver range_observer(web_contents, view);
742 EXPECT_TRUE(content::RequestCompositionInfoFromActiveWidget(web_contents)); 769 EXPECT_TRUE(content::RequestCompositionInfoFromActiveWidget(web_contents));
743 range_observer.Wait(); 770 range_observer.Wait();
744 }; 771 };
745 772
746 for (auto* view : views) 773 for (auto* view : views)
747 send_tab_set_composition_wait_for_bounds_change(view); 774 send_tab_set_composition_wait_for_bounds_change(view);
748 } 775 }
749 776
777 // This test verifies that committing text works as expected for all the frames
778 // on the page. Specifically, the test sends an IPC to the RenderWidget
779 // corresponding to a focused frame with a focused <input> to commit some text.
780 // Then, it verifies that the <input>'s value matches the committed text
781 // (https://crbug.com/688842).
782 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
783 ImeCommitTextForAllFrames) {
784 CreateIframePage("a(b,c(a))");
785 std::vector<content::RenderFrameHost*> frames{
786 GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
787 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0})};
788 for (size_t i = 0; i < frames.size(); ++i)
789 AddInputFieldToFrame(frames[i], "text", "", true);
790
791 std::vector<std::string> sample_text{"main", "child_b", "child_c", "child_a"};
792 ASSERT_EQ(frames.size(), sample_text.size());
793
794 // An observer of all text selection updates within a WebContents.
795 TextSelectionObserver observer(active_contents());
796 for (size_t index = 0; index < frames.size(); ++index) {
797 // Focus the input and listen to 'input' event inside the frame. When the
798 // event fires, select all the text inside the input. This will trigger a
799 // selection update on the browser side.
800 ASSERT_TRUE(ExecuteScript(frames[index],
801 "window.focus();"
802 "var input = document.querySelector('input');"
803 "input.focus();"
804 "window.addEventListener('input', function(e) {"
805 " input.select();"
806 "});"))
807 << "Could not run script in frame with index:" << index;
808
809 // Commit some text for this frame.
810 content::SendImeCommitTextToWidget(
811 frames[index]->GetView()->GetRenderWidgetHost(),
812 base::UTF8ToUTF16(sample_text[index]),
813 std::vector<ui::CompositionUnderline>(), gfx::Range(), 0);
814
815 // Verify that the text we committed is now selected by listening to a
816 // selection update from a RenderWidgetHostView which has the expected
817 // selected text.
818 observer.WaitForSelectedText(sample_text[index]);
819 }
820 }
821
750 // TODO(ekaramad): Some of the following tests should be active on Android as 822 // TODO(ekaramad): Some of the following tests should be active on Android as
751 // well. Enable them when the corresponding feature is implemented for Android 823 // well. Enable them when the corresponding feature is implemented for Android
752 // (https://crbug.com/602723). 824 // (https://crbug.com/602723).
753 #if !defined(OS_ANDROID) 825 #if !defined(OS_ANDROID)
754 // This test creates a page with multiple child frames and adds an <input> to 826 // This test creates a page with multiple child frames and adds an <input> to
755 // each frame. Then, sequentially, each <input> is focused by sending a tab key. 827 // each frame. Then, sequentially, each <input> is focused by sending a tab key.
756 // Then, after |TextInputState.type| for a view is changed to text, another key 828 // Then, after |TextInputState.type| for a view is changed to text, another key
757 // is pressed (a character) and then the test verifies that TextInputManager 829 // is pressed (a character) and then the test verifies that TextInputManager
758 // receives the corresponding update on the change in selection bounds on the 830 // receives the corresponding update on the change in selection bounds on the
759 // browser side. 831 // browser side.
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 1419
1348 // Closing this WebContents while we still hold on to our TestBrowserClient. 1420 // Closing this WebContents while we still hold on to our TestBrowserClient.
1349 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt( 1421 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1350 1, TabStripModel::CLOSE_USER_GESTURE)); 1422 1, TabStripModel::CLOSE_USER_GESTURE));
1351 1423
1352 // For the cleanup of the original WebContents in tab index 0. 1424 // For the cleanup of the original WebContents in tab index 0.
1353 content::SetBrowserClientForTesting(old_browser_client); 1425 content::SetBrowserClientForTesting(old_browser_client);
1354 } 1426 }
1355 #endif // defined(MAC_OSX) 1427 #endif // defined(MAC_OSX)
1356 #endif // !defined(OS_ANDROID) 1428 #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