summaryrefslogtreecommitdiffstats
path: root/chrome/test/data/pdf/basic_test_material.js
blob: 9328525b55a087620c2493b62f1da8ca5c7c303b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

var tests = [
  /**
   * Test that some key elements exist and that they have the appropriate
   * constructor name. This verifies that polymer is working correctly.
   */
  function testHasElements() {
    var elementNames = [
      'viewer-pdf-toolbar',
      'viewer-zoom-toolbar',
      'viewer-password-screen',
      'viewer-error-screen'
    ];
    for (var i = 0; i < elementNames.length; i++) {
      var elements = document.querySelectorAll(elementNames[i]);
      chrome.test.assertEq(1, elements.length);
      var element = elements[0];
      chrome.test.assertTrue(
          String(element.constructor).indexOf(elementNames[i]) != -1);
    }
    chrome.test.succeed();
  },

  /**
   * Test that the plugin element exists and is navigated to the correct URL.
   */
  function testPluginElement() {
    var plugin = document.getElementById('plugin');
    chrome.test.assertEq('embed', plugin.localName);

    chrome.test.assertTrue(
        plugin.getAttribute('src').indexOf('/pdf/test.pdf') != -1);
    chrome.test.succeed();
  },

  /**
   * Test that shouldIgnoreKeyEvents correctly searches through the shadow DOM
   * to find input fields.
   */
  function testIgnoreKeyEvents() {
    // Test that the traversal through the shadow DOM works correctly.
    var toolbar = document.getElementById('material-toolbar');
    toolbar.$.pageselector.$.input.focus();
    chrome.test.assertTrue(shouldIgnoreKeyEvents(toolbar));

    // Test case where the active element has a shadow root of its own.
    toolbar.$.buttons.children[1].focus();
    chrome.test.assertFalse(shouldIgnoreKeyEvents(toolbar));

    chrome.test.assertFalse(
        shouldIgnoreKeyEvents(document.getElementById('plugin')));

    chrome.test.succeed();
  },

  /**
   * Test that the bookmarks menu can be closed by clicking the plugin and
   * pressing escape.
   */
  function testOpenCloseBookmarks() {
    var toolbar = $('material-toolbar');
    toolbar.show();
    var dropdown = toolbar.$.bookmarks;
    var plugin = $('plugin');
    var ESC_KEY = 27;

    // Clicking on the plugin should close the bookmarks menu.
    chrome.test.assertFalse(dropdown.dropdownOpen);
    MockInteractions.tap(dropdown.$.icon);
    chrome.test.assertTrue(dropdown.dropdownOpen);
    MockInteractions.tap(plugin);
    chrome.test.assertFalse(dropdown.dropdownOpen,
        "Clicking plugin closes dropdown");

    MockInteractions.tap(dropdown.$.icon);
    chrome.test.assertTrue(dropdown.dropdownOpen);
    MockInteractions.pressAndReleaseKeyOn(document, ESC_KEY);
    chrome.test.assertFalse(dropdown.dropdownOpen,
        "Escape key closes dropdown");
    chrome.test.assertTrue(toolbar.opened,
        "First escape key does not close toolbar");

    MockInteractions.pressAndReleaseKeyOn(document, ESC_KEY);
    chrome.test.assertFalse(toolbar.opened,
        "Second escape key closes toolbar");

    chrome.test.succeed();
  }
];

importTestHelpers().then(function() {
  chrome.test.runTests(tests);
});