| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview Tests for cr-action-menu element. Runs as an interactive UI | 6 * @fileoverview Tests for cr-action-menu element. Runs as an interactive UI |
| 7 * test, since many of these tests check focus behavior. | 7 * test, since many of these tests check focus behavior. |
| 8 */ | 8 */ |
| 9 suite('CrActionMenu', function() { | 9 suite('CrActionMenu', function() { |
| 10 /** @type {?CrActionMenuElement} */ | 10 /** @type {?CrActionMenuElement} */ |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 }); | 89 }); |
| 90 | 90 |
| 91 test('close on resize', function() { | 91 test('close on resize', function() { |
| 92 menu.showAt(document.querySelector('#dots')); | 92 menu.showAt(document.querySelector('#dots')); |
| 93 assertTrue(menu.open); | 93 assertTrue(menu.open); |
| 94 | 94 |
| 95 window.dispatchEvent(new CustomEvent('resize')); | 95 window.dispatchEvent(new CustomEvent('resize')); |
| 96 assertFalse(menu.open); | 96 assertFalse(menu.open); |
| 97 }); | 97 }); |
| 98 | 98 |
| 99 test('close on popstate', function() { |
| 100 menu.showAt(document.querySelector('#dots')); |
| 101 assertTrue(menu.open); |
| 102 |
| 103 window.dispatchEvent(new CustomEvent('popstate')); |
| 104 assertFalse(menu.open); |
| 105 }); |
| 106 |
| 99 /** @param {string} key The key to use for closing. */ | 107 /** @param {string} key The key to use for closing. */ |
| 100 function testFocusAfterClosing(key) { | 108 function testFocusAfterClosing(key) { |
| 101 return new Promise(function(resolve) { | 109 return new Promise(function(resolve) { |
| 102 var dots = document.querySelector('#dots'); | 110 var dots = document.querySelector('#dots'); |
| 103 menu.showAt(dots); | 111 menu.showAt(dots); |
| 104 assertTrue(menu.open); | 112 assertTrue(menu.open); |
| 105 | 113 |
| 106 // Check that focus returns to the anchor element. | 114 // Check that focus returns to the anchor element. |
| 107 dots.addEventListener('focus', resolve); | 115 dots.addEventListener('focus', resolve); |
| 108 MockInteractions.keyDownOn(menu, key, [], key); | 116 MockInteractions.keyDownOn(menu, key, [], key); |
| 109 assertFalse(menu.open); | 117 assertFalse(menu.open); |
| 110 }); | 118 }); |
| 111 } | 119 } |
| 112 | 120 |
| 113 test('close on Tab', function() { return testFocusAfterClosing('Tab'); }); | 121 test('close on Tab', function() { return testFocusAfterClosing('Tab'); }); |
| 114 test('close on Escape', function() { | 122 test('close on Escape', function() { |
| 115 return testFocusAfterClosing('Escape'); | 123 return testFocusAfterClosing('Escape'); |
| 116 }); | 124 }); |
| 117 }); | 125 }); |
| OLD | NEW |