OLD | NEW |
---|---|
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 // An enum to parameterize the tests so that the tests can be run with and |
msw
2017/04/24 18:53:39
Yikes, ditto. Maybe use a test utils file and/or t
varkha
2017/04/26 04:52:59
Done.
| |
16 // without the secondary-ui-md flag. | |
17 enum class SecondaryUiMd { | |
18 ENABLED, | |
19 DISABLED, | |
20 }; | |
21 | |
22 // Generates the test name suffix depending on the value of the SecondaryUiMd | |
23 // param. | |
24 std::string SecondaryUiMdStatusToString( | |
25 const ::testing::TestParamInfo<SecondaryUiMd>& info) { | |
26 switch (info.param) { | |
27 case SecondaryUiMd::ENABLED: | |
28 return "SecondaryUiMdEnabled"; | |
29 case SecondaryUiMd::DISABLED: | |
30 return "SecondaryUiMdDisabled"; | |
31 } | |
32 NOTREACHED(); | |
33 return std::string(); | |
34 } | |
35 | |
36 class ZoomDecorationTest : public ChromeRenderViewHostTestHarness, | |
37 public ::testing::WithParamInterface<SecondaryUiMd> { | |
38 public: | |
39 ZoomDecorationTest() {} | |
40 ~ZoomDecorationTest() override {} | |
41 | |
42 protected: | |
43 // testing::Test: | |
44 void SetUp() override { | |
45 // TODO(crbug.com/630357): Remove parameterized testing for this class when | |
46 // secondary-ui-md is enabled by default on all platforms. | |
47 if (GetParam() == SecondaryUiMd::ENABLED) { | |
48 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
49 switches::kExtendMdToSecondaryUi); | |
50 } | |
51 ChromeRenderViewHostTestHarness::SetUp(); | |
52 } | |
53 | |
54 DISALLOW_COPY_AND_ASSIGN(ZoomDecorationTest); | |
55 }; | |
13 | 56 |
14 class MockZoomDecoration : public ZoomDecoration { | 57 class MockZoomDecoration : public ZoomDecoration { |
15 public: | 58 public: |
16 explicit MockZoomDecoration(LocationBarViewMac* owner) | 59 explicit MockZoomDecoration(LocationBarViewMac* owner) |
17 : ZoomDecoration(owner), update_ui_count_(0) {} | 60 : ZoomDecoration(owner), update_ui_count_(0) {} |
18 bool ShouldShowDecoration() const override { return true; } | 61 bool ShouldShowDecoration() const override { return true; } |
19 void UpdateUI(zoom::ZoomController* zoom_controller, | 62 void UpdateUI(zoom::ZoomController* zoom_controller, |
20 NSString* tooltip_string, | 63 NSString* tooltip_string, |
21 bool location_bar_is_dark) override { | 64 bool location_bar_is_dark) override { |
22 ++update_ui_count_; | 65 ++update_ui_count_; |
(...skipping 15 matching lines...) Expand all Loading... | |
38 bool IsAtDefaultZoom() const override { return zoom_percent_ == 100; } | 81 bool IsAtDefaultZoom() const override { return zoom_percent_ == 100; } |
39 | 82 |
40 int zoom_percent_; | 83 int zoom_percent_; |
41 | 84 |
42 private: | 85 private: |
43 DISALLOW_COPY_AND_ASSIGN(MockZoomController); | 86 DISALLOW_COPY_AND_ASSIGN(MockZoomController); |
44 }; | 87 }; |
45 | 88 |
46 // Test that UpdateIfNecessary performs redraws only when the zoom percent | 89 // Test that UpdateIfNecessary performs redraws only when the zoom percent |
47 // changes. | 90 // changes. |
48 TEST_F(ZoomDecorationTest, ChangeZoomPercent) { | 91 TEST_P(ZoomDecorationTest, ChangeZoomPercent) { |
49 MockZoomDecoration decoration(NULL); | 92 MockZoomDecoration decoration(NULL); |
50 MockZoomController controller(web_contents()); | 93 MockZoomController controller(web_contents()); |
51 | 94 |
52 controller.zoom_percent_ = 100; | 95 controller.zoom_percent_ = 100; |
53 decoration.UpdateIfNecessary(&controller, | 96 decoration.UpdateIfNecessary(&controller, |
54 /*default_zoom_changed=*/false, | 97 /*default_zoom_changed=*/false, |
55 false); | 98 false); |
56 EXPECT_EQ(1, decoration.update_ui_count_); | 99 EXPECT_EQ(1, decoration.update_ui_count_); |
57 | 100 |
58 decoration.UpdateIfNecessary(&controller, | 101 decoration.UpdateIfNecessary(&controller, |
59 /*default_zoom_changed=*/false, | 102 /*default_zoom_changed=*/false, |
60 false); | 103 false); |
61 EXPECT_EQ(1, decoration.update_ui_count_); | 104 EXPECT_EQ(1, decoration.update_ui_count_); |
62 | 105 |
63 controller.zoom_percent_ = 80; | 106 controller.zoom_percent_ = 80; |
64 decoration.UpdateIfNecessary(&controller, | 107 decoration.UpdateIfNecessary(&controller, |
65 /*default_zoom_changed=*/false, | 108 /*default_zoom_changed=*/false, |
66 false); | 109 false); |
67 EXPECT_EQ(2, decoration.update_ui_count_); | 110 EXPECT_EQ(2, decoration.update_ui_count_); |
68 | 111 |
69 // Always redraw if the default zoom changes. | 112 // Always redraw if the default zoom changes. |
70 decoration.UpdateIfNecessary(&controller, | 113 decoration.UpdateIfNecessary(&controller, |
71 /*default_zoom_changed=*/true, | 114 /*default_zoom_changed=*/true, |
72 false); | 115 false); |
73 EXPECT_EQ(3, decoration.update_ui_count_); | 116 EXPECT_EQ(3, decoration.update_ui_count_); |
74 } | 117 } |
75 | 118 |
119 // Prefix for test instantiations intentionally left blank since the test | |
120 // fixture class has a single parameterization. | |
121 INSTANTIATE_TEST_CASE_P(, | |
122 ZoomDecorationTest, | |
123 ::testing::Values(SecondaryUiMd::ENABLED, | |
124 SecondaryUiMd::DISABLED), | |
125 &SecondaryUiMdStatusToString); | |
126 | |
76 } // namespace | 127 } // namespace |
OLD | NEW |