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

Unified Diff: ui/views/widget/widget_unittest.cc

Issue 1533883002: MacViews: Implement BridgedNativeWidget::OnDeviceScaleFactorChanged function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review remarks. Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/cocoa/bridged_native_widget.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/widget/widget_unittest.cc
diff --git a/ui/views/widget/widget_unittest.cc b/ui/views/widget/widget_unittest.cc
index 5bb82e6943d7910cdb4259df78913c24d080e51e..db8b112fd28889bade347cfc1a00ae74e7b2ed6f 100644
--- a/ui/views/widget/widget_unittest.cc
+++ b/ui/views/widget/widget_unittest.cc
@@ -3398,5 +3398,51 @@ TEST_F(WidgetTest, AlwaysOnTop) {
widget->CloseNow();
}
+namespace {
+
+class ScaleFactorView : public View {
+ public:
+ ScaleFactorView() = default;
sadrul 2015/12/22 08:13:34 How is this different from 'ScaleFactorView() {}'?
Andrey Kraynov 2015/12/22 08:38:57 Both forms of ctor will behave the same here. But
+
+ // Overridden from ui::LayerDelegate:
+ void OnDeviceScaleFactorChanged(float device_scale_factor) override {
+ last_scale_factor_ = device_scale_factor;
+ View::OnDeviceScaleFactorChanged(device_scale_factor);
+ }
+
+ float last_scale_factor() const { return last_scale_factor_; };
+
+ private:
+ float last_scale_factor_ = 0.f;
+
+ DISALLOW_COPY_AND_ASSIGN(ScaleFactorView);
+};
+
+struct WidgetCloser {
+ inline void operator()(Widget* widget) const { widget->CloseNow(); }
+};
sadrul 2015/12/22 08:13:34 Hm, we should be using this in more tests above.
Andrey Kraynov 2015/12/22 08:38:57 Don't you mind if I will create a CL to use this p
+
+}
+
+// Ensure scale factor changes are propagated from the native Widget.
+TEST_F(WidgetTest, OnDeviceScaleFactorChanged) {
+ // Automatically close the widget, but not delete it.
+ scoped_ptr<Widget, WidgetCloser> widget(CreateTopLevelPlatformWidget());
+ ScaleFactorView* view = new ScaleFactorView;
+ widget->GetRootView()->AddChildView(view);
+ float scale_factor = widget->GetLayer()->device_scale_factor();
+ EXPECT_NE(scale_factor, 0.f);
+
+ // For views that are not layer-backed, adding the view won't notify the view
+ // about the initial scale factor. Fake it.
+ view->OnDeviceScaleFactorChanged(scale_factor);
+ EXPECT_EQ(scale_factor, view->last_scale_factor());
+
+ // Changes should be propagated.
+ scale_factor *= 2.0f;
+ widget->GetLayer()->OnDeviceScaleFactorChanged(scale_factor);
+ EXPECT_EQ(scale_factor, view->last_scale_factor());
+}
+
} // namespace test
} // namespace views
« no previous file with comments | « ui/views/cocoa/bridged_native_widget.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698