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" | 5 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" |
6 #include "chrome/browser/ui/zoom/zoom_controller.h" | 6 #include "chrome/browser/ui/zoom/zoom_controller.h" |
7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
11 class ZoomDecorationTest : public ChromeRenderViewHostTestHarness {}; | 11 class ZoomDecorationTest : public ChromeRenderViewHostTestHarness {}; |
12 | 12 |
13 class MockZoomDecoration : public ZoomDecoration { | 13 class MockZoomDecoration : public ZoomDecoration { |
14 public: | 14 public: |
15 explicit MockZoomDecoration(LocationBarViewMac* owner) | 15 explicit MockZoomDecoration(LocationBarViewMac* owner) |
16 : ZoomDecoration(owner), update_ui_count_(0) {} | 16 : ZoomDecoration(owner), update_ui_count_(0) {} |
17 virtual bool ShouldShowDecoration() const override { return true; } | 17 bool ShouldShowDecoration() const override { return true; } |
18 virtual void ShowAndUpdateUI(ZoomController* zoom_controller, | 18 void ShowAndUpdateUI(ZoomController* zoom_controller, |
19 NSString* tooltip_string) override { | 19 NSString* tooltip_string) override { |
20 ++update_ui_count_; | 20 ++update_ui_count_; |
21 ZoomDecoration::ShowAndUpdateUI(zoom_controller, tooltip_string); | 21 ZoomDecoration::ShowAndUpdateUI(zoom_controller, tooltip_string); |
22 } | 22 } |
23 | 23 |
24 int update_ui_count_; | 24 int update_ui_count_; |
25 | 25 |
26 private: | 26 private: |
27 DISALLOW_COPY_AND_ASSIGN(MockZoomDecoration); | 27 DISALLOW_COPY_AND_ASSIGN(MockZoomDecoration); |
28 }; | 28 }; |
29 | 29 |
30 class MockZoomController : public ZoomController { | 30 class MockZoomController : public ZoomController { |
31 public: | 31 public: |
32 explicit MockZoomController(content::WebContents* web_contents) | 32 explicit MockZoomController(content::WebContents* web_contents) |
33 : ZoomController(web_contents) {} | 33 : ZoomController(web_contents) {} |
34 virtual int GetZoomPercent() const override { return zoom_percent_; } | 34 int GetZoomPercent() const override { return zoom_percent_; } |
35 | 35 |
36 int zoom_percent_; | 36 int zoom_percent_; |
37 | 37 |
38 private: | 38 private: |
39 DISALLOW_COPY_AND_ASSIGN(MockZoomController); | 39 DISALLOW_COPY_AND_ASSIGN(MockZoomController); |
40 }; | 40 }; |
41 | 41 |
42 // Test that UpdateIfNecessary performs redraws only when the zoom percent | 42 // Test that UpdateIfNecessary performs redraws only when the zoom percent |
43 // changes. | 43 // changes. |
44 TEST_F(ZoomDecorationTest, ChangeZoomPercent) { | 44 TEST_F(ZoomDecorationTest, ChangeZoomPercent) { |
45 MockZoomDecoration decoration(NULL); | 45 MockZoomDecoration decoration(NULL); |
46 MockZoomController controller(web_contents()); | 46 MockZoomController controller(web_contents()); |
47 | 47 |
48 controller.zoom_percent_ = 100; | 48 controller.zoom_percent_ = 100; |
49 decoration.UpdateIfNecessary(&controller); | 49 decoration.UpdateIfNecessary(&controller); |
50 EXPECT_EQ(1, decoration.update_ui_count_); | 50 EXPECT_EQ(1, decoration.update_ui_count_); |
51 | 51 |
52 decoration.UpdateIfNecessary(&controller); | 52 decoration.UpdateIfNecessary(&controller); |
53 EXPECT_EQ(1, decoration.update_ui_count_); | 53 EXPECT_EQ(1, decoration.update_ui_count_); |
54 | 54 |
55 controller.zoom_percent_ = 80; | 55 controller.zoom_percent_ = 80; |
56 decoration.UpdateIfNecessary(&controller); | 56 decoration.UpdateIfNecessary(&controller); |
57 EXPECT_EQ(2, decoration.update_ui_count_); | 57 EXPECT_EQ(2, decoration.update_ui_count_); |
58 } | 58 } |
59 | 59 |
60 } // namespace | 60 } // namespace |
OLD | NEW |