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

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

Issue 2122023002: Cross-process frames should be notified of device scale factor changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Version of patch without second test. 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
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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 OverscrollMode completed_mode_; 158 OverscrollMode completed_mode_;
159 float delta_x_; 159 float delta_x_;
160 float delta_y_; 160 float delta_y_;
161 161
162 DISALLOW_COPY_AND_ASSIGN(TestOverscrollDelegate); 162 DISALLOW_COPY_AND_ASSIGN(TestOverscrollDelegate);
163 }; 163 };
164 164
165 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { 165 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate {
166 public: 166 public:
167 MockRenderWidgetHostDelegate() 167 MockRenderWidgetHostDelegate()
168 : rwh_(nullptr), is_fullscreen_(false), focused_widget_(nullptr) {} 168 : rwh_(nullptr),
169 is_fullscreen_(false),
170 focused_widget_(nullptr),
171 last_device_scale_factor_(0.0) {}
169 ~MockRenderWidgetHostDelegate() override {} 172 ~MockRenderWidgetHostDelegate() override {}
170 const NativeWebKeyboardEvent* last_event() const { return last_event_.get(); } 173 const NativeWebKeyboardEvent* last_event() const { return last_event_.get(); }
171 void set_widget_host(RenderWidgetHostImpl* rwh) { rwh_ = rwh; } 174 void set_widget_host(RenderWidgetHostImpl* rwh) { rwh_ = rwh; }
172 void set_is_fullscreen(bool is_fullscreen) { is_fullscreen_ = is_fullscreen; } 175 void set_is_fullscreen(bool is_fullscreen) { is_fullscreen_ = is_fullscreen; }
173 TextInputManager* GetTextInputManager() override { 176 TextInputManager* GetTextInputManager() override {
174 return &text_input_manager_; 177 return &text_input_manager_;
175 } 178 }
176 RenderWidgetHostImpl* GetFocusedRenderWidgetHost( 179 RenderWidgetHostImpl* GetFocusedRenderWidgetHost(
177 RenderWidgetHostImpl* widget_host) override { 180 RenderWidgetHostImpl* widget_host) override {
178 return !!focused_widget_ ? focused_widget_ : widget_host; 181 return !!focused_widget_ ? focused_widget_ : widget_host;
179 } 182 }
180 void set_focused_widget(RenderWidgetHostImpl* focused_widget) { 183 void set_focused_widget(RenderWidgetHostImpl* focused_widget) {
181 focused_widget_ = focused_widget; 184 focused_widget_ = focused_widget;
182 } 185 }
183 186
187 double get_last_device_scale_factor() { return last_device_scale_factor_; }
188 void UpdateDeviceScaleFactor(double device_scale_factor) override {
189 last_device_scale_factor_ = device_scale_factor;
190 }
191
184 protected: 192 protected:
185 // RenderWidgetHostDelegate: 193 // RenderWidgetHostDelegate:
186 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, 194 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
187 bool* is_keyboard_shortcut) override { 195 bool* is_keyboard_shortcut) override {
188 last_event_.reset(new NativeWebKeyboardEvent(event)); 196 last_event_.reset(new NativeWebKeyboardEvent(event));
189 return true; 197 return true;
190 } 198 }
191 void Cut() override {} 199 void Cut() override {}
192 void Copy() override {} 200 void Copy() override {}
193 void Paste() override {} 201 void Paste() override {}
194 void SelectAll() override {} 202 void SelectAll() override {}
195 void SendScreenRects() override { 203 void SendScreenRects() override {
196 if (rwh_) 204 if (rwh_)
197 rwh_->SendScreenRects(); 205 rwh_->SendScreenRects();
198 } 206 }
199 bool IsFullscreenForCurrentTab() const override { return is_fullscreen_; } 207 bool IsFullscreenForCurrentTab() const override { return is_fullscreen_; }
200 208
201 private: 209 private:
202 std::unique_ptr<NativeWebKeyboardEvent> last_event_; 210 std::unique_ptr<NativeWebKeyboardEvent> last_event_;
203 RenderWidgetHostImpl* rwh_; 211 RenderWidgetHostImpl* rwh_;
204 bool is_fullscreen_; 212 bool is_fullscreen_;
205 TextInputManager text_input_manager_; 213 TextInputManager text_input_manager_;
206 RenderWidgetHostImpl* focused_widget_; 214 RenderWidgetHostImpl* focused_widget_;
215 double last_device_scale_factor_;
207 216
208 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHostDelegate); 217 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHostDelegate);
209 }; 218 };
210 219
211 // Simple observer that keeps track of changes to a window for tests. 220 // Simple observer that keeps track of changes to a window for tests.
212 class TestWindowObserver : public aura::WindowObserver { 221 class TestWindowObserver : public aura::WindowObserver {
213 public: 222 public:
214 explicit TestWindowObserver(aura::Window* window_to_observe) 223 explicit TestWindowObserver(aura::Window* window_to_observe)
215 : window_(window_to_observe) { 224 : window_(window_to_observe) {
216 window_->AddObserver(this); 225 window_->AddObserver(this);
(...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 "100x100", 1465 "100x100",
1457 std::get<0>(params).physical_backing_size.ToString()); // backing size 1466 std::get<0>(params).physical_backing_size.ToString()); // backing size
1458 } 1467 }
1459 1468
1460 widget_host_->ResetSizeAndRepaintPendingFlags(); 1469 widget_host_->ResetSizeAndRepaintPendingFlags();
1461 sink_->ClearMessages(); 1470 sink_->ClearMessages();
1462 1471
1463 aura_test_helper_->test_screen()->SetDeviceScaleFactor(2.0f); 1472 aura_test_helper_->test_screen()->SetDeviceScaleFactor(2.0f);
1464 EXPECT_EQ("200x200", view_->GetPhysicalBackingSize().ToString()); 1473 EXPECT_EQ("200x200", view_->GetPhysicalBackingSize().ToString());
1465 // Extra ScreenInfoChanged message for |parent_view_|. 1474 // Extra ScreenInfoChanged message for |parent_view_|.
1466 EXPECT_EQ(1u, sink_->message_count()); 1475 EXPECT_EQ(0u, sink_->message_count());
1467 { 1476 auto view_delegate = static_cast<MockRenderWidgetHostDelegate*>(
1468 const IPC::Message* msg = sink_->GetMessageAt(0); 1477 static_cast<RenderWidgetHostImpl*>(view_->GetRenderWidgetHost())
1469 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); 1478 ->delegate());
1470 ViewMsg_Resize::Param params; 1479 EXPECT_EQ(2.0f, view_delegate->get_last_device_scale_factor());
1471 ViewMsg_Resize::Read(msg, &params);
1472 EXPECT_EQ(2.0f, std::get<0>(params).screen_info.deviceScaleFactor);
1473 EXPECT_EQ("100x100", std::get<0>(params).new_size.ToString()); // dip size
1474 EXPECT_EQ(
1475 "200x200",
1476 std::get<0>(params).physical_backing_size.ToString()); // backing size
1477 }
1478 1480
1479 widget_host_->ResetSizeAndRepaintPendingFlags(); 1481 widget_host_->ResetSizeAndRepaintPendingFlags();
1480 sink_->ClearMessages(); 1482 sink_->ClearMessages();
1481 1483
1482 aura_test_helper_->test_screen()->SetDeviceScaleFactor(1.0f); 1484 aura_test_helper_->test_screen()->SetDeviceScaleFactor(1.0f);
1483 // Extra ScreenInfoChanged message for |parent_view_|. 1485 // Extra ScreenInfoChanged message for |parent_view_|.
1484 EXPECT_EQ(1u, sink_->message_count()); 1486 EXPECT_EQ(0u, sink_->message_count());
1487 EXPECT_EQ(1.0f, view_delegate->get_last_device_scale_factor());
1485 EXPECT_EQ("100x100", view_->GetPhysicalBackingSize().ToString()); 1488 EXPECT_EQ("100x100", view_->GetPhysicalBackingSize().ToString());
1486 {
1487 const IPC::Message* msg = sink_->GetMessageAt(0);
1488 EXPECT_EQ(ViewMsg_Resize::ID, msg->type());
1489 ViewMsg_Resize::Param params;
1490 ViewMsg_Resize::Read(msg, &params);
1491 EXPECT_EQ(1.0f, std::get<0>(params).screen_info.deviceScaleFactor);
1492 EXPECT_EQ("100x100", std::get<0>(params).new_size.ToString()); // dip size
1493 EXPECT_EQ(
1494 "100x100",
1495 std::get<0>(params).physical_backing_size.ToString()); // backing size
1496 }
1497 } 1489 }
1498 1490
1499 // Checks that InputMsg_CursorVisibilityChange IPC messages are dispatched 1491 // Checks that InputMsg_CursorVisibilityChange IPC messages are dispatched
1500 // to the renderer at the correct times. 1492 // to the renderer at the correct times.
1501 TEST_F(RenderWidgetHostViewAuraTest, CursorVisibilityChange) { 1493 TEST_F(RenderWidgetHostViewAuraTest, CursorVisibilityChange) {
1502 view_->InitAsChild(nullptr); 1494 view_->InitAsChild(nullptr);
1503 aura::client::ParentWindowWithContext( 1495 aura::client::ParentWindowWithContext(
1504 view_->GetNativeView(), 1496 view_->GetNativeView(),
1505 parent_view_->GetNativeView()->GetRootWindow(), 1497 parent_view_->GetNativeView()->GetRootWindow(),
1506 gfx::Rect()); 1498 gfx::Rect());
(...skipping 3071 matching lines...) Expand 10 before | Expand all | Expand 10 after
4578 4570
4579 // Retrieve the selected text from clipboard and verify it is as expected. 4571 // Retrieve the selected text from clipboard and verify it is as expected.
4580 base::string16 result_text; 4572 base::string16 result_text;
4581 clipboard->ReadText(ui::CLIPBOARD_TYPE_SELECTION, &result_text); 4573 clipboard->ReadText(ui::CLIPBOARD_TYPE_SELECTION, &result_text);
4582 EXPECT_EQ(expected_text, result_text); 4574 EXPECT_EQ(expected_text, result_text);
4583 } 4575 }
4584 } 4576 }
4585 #endif 4577 #endif
4586 4578
4587 } // namespace content 4579 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698