64 lines
2.7 KiB
JavaScript
64 lines
2.7 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('assert');
|
|
const { chromium } = require('playwright');
|
|
const { _private } = require('../src/services/aistudio_api_key_service');
|
|
|
|
(async () => {
|
|
const browser = await chromium.launch({ headless: true });
|
|
try {
|
|
const page = await browser.newPage({ viewport: { width: 1200, height: 800 } });
|
|
await page.setContent(`
|
|
<button id="create-api-key">Create API key</button>
|
|
<script>
|
|
setTimeout(() => {
|
|
const consent = document.createElement('div');
|
|
consent.setAttribute('role', 'dialog');
|
|
consent.style.cssText = 'width:500px;height:300px';
|
|
consent.innerHTML = '<p>Go Further. Build Smarter. Gemini API Additional Terms of Service and Google Privacy Policy.</p><button>Continue</button>';
|
|
document.body.appendChild(consent);
|
|
}, 300);
|
|
</script>
|
|
`);
|
|
const delayedStartedAt = Date.now();
|
|
const delayed = await _private.waitForCreationDialogOrConsent(page, 5000);
|
|
assert.strictEqual(delayed.consent, true,
|
|
'创建框点击期间延迟出现的 Additional Terms 必须被立即识别');
|
|
assert(Date.now() - delayedStartedAt < 2000,
|
|
'检测到条款后不能继续空等完整的创建框超时');
|
|
|
|
await page.setContent(`
|
|
<div id="first" role="dialog" style="width:500px;height:300px">
|
|
<p>Welcome to AI Studio</p>
|
|
<label><input type="checkbox"> I agree to the terms</label>
|
|
<button id="first-continue" class="ms-button-primary">Continue</button>
|
|
</div>
|
|
<script>
|
|
document.getElementById('first-continue').addEventListener('click', () => {
|
|
document.getElementById('first').remove();
|
|
setTimeout(() => {
|
|
const second = document.createElement('div');
|
|
second.id = 'second';
|
|
second.setAttribute('role', 'dialog');
|
|
second.style.cssText = 'width:500px;height:300px';
|
|
second.innerHTML = '<p>Go Further. Build Smarter. Gemini API Additional Terms of Service and Google Privacy Policy.</p><button id="second-continue">Continue</button>';
|
|
document.body.appendChild(second);
|
|
document.getElementById('second-continue').addEventListener('click', () => second.remove());
|
|
}, 800);
|
|
});
|
|
</script>
|
|
`);
|
|
|
|
const handled = await _private.dismissWelcomeConsent(page, () => {});
|
|
assert.strictEqual(handled, true);
|
|
assert.strictEqual(await page.locator('[role="dialog"]').count(), 0,
|
|
'第一层条款关闭后的延迟 Additional Terms 也必须被处理');
|
|
console.log('aistudio_consent_sequence.test.js: PASS');
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
})().catch(error => {
|
|
console.error(error);
|
|
process.exitCode = 1;
|
|
});
|