| 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 suite('cr-dialog', function() { | 5 suite('cr-dialog', function() { |
| 6 setup(function() { | 6 setup(function() { |
| 7 PolymerTest.clearBody(); | 7 PolymerTest.clearBody(); |
| 8 }); | 8 }); |
| 9 | 9 |
| 10 test('focuses title on show', function() { | 10 test('focuses title on show', function() { |
| 11 document.body.innerHTML = ` | 11 document.body.innerHTML = ` |
| 12 <dialog is="cr-dialog"> | 12 <dialog is="cr-dialog"> |
| 13 <div class="title">title</div> | 13 <div class="title">title</div> |
| 14 <div class="body"><button>button</button></div> | 14 <div class="body"><button>button</button></div> |
| 15 </dialog>`; | 15 </dialog>`; |
| 16 | 16 |
| 17 assertFalse(document.activeElement.matches('div.title')); | 17 var dialog = document.body.querySelector('dialog'); |
| 18 assertFalse(document.activeElement.matches('button')); | 18 var button = document.body.querySelector('button'); |
| 19 | 19 |
| 20 document.body.querySelector('dialog').showModal(); | 20 assertNotEquals(dialog, document.activeElement); |
| 21 assertNotEquals(button, document.activeElement); |
| 21 | 22 |
| 22 expectTrue(document.activeElement.matches('div.title')); | 23 dialog.showModal(); |
| 23 expectFalse(document.activeElement.matches('button')); | 24 |
| 25 expectEquals(dialog, document.activeElement); |
| 26 expectNotEquals(button, document.activeElement); |
| 24 }); | 27 }); |
| 25 | 28 |
| 26 test('focuses [autofocus] instead of title when present', function() { | 29 test('focuses [autofocus] instead of title when present', function() { |
| 27 document.body.innerHTML = ` | 30 document.body.innerHTML = ` |
| 28 <dialog is="cr-dialog"> | 31 <dialog is="cr-dialog"> |
| 29 <div class="title">title</div> | 32 <div class="title">title</div> |
| 30 <div class="body"><button autofocus>button</button></div> | 33 <div class="body"><button autofocus>button</button></div> |
| 31 </dialog>`; | 34 </dialog>`; |
| 32 | 35 |
| 33 assertFalse(document.activeElement.matches('button')); | 36 var dialog = document.body.querySelector('dialog'); |
| 34 assertFalse(document.activeElement.matches('div.title')); | 37 var button = document.body.querySelector('button'); |
| 35 | 38 |
| 36 document.body.querySelector('dialog').showModal(); | 39 assertNotEquals(dialog, document.activeElement); |
| 40 assertNotEquals(button, document.activeElement); |
| 37 | 41 |
| 38 expectTrue(document.activeElement.matches('button')); | 42 dialog.showModal(); |
| 39 expectFalse(document.activeElement.matches('div.title')); | 43 |
| 44 expectNotEquals(dialog, document.activeElement); |
| 45 expectEquals(button, document.activeElement); |
| 40 }); | 46 }); |
| 41 }); | 47 }); |
| OLD | NEW |