| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 var tests = [ | |
| 6 /** | |
| 7 * Test that some key elements exist and that they have the appropriate | |
| 8 * constructor name. This verifies that polymer is working correctly. | |
| 9 */ | |
| 10 function testHasElements() { | |
| 11 var elementNames = [ | |
| 12 'viewer-pdf-toolbar', | |
| 13 'viewer-zoom-toolbar', | |
| 14 'viewer-password-screen', | |
| 15 'viewer-error-screen' | |
| 16 ]; | |
| 17 for (var i = 0; i < elementNames.length; i++) { | |
| 18 var elements = document.querySelectorAll(elementNames[i]); | |
| 19 chrome.test.assertEq(1, elements.length); | |
| 20 var element = elements[0]; | |
| 21 chrome.test.assertTrue( | |
| 22 String(element.constructor).indexOf(elementNames[i]) != -1); | |
| 23 } | |
| 24 chrome.test.succeed(); | |
| 25 }, | |
| 26 | |
| 27 /** | |
| 28 * Test that the plugin element exists and is navigated to the correct URL. | |
| 29 */ | |
| 30 function testPluginElement() { | |
| 31 var plugin = document.getElementById('plugin'); | |
| 32 chrome.test.assertEq('embed', plugin.localName); | |
| 33 | |
| 34 chrome.test.assertTrue( | |
| 35 plugin.getAttribute('src').indexOf('/pdf/test.pdf') != -1); | |
| 36 chrome.test.succeed(); | |
| 37 }, | |
| 38 | |
| 39 /** | |
| 40 * Test that shouldIgnoreKeyEvents correctly searches through the shadow DOM | |
| 41 * to find input fields. | |
| 42 */ | |
| 43 function testIgnoreKeyEvents() { | |
| 44 // Test that the traversal through the shadow DOM works correctly. | |
| 45 var toolbar = document.getElementById('material-toolbar'); | |
| 46 toolbar.$.pageselector.$.input.focus(); | |
| 47 chrome.test.assertTrue(shouldIgnoreKeyEvents(toolbar)); | |
| 48 | |
| 49 // Test case where the active element has a shadow root of its own. | |
| 50 toolbar.$.buttons.children[1].focus(); | |
| 51 chrome.test.assertFalse(shouldIgnoreKeyEvents(toolbar)); | |
| 52 | |
| 53 chrome.test.assertFalse( | |
| 54 shouldIgnoreKeyEvents(document.getElementById('plugin'))); | |
| 55 | |
| 56 chrome.test.succeed(); | |
| 57 }, | |
| 58 | |
| 59 /** | |
| 60 * Test that the bookmarks menu can be closed by clicking the plugin and | |
| 61 * pressing escape. | |
| 62 */ | |
| 63 function testOpenCloseBookmarks() { | |
| 64 var toolbar = $('material-toolbar'); | |
| 65 toolbar.show(); | |
| 66 var dropdown = toolbar.$.bookmarks; | |
| 67 var plugin = $('plugin'); | |
| 68 var ESC_KEY = 27; | |
| 69 | |
| 70 // Clicking on the plugin should close the bookmarks menu. | |
| 71 chrome.test.assertFalse(dropdown.dropdownOpen); | |
| 72 MockInteractions.tap(dropdown.$.icon); | |
| 73 chrome.test.assertTrue(dropdown.dropdownOpen); | |
| 74 MockInteractions.tap(plugin); | |
| 75 chrome.test.assertFalse(dropdown.dropdownOpen, | |
| 76 "Clicking plugin closes dropdown"); | |
| 77 | |
| 78 MockInteractions.tap(dropdown.$.icon); | |
| 79 chrome.test.assertTrue(dropdown.dropdownOpen); | |
| 80 MockInteractions.pressAndReleaseKeyOn(document, ESC_KEY); | |
| 81 chrome.test.assertFalse(dropdown.dropdownOpen, | |
| 82 "Escape key closes dropdown"); | |
| 83 chrome.test.assertTrue(toolbar.opened, | |
| 84 "First escape key does not close toolbar"); | |
| 85 | |
| 86 MockInteractions.pressAndReleaseKeyOn(document, ESC_KEY); | |
| 87 chrome.test.assertFalse(toolbar.opened, | |
| 88 "Second escape key closes toolbar"); | |
| 89 | |
| 90 chrome.test.succeed(); | |
| 91 }, | |
| 92 | |
| 93 /** | |
| 94 * Test that the PDF filename is correctly extracted from URLs with query | |
| 95 * parameters and fragments. | |
| 96 */ | |
| 97 function testGetFilenameFromURL(url) { | |
| 98 chrome.test.assertEq( | |
| 99 'path.pdf', | |
| 100 getFilenameFromURL( | |
| 101 'http://example/com/path/with/multiple/sections/path.pdf')); | |
| 102 | |
| 103 chrome.test.assertEq( | |
| 104 'fragment.pdf', | |
| 105 getFilenameFromURL('http://example.com/fragment.pdf#zoom=100/Title')); | |
| 106 | |
| 107 chrome.test.assertEq( | |
| 108 'query.pdf', getFilenameFromURL('http://example.com/query.pdf?p=a/b')); | |
| 109 | |
| 110 chrome.test.assertEq( | |
| 111 'both.pdf', | |
| 112 getFilenameFromURL('http://example.com/both.pdf?p=a/b#zoom=100/Title')); | |
| 113 | |
| 114 chrome.test.assertEq( | |
| 115 'name with spaces.pdf', | |
| 116 getFilenameFromURL('http://example.com/name%20with%20spaces.pdf')); | |
| 117 | |
| 118 chrome.test.assertEq( | |
| 119 'invalid%EDname.pdf', | |
| 120 getFilenameFromURL('http://example.com/invalid%EDname.pdf')); | |
| 121 | |
| 122 chrome.test.succeed(); | |
| 123 } | |
| 124 ]; | |
| 125 | |
| 126 importTestHelpers().then(function() { | |
| 127 chrome.test.runTests(tests); | |
| 128 }); | |
| OLD | NEW |