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();
64 function testSetZoom() {
65 var mockSizer
= new MockSizer();
66 var mockWindow
= new MockWindow(100, 100, mockSizer
);
67 var mockCallback
= new MockViewportChangedCallback();
68 var viewport
= new Viewport(mockWindow
, mockSizer
, mockCallback
.callback
,
69 function() {}, function() {}, 0, 1, 0);
71 // Test setting the zoom without the document dimensions set. The sizer
72 // shouldn't change size.
74 viewport
.setZoom(0.5);
75 chrome
.test
.assertEq(0.5, viewport
.zoom
);
76 chrome
.test
.assertTrue(mockCallback
.wasCalled
);
77 chrome
.test
.assertEq('0px', mockSizer
.style
.width
);
78 chrome
.test
.assertEq('0px', mockSizer
.style
.height
);
79 chrome
.test
.assertEq(0, mockWindow
.pageXOffset
);
80 chrome
.test
.assertEq(0, mockWindow
.pageYOffset
);
83 viewport
.setDocumentDimensions(new MockDocumentDimensions(200, 200));
87 viewport
.setZoom(0.5);
88 chrome
.test
.assertEq(0.5, viewport
.zoom
);
89 chrome
.test
.assertTrue(mockCallback
.wasCalled
);
90 chrome
.test
.assertEq('100px', mockSizer
.style
.width
);
91 chrome
.test
.assertEq('100px', mockSizer
.style
.height
);
96 chrome
.test
.assertEq(2, viewport
.zoom
);
97 chrome
.test
.assertTrue(mockCallback
.wasCalled
);
98 chrome
.test
.assertEq('400px', mockSizer
.style
.width
);
99 chrome
.test
.assertEq('400px', mockSizer
.style
.height
);
101 // Test that the scroll position scales correctly. It scales relative to the
102 // top-left of the page.
104 mockWindow
.pageXOffset
= 50;
105 mockWindow
.pageYOffset
= 50;
107 chrome
.test
.assertEq('400px', mockSizer
.style
.width
);
108 chrome
.test
.assertEq('400px', mockSizer
.style
.height
);
109 chrome
.test
.assertEq(100, mockWindow
.pageXOffset
);
110 chrome
.test
.assertEq(100, mockWindow
.pageYOffset
);
111 mockWindow
.scrollTo(250, 250);
113 chrome
.test
.assertEq('200px', mockSizer
.style
.width
);
114 chrome
.test
.assertEq('200px', mockSizer
.style
.height
);
115 chrome
.test
.assertEq(100, mockWindow
.pageXOffset
);
116 chrome
.test
.assertEq(100, mockWindow
.pageYOffset
);
118 var documentDimensions
= new MockDocumentDimensions(0, 0);
119 documentDimensions
.addPage(200, 200);
120 viewport
.setDocumentDimensions(documentDimensions
);
121 mockWindow
.scrollTo(0, 0);
122 viewport
.fitToPage();
124 chrome
.test
.assertEq(Viewport
.FittingType
.NONE
, viewport
.fittingType
);
125 chrome
.test
.assertEq('200px', mockSizer
.style
.width
);
126 chrome
.test
.assertEq('200px', mockSizer
.style
.height
);
127 chrome
.test
.assertEq(0, mockWindow
.pageXOffset
);
128 chrome
.test
.assertEq(0, mockWindow
.pageYOffset
);
130 viewport
.fitToWidth();
132 chrome
.test
.assertEq(Viewport
.FittingType
.NONE
, viewport
.fittingType
);
133 chrome
.test
.assertEq('200px', mockSizer
.style
.width
);
134 chrome
.test
.assertEq('200px', mockSizer
.style
.height
);
135 chrome
.test
.assertEq(0, mockWindow
.pageXOffset
);
136 chrome
.test
.assertEq(0, mockWindow
.pageYOffset
);
138 chrome
.test
.succeed();
141 function testGetMostVisiblePage() {
142 var mockWindow
= new MockWindow(100, 100);
143 var viewport
= new Viewport(mockWindow
, new MockSizer(), function() {},
144 function() {}, function() {}, 0, 1, 0);
146 var documentDimensions
= new MockDocumentDimensions(100, 100);
147 documentDimensions
.addPage(50, 100);
148 documentDimensions
.addPage(100, 100);
149 documentDimensions
.addPage(100, 200);
150 viewport
.setDocumentDimensions(documentDimensions
);
153 // Scrolled to the start of the first page.
154 mockWindow
.scrollTo(0, 0);
155 chrome
.test
.assertEq(0, viewport
.getMostVisiblePage());
157 // Scrolled to the start of the second page.
158 mockWindow
.scrollTo(0, 100);
159 chrome
.test
.assertEq(1, viewport
.getMostVisiblePage());
161 // Scrolled half way through the first page.
162 mockWindow
.scrollTo(0, 50);
163 chrome
.test
.assertEq(0, viewport
.getMostVisiblePage());
165 // Scrolled just over half way through the first page.
166 mockWindow
.scrollTo(0, 51);
167 chrome
.test
.assertEq(1, viewport
.getMostVisiblePage());
169 // Scrolled most of the way through the second page.
170 mockWindow
.scrollTo(0, 180);
171 chrome
.test
.assertEq(2, viewport
.getMostVisiblePage());
173 // Scrolled just past half way through the second page.
174 mockWindow
.scrollTo(0, 160);
175 chrome
.test
.assertEq(1, viewport
.getMostVisiblePage());
177 // Scrolled just over half way through the first page with 2x zoom.
179 mockWindow
.scrollTo(0, 151);
180 chrome
.test
.assertEq(1, viewport
.getMostVisiblePage());
182 // Zoomed out with the entire document visible.
183 viewport
.setZoom(0.25);
184 mockWindow
.scrollTo(0, 0);
185 chrome
.test
.assertEq(0, viewport
.getMostVisiblePage());
186 chrome
.test
.succeed();
189 function testFitToWidth() {
190 var mockWindow
= new MockWindow(100, 100);
191 var mockSizer
= new MockSizer();
192 var mockCallback
= new MockViewportChangedCallback();
193 var viewport
= new Viewport(mockWindow
, mockSizer
, mockCallback
.callback
,
194 function() {}, function() {}, 0, 1, 0);
195 var documentDimensions
= new MockDocumentDimensions();
197 // Test with a document width which matches the window width.
198 documentDimensions
.addPage(100, 100);
199 viewport
.setDocumentDimensions(documentDimensions
);
200 viewport
.setZoom(0.1);
201 mockCallback
.reset();
202 viewport
.fitToWidth();
203 chrome
.test
.assertEq(Viewport
.FittingType
.FIT_TO_WIDTH
,
204 viewport
.fittingType
);
205 chrome
.test
.assertTrue(mockCallback
.wasCalled
);
206 chrome
.test
.assertEq('100px', mockSizer
.style
.width
);
207 chrome
.test
.assertEq(1, viewport
.zoom
);
209 // Test with a document width which is twice the size of the window width.
210 documentDimensions
.reset();
211 documentDimensions
.addPage(200, 100);
212 viewport
.setDocumentDimensions(documentDimensions
);
213 mockCallback
.reset();
214 viewport
.fitToWidth();
215 chrome
.test
.assertEq(Viewport
.FittingType
.FIT_TO_WIDTH
,
216 viewport
.fittingType
);
217 chrome
.test
.assertTrue(mockCallback
.wasCalled
);
218 chrome
.test
.assertEq('100px', mockSizer
.style
.width
);
219 chrome
.test
.assertEq(0.5, viewport
.zoom
);
221 // Test with a document width which is half the size of the window width.
222 documentDimensions
.reset();
223 documentDimensions
.addPage(50, 100);
224 viewport
.setDocumentDimensions(documentDimensions
);
225 mockCallback
.reset();
226 viewport
.fitToWidth();
227 chrome
.test
.assertEq(Viewport
.FittingType
.FIT_TO_WIDTH
,
228 viewport
.fittingType
);
229 chrome
.test
.assertTrue(mockCallback
.wasCalled
);
230 chrome
.test
.assertEq('100px', mockSizer
.style
.width
);
231 chrome
.test
.assertEq(2, viewport
.zoom
);
233 // Test that the scroll position stays the same relative to the page after
234 // fit to page is called.
235 documentDimensions
.reset();
236 documentDimensions
.addPage(50, 400);
237 viewport
.setDocumentDimensions(documentDimensions
);
239 mockWindow
.scrollTo(0, 100);
240 mockCallback
.reset();
241 viewport
.fitToWidth();
242 chrome
.test
.assertEq(Viewport
.FittingType
.FIT_TO_WIDTH
,
243 viewport
.fittingType
);
244 chrome
.test
.assertTrue(mockCallback
.wasCalled
);
245 chrome
.test
.assertEq(2, viewport
.zoom
);
246 chrome
.test
.assertEq(0, viewport
.position
.x
);
247 chrome
.test
.assertEq(200, viewport
.position
.y
);
249 // Test fitting works with scrollbars. The page will need to be zoomed to
250 // fit to width, which will cause the page height to span outside of the
251 // viewport, triggering 15px scrollbars to be shown.
252 viewport
= new Viewport(mockWindow
, mockSizer
, mockCallback
.callback
,
253 function() {}, function() {}, 15, 1, 0);
254 documentDimensions
.reset();
255 documentDimensions
.addPage(50, 100);
256 viewport
.setDocumentDimensions(documentDimensions
);
257 mockCallback
.reset();
258 viewport
.fitToWidth();
259 chrome
.test
.assertEq(Viewport
.FittingType
.FIT_TO_WIDTH
,
260 viewport
.fittingType
);
261 chrome
.test
.assertTrue(mockCallback
.wasCalled
);
262 chrome
.test
.assertEq('85px', mockSizer
.style
.width
);
263 chrome
.test
.assertEq(1.7, viewport
.zoom
);
264 chrome
.test
.succeed();
267 function testFitToPage() {
268 var mockWindow
= new MockWindow(100, 100);
269 var mockSizer
= new MockSizer();
270 var mockCallback
= new MockViewportChangedCallback();
271 var viewport
= new Viewport(mockWindow
, mockSizer
, mockCallback
.callback
,
272 function() {}, function() {}, 0, 1, 0);
273 var documentDimensions
= new MockDocumentDimensions();
275 // Test with a page size which matches the window size.
276 documentDimensions
.addPage(100, 100);
277 viewport
.setDocumentDimensions(documentDimensions
);
278 viewport
.setZoom(0.1);
279 mockCallback
.reset();
280 viewport
.fitToPage();
281 chrome
.test
.assertEq(Viewport
.FittingType
.FIT_TO_PAGE
,
282 viewport
.fittingType
);
283 chrome
.test
.assertTrue(mockCallback
.wasCalled
);
284 chrome
.test
.assertEq('100px', mockSizer
.style
.width
);
285 chrome
.test
.assertEq('100px', mockSizer
.style
.height
);
286 chrome
.test
.assertEq(1, viewport
.zoom
);
288 // Test with a page size whose width is larger than its height.
289 documentDimensions
.reset();
290 documentDimensions
.addPage(200, 100);
291 viewport
.setDocumentDimensions(documentDimensions
);
292 mockCallback
.reset();
293 viewport
.fitToPage();
294 chrome
.test
.assertEq(Viewport
.FittingType
.FIT_TO_PAGE
,
295 viewport
.fittingType
);
296 chrome
.test
.assertTrue(mockCallback
.wasCalled
);
297 chrome
.test
.assertEq('100px', mockSizer
.style
.width
);
298 chrome
.test
.assertEq('50px', mockSizer
.style
.height
);
299 chrome
.test
.assertEq(0.5, viewport
.zoom
);
301 // Test with a page size whose height is larger than its width.
302 documentDimensions
.reset();
303 documentDimensions
.addPage(100, 200);
304 viewport
.setDocumentDimensions(documentDimensions
);
305 mockCallback
.reset();
306 viewport
.fitToPage();
307 chrome
.test
.assertEq(Viewport
.FittingType
.FIT_TO_PAGE
,
308 viewport
.fittingType
);
309 chrome
.test
.assertTrue(mockCallback
.wasCalled
);
310 chrome
.test
.assertEq('50px', mockSizer
.style
.width
);
311 chrome
.test
.assertEq('100px', mockSizer
.style
.height
);
312 chrome
.test
.assertEq(0.5, viewport
.zoom
);
314 // Test that when there are multiple pages the height of the most visible
315 // page and the width of the widest page are sized to.
316 documentDimensions
.reset();
317 documentDimensions
.addPage(100, 100);
318 documentDimensions
.addPage(200, 400);
319 viewport
.setDocumentDimensions(documentDimensions
);
321 mockWindow
.scrollTo(0, 0);
322 mockCallback
.reset();
323 viewport
.fitToPage();
324 chrome
.test
.assertEq(Viewport
.FittingType
.FIT_TO_PAGE
,
325 viewport
.fittingType
);
326 chrome
.test
.assertTrue(mockCallback
.wasCalled
);
327 chrome
.test
.assertEq('100px', mockSizer
.style
.width
);
328 chrome
.test
.assertEq('250px', mockSizer
.style
.height
);
329 chrome
.test
.assertEq(0.5, viewport
.zoom
);
331 mockWindow
.scrollTo(0, 100);
332 mockCallback
.reset();
333 viewport
.fitToPage();
334 chrome
.test
.assertTrue(mockCallback
.wasCalled
);
335 chrome
.test
.assertEq('50px', mockSizer
.style
.width
);
336 chrome
.test
.assertEq('125px', mockSizer
.style
.height
);
337 chrome
.test
.assertEq(0.25, viewport
.zoom
);
339 // Test that the top of the most visible page is scrolled to.
340 documentDimensions
.reset();
341 documentDimensions
.addPage(200, 200);
342 documentDimensions
.addPage(100, 400);
343 viewport
.setDocumentDimensions(documentDimensions
);
345 mockWindow
.scrollTo(0, 0);
346 viewport
.fitToPage();
347 chrome
.test
.assertEq(Viewport
.FittingType
.FIT_TO_PAGE
,
348 viewport
.fittingType
);
349 chrome
.test
.assertEq(0.5, viewport
.zoom
);
350 chrome
.test
.assertEq(0, viewport
.position
.x
);
351 chrome
.test
.assertEq(0, viewport
.position
.y
);
353 mockWindow
.scrollTo(0, 175);
354 viewport
.fitToPage();
355 chrome
.test
.assertEq(0.25, viewport
.zoom
);
356 chrome
.test
.assertEq(0, viewport
.position
.x
);
357 chrome
.test
.assertEq(50, viewport
.position
.y
);
359 // Test that when the window size changes, fit-to-page occurs but does not
360 // scroll to the top of the page (it should stay at the scaled scroll
362 mockWindow
.scrollTo(0, 0);
363 viewport
.fitToPage();
364 chrome
.test
.assertEq(Viewport
.FittingType
.FIT_TO_PAGE
,
365 viewport
.fittingType
);
366 chrome
.test
.assertEq(0.5, viewport
.zoom
);
367 mockWindow
.scrollTo(0, 10);
368 mockWindow
.setSize(50, 50);
369 chrome
.test
.assertEq(0.25, viewport
.zoom
);
370 chrome
.test
.assertEq(0, viewport
.position
.x
);
371 chrome
.test
.assertEq(5, viewport
.position
.y
);
373 chrome
.test
.succeed();
376 function testGoToPage() {
377 var mockWindow
= new MockWindow(100, 100);
378 var mockSizer
= new MockSizer();
379 var mockCallback
= new MockViewportChangedCallback();
380 var viewport
= new Viewport(mockWindow
, mockSizer
, mockCallback
.callback
,
381 function() {}, function() {}, 0, 1, 0);
382 var documentDimensions
= new MockDocumentDimensions();
384 documentDimensions
.addPage(100, 100);
385 documentDimensions
.addPage(200, 200);
386 documentDimensions
.addPage(100, 400);
387 viewport
.setDocumentDimensions(documentDimensions
);
390 mockCallback
.reset();
391 viewport
.goToPage(0);
392 chrome
.test
.assertTrue(mockCallback
.wasCalled
);
393 chrome
.test
.assertEq(0, viewport
.position
.x
);
394 chrome
.test
.assertEq(0, viewport
.position
.y
);
396 mockCallback
.reset();
397 viewport
.goToPage(1);
398 chrome
.test
.assertTrue(mockCallback
.wasCalled
);
399 chrome
.test
.assertEq(0, viewport
.position
.x
);
400 chrome
.test
.assertEq(100, viewport
.position
.y
);
402 mockCallback
.reset();
403 viewport
.goToPage(2);
404 chrome
.test
.assertTrue(mockCallback
.wasCalled
);
405 chrome
.test
.assertEq(0, viewport
.position
.x
);
406 chrome
.test
.assertEq(300, viewport
.position
.y
);
408 viewport
.setZoom(0.5);
409 mockCallback
.reset();
410 viewport
.goToPage(2);
411 chrome
.test
.assertTrue(mockCallback
.wasCalled
);
412 chrome
.test
.assertEq(0, viewport
.position
.x
);
413 chrome
.test
.assertEq(150, viewport
.position
.y
);
414 chrome
.test
.succeed();
417 function testGetPageScreenRect() {
418 var mockWindow
= new MockWindow(100, 100);
419 var mockSizer
= new MockSizer();
420 var mockCallback
= new MockViewportChangedCallback();
421 var viewport
= new Viewport(mockWindow
, mockSizer
, mockCallback
.callback
,
422 function() {}, function() {}, 0, 1, 0);
423 var documentDimensions
= new MockDocumentDimensions();
424 documentDimensions
.addPage(100, 100);
425 documentDimensions
.addPage(200, 200);
426 viewport
.setDocumentDimensions(documentDimensions
);
429 // Test that the rect of the first page is positioned/sized correctly.
430 mockWindow
.scrollTo(0, 0);
431 var rect1
= viewport
.getPageScreenRect(0);
432 chrome
.test
.assertEq(Viewport
.PAGE_SHADOW
.left
+ 100 / 2, rect1
.x
);
433 chrome
.test
.assertEq(Viewport
.PAGE_SHADOW
.top
, rect1
.y
);
434 chrome
.test
.assertEq(100 - Viewport
.PAGE_SHADOW
.right
-
435 Viewport
.PAGE_SHADOW
.left
, rect1
.width
);
436 chrome
.test
.assertEq(100 - Viewport
.PAGE_SHADOW
.bottom
-
437 Viewport
.PAGE_SHADOW
.top
, rect1
.height
);
439 // Check that when we scroll, the rect of the first page is updated
441 mockWindow
.scrollTo(100, 10);
442 var rect2
= viewport
.getPageScreenRect(0);
443 chrome
.test
.assertEq(rect1
.x
- 100, rect2
.x
);
444 chrome
.test
.assertEq(rect1
.y
- 10, rect2
.y
);
445 chrome
.test
.assertEq(rect1
.width
, rect2
.width
);
446 chrome
.test
.assertEq(rect1
.height
, rect2
.height
);
448 // Check the rect of the second page is positioned/sized correctly.
449 mockWindow
.scrollTo(0, 100);
450 rect1
= viewport
.getPageScreenRect(1);
451 chrome
.test
.assertEq(Viewport
.PAGE_SHADOW
.left
, rect1
.x
);
452 chrome
.test
.assertEq(Viewport
.PAGE_SHADOW
.top
, rect1
.y
);
453 chrome
.test
.assertEq(200 - Viewport
.PAGE_SHADOW
.right
-
454 Viewport
.PAGE_SHADOW
.left
, rect1
.width
);
455 chrome
.test
.assertEq(200 - Viewport
.PAGE_SHADOW
.bottom
-
456 Viewport
.PAGE_SHADOW
.top
, rect1
.height
);
457 chrome
.test
.succeed();
460 function testBeforeZoomAfterZoom() {
461 var mockWindow
= new MockWindow(100, 100);
462 var mockSizer
= new MockSizer();
464 var afterZoomCalled
= false;
465 var beforeZoomCalled
= false;
466 var afterZoom = function() {
467 afterZoomCalled
= true;
468 chrome
.test
.assertTrue(beforeZoomCalled
);
469 chrome
.test
.assertEq(0.5, viewport
.zoom
);
471 var beforeZoom = function() {
472 beforeZoomCalled
= true;
473 chrome
.test
.assertFalse(afterZoomCalled
);
474 chrome
.test
.assertEq(1, viewport
.zoom
);
476 viewport
= new Viewport(mockWindow
, mockSizer
, function() {},
477 beforeZoom
, afterZoom
, 0, 1, 0);
478 viewport
.setZoom(0.5);
479 chrome
.test
.succeed();
482 function testInitialSetDocumentDimensionsZoomConstrained() {
484 new Viewport(new MockWindow(100, 100), new MockSizer(), function() {},
485 function() {}, function() {}, 0, 1.2, 0);
486 viewport
.setDocumentDimensions(new MockDocumentDimensions(50, 50));
487 chrome
.test
.assertEq(1.2, viewport
.zoom
);
488 chrome
.test
.succeed();
491 function testInitialSetDocumentDimensionsZoomUnconstrained() {
492 var viewport
= new Viewport(
493 new MockWindow(100, 100),
494 new MockSizer(), function() {}, function() {}, function() {}, 0, 3, 0);
495 viewport
.setDocumentDimensions(new MockDocumentDimensions(50, 50));
496 chrome
.test
.assertEq(2, viewport
.zoom
);
497 chrome
.test
.succeed();
500 function testToolbarHeightOffset() {
501 var mockSizer
= new MockSizer();
502 var mockWindow
= new MockWindow(100, 100);
503 var viewport
= new Viewport(mockWindow
,
504 mockSizer
, function() {}, function() {}, function() {}, 0, 1, 50);
505 var documentDimensions
= new MockDocumentDimensions(0, 0);
506 documentDimensions
.addPage(50, 500);
507 viewport
.setDocumentDimensions(documentDimensions
);
510 // Check that the sizer incorporates the toolbar height.
511 chrome
.test
.assertEq('550px', mockSizer
.style
.height
);
512 chrome
.test
.assertEq('50px', mockSizer
.style
.width
);
513 chrome
.test
.assertEq(0, viewport
.position
.x
);
515 // Check the sizer incorporates the toolbar height correctly even if zoomed.
517 chrome
.test
.assertEq('1050px', mockSizer
.style
.height
);
518 chrome
.test
.assertEq('100px', mockSizer
.style
.width
);
520 // Test that the viewport scrolls to the correct offset when fit-to-page is
521 // enabled. The top of the viewport should be at the start of the document.
522 viewport
.fitToPage();
523 chrome
.test
.assertEq(0, viewport
.position
.y
);
525 // Check that going to a page scrolls to the correct offset when fit-to-page
526 // is enabled. The top of the viewport should be at the start of the
528 mockWindow
.scrollTo(0, 100);
529 viewport
.goToPage(0);
530 chrome
.test
.assertEq(0, viewport
.position
.y
);
532 // Check that going to a page scrolls to the correct offset when fit-to-page
533 // is not enabled. The top of the viewport should be before start of the
536 viewport
.goToPage(0);
537 chrome
.test
.assertEq(-50, viewport
.position
.y
);
538 chrome
.test
.succeed();
542 chrome
.test
.runTests(tests
);