summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/shadow-dom/focus-navigation/delegatesFocus-highlight-sibling.html
blob: dde18128ad8247f21c7e86d20fbe409de29ca6e5 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="resources/shadow-dom.js"></script>
<script src="resources/focus-utils.js"></script>
<!-- Adapted from http://jsbin.com/dexinu/6/edit for layout test -->

<template id='XMenuTemplate'>
  <style>
    :host {
      display: inline-block;
      position: relative;
      background-color: #aaa;
    }
    :host(:focus) {
      background-color: #ccc;
    }
    li {
      display: inline-block;
      position: relative;
      background-color: #eee;
    }
    li:focus {
      background-color: #fff;
    }
  </style>
  <li tabindex='0'>Item One</li>
  <li tabindex='0'>Item Two</li>
  <li tabindex='0'>Item Three</li>
</template>

<section>
  <x-menu id='XMenu1' tabindex='0'></x-menu>
</section>
<section>
  <x-menu id='XMenu2' tabindex='0' delegatesFocus></x-menu>
  <x-menu id='XMenu3' tabindex='0' delegatesFocus></x-menu>
</section>
<section>
  <x-menu id='XMenu4' tabindex='0' delegatesFocus></x-menu>
</section>

<script>
'use strict';

const template = document.querySelector('#XMenuTemplate');

customElements.define('x-menu', class extends HTMLElement {
    connectedCallback() {
        const delegatesFocus = this.hasAttribute('delegatesFocus');
        this.attachShadow({mode: 'open', delegatesFocus: delegatesFocus})
            .appendChild(document.importNode(template.content, true));
    }
});

promise_test(async () => {
    let xmenu1 = document.getElementById('XMenu1');

    xmenu1.focus();
    await navigateFocusForward();
    await navigateFocusForward();
    await navigateFocusForward();
    assert_equals(document.activeElement.id, 'XMenu1');
    assert_background_color('XMenu1', 'rgb(204, 204, 204)');
    assert_background_color('XMenu2', 'rgb(170, 170, 170)');
    assert_background_color('XMenu3', 'rgb(170, 170, 170)');
    assert_background_color('XMenu4', 'rgb(170, 170, 170)');

    await navigateFocusForward();
    await navigateFocusForward();
    await navigateFocusForward();
    assert_equals(document.activeElement.id, 'XMenu2');
    await assert_background_color('XMenu1', 'rgb(170, 170, 170)');
    await assert_background_color('XMenu2', 'rgb(204, 204, 204)');
    await assert_background_color('XMenu3', 'rgb(170, 170, 170)');
    await assert_background_color('XMenu4', 'rgb(170, 170, 170)');

    await navigateFocusForward();
    await navigateFocusForward();
    await navigateFocusForward();
    assert_equals(document.activeElement.id, 'XMenu3');
    assert_background_color('XMenu1', 'rgb(170, 170, 170)');
    assert_background_color('XMenu2', 'rgb(170, 170, 170)');
    assert_background_color('XMenu3', 'rgb(204, 204, 204)');
    assert_background_color('XMenu4', 'rgb(170, 170, 170)');

    await navigateFocusForward();
    await navigateFocusForward();
    await navigateFocusForward();
    assert_equals(document.activeElement.id, 'XMenu4');
    assert_background_color('XMenu1', 'rgb(170, 170, 170)');
    assert_background_color('XMenu2', 'rgb(170, 170, 170)');
    assert_background_color('XMenu3', 'rgb(170, 170, 170)');
    assert_background_color('XMenu4', 'rgb(204, 204, 204)');

    await navigateFocusBackward();
    await navigateFocusBackward();
    await navigateFocusBackward();
    assert_equals(document.activeElement.id, 'XMenu3');
    assert_background_color('XMenu1', 'rgb(170, 170, 170)');
    assert_background_color('XMenu2', 'rgb(170, 170, 170)');
    assert_background_color('XMenu3', 'rgb(204, 204, 204)');
    assert_background_color('XMenu4', 'rgb(170, 170, 170)');

    await navigateFocusBackward();
    await navigateFocusBackward();
    await navigateFocusBackward();
    assert_equals(document.activeElement.id, 'XMenu2');
    assert_background_color('XMenu1', 'rgb(170, 170, 170)');
    assert_background_color('XMenu2', 'rgb(204, 204, 204)');
    assert_background_color('XMenu3', 'rgb(170, 170, 170)');
    assert_background_color('XMenu4', 'rgb(170, 170, 170)');

    await navigateFocusBackward();
    await navigateFocusBackward();
    await navigateFocusBackward();
    assert_equals(document.activeElement.id, 'XMenu1');
    assert_background_color('XMenu1', 'rgb(204, 204, 204)');
    assert_background_color('XMenu2', 'rgb(170, 170, 170)');
    assert_background_color('XMenu3', 'rgb(170, 170, 170)');
    assert_background_color('XMenu4', 'rgb(170, 170, 170)');
}, 'crbug/474687 :focus style should properly be applied to shadow hosts.');
</script>