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

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: Fix test on Retina 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
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..8def9d499b68bab5c5734b571b0efa67b523ccd5 100644
--- a/ui/views/widget/widget_unittest.cc
+++ b/ui/views/widget/widget_unittest.cc
@@ -3398,5 +3398,47 @@ TEST_F(WidgetTest, AlwaysOnTop) {
widget->CloseNow();
}
+namespace {
+
+class ScaleFactorView : public View {
+ public:
+ ScaleFactorView() = default;
+
+ // 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(); }
+};
+
+}
+
+TEST_F(WidgetTest, OnDeviceScaleFactorChanged) {
tapted 2015/12/21 07:20:16 nit: comment describing the test like // Ensure sc
Andrey Kraynov 2015/12/21 09:47:19 Done.
+ // Automatically close the widget, but not delete it.
+ scoped_ptr<Widget, WidgetCloser> widget(CreateTopLevelPlatformWidget());
tapted 2015/12/21 07:20:16 ooh neat. we should do this more. WidgetCloser pro
Andrey Kraynov 2015/12/21 09:47:19 IMHO, this line can be much better with implemente
tapted 2015/12/21 22:54:11 For this example, I think it's more useful if Crea
+ ScaleFactorView* view = new ScaleFactorView;
+ widget->GetRootView()->AddChildView(view);
+ float scale_factor = widget->GetLayer()->device_scale_factor();
tapted 2015/12/21 07:23:49 heh, I guess we should check that this isn't 0 as
Andrey Kraynov 2015/12/21 09:47:19 Done.
+
+ // Adding the view should notify the view about the initial scale factor.
tapted 2015/12/21 07:20:16 I guess // For views that are not layer-backed,
Andrey Kraynov 2015/12/21 09:47:19 Unfortunately, ui::Layer class compares scale fact
tapted 2015/12/21 22:54:11 yep - I think that's fine. Just takes "faking it"
+ 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
« ui/views/cocoa/bridged_native_widget.mm ('K') | « 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