/**
* Copyright 2018 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import expect from 'expect';
import {
getTestState,
setupTestBrowserHooks,
setupTestPageAndContextHooks,
describeFailsFirefox,
} from './mocha-utils'; // eslint-disable-line import/extensions
describeFailsFirefox('Accessibility', function () {
setupTestBrowserHooks();
setupTestPageAndContextHooks();
it('should work', async () => {
const { page, isFirefox } = getTestState();
await page.setContent(`
`);
const golden = isFirefox
? {
role: 'entry',
name: '',
value: 'Edit this image: my fake image',
children: [
{
role: 'text',
name: 'my fake image',
},
],
}
: {
role: 'textbox',
name: '',
value: 'Edit this image: ',
children: [
{
role: 'text',
name: 'Edit this image:',
},
{
role: 'img',
name: 'my fake image',
},
],
};
const snapshot = await page.accessibility.snapshot();
expect(snapshot.children[0]).toEqual(golden);
});
// Firefox does not support contenteditable="plaintext-only".
describeFailsFirefox('plaintext contenteditable', function () {
it('plain text field with role should not have children', async () => {
const { page } = getTestState();
await page.setContent(`
Edit this image:
`);
const snapshot = await page.accessibility.snapshot();
expect(snapshot.children[0]).toEqual({
role: 'textbox',
name: '',
value: 'Edit this image:',
});
});
it('plain text field without role should not have content', async () => {
const { page } = getTestState();
await page.setContent(`
Edit this image:
`);
const snapshot = await page.accessibility.snapshot();
expect(snapshot.children[0]).toEqual({
role: 'generic',
name: '',
});
});
it('plain text field with tabindex and without role should not have content', async () => {
const { page } = getTestState();
await page.setContent(`
Edit this image:
`);
const snapshot = await page.accessibility.snapshot();
expect(snapshot.children[0]).toEqual({
role: 'generic',
name: '',
});
});
});
it('non editable textbox with role and tabIndex and label should not have children', async () => {
const { page, isFirefox } = getTestState();
await page.setContent(`
this is the inner content
`);
const golden = isFirefox
? {
role: 'entry',
name: 'my favorite textbox',
value: 'this is the inner content yo',
}
: {
role: 'textbox',
name: 'my favorite textbox',
value: 'this is the inner content ',
};
const snapshot = await page.accessibility.snapshot();
expect(snapshot.children[0]).toEqual(golden);
});
it('checkbox with and tabIndex and label should not have children', async () => {
const { page, isFirefox } = getTestState();
await page.setContent(`