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

Side by Side Diff: chrome/browser/ui/cocoa/location_bar/zoom_decoration_unittest.mm

Issue 2834493007: MacViews: Allows the toolkit-views Zoom Dialog to be used (Closed)
Patch Set: MacViews: Allows the toolkit-views Zoom Dialog to be used (keep anchoring) Created 3 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h"
6
7 #include "base/command_line.h"
5 #include "base/macros.h" 8 #include "base/macros.h"
6 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h"
7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
8 #include "components/zoom/zoom_controller.h" 10 #include "components/zoom/zoom_controller.h"
11 #include "ui/base/ui_base_switches.h"
9 12
10 namespace { 13 namespace {
11 14
12 class ZoomDecorationTest : public ChromeRenderViewHostTestHarness {}; 15 class ZoomDecorationTest : public ChromeRenderViewHostTestHarness,
16 public ::testing::WithParamInterface<bool> {
17 public:
18 ZoomDecorationTest() {}
19 ~ZoomDecorationTest() override {}
20
21 protected:
22 // testing::Test:
23 void SetUp() override {
24 // TODO(crbug.com/630357): Remove parameterized testing for this class when
25 // secondary-ui-md is enabled by default on all platforms.
26 if (GetParam()) {
27 base::CommandLine::ForCurrentProcess()->AppendSwitch(
28 switches::kExtendMdToSecondaryUi);
29 }
30 ChromeRenderViewHostTestHarness::SetUp();
31 }
32
33 DISALLOW_COPY_AND_ASSIGN(ZoomDecorationTest);
34 };
13 35
14 class MockZoomDecoration : public ZoomDecoration { 36 class MockZoomDecoration : public ZoomDecoration {
15 public: 37 public:
16 explicit MockZoomDecoration(LocationBarViewMac* owner) 38 explicit MockZoomDecoration(LocationBarViewMac* owner)
17 : ZoomDecoration(owner), update_ui_count_(0) {} 39 : ZoomDecoration(owner), update_ui_count_(0) {}
18 bool ShouldShowDecoration() const override { return true; } 40 bool ShouldShowDecoration() const override { return true; }
19 void UpdateUI(zoom::ZoomController* zoom_controller, 41 void UpdateUI(zoom::ZoomController* zoom_controller,
20 NSString* tooltip_string, 42 NSString* tooltip_string,
21 bool location_bar_is_dark) override { 43 bool location_bar_is_dark) override {
22 ++update_ui_count_; 44 ++update_ui_count_;
(...skipping 15 matching lines...) Expand all
38 bool IsAtDefaultZoom() const override { return zoom_percent_ == 100; } 60 bool IsAtDefaultZoom() const override { return zoom_percent_ == 100; }
39 61
40 int zoom_percent_; 62 int zoom_percent_;
41 63
42 private: 64 private:
43 DISALLOW_COPY_AND_ASSIGN(MockZoomController); 65 DISALLOW_COPY_AND_ASSIGN(MockZoomController);
44 }; 66 };
45 67
46 // Test that UpdateIfNecessary performs redraws only when the zoom percent 68 // Test that UpdateIfNecessary performs redraws only when the zoom percent
47 // changes. 69 // changes.
48 TEST_F(ZoomDecorationTest, ChangeZoomPercent) { 70 TEST_P(ZoomDecorationTest, ChangeZoomPercent) {
49 MockZoomDecoration decoration(NULL); 71 MockZoomDecoration decoration(NULL);
50 MockZoomController controller(web_contents()); 72 MockZoomController controller(web_contents());
51 73
52 controller.zoom_percent_ = 100; 74 controller.zoom_percent_ = 100;
53 decoration.UpdateIfNecessary(&controller, 75 decoration.UpdateIfNecessary(&controller,
54 /*default_zoom_changed=*/false, 76 /*default_zoom_changed=*/false,
55 false); 77 false);
56 EXPECT_EQ(1, decoration.update_ui_count_); 78 EXPECT_EQ(1, decoration.update_ui_count_);
57 79
58 decoration.UpdateIfNecessary(&controller, 80 decoration.UpdateIfNecessary(&controller,
59 /*default_zoom_changed=*/false, 81 /*default_zoom_changed=*/false,
60 false); 82 false);
61 EXPECT_EQ(1, decoration.update_ui_count_); 83 EXPECT_EQ(1, decoration.update_ui_count_);
62 84
63 controller.zoom_percent_ = 80; 85 controller.zoom_percent_ = 80;
64 decoration.UpdateIfNecessary(&controller, 86 decoration.UpdateIfNecessary(&controller,
65 /*default_zoom_changed=*/false, 87 /*default_zoom_changed=*/false,
66 false); 88 false);
67 EXPECT_EQ(2, decoration.update_ui_count_); 89 EXPECT_EQ(2, decoration.update_ui_count_);
68 90
69 // Always redraw if the default zoom changes. 91 // Always redraw if the default zoom changes.
70 decoration.UpdateIfNecessary(&controller, 92 decoration.UpdateIfNecessary(&controller,
71 /*default_zoom_changed=*/true, 93 /*default_zoom_changed=*/true,
72 false); 94 false);
73 EXPECT_EQ(3, decoration.update_ui_count_); 95 EXPECT_EQ(3, decoration.update_ui_count_);
74 } 96 }
75 97
98 // Prefix for test instantiations intentionally left blank since the test
99 // fixture class has a single parameterization.
100 INSTANTIATE_TEST_CASE_P(, ZoomDecorationTest, testing::Bool());
101
76 } // namespace 102 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698