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
3 // found in the LICENSE file.
5 chrome.test.runTests(function() {
15 this.zooms.push(zoom);
21 * A mock implementation of the function used by ZoomManager to set the
24 class MockBrowserZoomSetter {
31 * The function implementing setBrowserZoomFunction.
33 setBrowserZoom(zoom) {
34 chrome.test.assertFalse(this.started);
38 return new Promise(function(resolve, reject) {
39 this.resolve_ = resolve;
44 * Resolves the promise returned by a call to setBrowserZoom.
53 function testZoomChange() {
54 let viewport = new MockViewport();
55 let browserZoomSetter = new MockBrowserZoomSetter();
56 let zoomManager = new ZoomManager(
57 viewport, browserZoomSetter.setBrowserZoom.bind(browserZoomSetter),
60 zoomManager.onPdfZoomChange();
61 chrome.test.assertEq(2, browserZoomSetter.zoom);
62 chrome.test.assertTrue(browserZoomSetter.started);
63 chrome.test.succeed();
66 function testBrowserZoomChange() {
67 let viewport = new MockViewport();
68 let zoomManager = new ZoomManager(viewport, chrome.test.fail, 1);
69 zoomManager.onBrowserZoomChange(3);
70 chrome.test.assertEq(1, viewport.zooms.length);
71 chrome.test.assertEq(3, viewport.zooms[0]);
72 chrome.test.assertEq(3, viewport.zoom);
73 chrome.test.succeed();
76 function testSmallZoomChange() {
77 let viewport = new MockViewport();
78 let browserZoomSetter = new MockBrowserZoomSetter();
79 let zoomManager = new ZoomManager(
80 viewport, browserZoomSetter.setBrowserZoom.bind(browserZoomSetter),
82 viewport.zoom = 2.0001;
83 zoomManager.onPdfZoomChange();
84 chrome.test.assertEq(1, browserZoomSetter.zoom);
85 chrome.test.assertFalse(browserZoomSetter.started);
86 chrome.test.succeed();
89 function testSmallBrowserZoomChange() {
90 let viewport = new MockViewport();
91 let zoomManager = new ZoomManager(viewport, chrome.test.fail, 1);
92 zoomManager.onBrowserZoomChange(0.999);
93 chrome.test.assertEq(0, viewport.zooms.length);
94 chrome.test.assertEq(1, viewport.zoom);
95 chrome.test.succeed();
98 function testMultiplePdfZoomChanges() {
99 let viewport = new MockViewport();
100 let browserZoomSetter = new MockBrowserZoomSetter();
101 let zoomManager = new ZoomManager(
102 viewport, browserZoomSetter.setBrowserZoom.bind(browserZoomSetter),
105 zoomManager.onPdfZoomChange();
107 zoomManager.onPdfZoomChange();
108 chrome.test.assertTrue(browserZoomSetter.started);
109 chrome.test.assertEq(2, browserZoomSetter.zoom);
110 browserZoomSetter.complete();
111 Promise.resolve().then(function() {
112 chrome.test.assertTrue(browserZoomSetter.started);
113 chrome.test.assertEq(3, browserZoomSetter.zoom);
114 chrome.test.succeed();
118 function testMultipleBrowserZoomChanges() {
119 let viewport = new MockViewport();
120 let zoomManager = new ZoomManager(viewport, chrome.test.fail, 1);
121 zoomManager.onBrowserZoomChange(2);
122 zoomManager.onBrowserZoomChange(3);
123 chrome.test.assertEq(2, viewport.zooms.length);
124 chrome.test.assertEq(2, viewport.zooms[0]);
125 chrome.test.assertEq(3, viewport.zooms[1]);
126 chrome.test.assertEq(3, viewport.zoom);
127 chrome.test.succeed();