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.
7 * Test that ToolbarManager.forceHideTopToolbar hides (or shows) the top
8 * toolbar correctly for different mouse movements.
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
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', {
31 toolbarManager.showToolbarsForMouseMove(e);
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
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();
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 = {
75 var toolbar = document.getElementById('material-toolbar');
76 var bookmarksDropdown = toolbar.$.bookmarks;
79 new ToolbarManager(mockWindow, toolbar, mockZoomToolbar);
80 toolbarManager.enableToolbars();
82 chrome.test.assertEq(680, bookmarksDropdown.lowerBound);
84 mockWindow.setSize(1920, 480);
85 chrome.test.assertEq(80, bookmarksDropdown.lowerBound);
87 chrome.test.succeed();
91 importTestHelpers().then(function() {
92 chrome.test.runTests(tests);