Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: content/browser/host_zoom_map_impl_browsertest.cc

Issue 1804023002: Fix page zoom to be frame-centric for out-of-process frames. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove 'anonymous'. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 #include "content/browser/host_zoom_map_impl.h" 5 #include "content/browser/host_zoom_map_impl.h"
6 6
7 #include "content/public/browser/render_process_host.h" 7 #include "content/public/browser/render_process_host.h"
8 #include "content/public/browser/render_view_host.h" 8 #include "content/public/browser/render_view_host.h"
9 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
10 #include "content/public/test/content_browser_test.h" 10 #include "content/public/test/content_browser_test.h"
11 #include "content/public/test/content_browser_test_utils.h"
11 #include "content/shell/browser/shell.h" 12 #include "content/shell/browser/shell.h"
13 #include "net/dns/mock_host_resolver.h"
12 #include "url/gurl.h" 14 #include "url/gurl.h"
13 15
14 namespace content { 16 namespace content {
15 17
16 class HostZoomMapImplBrowserTest : public ContentBrowserTest { 18 class HostZoomMapImplBrowserTest : public ContentBrowserTest {
19 protected:
20 void SetUpOnMainThread() override {
21 host_resolver()->AddRule("*", "127.0.0.1");
22 ASSERT_TRUE(embedded_test_server()->Start());
23 }
17 }; 24 };
18 25
19 void RunTestForURL(const GURL& url, 26 void RunTestForURL(const GURL& url,
20 Shell* shell, 27 Shell* shell,
21 double host_zoom_level, 28 double host_zoom_level,
22 double temp_zoom_level) { 29 double temp_zoom_level) {
23 shell->LoadURL(url);
24 WebContents* web_contents = shell->web_contents(); 30 WebContents* web_contents = shell->web_contents();
25 31
26 HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>( 32 HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>(
27 HostZoomMap::GetForWebContents(web_contents)); 33 HostZoomMap::GetForWebContents(web_contents));
28 34
29 int view_id = web_contents->GetRoutingID(); 35 int view_id = web_contents->GetRoutingID();
30 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); 36 int render_process_id = web_contents->GetRenderProcessHost()->GetID();
31 37
32 // Assume caller has set the zoom level to |host_zoom_level| using 38 // 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 39 // either a host or host+scheme entry in the HostZoomMap prior to
34 // calling this function. 40 // calling this function.
35 EXPECT_DOUBLE_EQ(host_zoom_level, host_zoom_map->GetZoomLevelForView( 41 EXPECT_DOUBLE_EQ(host_zoom_level, host_zoom_map->GetZoomLevelForView(
36 url, render_process_id, view_id)); 42 url, render_process_id, view_id));
37 43
38 // Make sure that GetZoomLevelForView() works for temporary zoom levels. 44 // Make sure that GetZoomLevelForView() works for temporary zoom levels.
39 host_zoom_map->SetTemporaryZoomLevel(render_process_id, view_id, 45 host_zoom_map->SetTemporaryZoomLevel(render_process_id, view_id,
40 temp_zoom_level); 46 temp_zoom_level);
41 EXPECT_DOUBLE_EQ(temp_zoom_level, host_zoom_map->GetZoomLevelForView( 47 EXPECT_DOUBLE_EQ(temp_zoom_level, host_zoom_map->GetZoomLevelForView(
42 url, render_process_id, view_id)); 48 url, render_process_id, view_id));
43 // Clear the temporary zoom level in case subsequent test calls use the same 49 // Clear the temporary zoom level in case subsequent test calls use the same
44 // web_contents. 50 // web_contents.
45 host_zoom_map->ClearTemporaryZoomLevel(render_process_id, view_id); 51 host_zoom_map->ClearTemporaryZoomLevel(render_process_id, view_id);
46 } 52 }
47 53
48 // Test to make sure that GetZoomForView() works properly for zoom levels 54 // Test to make sure that GetZoomForView() works properly for zoom levels
49 // stored by host value, and can distinguish temporary zoom levels from 55 // stored by host value, and can distinguish temporary zoom levels from
50 // these. 56 // these.
51 IN_PROC_BROWSER_TEST_F(HostZoomMapImplBrowserTest, GetZoomForView_Host) { 57 IN_PROC_BROWSER_TEST_F(HostZoomMapImplBrowserTest, GetZoomForView_Host) {
52 GURL url("http://abc.com"); 58 GURL url(embedded_test_server()->GetURL("abc.com", "/"));
59
60 // We must navigate so the WebContents has a committed entry.
61 EXPECT_TRUE(NavigateToURL(shell(), url));
53 62
54 HostZoomMap* host_zoom_map = 63 HostZoomMap* host_zoom_map =
55 HostZoomMap::GetForWebContents(shell()->web_contents()); 64 HostZoomMap::GetForWebContents(shell()->web_contents());
56 65
57 double default_zoom_level = host_zoom_map->GetDefaultZoomLevel(); 66 double default_zoom_level = host_zoom_map->GetDefaultZoomLevel();
58 double host_zoom_level = default_zoom_level + 1.0; 67 double host_zoom_level = default_zoom_level + 1.0;
59 double temp_zoom_level = default_zoom_level + 2.0; 68 double temp_zoom_level = default_zoom_level + 2.0;
60 69
61 host_zoom_map->SetZoomLevelForHost(url.host(), host_zoom_level); 70 host_zoom_map->SetZoomLevelForHost(url.host(), host_zoom_level);
62 71
63 RunTestForURL(url, shell(), host_zoom_level, temp_zoom_level); 72 RunTestForURL(url, shell(), host_zoom_level, temp_zoom_level);
64 } 73 }
65 74
66 // Test to make sure that GetZoomForView() works properly for zoom levels 75 // Test to make sure that GetZoomForView() works properly for zoom levels
67 // stored by host and scheme values, and can distinguish temporary zoom levels 76 // stored by host and scheme values, and can distinguish temporary zoom levels
68 // from these. 77 // from these.
69 IN_PROC_BROWSER_TEST_F(HostZoomMapImplBrowserTest, 78 IN_PROC_BROWSER_TEST_F(HostZoomMapImplBrowserTest,
70 GetZoomForView_HostAndScheme) { 79 GetZoomForView_HostAndScheme) {
71 GURL url("http://abc.com"); 80 GURL url(embedded_test_server()->GetURL("abc.com", "/"));
81
82 // We must navigate so the WebContents has a committed entry.
83 EXPECT_TRUE(NavigateToURL(shell(), url));
72 84
73 HostZoomMap* host_zoom_map = 85 HostZoomMap* host_zoom_map =
74 HostZoomMap::GetForWebContents(shell()->web_contents()); 86 HostZoomMap::GetForWebContents(shell()->web_contents());
75 87
76 double default_zoom_level = host_zoom_map->GetDefaultZoomLevel(); 88 double default_zoom_level = host_zoom_map->GetDefaultZoomLevel();
77 double host_zoom_level = default_zoom_level + 1.0; 89 double host_zoom_level = default_zoom_level + 1.0;
78 double temp_zoom_level = default_zoom_level + 2.0; 90 double temp_zoom_level = default_zoom_level + 2.0;
79 91
80 host_zoom_map->SetZoomLevelForHostAndScheme(url.scheme(), url.host(), 92 host_zoom_map->SetZoomLevelForHostAndScheme(url.scheme(), url.host(),
81 host_zoom_level); 93 host_zoom_level);
82 94
83 RunTestForURL(url, shell(), host_zoom_level, temp_zoom_level); 95 RunTestForURL(url, shell(), host_zoom_level, temp_zoom_level);
84 } 96 }
85 97
86 } // namespace content 98 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698