4
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
5
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
6
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
7
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
8
Code distributed by Google as part of the polymer project is also
9
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
14
<title>iron-menubar-behavior tests</title>
16
<meta charset="utf-8">
17
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
18
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
20
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
21
<script src="../../web-component-tester/browser.js"></script>
22
<link rel="import" href="../../iron-test-helpers/iron-test-helpers.html">
23
<link rel="import" href="test-menubar.html">
28
<test-fixture id="basic">
38
<test-fixture id="multi">
48
<test-fixture id="rtl">
62
suite('menubar a11y tests', function() {
64
test('menubar has role="menubar"', function() {
65
var menubar = fixture('basic');
66
assert.equal(menubar.getAttribute('role'), 'menubar', 'has role="menubar"');
69
test('first item gets focus when menubar is focused', function(done) {
70
var menubar = fixture('basic');
71
MockInteractions.focus(menubar);
72
Polymer.Base.async(function() {
73
assert.equal(Polymer.dom(document).activeElement, menubar.firstElementChild, 'document.activeElement is first item')
78
test('selected item gets focus when menubar is focused', function(done) {
79
var menubar = fixture('basic');
81
MockInteractions.focus(menubar);
82
Polymer.Base.async(function() {
83
assert.equal(Polymer.dom(document).activeElement, menubar.selectedItem, 'document.activeElement is selected item');
88
test('focusing non-item content does not auto-focus an item', function(done) {
89
var menubar = fixture('basic');
90
menubar.extraContent.focus();
91
Polymer.Base.async(function() {
92
var ownerRoot = Polymer.dom(menubar.extraContent).getOwnerRoot() || document;
93
var activeElement = Polymer.dom(ownerRoot).activeElement;
94
assert.equal(activeElement, menubar.extraContent, 'menubar.extraContent is focused');
95
assert.equal(Polymer.dom(document).activeElement, menubar, 'menubar is document.activeElement');
100
test('last activated item in a multi select menubar is focused', function(done) {
101
var menubar = fixture('multi');
102
menubar.selected = 0;
103
menubar.items[1].click();
104
Polymer.Base.async(function() {
105
assert.equal(Polymer.dom(document).activeElement, menubar.items[1], 'document.activeElement is last activated item');
110
test('deselection in a multi select menubar focuses deselected item', function(done) {
111
var menubar = fixture('multi');
112
menubar.selected = 0;
113
menubar.items[0].click();
114
Polymer.Base.async(function() {
115
assert.equal(Polymer.dom(document).activeElement, menubar.items[0], 'document.activeElement is last activated item');
120
suite('left / right keys are reversed when the menubar has RTL directionality', function() {
124
test('left key moves to the next item', function() {
125
var rtlContainer = fixture('rtl');
126
var menubar = rtlContainer.querySelector('test-menubar');
127
menubar.selected = 0;
128
menubar.items[1].click();
130
assert.equal(Polymer.dom(document).activeElement, menubar.items[1]);
132
MockInteractions.pressAndReleaseKeyOn(menubar, LEFT);
134
assert.equal(Polymer.dom(document).activeElement, menubar.items[2],
135
'`document.activeElement` should be the next item.');
136
assert.equal(menubar.selected, 1,
137
'`menubar.selected` should not change.');
140
test('right key moves to the previous item', function() {
141
var rtlContainer = fixture('rtl');
142
var menubar = rtlContainer.querySelector('test-menubar');
143
menubar.selected = 0;
144
menubar.items[1].click();
146
assert.equal(Polymer.dom(document).activeElement, menubar.items[1]);
148
MockInteractions.pressAndReleaseKeyOn(menubar, RIGHT);
150
assert.equal(Polymer.dom(document).activeElement, menubar.items[0],
151
'`document.activeElement` should be the previous item');
152
assert.equal(menubar.selected, 1,
153
'`menubar.selected` should not change.');