1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/host_zoom_map_impl.h"
7 #include "content/public/browser/render_process_host.h"
8 #include "content/public/browser/render_view_host.h"
9 #include "content/public/browser/web_contents.h"
10 #include "content/public/test/content_browser_test.h"
11 #include "content/shell/browser/shell.h"
16 class HostZoomMapImplBrowserTest
: public ContentBrowserTest
{
19 void RunTestForURL(const GURL
& url
,
21 double host_zoom_level
,
22 double temp_zoom_level
) {
24 WebContents
* web_contents
= shell
->web_contents();
26 HostZoomMapImpl
* host_zoom_map
= static_cast<HostZoomMapImpl
*>(
27 HostZoomMap::GetForWebContents(web_contents
));
29 int view_id
= web_contents
->GetRoutingID();
30 int render_process_id
= web_contents
->GetRenderProcessHost()->GetID();
32 // Assume caller has set the zoom level to |host_zoom_level| using
33 // either a host or host+scheme entry in the HostZoomMap prior to
34 // calling this function.
35 EXPECT_DOUBLE_EQ(host_zoom_level
, host_zoom_map
->GetZoomLevelForView(
36 url
, render_process_id
, view_id
));
38 // Make sure that GetZoomLevelForView() works for temporary zoom levels.
39 host_zoom_map
->SetTemporaryZoomLevel(render_process_id
, view_id
,
41 EXPECT_DOUBLE_EQ(temp_zoom_level
, host_zoom_map
->GetZoomLevelForView(
42 url
, render_process_id
, view_id
));
43 // Clear the temporary zoom level in case subsequent test calls use the same
45 host_zoom_map
->ClearTemporaryZoomLevel(render_process_id
, view_id
);
48 // Test to make sure that GetZoomForView() works properly for zoom levels
49 // stored by host value, and can distinguish temporary zoom levels from
51 IN_PROC_BROWSER_TEST_F(HostZoomMapImplBrowserTest
, GetZoomForView_Host
) {
52 GURL
url("http://abc.com");
54 HostZoomMap
* host_zoom_map
=
55 HostZoomMap::GetForWebContents(shell()->web_contents());
57 double default_zoom_level
= host_zoom_map
->GetDefaultZoomLevel();
58 double host_zoom_level
= default_zoom_level
+ 1.0;
59 double temp_zoom_level
= default_zoom_level
+ 2.0;
61 host_zoom_map
->SetZoomLevelForHost(url
.host(), host_zoom_level
);
63 RunTestForURL(url
, shell(), host_zoom_level
, temp_zoom_level
);
66 // Test to make sure that GetZoomForView() works properly for zoom levels
67 // stored by host and scheme values, and can distinguish temporary zoom levels
69 IN_PROC_BROWSER_TEST_F(HostZoomMapImplBrowserTest
,
70 GetZoomForView_HostAndScheme
) {
71 GURL
url("http://abc.com");
73 HostZoomMap
* host_zoom_map
=
74 HostZoomMap::GetForWebContents(shell()->web_contents());
76 double default_zoom_level
= host_zoom_map
->GetDefaultZoomLevel();
77 double host_zoom_level
= default_zoom_level
+ 1.0;
78 double temp_zoom_level
= default_zoom_level
+ 2.0;
80 host_zoom_map
->SetZoomLevelForHostAndScheme(url
.scheme(), url
.host(),
83 RunTestForURL(url
, shell(), host_zoom_level
, temp_zoom_level
);
86 } // namespace content