Commit 678cad15 authored by blundell's avatar blundell Committed by Commit bot

Add browsertest that zoom is preserved on reload

Zoom should be preserved on reload. However, this behavior is not currently
reliably covered by tests (there is a layout test that attempts to cover this
behavior, but it is broken and will shortly be removed, as per comment 28 on
crbug.com/673065). This CL adds a proper test of this behavior.

BUG=673065

Review-Url: https://codereview.chromium.org/2608213003
Cr-Commit-Position: refs/heads/master@{#441449}
parent c102fd84
......@@ -10,6 +10,8 @@
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/host_zoom_map.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/common/page_zoom.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
......@@ -23,7 +25,25 @@
namespace content {
// This file contains tests to make sure that subframes zoom in a manner
// This class contains basic tests of zoom functionality.
class ZoomBrowserTest : public ContentBrowserTest {
public:
ZoomBrowserTest() {}
protected:
void SetUpOnMainThread() override {
host_resolver()->AddRule("*", "127.0.0.1");
SetupCrossSiteRedirector(embedded_test_server());
ASSERT_TRUE(embedded_test_server()->Start());
}
WebContentsImpl* web_contents() {
return static_cast<WebContentsImpl*>(shell()->web_contents());
}
};
// This class contains tests to make sure that subframes zoom in a manner
// consistent with the top-level frame, even when the subframes are cross-site.
// Particular things we want to make sure of:
//
......@@ -138,6 +158,40 @@ struct FrameResizeObserver {
double tolerance;
};
// This struct is used to wait until a resize has occurred.
struct ResizeObserver {
ResizeObserver(RenderFrameHost* host)
: frame_host(host) {
SetupOnResizeCallback(host);
}
void SetupOnResizeCallback(const ToRenderFrameHost& adapter) {
const char kOnResizeCallbackSetup[] =
"document.body.onresize = function(){"
" window.domAutomationController.setAutomationId(0);"
" window.domAutomationController.send('Resized');"
"};";
EXPECT_TRUE(ExecuteScript(
adapter, kOnResizeCallbackSetup));
}
bool IsResizeCallback(const std::string& status_msg) {
return status_msg == "Resized";
}
RenderFrameHost* frame_host;
};
void WaitForResize(DOMMessageQueue& msg_queue, ResizeObserver& observer) {
std::string status;
while (msg_queue.WaitForMessage(&status)) {
// Strip the double quotes from the message.
status = status.substr(1, status.length() -2);
if (observer.IsResizeCallback(status))
break;
}
}
void WaitAndCheckFrameZoom(
DOMMessageQueue& msg_queue,
std::vector<FrameResizeObserver>& frame_observers) {
......@@ -161,6 +215,65 @@ void WaitAndCheckFrameZoom(
} // namespace
IN_PROC_BROWSER_TEST_F(ZoomBrowserTest, ZoomPreservedOnReload) {
std::string top_level_host("a.com");
GURL main_url(embedded_test_server()->GetURL(
top_level_host, "/cross_site_iframe_factory.html?a(b(a))"));
EXPECT_TRUE(NavigateToURL(shell(), main_url));
NavigationEntry* entry =
web_contents()->GetController().GetLastCommittedEntry();
ASSERT_TRUE(entry);
GURL loaded_url = HostZoomMap::GetURLFromEntry(entry);
EXPECT_EQ(top_level_host, loaded_url.host());
FrameTreeNode* root =
static_cast<WebContentsImpl*>(web_contents())->GetFrameTree()->root();
double main_frame_window_border = GetMainframeWindowBorder(web_contents());
HostZoomMap* host_zoom_map = HostZoomMap::GetForWebContents(web_contents());
double default_zoom_level = host_zoom_map->GetDefaultZoomLevel();
EXPECT_EQ(0.0, default_zoom_level);
EXPECT_DOUBLE_EQ(
1.0, GetMainFrameZoomFactor(web_contents(), main_frame_window_border));
const double new_zoom_factor = 2.5;
// Set the new zoom, wait for the page to be resized, and sanity-check that
// the zoom was applied.
{
DOMMessageQueue msg_queue;
ResizeObserver observer(root->current_frame_host());
const double new_zoom_level =
default_zoom_level + ZoomFactorToZoomLevel(new_zoom_factor);
host_zoom_map->SetZoomLevelForHost(top_level_host, new_zoom_level);
WaitForResize(msg_queue, observer);
}
// Make this comparison approximate for Nexus5X test;
// https://crbug.com/622858.
EXPECT_NEAR(
new_zoom_factor,
GetMainFrameZoomFactor(web_contents(), main_frame_window_border),
0.01);
// Now the actual test: Reload the page and check that the main frame is
// still properly zoomed.
WindowedNotificationObserver load_stop_observer(
NOTIFICATION_LOAD_STOP,
NotificationService::AllSources());
shell()->Reload();
load_stop_observer.Wait();
EXPECT_NEAR(
new_zoom_factor,
GetMainFrameZoomFactor(web_contents(), main_frame_window_border),
0.01);
}
IN_PROC_BROWSER_TEST_F(IFrameZoomBrowserTest, SubframesZoomProperly) {
std::string top_level_host("a.com");
GURL main_url(embedded_test_server()->GetURL(
......
......@@ -585,7 +585,6 @@ test("content_browsertests") {
"../browser/generic_sensor_browsertest.cc",
"../browser/gpu/gpu_ipc_browsertests.cc",
"../browser/host_zoom_map_impl_browsertest.cc",
"../browser/iframe_zoom_browsertest.cc",
"../browser/indexed_db/indexed_db_browsertest.cc",
"../browser/indexed_db/mock_browsertest_indexed_db_class_factory.cc",
"../browser/indexed_db/mock_browsertest_indexed_db_class_factory.h",
......@@ -646,6 +645,7 @@ test("content_browsertests") {
"../browser/web_contents/web_contents_view_aura_browsertest.cc",
"../browser/webkit_browsertest.cc",
"../browser/webui/web_ui_mojo_browsertest.cc",
"../browser/zoom_browsertest.cc",
"../child/site_isolation_stats_gatherer_browsertest.cc",
"../renderer/accessibility/render_accessibility_impl_browsertest.cc",
"../renderer/gin_browsertest.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment