Iomatex_OS/android_console/tests/browser_bench.cjs

64 lines
5.1 KiB
JavaScript

const {chromium}=require(process.env.PLAYWRIGHT_MODULE || 'playwright');
const {execFileSync}=require('child_process');
(async()=>{
const browser=await chromium.launch({headless:true,executablePath:process.env.CHROMIUM_EXECUTABLE});const page=await browser.newPage({viewport:{width:1280,height:900}});const errors=[];page.on('pageerror',e=>errors.push(e.message));
let cookie='';
await page.route('http://127.0.0.1:18080/**',async route=>{
const req=route.request();let args=['-sS','-i','--max-time','8',req.url()];if(cookie)args.push('-H','Cookie: '+cookie);if(req.method()==='POST')args.push('-H','Content-Type: application/json','--data-binary','@-');
const raw=execFileSync('/mnt/c/Windows/System32/curl.exe',args,{input:req.postData()||'',maxBuffer:10000000});const pos=raw.indexOf('\r\n\r\n');const h=raw.subarray(0,pos).toString();const headers={};for(const line of h.split('\r\n').slice(1)){let k=line.indexOf(':');if(k>0)headers[line.slice(0,k).toLowerCase()]=line.slice(k+1).trim();}if(headers['set-cookie'])cookie=headers['set-cookie'].split(';')[0];delete headers['content-length'];delete headers['connection'];
await route.fulfill({status:Number(h.split(' ')[1]),headers,body:raw.subarray(pos+4)});
});
await page.goto('http://127.0.0.1:18080/');await page.waitForTimeout(1500);
console.log('Inputs:',await page.locator('input').evaluateAll(xs=>xs.map(x=>({id:x.id,type:x.type}))));
const xml=execFileSync(process.env.ADB || '/mnt/c/Users/Andrei/AppData/Local/Android/Sdk/platform-tools/adb.exe',['-s',process.env.ANDROID_SERIAL || '192.168.0.186:5555','shell','run-as '+(process.env.CONSOLE_PACKAGE || 'com.iomatex.console')+' cat shared_prefs/console.xml'],{encoding:'utf8'});const password=xml.match(/name="password">([^<]+)/)[1];
await page.locator('input[type=password]').fill(password);
await page.locator('input[type=password]').press('Enter');await page.waitForTimeout(2000);
console.log('Errors:',errors);
if(await page.locator('[data-tab=modbus]').count())throw new Error('Modbus must not be exposed');
await page.locator('.displayCard').waitFor();
const healthText=await page.locator('body').innerText();
if(!healthText.includes('soc-thermal') || !healthText.includes('gpu-thermal'))throw new Error('Real thermal sensors missing');
if(await page.locator('.displayModePanel, .audioDeviceGrid').count())throw new Error('Linux display controls exposed');
console.log('Theme:',await page.locator('html').getAttribute('data-theme'));
for(const width of [360,768,1024,1440]) {
await page.setViewportSize({width,height:900});
const overflow=await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth);
if(overflow)throw new Error('Horizontal overflow at '+width);
await page.screenshot({path:'/tmp/android-console-'+width+'.png',fullPage:true});
}
await page.locator('[data-tab=tscreen]').click();await page.waitForTimeout(2000);
await page.locator('#itscreenRegistrationStatus').waitFor();
const host=page.locator('#itscreenCustomHost');
if(await host.count()){
const original=await host.inputValue();
if(await page.locator('#itscreenRegisterBtn').isEnabled())throw new Error('Unchanged registration enabled');
await host.fill('https://example.com');
await page.waitForFunction(()=>{const button=document.getElementById('itscreenRegisterBtn');return button && !button.disabled;},{},{timeout:15000});
await host.fill(original);
if(await page.locator('#itscreenRegisterBtn').isEnabled())throw new Error('Restored registration enabled');
}
if(await page.locator('.itscreenLogsCard').count())throw new Error('Unsupported log controls exposed');
for(const width of [360,768,1024,1440]){
await page.setViewportSize({width,height:900});
if(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth))throw new Error('Registration overflow at '+width);
}
await page.locator('[data-tab=security]').click();await page.waitForTimeout(1500);
await page.locator('.accountSecurityCard').waitFor();
const save=page.locator('[data-account-password-form] button[type=submit]');
if(await save.isEnabled())throw new Error('Unchanged password enabled');
await page.locator('[autocomplete=current-password]').fill('current-test');
await page.locator('[autocomplete=new-password]').nth(0).fill('replacement-test');
await page.locator('[autocomplete=new-password]').nth(1).fill('replacement-test');
if(!await save.isEnabled())throw new Error('Valid password form disabled');
await page.locator('[autocomplete=new-password]').nth(1).fill('');
if(await save.isEnabled())throw new Error('Invalid password form enabled');
if(!await page.locator('#timezoneSearchInput').inputValue())throw new Error('Time zone missing');
for(const tab of ['security','network']){
await page.locator('[data-tab='+tab+']').click();await page.waitForTimeout(1500);
for(const width of [360,768,1024,1440]){await page.setViewportSize({width,height:900});if(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth))throw new Error(tab+' overflow '+width);}
}
await page.locator('#wifiSsid').waitFor();
console.log('PASS Display, registration, region, password dirty state and network UI at four widths');
await browser.close();if(errors.length)process.exit(1);
})();