OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
11 #import "chrome/browser/ui/cocoa/browser/zoom_bubble_controller.h" | 11 #import "chrome/browser/ui/cocoa/browser/zoom_bubble_controller.h" |
12 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 12 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
13 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 13 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
14 #include "chrome/browser/ui/cocoa/run_loop_testing.h" | 14 #include "chrome/browser/ui/cocoa/run_loop_testing.h" |
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
16 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
17 #include "components/toolbar/test_toolbar_model.h" | 17 #include "components/toolbar/test_toolbar_model.h" |
18 #include "components/ui/zoom/page_zoom.h" | 18 #include "components/zoom/page_zoom.h" |
19 #include "components/ui/zoom/zoom_controller.h" | 19 #include "components/zoom/zoom_controller.h" |
20 #include "content/public/browser/host_zoom_map.h" | 20 #include "content/public/browser/host_zoom_map.h" |
21 #include "content/public/test/test_utils.h" | 21 #include "content/public/test/test_utils.h" |
22 | 22 |
23 class ZoomDecorationTest : public InProcessBrowserTest { | 23 class ZoomDecorationTest : public InProcessBrowserTest { |
24 protected: | 24 protected: |
25 ZoomDecorationTest() | 25 ZoomDecorationTest() |
26 : InProcessBrowserTest(), | 26 : InProcessBrowserTest(), |
27 should_quit_on_zoom_(false) { | 27 should_quit_on_zoom_(false) { |
28 } | 28 } |
29 | 29 |
(...skipping 22 matching lines...) Expand all Loading... |
52 [BrowserWindowController browserWindowControllerForWindow: | 52 [BrowserWindowController browserWindowControllerForWindow: |
53 browser->window()->GetNativeWindow()]; | 53 browser->window()->GetNativeWindow()]; |
54 return [controller locationBarBridge]->zoom_decoration_.get(); | 54 return [controller locationBarBridge]->zoom_decoration_.get(); |
55 } | 55 } |
56 | 56 |
57 void Zoom(content::PageZoom zoom) { | 57 void Zoom(content::PageZoom zoom) { |
58 content::WebContents* web_contents = | 58 content::WebContents* web_contents = |
59 browser()->tab_strip_model()->GetActiveWebContents(); | 59 browser()->tab_strip_model()->GetActiveWebContents(); |
60 | 60 |
61 base::AutoReset<bool> reset(&should_quit_on_zoom_, true); | 61 base::AutoReset<bool> reset(&should_quit_on_zoom_, true); |
62 ui_zoom::PageZoom::Zoom(web_contents, zoom); | 62 zoom::PageZoom::Zoom(web_contents, zoom); |
63 content::RunMessageLoop(); | 63 content::RunMessageLoop(); |
64 } | 64 } |
65 | 65 |
66 void OnZoomChanged(const content::HostZoomMap::ZoomLevelChange& host) { | 66 void OnZoomChanged(const content::HostZoomMap::ZoomLevelChange& host) { |
67 if (should_quit_on_zoom_) { | 67 if (should_quit_on_zoom_) { |
68 base::MessageLoop::current()->PostTask( | 68 base::MessageLoop::current()->PostTask( |
69 FROM_HERE, | 69 FROM_HERE, |
70 base::Bind(&base::MessageLoop::QuitWhenIdle, | 70 base::Bind(&base::MessageLoop::QuitWhenIdle, |
71 base::Unretained(base::MessageLoop::current()))); | 71 base::Unretained(base::MessageLoop::current()))); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 private: | 75 private: |
76 bool should_quit_on_zoom_; | 76 bool should_quit_on_zoom_; |
77 std::unique_ptr<content::HostZoomMap::Subscription> zoom_subscription_; | 77 std::unique_ptr<content::HostZoomMap::Subscription> zoom_subscription_; |
78 | 78 |
79 DISALLOW_COPY_AND_ASSIGN(ZoomDecorationTest); | 79 DISALLOW_COPY_AND_ASSIGN(ZoomDecorationTest); |
80 }; | 80 }; |
81 | 81 |
82 IN_PROC_BROWSER_TEST_F(ZoomDecorationTest, BubbleAtDefaultZoom) { | 82 IN_PROC_BROWSER_TEST_F(ZoomDecorationTest, BubbleAtDefaultZoom) { |
83 ZoomDecoration* zoom_decoration = GetZoomDecoration(); | 83 ZoomDecoration* zoom_decoration = GetZoomDecoration(); |
84 | 84 |
85 // TODO(wjmaclean): This shouldn't be necessary, but at present this test | 85 // TODO(wjmaclean): This shouldn't be necessary, but at present this test |
86 // assumes the various Zoom() calls do not invoke a notification | 86 // assumes the various Zoom() calls do not invoke a notification |
87 // bubble, which prior to https://codereview.chromium.org/940673002/ | 87 // bubble, which prior to https://codereview.chromium.org/940673002/ |
88 // was accomplished by not showing the bubble for inactive windows. | 88 // was accomplished by not showing the bubble for inactive windows. |
89 // Since we now need to be able to show the zoom bubble as a notification | 89 // Since we now need to be able to show the zoom bubble as a notification |
90 // on non-active pages, this test should be revised to account for | 90 // on non-active pages, this test should be revised to account for |
91 // these notifications. | 91 // these notifications. |
92 ui_zoom::ZoomController::FromWebContents( | 92 zoom::ZoomController::FromWebContents(GetLocationBar()->GetWebContents()) |
93 GetLocationBar()->GetWebContents())->SetShowsNotificationBubble(false); | 93 ->SetShowsNotificationBubble(false); |
94 | 94 |
95 // Zoom in and reset. | 95 // Zoom in and reset. |
96 EXPECT_FALSE(zoom_decoration->IsVisible()); | 96 EXPECT_FALSE(zoom_decoration->IsVisible()); |
97 Zoom(content::PAGE_ZOOM_IN); | 97 Zoom(content::PAGE_ZOOM_IN); |
98 EXPECT_TRUE(zoom_decoration->IsVisible()); | 98 EXPECT_TRUE(zoom_decoration->IsVisible()); |
99 Zoom(content::PAGE_ZOOM_RESET); | 99 Zoom(content::PAGE_ZOOM_RESET); |
100 EXPECT_FALSE(zoom_decoration->IsVisible()); | 100 EXPECT_FALSE(zoom_decoration->IsVisible()); |
101 | 101 |
102 // Zoom in and show bubble then reset. | 102 // Zoom in and show bubble then reset. |
103 Zoom(content::PAGE_ZOOM_IN); | 103 Zoom(content::PAGE_ZOOM_IN); |
104 EXPECT_TRUE(zoom_decoration->IsVisible()); | 104 EXPECT_TRUE(zoom_decoration->IsVisible()); |
105 zoom_decoration->ShowBubble(false); | 105 zoom_decoration->ShowBubble(false); |
106 Zoom(content::PAGE_ZOOM_RESET); | 106 Zoom(content::PAGE_ZOOM_RESET); |
107 EXPECT_TRUE(zoom_decoration->IsVisible()); | 107 EXPECT_TRUE(zoom_decoration->IsVisible()); |
108 | 108 |
109 // Hide bubble and verify the decoration is hidden. | 109 // Hide bubble and verify the decoration is hidden. |
110 zoom_decoration->CloseBubble(); | 110 zoom_decoration->CloseBubble(); |
111 EXPECT_FALSE(zoom_decoration->IsVisible()); | 111 EXPECT_FALSE(zoom_decoration->IsVisible()); |
112 } | 112 } |
113 | 113 |
114 // Regression test for https://crbug.com/462482. | 114 // Regression test for https://crbug.com/462482. |
115 IN_PROC_BROWSER_TEST_F(ZoomDecorationTest, IconRemainsVisibleAfterBubble) { | 115 IN_PROC_BROWSER_TEST_F(ZoomDecorationTest, IconRemainsVisibleAfterBubble) { |
116 ZoomDecoration* zoom_decoration = GetZoomDecoration(); | 116 ZoomDecoration* zoom_decoration = GetZoomDecoration(); |
117 | 117 |
118 // See comment in BubbleAtDefaultZoom regarding this next line. | 118 // See comment in BubbleAtDefaultZoom regarding this next line. |
119 ui_zoom::ZoomController::FromWebContents( | 119 zoom::ZoomController::FromWebContents(GetLocationBar()->GetWebContents()) |
120 GetLocationBar()->GetWebContents())->SetShowsNotificationBubble(false); | 120 ->SetShowsNotificationBubble(false); |
121 | 121 |
122 // Zoom in to turn on decoration icon. | 122 // Zoom in to turn on decoration icon. |
123 EXPECT_FALSE(zoom_decoration->IsVisible()); | 123 EXPECT_FALSE(zoom_decoration->IsVisible()); |
124 Zoom(content::PAGE_ZOOM_IN); | 124 Zoom(content::PAGE_ZOOM_IN); |
125 EXPECT_TRUE(zoom_decoration->IsVisible()); | 125 EXPECT_TRUE(zoom_decoration->IsVisible()); |
126 | 126 |
127 // Show zoom bubble, verify decoration icon remains visible. | 127 // Show zoom bubble, verify decoration icon remains visible. |
128 zoom_decoration->ShowBubble(/* auto_close = */false); | 128 zoom_decoration->ShowBubble(/* auto_close = */false); |
129 EXPECT_TRUE(zoom_decoration->IsVisible()); | 129 EXPECT_TRUE(zoom_decoration->IsVisible()); |
130 | 130 |
(...skipping 25 matching lines...) Expand all Loading... |
156 | 156 |
157 // Create a new browser so that it can be closed properly. | 157 // Create a new browser so that it can be closed properly. |
158 Browser* browser2 = CreateBrowser(browser()->profile()); | 158 Browser* browser2 = CreateBrowser(browser()->profile()); |
159 ZoomDecoration* zoom_decoration = GetZoomDecorationForBrowser(browser2); | 159 ZoomDecoration* zoom_decoration = GetZoomDecorationForBrowser(browser2); |
160 zoom_decoration->ShowBubble(true); | 160 zoom_decoration->ShowBubble(true); |
161 | 161 |
162 // Test shouldn't crash. | 162 // Test shouldn't crash. |
163 browser2->window()->Close(); | 163 browser2->window()->Close(); |
164 content::RunAllPendingInMessageLoop(); | 164 content::RunAllPendingInMessageLoop(); |
165 } | 165 } |
OLD | NEW |