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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_aura_unittest.cc

Issue 2208093004: Use focused RenderWidgetHostImpl instead of TextInputManager::GetActiveWidget() to obtain TextSelec… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing kenrb@'s comments Created 4 years, 4 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 | « content/browser/renderer_host/render_widget_host_view_aura.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_view_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <tuple> 10 #include <tuple>
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 #include "ui/aura/env.h" 69 #include "ui/aura/env.h"
70 #include "ui/aura/layout_manager.h" 70 #include "ui/aura/layout_manager.h"
71 #include "ui/aura/test/aura_test_helper.h" 71 #include "ui/aura/test/aura_test_helper.h"
72 #include "ui/aura/test/aura_test_utils.h" 72 #include "ui/aura/test/aura_test_utils.h"
73 #include "ui/aura/test/test_cursor_client.h" 73 #include "ui/aura/test/test_cursor_client.h"
74 #include "ui/aura/test/test_screen.h" 74 #include "ui/aura/test/test_screen.h"
75 #include "ui/aura/test/test_window_delegate.h" 75 #include "ui/aura/test/test_window_delegate.h"
76 #include "ui/aura/window.h" 76 #include "ui/aura/window.h"
77 #include "ui/aura/window_event_dispatcher.h" 77 #include "ui/aura/window_event_dispatcher.h"
78 #include "ui/aura/window_observer.h" 78 #include "ui/aura/window_observer.h"
79 #include "ui/base/clipboard/clipboard.h"
79 #include "ui/base/ui_base_types.h" 80 #include "ui/base/ui_base_types.h"
80 #include "ui/compositor/compositor.h" 81 #include "ui/compositor/compositor.h"
81 #include "ui/compositor/layer_tree_owner.h" 82 #include "ui/compositor/layer_tree_owner.h"
82 #include "ui/compositor/test/draw_waiter_for_test.h" 83 #include "ui/compositor/test/draw_waiter_for_test.h"
83 #include "ui/events/blink/blink_event_util.h" 84 #include "ui/events/blink/blink_event_util.h"
84 #include "ui/events/event.h" 85 #include "ui/events/event.h"
85 #include "ui/events/event_utils.h" 86 #include "ui/events/event_utils.h"
86 #include "ui/events/gesture_detection/gesture_configuration.h" 87 #include "ui/events/gesture_detection/gesture_configuration.h"
87 #include "ui/events/keycodes/dom/dom_code.h" 88 #include "ui/events/keycodes/dom/dom_code.h"
88 #include "ui/events/keycodes/dom/keycode_converter.h" 89 #include "ui/events/keycodes/dom/keycode_converter.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 OverscrollMode current_mode_; 157 OverscrollMode current_mode_;
157 OverscrollMode completed_mode_; 158 OverscrollMode completed_mode_;
158 float delta_x_; 159 float delta_x_;
159 float delta_y_; 160 float delta_y_;
160 161
161 DISALLOW_COPY_AND_ASSIGN(TestOverscrollDelegate); 162 DISALLOW_COPY_AND_ASSIGN(TestOverscrollDelegate);
162 }; 163 };
163 164
164 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { 165 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate {
165 public: 166 public:
166 MockRenderWidgetHostDelegate() : rwh_(nullptr), is_fullscreen_(false) {} 167 MockRenderWidgetHostDelegate()
168 : rwh_(nullptr), is_fullscreen_(false), focused_widget_(nullptr) {}
167 ~MockRenderWidgetHostDelegate() override {} 169 ~MockRenderWidgetHostDelegate() override {}
168 const NativeWebKeyboardEvent* last_event() const { return last_event_.get(); } 170 const NativeWebKeyboardEvent* last_event() const { return last_event_.get(); }
169 void set_widget_host(RenderWidgetHostImpl* rwh) { rwh_ = rwh; } 171 void set_widget_host(RenderWidgetHostImpl* rwh) { rwh_ = rwh; }
170 void set_is_fullscreen(bool is_fullscreen) { is_fullscreen_ = is_fullscreen; } 172 void set_is_fullscreen(bool is_fullscreen) { is_fullscreen_ = is_fullscreen; }
171 TextInputManager* GetTextInputManager() override { 173 TextInputManager* GetTextInputManager() override {
172 return &text_input_manager_; 174 return &text_input_manager_;
173 } 175 }
176 RenderWidgetHostImpl* GetFocusedRenderWidgetHost(
177 RenderWidgetHostImpl* widget_host) override {
178 return !!focused_widget_ ? focused_widget_ : widget_host;
179 }
180 void set_focused_widget(RenderWidgetHostImpl* focused_widget) {
181 focused_widget_ = focused_widget;
182 }
174 183
175 protected: 184 protected:
176 // RenderWidgetHostDelegate: 185 // RenderWidgetHostDelegate:
177 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, 186 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
178 bool* is_keyboard_shortcut) override { 187 bool* is_keyboard_shortcut) override {
179 last_event_.reset(new NativeWebKeyboardEvent(event)); 188 last_event_.reset(new NativeWebKeyboardEvent(event));
180 return true; 189 return true;
181 } 190 }
182 void Cut() override {} 191 void Cut() override {}
183 void Copy() override {} 192 void Copy() override {}
184 void Paste() override {} 193 void Paste() override {}
185 void SelectAll() override {} 194 void SelectAll() override {}
186 void SendScreenRects() override { 195 void SendScreenRects() override {
187 if (rwh_) 196 if (rwh_)
188 rwh_->SendScreenRects(); 197 rwh_->SendScreenRects();
189 } 198 }
190 bool IsFullscreenForCurrentTab() const override { return is_fullscreen_; } 199 bool IsFullscreenForCurrentTab() const override { return is_fullscreen_; }
191 200
192 private: 201 private:
193 std::unique_ptr<NativeWebKeyboardEvent> last_event_; 202 std::unique_ptr<NativeWebKeyboardEvent> last_event_;
194 RenderWidgetHostImpl* rwh_; 203 RenderWidgetHostImpl* rwh_;
195 bool is_fullscreen_; 204 bool is_fullscreen_;
196 TextInputManager text_input_manager_; 205 TextInputManager text_input_manager_;
206 RenderWidgetHostImpl* focused_widget_;
197 207
198 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHostDelegate); 208 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHostDelegate);
199 }; 209 };
200 210
201 // Simple observer that keeps track of changes to a window for tests. 211 // Simple observer that keeps track of changes to a window for tests.
202 class TestWindowObserver : public aura::WindowObserver { 212 class TestWindowObserver : public aura::WindowObserver {
203 public: 213 public:
204 explicit TestWindowObserver(aura::Window* window_to_observe) 214 explicit TestWindowObserver(aura::Window* window_to_observe)
205 : window_(window_to_observe) { 215 : window_(window_to_observe) {
206 window_->AddObserver(this); 216 window_->AddObserver(this);
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 WebInputEventTraits::GetUniqueTouchEventId(*event)); 571 WebInputEventTraits::GetUniqueTouchEventId(*event));
562 } 572 }
563 573
564 const ui::MotionEventAura& pointer_state() { 574 const ui::MotionEventAura& pointer_state() {
565 return view_->pointer_state_for_test(); 575 return view_->pointer_state_for_test();
566 } 576 }
567 577
568 protected: 578 protected:
569 BrowserContext* browser_context() { return browser_context_.get(); } 579 BrowserContext* browser_context() { return browser_context_.get(); }
570 580
581 MockRenderWidgetHostDelegate* render_widget_host_delegate() const {
582 return delegates_.back().get();
583 }
584
571 // Sets the |view| active in TextInputManager with the given |type|. |type| 585 // Sets the |view| active in TextInputManager with the given |type|. |type|
572 // cannot be ui::TEXT_INPUT_TYPE_NONE. 586 // cannot be ui::TEXT_INPUT_TYPE_NONE.
587 // Must not be called in the destruction path of |view|.
573 void ActivateViewForTextInputManager(RenderWidgetHostViewBase* view, 588 void ActivateViewForTextInputManager(RenderWidgetHostViewBase* view,
574 ui::TextInputType type) { 589 ui::TextInputType type) {
575 DCHECK_NE(ui::TEXT_INPUT_TYPE_NONE, type); 590 DCHECK_NE(ui::TEXT_INPUT_TYPE_NONE, type);
591 // First mock-focus the widget if not already.
592 if (render_widget_host_delegate()->GetFocusedRenderWidgetHost(
593 widget_host_) != view->GetRenderWidgetHost()) {
594 render_widget_host_delegate()->set_focused_widget(
595 RenderWidgetHostImpl::From(view->GetRenderWidgetHost()));
596 }
597
576 TextInputManager* manager = 598 TextInputManager* manager =
577 static_cast<RenderWidgetHostImpl*>(view->GetRenderWidgetHost()) 599 static_cast<RenderWidgetHostImpl*>(view->GetRenderWidgetHost())
578 ->delegate() 600 ->delegate()
579 ->GetTextInputManager(); 601 ->GetTextInputManager();
580 if (manager->GetActiveWidget()) { 602 if (manager->GetActiveWidget()) {
581 manager->active_view_for_testing()->TextInputStateChanged( 603 manager->active_view_for_testing()->TextInputStateChanged(
582 TextInputState()); 604 TextInputState());
583 } 605 }
584 606
585 if (!view) 607 if (!view)
(...skipping 3640 matching lines...) Expand 10 before | Expand all | Expand 10 after
4226 4248
4227 RenderWidgetHost* widget_for_third_process = 4249 RenderWidgetHost* widget_for_third_process =
4228 view_for_third_process_->GetRenderWidgetHost(); 4250 view_for_third_process_->GetRenderWidgetHost();
4229 view_for_third_process_->Destroy(); 4251 view_for_third_process_->Destroy();
4230 delete widget_for_third_process; 4252 delete widget_for_third_process;
4231 4253
4232 RenderWidgetHostViewAuraTest::TearDown(); 4254 RenderWidgetHostViewAuraTest::TearDown();
4233 } 4255 }
4234 4256
4235 protected: 4257 protected:
4236 MockRenderWidgetHostDelegate* render_widget_host_delegate() const {
4237 return delegates_.back().get();
4238 }
4239
4240 ui::TextInputClient* text_input_client() const { return view_; } 4258 ui::TextInputClient* text_input_client() const { return view_; }
4241 4259
4242 bool has_composition_text() const { 4260 bool has_composition_text() const {
4243 return tab_view()->has_composition_text_; 4261 return tab_view()->has_composition_text_;
4244 } 4262 }
4245 4263
4246 MockRenderProcessHost* CreateNewProcessHost() { 4264 MockRenderProcessHost* CreateNewProcessHost() {
4247 MockRenderProcessHost* process_host = 4265 MockRenderProcessHost* process_host =
4248 new MockRenderProcessHost(browser_context()); 4266 new MockRenderProcessHost(browser_context());
4249 return process_host; 4267 return process_host;
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
4532 // This method always returns true. 4550 // This method always returns true.
4533 EXPECT_TRUE(text_input_client()->GetSelectionRange(&range_from_client)); 4551 EXPECT_TRUE(text_input_client()->GetSelectionRange(&range_from_client));
4534 EXPECT_EQ(expected_range, range_from_client); 4552 EXPECT_EQ(expected_range, range_from_client);
4535 4553
4536 // Changing range to make sure that the next view has a different text 4554 // Changing range to make sure that the next view has a different text
4537 // selection. 4555 // selection.
4538 expected_range.set_end(expected_range.end() + 1U); 4556 expected_range.set_end(expected_range.end() + 1U);
4539 } 4557 }
4540 } 4558 }
4541 4559
4560 #if defined(USE_X11) && !defined(OS_CHROMEOS)
4561 // This test will verify that after selection, the selected text is written to
4562 // the clipboard from the focused widget.
4563 TEST_F(InputMethodStateAuraTest, SelectedTextCopiedToClipboard) {
4564 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
4565 EXPECT_TRUE(!!clipboard);
4566 std::vector<std::string> texts = {"text0", "text1", "text2", "text3"};
4567 for (auto index : active_view_sequence_) {
4568 clipboard->Clear(ui::CLIPBOARD_TYPE_SELECTION);
4569
4570 // Focus the corresponding widget.
4571 render_widget_host_delegate()->set_focused_widget(
4572 RenderWidgetHostImpl::From(views_[index]->GetRenderWidgetHost()));
4573
4574 // Change the selection of the currently focused widget. It suffices to just
4575 // call the method on the view.
4576 base::string16 expected_text = base::ASCIIToUTF16(texts[index]);
4577 views_[index]->SelectionChanged(expected_text, 0U, gfx::Range(0, 5));
4578
4579 // Retrieve the selected text from clipboard and verify it is as expected.
4580 base::string16 result_text;
4581 clipboard->ReadText(ui::CLIPBOARD_TYPE_SELECTION, &result_text);
4582 EXPECT_EQ(expected_text, result_text);
4583 }
4584 }
4585 #endif
4586
4542 } // namespace content 4587 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698