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

Side by Side 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 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 <algorithm> 5 #include <algorithm>
6 #include <set> 6 #include <set>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 3380 matching lines...) Expand 10 before | Expand all | Expand 10 after
3391 TEST_F(WidgetTest, AlwaysOnTop) { 3391 TEST_F(WidgetTest, AlwaysOnTop) {
3392 Widget* widget = CreateTopLevelNativeWidget(); 3392 Widget* widget = CreateTopLevelNativeWidget();
3393 EXPECT_FALSE(widget->IsAlwaysOnTop()); 3393 EXPECT_FALSE(widget->IsAlwaysOnTop());
3394 widget->SetAlwaysOnTop(true); 3394 widget->SetAlwaysOnTop(true);
3395 EXPECT_TRUE(widget->IsAlwaysOnTop()); 3395 EXPECT_TRUE(widget->IsAlwaysOnTop());
3396 widget->SetAlwaysOnTop(false); 3396 widget->SetAlwaysOnTop(false);
3397 EXPECT_FALSE(widget->IsAlwaysOnTop()); 3397 EXPECT_FALSE(widget->IsAlwaysOnTop());
3398 widget->CloseNow(); 3398 widget->CloseNow();
3399 } 3399 }
3400 3400
3401 namespace {
3402
3403 class ScaleFactorView : public View {
3404 public:
3405 ScaleFactorView() = default;
3406
3407 // Overridden from ui::LayerDelegate:
3408 void OnDeviceScaleFactorChanged(float device_scale_factor) override {
3409 last_scale_factor_ = device_scale_factor;
3410 View::OnDeviceScaleFactorChanged(device_scale_factor);
3411 }
3412
3413 float last_scale_factor() const { return last_scale_factor_; };
3414
3415 private:
3416 float last_scale_factor_ = 0.f;
3417
3418 DISALLOW_COPY_AND_ASSIGN(ScaleFactorView);
3419 };
3420
3421 struct WidgetCloser {
3422 inline void operator()(Widget* widget) const { widget->CloseNow(); }
3423 };
3424
3425 }
3426
3427 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.
3428 // Automatically close the widget, but not delete it.
3429 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
3430 ScaleFactorView* view = new ScaleFactorView;
3431 widget->GetRootView()->AddChildView(view);
3432 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.
3433
3434 // 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"
3435 EXPECT_EQ(scale_factor, view->last_scale_factor());
3436
3437 // Changes should be propagated.
3438 scale_factor *= 2.0f;
3439 widget->GetLayer()->OnDeviceScaleFactorChanged(scale_factor);
3440 EXPECT_EQ(scale_factor, view->last_scale_factor());
3441 }
3442
3401 } // namespace test 3443 } // namespace test
3402 } // namespace views 3444 } // namespace views
OLDNEW
« 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