Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: chrome/test/data/webui/cr_elements/cr_dialog_test.js

Issue 2727663006: MD WebUI: change how initial focus works in <dialog>s now that they know about shadow DOM (Closed)
Patch Set: fix tests Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/webui/resources/cr_elements/cr_dialog/cr_dialog.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 });
OLDNEW
« no previous file with comments | « no previous file | ui/webui/resources/cr_elements/cr_dialog/cr_dialog.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698