OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var tests = [ | 5 var tests = [ |
6 function testDocumentNeedsScrollbars() { | 6 function testDocumentNeedsScrollbars() { |
7 var viewport = | 7 var viewport = |
8 new Viewport(new MockWindow(100, 100), new MockSizer(), function() {}, | 8 new Viewport(new MockWindow(100, 100), new MockSizer(), function() {}, |
9 function() {}, function() {}, 10, 1); | 9 function() {}, function() {}, 10, 1); |
10 var scrollbars; | 10 var scrollbars; |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 }, | 484 }, |
485 | 485 |
486 function testInitialSetDocumentDimensionsZoomUnconstrained() { | 486 function testInitialSetDocumentDimensionsZoomUnconstrained() { |
487 var viewport = new Viewport( | 487 var viewport = new Viewport( |
488 new MockWindow(100, 100), | 488 new MockWindow(100, 100), |
489 new MockSizer(), function() {}, function() {}, function() {}, 0, 3); | 489 new MockSizer(), function() {}, function() {}, function() {}, 0, 3); |
490 viewport.setDocumentDimensions(new MockDocumentDimensions(50, 50)); | 490 viewport.setDocumentDimensions(new MockDocumentDimensions(50, 50)); |
491 chrome.test.assertEq(2, viewport.zoom); | 491 chrome.test.assertEq(2, viewport.zoom); |
492 chrome.test.succeed(); | 492 chrome.test.succeed(); |
493 }, | 493 }, |
| 494 |
| 495 function testToolbarHeightOffset() { |
| 496 var mockSizer = new MockSizer(); |
| 497 var mockWindow = new MockWindow(100, 100); |
| 498 var viewport = new Viewport(mockWindow, |
| 499 mockSizer, function() {}, function() {}, function() {}, 0, 1); |
| 500 viewport.topToolbarHeight = 50; |
| 501 var documentDimensions = new MockDocumentDimensions(0, 0); |
| 502 documentDimensions.addPage(50, 500); |
| 503 viewport.setDocumentDimensions(documentDimensions); |
| 504 viewport.setZoom(1); |
| 505 |
| 506 // Check that the sizer incorporates the toolbar height. |
| 507 chrome.test.assertEq('550px', mockSizer.style.height); |
| 508 chrome.test.assertEq('50px', mockSizer.style.width); |
| 509 chrome.test.assertEq(0, viewport.position.x); |
| 510 |
| 511 // Check the sizer incorporates the toolbar height correctly even if zoomed. |
| 512 viewport.setZoom(2); |
| 513 chrome.test.assertEq('1050px', mockSizer.style.height); |
| 514 chrome.test.assertEq('100px', mockSizer.style.width); |
| 515 |
| 516 // Test that the viewport scrolls to the correct offset when fit-to-page is |
| 517 // enabled. The top of the viewport should be at the start of the document. |
| 518 viewport.fitToPage(); |
| 519 chrome.test.assertEq(0, viewport.position.y); |
| 520 |
| 521 // Check that going to a page scrolls to the correct offset when fit-to-page |
| 522 // is enabled. The top of the viewport should be at the start of the |
| 523 // document. |
| 524 mockWindow.scrollTo(0, 100); |
| 525 viewport.goToPage(0); |
| 526 chrome.test.assertEq(0, viewport.position.y); |
| 527 |
| 528 // Check that going to a page scrolls to the correct offset when fit-to-page |
| 529 // is not enabled. The top of the viewport should be before start of the |
| 530 // document. |
| 531 viewport.setZoom(1); |
| 532 viewport.goToPage(0); |
| 533 chrome.test.assertEq(-50, viewport.position.y); |
| 534 chrome.test.succeed(); |
| 535 } |
494 ]; | 536 ]; |
495 | 537 |
496 chrome.test.runTests(tests); | 538 chrome.test.runTests(tests); |
OLD | NEW |