| 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 835867d5817b4e09ed56a54c97a960a27c790fd1..55e2b482d23ad1ec3558f2134c96013e105ff3ef 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,6 +14,8 @@
|
| #include "components/zoom/zoom_observer.h"
|
| #include "content/public/browser/host_zoom_map.h"
|
| #include "content/public/browser/navigation_handle.h"
|
| +#include "content/public/browser/storage_partition.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"
|
| @@ -26,6 +29,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
|
| @@ -34,6 +48,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->GetZoomScopeIsPerOriginPref());
|
| + }
|
| +
|
| void TearDown() override {
|
| zoom_controller_.reset();
|
| ChromeRenderViewHostTestHarness::TearDown();
|
| @@ -132,3 +151,190 @@ 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->SetZoomScopeIsPerOriginPref(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, DidFinishNavigation) {
|
| + 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);
|
| + std::unique_ptr<content::NavigationHandle> navigation_handle =
|
| + content::NavigationHandle::CreateNavigationHandleForTesting(
|
| + GURL(), rvh()->GetMainFrame(), true);
|
| + zoom_controller_->DidFinishNavigation(navigation_handle.get());
|
| + 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);
|
| + std::unique_ptr<content::NavigationHandle> navigation_handle =
|
| + content::NavigationHandle::CreateNavigationHandleForTesting(
|
| + GURL(), rvh()->GetMainFrame(), true);
|
| + zoom_controller_->DidFinishNavigation(navigation_handle.get());
|
| + 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);
|
| + std::unique_ptr<content::NavigationHandle> navigation_handle =
|
| + content::NavigationHandle::CreateNavigationHandleForTesting(
|
| + GURL(), rvh()->GetMainFrame(), true);
|
| + zoom_controller_->DidFinishNavigation(navigation_handle.get());
|
| + 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.
|
| + 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()));
|
| + }
|
| +}
|
|
|