1 // Copyright 2014 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.
6 function testDocumentNeedsScrollbars() {
8 new Viewport(new MockWindow(100, 100), new MockSizer(), function() {},
9 function() {}, function() {}, 10, 1, 0);
12 viewport.setDocumentDimensions(new MockDocumentDimensions(90, 90));
13 scrollbars = viewport.documentNeedsScrollbars_(1);
14 chrome.test.assertFalse(scrollbars.vertical);
15 chrome.test.assertFalse(scrollbars.horizontal);
17 viewport.setDocumentDimensions(new MockDocumentDimensions(100.49, 100.49));
18 scrollbars = viewport.documentNeedsScrollbars_(1);
19 chrome.test.assertFalse(scrollbars.vertical);
20 chrome.test.assertFalse(scrollbars.horizontal);
22 viewport.setDocumentDimensions(new MockDocumentDimensions(100.5, 100.5));
23 scrollbars = viewport.documentNeedsScrollbars_(1);
24 chrome.test.assertTrue(scrollbars.vertical);
25 chrome.test.assertTrue(scrollbars.horizontal);
27 viewport.setDocumentDimensions(new MockDocumentDimensions(110, 110));
28 scrollbars = viewport.documentNeedsScrollbars_(1);
29 chrome.test.assertTrue(scrollbars.vertical);
30 chrome.test.assertTrue(scrollbars.horizontal);
32 viewport.setDocumentDimensions(new MockDocumentDimensions(90, 101));
33 scrollbars = viewport.documentNeedsScrollbars_(1);
34 chrome.test.assertTrue(scrollbars.vertical);
35 chrome.test.assertFalse(scrollbars.horizontal);
37 viewport.setDocumentDimensions(new MockDocumentDimensions(101, 90));
38 scrollbars = viewport.documentNeedsScrollbars_(1);
39 chrome.test.assertFalse(scrollbars.vertical);
40 chrome.test.assertTrue(scrollbars.horizontal);
42 viewport.setDocumentDimensions(new MockDocumentDimensions(91, 101));
43 scrollbars = viewport.documentNeedsScrollbars_(1);
44 chrome.test.assertTrue(scrollbars.vertical);
45 chrome.test.assertTrue(scrollbars.horizontal);
47 viewport.setDocumentDimensions(new MockDocumentDimensions(101, 91));
48 scrollbars = viewport.documentNeedsScrollbars_(1);
49 chrome.test.assertTrue(scrollbars.vertical);
50 chrome.test.assertTrue(scrollbars.horizontal);
52 viewport.setDocumentDimensions(new MockDocumentDimensions(40, 51));
53 scrollbars = viewport.documentNeedsScrollbars_(2);
54 chrome.test.assertTrue(scrollbars.vertical);
55 chrome.test.assertFalse(scrollbars.horizontal);
57 viewport.setDocumentDimensions(new MockDocumentDimensions(101, 202));
58 scrollbars = viewport.documentNeedsScrollbars_(0.5);
59 chrome.test.assertTrue(scrollbars.vertical);
60 chrome.test.assertFalse(scrollbars.horizontal);
61 chrome.test.succeed();
63 // Test the case when there is a toolbar at the top.
64 var toolbarHeight = 10;
66 new Viewport(new MockWindow(100, 100), new MockSizer(), function() {},
67 function() {}, function() {}, 10, 1, toolbarHeight);
70 viewport.setDocumentDimensions(new MockDocumentDimensions(90, 90));
71 scrollbars = viewport.documentNeedsScrollbars_(1);
72 chrome.test.assertFalse(scrollbars.vertical);
73 chrome.test.assertFalse(scrollbars.horizontal);
75 viewport.setDocumentDimensions(new MockDocumentDimensions(91, 91));
76 scrollbars = viewport.documentNeedsScrollbars_(1);
77 chrome.test.assertTrue(scrollbars.vertical);
78 chrome.test.assertFalse(scrollbars.horizontal);
80 viewport.setDocumentDimensions(new MockDocumentDimensions(100, 100));
81 scrollbars = viewport.documentNeedsScrollbars_(1);
82 chrome.test.assertTrue(scrollbars.vertical);
83 chrome.test.assertFalse(scrollbars.horizontal);
85 viewport.setDocumentDimensions(new MockDocumentDimensions(101, 101));
86 scrollbars = viewport.documentNeedsScrollbars_(1);
87 chrome.test.assertTrue(scrollbars.vertical);
88 chrome.test.assertTrue(scrollbars.horizontal);
90 viewport.setDocumentDimensions(new MockDocumentDimensions(45, 45));
91 scrollbars = viewport.documentNeedsScrollbars_(2);
92 chrome.test.assertFalse(scrollbars.vertical);
93 chrome.test.assertFalse(scrollbars.horizontal);
95 viewport.setDocumentDimensions(new MockDocumentDimensions(46, 46));
96 scrollbars = viewport.documentNeedsScrollbars_(2);
97 chrome.test.assertTrue(scrollbars.vertical);
98 chrome.test.assertFalse(scrollbars.horizontal);
101 function testSetZoom() {
102 var mockSizer = new MockSizer();
103 var mockWindow = new MockWindow(100, 100, mockSizer);
104 var mockCallback = new MockViewportChangedCallback();
105 var viewport = new Viewport(mockWindow, mockSizer, mockCallback.callback,
106 function() {}, function() {}, 0, 1, 0);
108 // Test setting the zoom without the document dimensions set. The sizer
109 // shouldn't change size.
110 mockCallback.reset();
111 viewport.setZoom(0.5);
112 chrome.test.assertEq(0.5, viewport.zoom);
113 chrome.test.assertTrue(mockCallback.wasCalled);
114 chrome.test.assertEq('0px', mockSizer.style.width);
115 chrome.test.assertEq('0px', mockSizer.style.height);
116 chrome.test.assertEq(0, mockWindow.pageXOffset);
117 chrome.test.assertEq(0, mockWindow.pageYOffset);
120 viewport.setDocumentDimensions(new MockDocumentDimensions(200, 200));
123 mockCallback.reset();
124 viewport.setZoom(0.5);
125 chrome.test.assertEq(0.5, viewport.zoom);
126 chrome.test.assertTrue(mockCallback.wasCalled);
127 chrome.test.assertEq('100px', mockSizer.style.width);
128 chrome.test.assertEq('100px', mockSizer.style.height);
131 mockCallback.reset();
133 chrome.test.assertEq(2, viewport.zoom);
134 chrome.test.assertTrue(mockCallback.wasCalled);
135 chrome.test.assertEq('400px', mockSizer.style.width);
136 chrome.test.assertEq('400px', mockSizer.style.height);
138 // Test that the scroll position scales correctly. It scales relative to the
139 // top-left of the page.
141 mockWindow.pageXOffset = 50;
142 mockWindow.pageYOffset = 50;
144 chrome.test.assertEq('400px', mockSizer.style.width);
145 chrome.test.assertEq('400px', mockSizer.style.height);
146 chrome.test.assertEq(100, mockWindow.pageXOffset);
147 chrome.test.assertEq(100, mockWindow.pageYOffset);
148 mockWindow.scrollTo(250, 250);
150 chrome.test.assertEq('200px', mockSizer.style.width);
151 chrome.test.assertEq('200px', mockSizer.style.height);
152 chrome.test.assertEq(100, mockWindow.pageXOffset);
153 chrome.test.assertEq(100, mockWindow.pageYOffset);
155 var documentDimensions = new MockDocumentDimensions(0, 0);
156 documentDimensions.addPage(200, 200);
157 viewport.setDocumentDimensions(documentDimensions);
158 mockWindow.scrollTo(0, 0);
159 viewport.fitToPage();
161 chrome.test.assertEq(Viewport.FittingType.NONE, viewport.fittingType);
162 chrome.test.assertEq('200px', mockSizer.style.width);
163 chrome.test.assertEq('200px', mockSizer.style.height);
164 chrome.test.assertEq(0, mockWindow.pageXOffset);
165 chrome.test.assertEq(0, mockWindow.pageYOffset);
167 viewport.fitToWidth();
169 chrome.test.assertEq(Viewport.FittingType.NONE, viewport.fittingType);
170 chrome.test.assertEq('200px', mockSizer.style.width);
171 chrome.test.assertEq('200px', mockSizer.style.height);
172 chrome.test.assertEq(0, mockWindow.pageXOffset);
173 chrome.test.assertEq(0, mockWindow.pageYOffset);
175 chrome.test.succeed();
178 function testGetMostVisiblePage() {
179 var mockWindow = new MockWindow(100, 100);
180 var viewport = new Viewport(mockWindow, new MockSizer(), function() {},
181 function() {}, function() {}, 0, 1, 0);
183 var documentDimensions = new MockDocumentDimensions(100, 100);
184 documentDimensions.addPage(50, 100);
185 documentDimensions.addPage(100, 100);
186 documentDimensions.addPage(100, 200);
187 viewport.setDocumentDimensions(documentDimensions);
190 // Scrolled to the start of the first page.
191 mockWindow.scrollTo(0, 0);
192 chrome.test.assertEq(0, viewport.getMostVisiblePage());
194 // Scrolled to the start of the second page.
195 mockWindow.scrollTo(0, 100);
196 chrome.test.assertEq(1, viewport.getMostVisiblePage());
198 // Scrolled half way through the first page.
199 mockWindow.scrollTo(0, 50);
200 chrome.test.assertEq(0, viewport.getMostVisiblePage());
202 // Scrolled just over half way through the first page.
203 mockWindow.scrollTo(0, 51);
204 chrome.test.assertEq(1, viewport.getMostVisiblePage());
206 // Scrolled most of the way through the second page.
207 mockWindow.scrollTo(0, 180);
208 chrome.test.assertEq(2, viewport.getMostVisiblePage());
210 // Scrolled just past half way through the second page.
211 mockWindow.scrollTo(0, 160);
212 chrome.test.assertEq(1, viewport.getMostVisiblePage());
214 // Scrolled just over half way through the first page with 2x zoom.
216 mockWindow.scrollTo(0, 151);
217 chrome.test.assertEq(1, viewport.getMostVisiblePage());
219 // Zoomed out with the entire document visible.
220 viewport.setZoom(0.25);
221 mockWindow.scrollTo(0, 0);
222 chrome.test.assertEq(0, viewport.getMostVisiblePage());
223 chrome.test.succeed();
226 function testFitToWidth() {
227 var mockWindow = new MockWindow(100, 100);
228 var mockSizer = new MockSizer();
229 var mockCallback = new MockViewportChangedCallback();
230 var viewport = new Viewport(mockWindow, mockSizer, mockCallback.callback,
231 function() {}, function() {}, 0, 1, 0);
232 var documentDimensions = new MockDocumentDimensions();
234 // Test with a document width which matches the window width.
235 documentDimensions.addPage(100, 100);
236 viewport.setDocumentDimensions(documentDimensions);
237 viewport.setZoom(0.1);
238 mockCallback.reset();
239 viewport.fitToWidth();
240 chrome.test.assertEq(Viewport.FittingType.FIT_TO_WIDTH,
241 viewport.fittingType);
242 chrome.test.assertTrue(mockCallback.wasCalled);
243 chrome.test.assertEq('100px', mockSizer.style.width);
244 chrome.test.assertEq(1, viewport.zoom);
246 // Test with a document width which is twice the size of the window width.
247 documentDimensions.reset();
248 documentDimensions.addPage(200, 100);
249 viewport.setDocumentDimensions(documentDimensions);
250 mockCallback.reset();
251 viewport.fitToWidth();
252 chrome.test.assertEq(Viewport.FittingType.FIT_TO_WIDTH,
253 viewport.fittingType);
254 chrome.test.assertTrue(mockCallback.wasCalled);
255 chrome.test.assertEq('100px', mockSizer.style.width);
256 chrome.test.assertEq(0.5, viewport.zoom);
258 // Test with a document width which is half the size of the window width.
259 documentDimensions.reset();
260 documentDimensions.addPage(50, 100);
261 viewport.setDocumentDimensions(documentDimensions);
262 mockCallback.reset();
263 viewport.fitToWidth();
264 chrome.test.assertEq(Viewport.FittingType.FIT_TO_WIDTH,
265 viewport.fittingType);
266 chrome.test.assertTrue(mockCallback.wasCalled);
267 chrome.test.assertEq('100px', mockSizer.style.width);
268 chrome.test.assertEq(2, viewport.zoom);
270 // Test that the scroll position stays the same relative to the page after
271 // fit to page is called.
272 documentDimensions.reset();
273 documentDimensions.addPage(50, 400);
274 viewport.setDocumentDimensions(documentDimensions);
276 mockWindow.scrollTo(0, 100);
277 mockCallback.reset();
278 viewport.fitToWidth();
279 chrome.test.assertEq(Viewport.FittingType.FIT_TO_WIDTH,
280 viewport.fittingType);
281 chrome.test.assertTrue(mockCallback.wasCalled);
282 chrome.test.assertEq(2, viewport.zoom);
283 chrome.test.assertEq(0, viewport.position.x);
284 chrome.test.assertEq(200, viewport.position.y);
286 // Test fitting works with scrollbars. The page will need to be zoomed to
287 // fit to width, which will cause the page height to span outside of the
288 // viewport, triggering 15px scrollbars to be shown.
289 viewport = new Viewport(mockWindow, mockSizer, mockCallback.callback,
290 function() {}, function() {}, 15, 1, 0);
291 documentDimensions.reset();
292 documentDimensions.addPage(50, 100);
293 viewport.setDocumentDimensions(documentDimensions);
294 mockCallback.reset();
295 viewport.fitToWidth();
296 chrome.test.assertEq(Viewport.FittingType.FIT_TO_WIDTH,
297 viewport.fittingType);
298 chrome.test.assertTrue(mockCallback.wasCalled);
299 chrome.test.assertEq('85px', mockSizer.style.width);
300 chrome.test.assertEq(1.7, viewport.zoom);
301 chrome.test.succeed();
304 function testFitToPage() {
305 var mockWindow = new MockWindow(100, 100);
306 var mockSizer = new MockSizer();
307 var mockCallback = new MockViewportChangedCallback();
308 var viewport = new Viewport(mockWindow, mockSizer, mockCallback.callback,
309 function() {}, function() {}, 0, 1, 0);
310 var documentDimensions = new MockDocumentDimensions();
312 // Test with a page size which matches the window size.
313 documentDimensions.addPage(100, 100);
314 viewport.setDocumentDimensions(documentDimensions);
315 viewport.setZoom(0.1);
316 mockCallback.reset();
317 viewport.fitToPage();
318 chrome.test.assertEq(Viewport.FittingType.FIT_TO_PAGE,
319 viewport.fittingType);
320 chrome.test.assertTrue(mockCallback.wasCalled);
321 chrome.test.assertEq('100px', mockSizer.style.width);
322 chrome.test.assertEq('100px', mockSizer.style.height);
323 chrome.test.assertEq(1, viewport.zoom);
325 // Test with a page size whose width is larger than its height.
326 documentDimensions.reset();
327 documentDimensions.addPage(200, 100);
328 viewport.setDocumentDimensions(documentDimensions);
329 mockCallback.reset();
330 viewport.fitToPage();
331 chrome.test.assertEq(Viewport.FittingType.FIT_TO_PAGE,
332 viewport.fittingType);
333 chrome.test.assertTrue(mockCallback.wasCalled);
334 chrome.test.assertEq('100px', mockSizer.style.width);
335 chrome.test.assertEq('50px', mockSizer.style.height);
336 chrome.test.assertEq(0.5, viewport.zoom);
338 // Test with a page size whose height is larger than its width.
339 documentDimensions.reset();
340 documentDimensions.addPage(100, 200);
341 viewport.setDocumentDimensions(documentDimensions);
342 mockCallback.reset();
343 viewport.fitToPage();
344 chrome.test.assertEq(Viewport.FittingType.FIT_TO_PAGE,
345 viewport.fittingType);
346 chrome.test.assertTrue(mockCallback.wasCalled);
347 chrome.test.assertEq('50px', mockSizer.style.width);
348 chrome.test.assertEq('100px', mockSizer.style.height);
349 chrome.test.assertEq(0.5, viewport.zoom);
351 // Test that when there are multiple pages the height of the most visible
352 // page and the width of the widest page are sized to.
353 documentDimensions.reset();
354 documentDimensions.addPage(100, 100);
355 documentDimensions.addPage(200, 400);
356 viewport.setDocumentDimensions(documentDimensions);
358 mockWindow.scrollTo(0, 0);
359 mockCallback.reset();
360 viewport.fitToPage();
361 chrome.test.assertEq(Viewport.FittingType.FIT_TO_PAGE,
362 viewport.fittingType);
363 chrome.test.assertTrue(mockCallback.wasCalled);
364 chrome.test.assertEq('100px', mockSizer.style.width);
365 chrome.test.assertEq('250px', mockSizer.style.height);
366 chrome.test.assertEq(0.5, viewport.zoom);
368 mockWindow.scrollTo(0, 100);
369 mockCallback.reset();
370 viewport.fitToPage();
371 chrome.test.assertTrue(mockCallback.wasCalled);
372 chrome.test.assertEq('50px', mockSizer.style.width);
373 chrome.test.assertEq('125px', mockSizer.style.height);
374 chrome.test.assertEq(0.25, viewport.zoom);
376 // Test that the top of the most visible page is scrolled to.
377 documentDimensions.reset();
378 documentDimensions.addPage(200, 200);
379 documentDimensions.addPage(100, 400);
380 viewport.setDocumentDimensions(documentDimensions);
382 mockWindow.scrollTo(0, 0);
383 viewport.fitToPage();
384 chrome.test.assertEq(Viewport.FittingType.FIT_TO_PAGE,
385 viewport.fittingType);
386 chrome.test.assertEq(0.5, viewport.zoom);
387 chrome.test.assertEq(0, viewport.position.x);
388 chrome.test.assertEq(0, viewport.position.y);
390 mockWindow.scrollTo(0, 175);
391 viewport.fitToPage();
392 chrome.test.assertEq(0.25, viewport.zoom);
393 chrome.test.assertEq(0, viewport.position.x);
394 chrome.test.assertEq(50, viewport.position.y);
396 // Test that when the window size changes, fit-to-page occurs but does not
397 // scroll to the top of the page (it should stay at the scaled scroll
399 mockWindow.scrollTo(0, 0);
400 viewport.fitToPage();
401 chrome.test.assertEq(Viewport.FittingType.FIT_TO_PAGE,
402 viewport.fittingType);
403 chrome.test.assertEq(0.5, viewport.zoom);
404 mockWindow.scrollTo(0, 10);
405 mockWindow.setSize(50, 50);
406 chrome.test.assertEq(0.25, viewport.zoom);
407 chrome.test.assertEq(0, viewport.position.x);
408 chrome.test.assertEq(5, viewport.position.y);
410 chrome.test.succeed();
413 function testGoToPage() {
414 var mockWindow = new MockWindow(100, 100);
415 var mockSizer = new MockSizer();
416 var mockCallback = new MockViewportChangedCallback();
417 var viewport = new Viewport(mockWindow, mockSizer, mockCallback.callback,
418 function() {}, function() {}, 0, 1, 0);
419 var documentDimensions = new MockDocumentDimensions();
421 documentDimensions.addPage(100, 100);
422 documentDimensions.addPage(200, 200);
423 documentDimensions.addPage(100, 400);
424 viewport.setDocumentDimensions(documentDimensions);
427 mockCallback.reset();
428 viewport.goToPage(0);
429 chrome.test.assertTrue(mockCallback.wasCalled);
430 chrome.test.assertEq(0, viewport.position.x);
431 chrome.test.assertEq(0, viewport.position.y);
433 mockCallback.reset();
434 viewport.goToPage(1);
435 chrome.test.assertTrue(mockCallback.wasCalled);
436 chrome.test.assertEq(0, viewport.position.x);
437 chrome.test.assertEq(100, viewport.position.y);
439 mockCallback.reset();
440 viewport.goToPage(2);
441 chrome.test.assertTrue(mockCallback.wasCalled);
442 chrome.test.assertEq(0, viewport.position.x);
443 chrome.test.assertEq(300, viewport.position.y);
445 viewport.setZoom(0.5);
446 mockCallback.reset();
447 viewport.goToPage(2);
448 chrome.test.assertTrue(mockCallback.wasCalled);
449 chrome.test.assertEq(0, viewport.position.x);
450 chrome.test.assertEq(150, viewport.position.y);
451 chrome.test.succeed();
454 function testGetPageScreenRect() {
455 var mockWindow = new MockWindow(100, 100);
456 var mockSizer = new MockSizer();
457 var mockCallback = new MockViewportChangedCallback();
458 var viewport = new Viewport(mockWindow, mockSizer, mockCallback.callback,
459 function() {}, function() {}, 0, 1, 0);
460 var documentDimensions = new MockDocumentDimensions();
461 documentDimensions.addPage(100, 100);
462 documentDimensions.addPage(200, 200);
463 viewport.setDocumentDimensions(documentDimensions);
466 // Test that the rect of the first page is positioned/sized correctly.
467 mockWindow.scrollTo(0, 0);
468 var rect1 = viewport.getPageScreenRect(0);
469 chrome.test.assertEq(Viewport.PAGE_SHADOW.left + 100 / 2, rect1.x);
470 chrome.test.assertEq(Viewport.PAGE_SHADOW.top, rect1.y);
471 chrome.test.assertEq(100 - Viewport.PAGE_SHADOW.right -
472 Viewport.PAGE_SHADOW.left, rect1.width);
473 chrome.test.assertEq(100 - Viewport.PAGE_SHADOW.bottom -
474 Viewport.PAGE_SHADOW.top, rect1.height);
476 // Check that when we scroll, the rect of the first page is updated
478 mockWindow.scrollTo(100, 10);
479 var rect2 = viewport.getPageScreenRect(0);
480 chrome.test.assertEq(rect1.x - 100, rect2.x);
481 chrome.test.assertEq(rect1.y - 10, rect2.y);
482 chrome.test.assertEq(rect1.width, rect2.width);
483 chrome.test.assertEq(rect1.height, rect2.height);
485 // Check the rect of the second page is positioned/sized correctly.
486 mockWindow.scrollTo(0, 100);
487 rect1 = viewport.getPageScreenRect(1);
488 chrome.test.assertEq(Viewport.PAGE_SHADOW.left, rect1.x);
489 chrome.test.assertEq(Viewport.PAGE_SHADOW.top, rect1.y);
490 chrome.test.assertEq(200 - Viewport.PAGE_SHADOW.right -
491 Viewport.PAGE_SHADOW.left, rect1.width);
492 chrome.test.assertEq(200 - Viewport.PAGE_SHADOW.bottom -
493 Viewport.PAGE_SHADOW.top, rect1.height);
494 chrome.test.succeed();
497 function testBeforeZoomAfterZoom() {
498 var mockWindow = new MockWindow(100, 100);
499 var mockSizer = new MockSizer();
501 var afterZoomCalled = false;
502 var beforeZoomCalled = false;
503 var afterZoom = function() {
504 afterZoomCalled = true;
505 chrome.test.assertTrue(beforeZoomCalled);
506 chrome.test.assertEq(0.5, viewport.zoom);
508 var beforeZoom = function() {
509 beforeZoomCalled = true;
510 chrome.test.assertFalse(afterZoomCalled);
511 chrome.test.assertEq(1, viewport.zoom);
513 viewport = new Viewport(mockWindow, mockSizer, function() {},
514 beforeZoom, afterZoom, 0, 1, 0);
515 viewport.setZoom(0.5);
516 chrome.test.succeed();
519 function testInitialSetDocumentDimensionsZoomConstrained() {
521 new Viewport(new MockWindow(100, 100), new MockSizer(), function() {},
522 function() {}, function() {}, 0, 1.2, 0);
523 viewport.setDocumentDimensions(new MockDocumentDimensions(50, 50));
524 chrome.test.assertEq(1.2, viewport.zoom);
525 chrome.test.succeed();
528 function testInitialSetDocumentDimensionsZoomUnconstrained() {
529 var viewport = new Viewport(
530 new MockWindow(100, 100),
531 new MockSizer(), function() {}, function() {}, function() {}, 0, 3, 0);
532 viewport.setDocumentDimensions(new MockDocumentDimensions(50, 50));
533 chrome.test.assertEq(2, viewport.zoom);
534 chrome.test.succeed();
537 function testToolbarHeightOffset() {
538 var mockSizer = new MockSizer();
539 var mockWindow = new MockWindow(100, 100);
540 var viewport = new Viewport(mockWindow,
541 mockSizer, function() {}, function() {}, function() {}, 0, 1, 50);
542 var documentDimensions = new MockDocumentDimensions(0, 0);
543 documentDimensions.addPage(50, 500);
544 viewport.setDocumentDimensions(documentDimensions);
547 // Check that the sizer incorporates the toolbar height.
548 chrome.test.assertEq('550px', mockSizer.style.height);
549 chrome.test.assertEq('50px', mockSizer.style.width);
550 chrome.test.assertEq(0, viewport.position.x);
552 // Check the sizer incorporates the toolbar height correctly even if zoomed.
554 chrome.test.assertEq('1050px', mockSizer.style.height);
555 chrome.test.assertEq('100px', mockSizer.style.width);
557 // Test that the viewport scrolls to the correct offset when fit-to-page is
558 // enabled. The top of the viewport should be at the start of the document.
559 viewport.fitToPage();
560 chrome.test.assertEq(0, viewport.position.y);
562 // Check that going to a page scrolls to the correct offset when fit-to-page
563 // is enabled. The top of the viewport should be at the start of the
565 mockWindow.scrollTo(0, 100);
566 viewport.goToPage(0);
567 chrome.test.assertEq(0, viewport.position.y);
569 // Check that going to a page scrolls to the correct offset when fit-to-page
570 // is not enabled. The top of the viewport should be before start of the
573 viewport.goToPage(0);
574 chrome.test.assertEq(-50, viewport.position.y);
575 chrome.test.succeed();
579 chrome.test.runTests(tests);