2018-11-21 04:18:57 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2020-04-09 05:56:25 +00:00
|
|
|
const expect = require('expect');
|
2020-05-14 09:34:22 +00:00
|
|
|
const sinon = require('sinon');
|
|
|
|
|
2020-05-07 10:54:55 +00:00
|
|
|
const {
|
|
|
|
getTestState,
|
|
|
|
setupTestPageAndContextHooks,
|
|
|
|
setupTestBrowserHooks,
|
|
|
|
} = require('./mocha-utils');
|
2018-11-21 04:18:57 +00:00
|
|
|
|
2020-05-07 10:54:55 +00:00
|
|
|
describe('Page.Events.Dialog', function () {
|
2020-04-09 05:56:25 +00:00
|
|
|
setupTestBrowserHooks();
|
|
|
|
setupTestPageAndContextHooks();
|
2020-05-07 10:54:55 +00:00
|
|
|
it('should fire', async () => {
|
|
|
|
const { page } = getTestState();
|
2018-11-21 04:18:57 +00:00
|
|
|
|
2020-05-07 10:54:55 +00:00
|
|
|
page.on('dialog', (dialog) => {
|
2020-04-09 05:56:25 +00:00
|
|
|
expect(dialog.type()).toBe('alert');
|
|
|
|
expect(dialog.defaultValue()).toBe('');
|
|
|
|
expect(dialog.message()).toBe('yo');
|
|
|
|
dialog.accept();
|
2018-11-21 04:18:57 +00:00
|
|
|
});
|
2020-04-09 05:56:25 +00:00
|
|
|
await page.evaluate(() => alert('yo'));
|
|
|
|
});
|
2020-05-14 09:34:22 +00:00
|
|
|
|
2020-05-07 10:54:55 +00:00
|
|
|
itFailsFirefox('should allow accepting prompts', async () => {
|
|
|
|
const { page } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
2020-05-14 09:34:22 +00:00
|
|
|
const onDialog = sinon.stub().callsFake((dialog) => {
|
2020-04-09 05:56:25 +00:00
|
|
|
dialog.accept('answer!');
|
2018-11-21 04:18:57 +00:00
|
|
|
});
|
2020-05-14 09:34:22 +00:00
|
|
|
page.on('dialog', onDialog);
|
|
|
|
|
2020-04-09 05:56:25 +00:00
|
|
|
const result = await page.evaluate(() => prompt('question?', 'yes.'));
|
2020-05-14 09:34:22 +00:00
|
|
|
|
|
|
|
expect(onDialog.callCount).toEqual(1);
|
|
|
|
const dialog = onDialog.firstCall.args[0];
|
|
|
|
expect(dialog.type()).toBe('prompt');
|
|
|
|
expect(dialog.defaultValue()).toBe('yes.');
|
|
|
|
expect(dialog.message()).toBe('question?');
|
|
|
|
|
2020-04-09 05:56:25 +00:00
|
|
|
expect(result).toBe('answer!');
|
|
|
|
});
|
2020-05-07 10:54:55 +00:00
|
|
|
it('should dismiss the prompt', async () => {
|
|
|
|
const { page } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
2020-05-07 10:54:55 +00:00
|
|
|
page.on('dialog', (dialog) => {
|
2020-04-09 05:56:25 +00:00
|
|
|
dialog.dismiss();
|
2018-11-21 04:18:57 +00:00
|
|
|
});
|
2020-04-09 05:56:25 +00:00
|
|
|
const result = await page.evaluate(() => prompt('question?'));
|
|
|
|
expect(result).toBe(null);
|
2018-11-21 04:18:57 +00:00
|
|
|
});
|
2020-04-09 05:56:25 +00:00
|
|
|
});
|