OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "content/browser/host_zoom_map_impl.h" |
| 6 |
| 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" |
| 12 #include "url/gurl.h" |
| 13 |
| 14 namespace content { |
| 15 |
| 16 class HostZoomMapImplBrowserTest : public ContentBrowserTest { |
| 17 }; |
| 18 |
| 19 void RunTestForURL(const GURL& url, |
| 20 Shell* shell, |
| 21 double host_zoom_level, |
| 22 double temp_zoom_level) { |
| 23 shell->LoadURL(url); |
| 24 WebContents* web_contents = shell->web_contents(); |
| 25 |
| 26 HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>( |
| 27 HostZoomMap::GetForWebContents(web_contents)); |
| 28 |
| 29 int view_id = web_contents->GetRoutingID(); |
| 30 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); |
| 31 |
| 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)); |
| 37 |
| 38 // Make sure that GetZoomLevelForView() works for temporary zoom levels. |
| 39 host_zoom_map->SetTemporaryZoomLevel(render_process_id, view_id, |
| 40 temp_zoom_level); |
| 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 |
| 44 // web_contents. |
| 45 host_zoom_map->ClearTemporaryZoomLevel(render_process_id, view_id); |
| 46 } |
| 47 |
| 48 // Test to make sure that GetZoomForView() works properly for zoom levels |
| 49 // stored by host value, and can distinguish temporary zoom levels from |
| 50 // these. |
| 51 IN_PROC_BROWSER_TEST_F(HostZoomMapImplBrowserTest, GetZoomForView_Host) { |
| 52 GURL url("http://abc.com"); |
| 53 |
| 54 HostZoomMap* host_zoom_map = |
| 55 HostZoomMap::GetForWebContents(shell()->web_contents()); |
| 56 |
| 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; |
| 60 |
| 61 host_zoom_map->SetZoomLevelForHost(url.host(), host_zoom_level); |
| 62 |
| 63 RunTestForURL(url, shell(), host_zoom_level, temp_zoom_level); |
| 64 } |
| 65 |
| 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 |
| 68 // from these. |
| 69 IN_PROC_BROWSER_TEST_F(HostZoomMapImplBrowserTest, |
| 70 GetZoomForView_HostAndScheme) { |
| 71 GURL url("http://abc.com"); |
| 72 |
| 73 HostZoomMap* host_zoom_map = |
| 74 HostZoomMap::GetForWebContents(shell()->web_contents()); |
| 75 |
| 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; |
| 79 |
| 80 host_zoom_map->SetZoomLevelForHostAndScheme(url.scheme(), url.host(), |
| 81 host_zoom_level); |
| 82 |
| 83 RunTestForURL(url, shell(), host_zoom_level, temp_zoom_level); |
| 84 } |
| 85 |
| 86 } // namespace content |
OLD | NEW |