Commit 05ad3d7b authored by sauski's avatar sauski Committed by Commit Bot

HaTS Next: Reset zoom level for survey dialog

Previously the survey dialog inherited the default zoom level of the
browser, which caused some sizing issues. This CL resets the zoom level
for the HaTS website for the non-primary OTR profile in which the
survey is loaded.

Bug: 1147390
Change-Id: I7369ad83fae255731617d1a9a43a4c2fd588502d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2526344
Commit-Queue: Theodore Olsauskas-Warren <sauski@google.com>
Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827288}
parent 7b356bed
......@@ -25,6 +25,7 @@
#include "chrome/browser/ui/views/hats/hats_bubble_view.h"
#include "chrome/browser/ui/views/hats/hats_next_web_dialog.h"
#include "chrome/browser/ui/views/hats/hats_web_dialog.h"
#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
......@@ -33,6 +34,7 @@
#include "components/version_info/version_info.h"
#include "content/public/test/browser_test.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/common/page/page_zoom.h"
#include "url/gurl.h"
class HatsBubbleTest : public DialogBrowserTest {
......@@ -510,3 +512,27 @@ IN_PROC_BROWSER_TEST_F(HatsNextWebDialogBrowserTest, MaximumSize) {
EXPECT_EQ(HatsNextWebDialog::kMaxSize, dialog->CalculatePreferredSize());
}
}
IN_PROC_BROWSER_TEST_F(HatsNextWebDialogBrowserTest, ZoomLevel) {
// Ensure that the dialog correctly resets the zoom level to default.
browser()->profile()->GetZoomLevelPrefs()->SetDefaultZoomLevelPref(
blink::PageZoomFactorToZoomLevel(5.0f));
ASSERT_TRUE(embedded_test_server()->Start());
auto* dialog = new MockHatsNextWebDialog(
browser(), kHatsNextSurveyTriggerIDTesting,
embedded_test_server()->GetURL("/hats/hats_next_mock.html"),
base::TimeDelta::FromSeconds(100), base::DoNothing(), base::DoNothing());
// Allow the dialog to open before checking the zoom level of the contents.
base::RunLoop run_loop;
EXPECT_CALL(*dialog, ShowWidget).WillOnce(testing::Invoke([&run_loop]() {
run_loop.Quit();
}));
run_loop.Run();
EXPECT_TRUE(blink::PageZoomValuesEqual(
content::HostZoomMap::GetDefaultForBrowserContext(dialog->otr_profile_)
->GetZoomLevel(dialog->web_view_->GetWebContents()),
blink::PageZoomFactorToZoomLevel(1.0f)));
}
......@@ -27,6 +27,7 @@
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "net/base/url_util.h"
#include "third_party/blink/public/common/page/page_zoom.h"
#include "ui/base/ui_base_types.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/bubble/bubble_frame_view.h"
......@@ -163,6 +164,12 @@ HatsNextWebDialog::HatsNextWebDialog(Browser* browser,
otr_profile_->AddObserver(this);
set_close_on_deactivate(false);
// Override the default zoom level for ths HaTS dialog. Its size should align
// with native UI elements, rather than web content.
content::HostZoomMap::GetDefaultForBrowserContext(otr_profile_)
->SetZoomLevelForHost(hats_survey_url_.host(),
blink::PageZoomFactorToZoomLevel(1.0f));
SetButtons(ui::DIALOG_BUTTON_NONE);
SetLayoutManager(std::make_unique<views::FillLayout>());
......
......@@ -48,6 +48,7 @@ class HatsNextWebDialog : public views::BubbleDialogDelegateView,
FRIEND_TEST_ALL_PREFIXES(HatsNextWebDialogBrowserTest, SurveyLoaded);
FRIEND_TEST_ALL_PREFIXES(HatsNextWebDialogBrowserTest, DialogResize);
FRIEND_TEST_ALL_PREFIXES(HatsNextWebDialogBrowserTest, MaximumSize);
FRIEND_TEST_ALL_PREFIXES(HatsNextWebDialogBrowserTest, ZoomLevel);
HatsNextWebDialog(Browser* browser,
const std::string& trigger_id,
......
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