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.
7 * Test that some key elements exist and that they have the appropriate
8 * constructor name. This verifies that polymer is working correctly.
10 function testHasElements() {
13 'viewer-zoom-toolbar',
14 'viewer-password-screen',
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);
24 chrome.test.succeed();
28 * Test that the plugin element exists and is navigated to the correct URL.
30 function testPluginElement() {
31 var plugin = document.getElementById('plugin');
32 chrome.test.assertEq('embed', plugin.localName);
34 chrome.test.assertTrue(
35 plugin.getAttribute('src').indexOf('/pdf/test.pdf') != -1);
36 chrome.test.succeed();
40 * Test that shouldIgnoreKeyEvents correctly searches through the shadow DOM
41 * to find input fields.
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));
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));
53 chrome.test.assertFalse(
54 shouldIgnoreKeyEvents(document.getElementById('plugin')));
56 chrome.test.succeed();
60 * Test that the bookmarks menu can be closed by clicking the plugin and
63 function testOpenCloseBookmarks() {
64 var toolbar = $('material-toolbar');
66 var dropdown = toolbar.$.bookmarks;
67 var plugin = $('plugin');
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");
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");
86 MockInteractions.pressAndReleaseKeyOn(document, ESC_KEY);
87 chrome.test.assertFalse(toolbar.opened,
88 "Second escape key closes toolbar");
90 chrome.test.succeed();
94 * Test that the PDF filename is correctly extracted from URLs with query
95 * parameters and fragments.
97 function testGetFilenameFromURL(url) {
101 'http://example/com/path/with/multiple/sections/path.pdf'));
103 chrome.test.assertEq(
105 getFilenameFromURL('http://example.com/fragment.pdf#zoom=100/Title'));
107 chrome.test.assertEq(
108 'query.pdf', getFilenameFromURL('http://example.com/query.pdf?p=a/b'));
110 chrome.test.assertEq(
112 getFilenameFromURL('http://example.com/both.pdf?p=a/b#zoom=100/Title'));
114 chrome.test.assertEq(
115 'name with spaces.pdf',
116 getFilenameFromURL('http://example.com/name%20with%20spaces.pdf'));
118 chrome.test.assertEq(
119 'invalid%EDname.pdf',
120 getFilenameFromURL('http://example.com/invalid%EDname.pdf'));
122 chrome.test.succeed();
126 importTestHelpers().then(function() {
127 chrome.test.runTests(tests);