Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / chrome / test / data / pdf / toolbar_manager_test.js
blob51319a5e6d5c961b8cba47a30ac8fc566bb65466
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 var tests = [
6 /**
7 * Test that ToolbarManager.forceHideTopToolbar hides (or shows) the top
8 * toolbar correctly for different mouse movements.
9 */
10 function testToolbarManagerForceHideTopToolbar() {
11 var mockWindow = new MockWindow(1920, 1080);
13 var toolbar = Polymer.Base.create('viewer-pdf-toolbar');
14 var zoomToolbar = Polymer.Base.create('viewer-zoom-toolbar');
15 var toolbarManager = new ToolbarManager(mockWindow, toolbar, zoomToolbar);
17 // A cut-down version of MockInteractions.move, which is not exposed
18 // publicly.
19 var mouseMove = function(fromX, fromY, toX, toY, steps) {
20 var dx = Math.round((toX - fromX) / steps);
21 var dy = Math.round((toY - fromY) / steps);
23 // Deliberate <= to ensure that an event is run for toX, toY
24 for (var i = 0; i <= steps; i++) {
25 var e = new MouseEvent('mousemove', {
26 clientX: fromX,
27 clientY: fromY,
28 movementX: dx,
29 movementY: dy
30 });
31 toolbarManager.showToolbarsForMouseMove(e);
32 fromX += dx;
33 fromY += dy;
37 // Force hide the toolbar, then do a quick mousemove in the center of the
38 // window. Top toolbar should not show.
39 toolbarManager.forceHideTopToolbar();
40 chrome.test.assertFalse(toolbar.opened);
41 mouseMove(1900, 1000, 100, 1000, 2);
42 chrome.test.assertFalse(toolbar.opened);
43 // Move back into the zoom toolbar again. The top toolbar should still not
44 // show.
45 mouseMove(100, 1000, 1900, 1000, 2);
46 chrome.test.assertFalse(toolbar.opened);
48 // Hide the toolbar, wait for the timeout to expire, then move the mouse
49 // quickly. The top toolbar should show.
50 toolbarManager.forceHideTopToolbar();
51 chrome.test.assertFalse(toolbar.opened);
52 // Manually expire the timeout. This is the same as waiting 1 second.
53 mockWindow.runTimeout();
54 mouseMove(1900, 1000, 100, 1000, 2);
55 chrome.test.assertTrue(toolbar.opened);
57 // Force hide the toolbar, then move the mouse to the top of the screen. The
58 // top toolbar should show.
59 toolbarManager.forceHideTopToolbar();
60 chrome.test.assertFalse(toolbar.opened);
61 mouseMove(1900, 1000, 1000, 30, 5);
62 chrome.test.assertTrue(toolbar.opened);
64 chrome.test.succeed();
67 /**
68 * Test that changes to window height bubble down to dropdowns correctly.
70 function testToolbarManagerResizeDropdown() {
71 var mockWindow = new MockWindow(1920, 1080);
72 var mockZoomToolbar = {
73 clientHeight: 400
75 var toolbar = document.getElementById('material-toolbar');
76 var bookmarksDropdown = toolbar.$.bookmarks;
78 var toolbarManager =
79 new ToolbarManager(mockWindow, toolbar, mockZoomToolbar);
81 chrome.test.assertEq(680, bookmarksDropdown.lowerBound);
83 mockWindow.setSize(1920, 480);
84 chrome.test.assertEq(80, bookmarksDropdown.lowerBound);
86 chrome.test.succeed();
90 importTestHelpers().then(function() {
91 chrome.test.runTests(tests);
92 });