| Index: chrome/browser/ui/zoom/zoom_controller_unittest.cc
|
| diff --git a/chrome/browser/ui/zoom/zoom_controller_unittest.cc b/chrome/browser/ui/zoom/zoom_controller_unittest.cc
|
| index 18f76df90678a25aabd48d921efe3c8b90e09b41..8b830013940b014246c7f082c4b3a2e588f8be28 100644
|
| --- a/chrome/browser/ui/zoom/zoom_controller_unittest.cc
|
| +++ b/chrome/browser/ui/zoom/zoom_controller_unittest.cc
|
| @@ -5,6 +5,7 @@
|
| #include "base/message_loop/message_loop.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/browser_finder.h"
|
| +#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
|
| #include "chrome/test/base/chrome_render_view_host_test_harness.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| #include "components/prefs/pref_service.h"
|
| @@ -13,7 +14,9 @@
|
| #include "components/zoom/zoom_observer.h"
|
| #include "content/public/browser/host_zoom_map.h"
|
| #include "content/public/browser/navigation_details.h"
|
| +#include "content/public/browser/storage_partition.h"
|
| #include "content/public/common/frame_navigate_params.h"
|
| +#include "content/public/test/mock_render_process_host.h"
|
| #include "content/public/test/test_renderer_host.h"
|
| #include "content/public/test/test_utils.h"
|
| #include "ipc/ipc_message.h"
|
| @@ -27,6 +30,17 @@ class ZoomControllerTest : public ChromeRenderViewHostTestHarness {
|
| public:
|
| void SetUp() override {
|
| ChromeRenderViewHostTestHarness::SetUp();
|
| +
|
| + // We set the correct zoom scope pref before creating the ZoomController,
|
| + // so we can test without relying on the updating of the ZoomController's
|
| + // state in response to a scope change. We have specific tests for that
|
| + // logic (see OnDefaultZoomScopeChanged).
|
| + ChromeZoomLevelPrefs* zoom_prefs = static_cast<ChromeZoomLevelPrefs*>(
|
| + content::BrowserContext::GetDefaultStoragePartition(
|
| + web_contents()->GetBrowserContext())->GetZoomLevelDelegate());
|
| + ASSERT_TRUE(zoom_prefs);
|
| + SetUpPrefs(zoom_prefs);
|
| +
|
| zoom_controller_.reset(new ZoomController(web_contents()));
|
|
|
| // This call is needed so that the RenderViewHost reports being alive. This
|
| @@ -35,6 +49,11 @@ class ZoomControllerTest : public ChromeRenderViewHostTestHarness {
|
| base::string16(), MSG_ROUTING_NONE, MSG_ROUTING_NONE, false);
|
| }
|
|
|
| + virtual void SetUpPrefs(ChromeZoomLevelPrefs* zoom_prefs) {
|
| + // These tests assume we are per-origin by default.
|
| + ASSERT_TRUE(zoom_prefs->GetIsOriginScopePref());
|
| + }
|
| +
|
| void TearDown() override {
|
| zoom_controller_.reset();
|
| ChromeRenderViewHostTestHarness::TearDown();
|
| @@ -131,3 +150,186 @@ TEST_F(ZoomControllerTest, ObserveManualZoomCanShowBubble) {
|
| }
|
|
|
| }
|
| +
|
| +TEST_F(ZoomControllerTest, OnDefaultZoomScopeChanged) {
|
| + NavigateAndCommit(GURL("about:blank"));
|
| + double old_zoom_level = zoom_controller_->GetZoomLevel();
|
| + double new_zoom_level = old_zoom_level + 1.0;
|
| +
|
| + ZoomController::ZoomChangedEventData zoom_change_data1(
|
| + web_contents(),
|
| + old_zoom_level,
|
| + new_zoom_level,
|
| + ZoomController::ZOOM_MODE_DEFAULT,
|
| + true /* can_show_bubble */);
|
| + {
|
| + ZoomChangedWatcher zoom_change_watcher1(zoom_controller_.get(),
|
| + zoom_change_data1);
|
| + zoom_controller_->SetZoomLevel(new_zoom_level);
|
| + zoom_change_watcher1.Wait();
|
| + }
|
| +
|
| + // When changing the default scope from per-origin to per-tab,
|
| + // update the zoom mode from ZOOM_MODE_DEFAULT to ZOOM_MODE_ISOLATED
|
| + // and keep the previous host zoom level as a temporary level.
|
| + ZoomController::ZoomChangedEventData zoom_change_data2(
|
| + web_contents(),
|
| + new_zoom_level,
|
| + new_zoom_level,
|
| + ZoomController::ZOOM_MODE_ISOLATED,
|
| + true /* can_show_bubble */);
|
| + {
|
| + ZoomChangedWatcher zoom_change_watcher2(zoom_controller_.get(),
|
| + zoom_change_data2);
|
| + zoom_controller_->OnDefaultZoomScopeChanged();
|
| + zoom_change_watcher2.Wait();
|
| +
|
| + content::HostZoomMap* zoom_map =
|
| + content::HostZoomMap::GetForWebContents(web_contents());
|
| + EXPECT_TRUE(zoom_map->UsesTemporaryZoomLevel(process()->GetID(),
|
| + rvh()->GetRoutingID()));
|
| + }
|
| +}
|
| +
|
| +class ZoomControllerPerTabTest : public ZoomControllerTest {
|
| + public:
|
| + void SetUpPrefs(ChromeZoomLevelPrefs* zoom_prefs) override {
|
| + // These tests assume we are per-tab by default.
|
| + zoom_prefs->SetIsOriginScopePref(false);
|
| + }
|
| +};
|
| +
|
| +TEST_F(ZoomControllerPerTabTest, InitializedState) {
|
| + EXPECT_EQ(ZoomController::ZOOM_MODE_ISOLATED, zoom_controller_->zoom_mode());
|
| +
|
| + // Since we're in ZOOM_MODE_ISOLATED, we need a temporary zoom level.
|
| + content::HostZoomMap* zoom_map =
|
| + content::HostZoomMap::GetForWebContents(web_contents());
|
| + EXPECT_TRUE(zoom_map->UsesTemporaryZoomLevel(process()->GetID(),
|
| + rvh()->GetRoutingID()));
|
| +}
|
| +
|
| +TEST_F(ZoomControllerPerTabTest, DidNavigateMainFrame) {
|
| + double zoom_level = zoom_controller_->GetZoomLevel();
|
| + ZoomController::ZoomChangedEventData zoom_change_data(
|
| + web_contents(),
|
| + zoom_level,
|
| + zoom_level,
|
| + ZoomController::ZOOM_MODE_ISOLATED,
|
| + false);
|
| + ZoomChangedWatcher zoom_change_watcher(zoom_controller_.get(),
|
| + zoom_change_data);
|
| + zoom_controller_->DidNavigateMainFrame(content::LoadCommittedDetails(),
|
| + content::FrameNavigateParams());
|
| + zoom_change_watcher.Wait();
|
| +}
|
| +
|
| +TEST_F(ZoomControllerPerTabTest, Observe_ZoomController) {
|
| + NavigateAndCommit(GURL("about:blank"));
|
| +
|
| + double old_zoom_level = zoom_controller_->GetZoomLevel();
|
| + double new_zoom_level = old_zoom_level + 1.0;
|
| +
|
| + ZoomController::ZoomChangedEventData zoom_change_data(
|
| + web_contents(),
|
| + old_zoom_level,
|
| + new_zoom_level,
|
| + ZoomController::ZOOM_MODE_ISOLATED,
|
| + true /* can_show_bubble */);
|
| +
|
| + ZoomChangedWatcher zoom_change_watcher(zoom_controller_.get(),
|
| + zoom_change_data);
|
| + zoom_controller_->SetZoomLevel(new_zoom_level);
|
| + zoom_change_watcher.Wait();
|
| +}
|
| +
|
| +TEST_F(ZoomControllerPerTabTest, NavigationFromIsolated) {
|
| + double old_zoom_level = zoom_controller_->GetZoomLevel();
|
| + double new_zoom_level = old_zoom_level + 1.0;
|
| +
|
| + zoom_controller_->SetZoomLevel(new_zoom_level);
|
| +
|
| + // Zoom level and mode are preserved across navigation.
|
| + ZoomController::ZoomChangedEventData zoom_change_data(
|
| + web_contents(),
|
| + new_zoom_level,
|
| + new_zoom_level,
|
| + ZoomController::ZOOM_MODE_ISOLATED,
|
| + false /* can_show_bubble */);
|
| + ZoomChangedWatcher zoom_change_watcher(zoom_controller_.get(),
|
| + zoom_change_data);
|
| + zoom_controller_->DidNavigateMainFrame(content::LoadCommittedDetails(),
|
| + content::FrameNavigateParams());
|
| + zoom_change_watcher.Wait();
|
| +}
|
| +
|
| +TEST_F(ZoomControllerPerTabTest, ResetFromManualOnNavigation) {
|
| + NavigateAndCommit(GURL("about:blank"));
|
| +
|
| + double old_zoom_level = zoom_controller_->GetZoomLevel();
|
| + double new_zoom_level = old_zoom_level + 1.0;
|
| +
|
| + zoom_controller_->SetZoomMode(zoom::ZoomController::ZOOM_MODE_MANUAL);
|
| + ZoomController::ZoomChangedEventData zoom_change_data1(
|
| + web_contents(),
|
| + old_zoom_level,
|
| + new_zoom_level,
|
| + ZoomController::ZOOM_MODE_MANUAL,
|
| + true /* can_show_bubble */);
|
| + {
|
| + ZoomChangedWatcher zoom_change_watcher1(zoom_controller_.get(),
|
| + zoom_change_data1);
|
| + zoom_controller_->SetZoomLevel(new_zoom_level);
|
| + zoom_change_watcher1.Wait();
|
| + }
|
| +
|
| + // Zoom level and mode are reset.
|
| + ZoomController::ZoomChangedEventData zoom_change_data2(
|
| + web_contents(),
|
| + old_zoom_level,
|
| + old_zoom_level,
|
| + ZoomController::ZOOM_MODE_ISOLATED,
|
| + false /* can_show_bubble */);
|
| + {
|
| + ZoomChangedWatcher zoom_change_watcher2(zoom_controller_.get(),
|
| + zoom_change_data2);
|
| + zoom_controller_->DidNavigateMainFrame(content::LoadCommittedDetails(),
|
| + content::FrameNavigateParams());
|
| + zoom_change_watcher2.Wait();
|
| +
|
| + // Since we're in ZOOM_MODE_ISOLATED, we need a temporary zoom level.
|
| + // The reset should update the temporary zoom level, not clear it.
|
| + content::HostZoomMap* zoom_map =
|
| + content::HostZoomMap::GetForWebContents(web_contents());
|
| + EXPECT_TRUE(zoom_map->UsesTemporaryZoomLevel(process()->GetID(),
|
| + rvh()->GetRoutingID()));
|
| + }
|
| +}
|
| +
|
| +TEST_F(ZoomControllerPerTabTest, OnDefaultZoomScopeChanged) {
|
| + NavigateAndCommit(GURL("about:blank"));
|
| + double zoom_level = zoom_controller_->GetZoomLevel();
|
| +
|
| + // When changing the default scope from per-tab to per-origin,
|
| + // update the zoom mode from ZOOM_MODE_ISOLATED to ZOOM_MODE_DEFAULT
|
| + // and remove the temporary level.
|
| + // TODO See comment in ZoomController::UpdateZoomModeOnScopeChangeIfNeeded
|
| + // about the resulting per-host zoom level.
|
| + ZoomController::ZoomChangedEventData zoom_change_data(
|
| + web_contents(),
|
| + zoom_level,
|
| + zoom_level,
|
| + ZoomController::ZOOM_MODE_DEFAULT,
|
| + true /* can_show_bubble */);
|
| + {
|
| + ZoomChangedWatcher zoom_change_watcher(zoom_controller_.get(),
|
| + zoom_change_data);
|
| + zoom_controller_->OnDefaultZoomScopeChanged();
|
| + zoom_change_watcher.Wait();
|
| +
|
| + content::HostZoomMap* zoom_map =
|
| + content::HostZoomMap::GetForWebContents(web_contents());
|
| + EXPECT_FALSE(zoom_map->UsesTemporaryZoomLevel(process()->GetID(),
|
| + rvh()->GetRoutingID()));
|
| + }
|
| +}
|
|
|