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

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: 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 unified diff | Download patch
« no previous file with comments | « ui/views/cocoa/bridged_native_widget.mm ('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 <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;
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
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 };
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
3424
3425 }
3426
3427 // Ensure scale factor changes are propagated from the native Widget.
3428 TEST_F(WidgetTest, OnDeviceScaleFactorChanged) {
3429 // Automatically close the widget, but not delete it.
3430 scoped_ptr<Widget, WidgetCloser> widget(CreateTopLevelPlatformWidget());
3431 ScaleFactorView* view = new ScaleFactorView;
3432 widget->GetRootView()->AddChildView(view);
3433 float scale_factor = widget->GetLayer()->device_scale_factor();
3434 EXPECT_NE(scale_factor, 0.f);
3435
3436 // For views that are not layer-backed, adding the view won't notify the view
3437 // about the initial scale factor. Fake it.
3438 view->OnDeviceScaleFactorChanged(scale_factor);
3439 EXPECT_EQ(scale_factor, view->last_scale_factor());
3440
3441 // Changes should be propagated.
3442 scale_factor *= 2.0f;
3443 widget->GetLayer()->OnDeviceScaleFactorChanged(scale_factor);
3444 EXPECT_EQ(scale_factor, view->last_scale_factor());
3445 }
3446
3401 } // namespace test 3447 } // namespace test
3402 } // namespace views 3448 } // namespace views
OLDNEW
« 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