Fix QA initialization race and test photo compression
This commit is contained in:
parent
fc2047ca1e
commit
e2dde8ec2d
@ -11,14 +11,27 @@ test('legacy localStorage payload cannot execute XSS', async ({ page }) => {
|
||||
});
|
||||
test('safe insert helper handles foreign reference node', async ({ page }) => {
|
||||
await page.goto('/index.html', { waitUntil:'domcontentloaded' });
|
||||
await page.waitForFunction(()=>window.SunSafe?.insertBefore);
|
||||
const result=await page.evaluate(()=>{const a=document.createElement('div'),b=document.createElement('div'),n=document.createElement('span'),foreign=document.createElement('i');a.appendChild(foreign);document.body.append(a,b);try{window.SunSafe.insertBefore(b,n,foreign);return {ok:true,parent:n.parentNode===b}}catch(e){return {ok:false,error:String(e)}}});
|
||||
expect(result).toEqual({ok:true,parent:true});
|
||||
});
|
||||
test('shared PDF engine produces A4 PDF blob', async ({ page }) => {
|
||||
await page.goto('/index.html', { waitUntil:'domcontentloaded' });
|
||||
await page.waitForFunction(()=>window.SunPdfEngine?.fromJpegs);
|
||||
const result=await page.evaluate(async()=>{const fake=new Uint8Array([255,216,255,217]);const blob=window.SunPdfEngine.fromJpegs([{width:1000,height:1414,bytes:fake}]);const head=new TextDecoder().decode(new Uint8Array(await blob.arrayBuffer()).slice(0,8));return {type:blob.type,size:blob.size,head,w:window.SunPdfEngine.PAGE_W,h:window.SunPdfEngine.PAGE_H}});
|
||||
expect(result.type).toBe('application/pdf'); expect(result.size).toBeGreaterThan(150); expect(result.head.startsWith('%PDF-1.4')).toBeTruthy(); expect(result.w/result.h).toBeCloseTo(1/Math.sqrt(2),3);
|
||||
});
|
||||
test('chat photo guard compresses a large camera image', async ({ page }) => {
|
||||
await page.goto('/index.html', { waitUntil:'domcontentloaded' });
|
||||
await page.waitForFunction(()=>window.SunAttachmentGuard?.prepareAttachment);
|
||||
const result=await page.evaluate(async()=>{
|
||||
const c=document.createElement('canvas');c.width=3000;c.height=2200;const x=c.getContext('2d');
|
||||
const g=x.createLinearGradient(0,0,c.width,c.height);g.addColorStop(0,'#172a3a');g.addColorStop(.5,'#d79a4a');g.addColorStop(1,'#f1e3ca');x.fillStyle=g;x.fillRect(0,0,c.width,c.height);
|
||||
for(let i=0;i<1200;i++){x.fillStyle=`rgba(${i%255},${(i*7)%255},${(i*13)%255},.55)`;x.fillRect((i*31)%3000,(i*47)%2200,90,55)}
|
||||
const blob=await new Promise(r=>c.toBlob(r,'image/jpeg',1));const input=new File([blob],'camera-photo.jpg',{type:'image/jpeg'});const out=await window.SunAttachmentGuard.prepareAttachment(input);const bm=await createImageBitmap(out.file);const data={original:input.size,size:out.file.size,width:bm.width,height:bm.height,type:out.file.type,name:out.file.name};bm.close();return data;
|
||||
});
|
||||
expect(Math.max(result.width,result.height)).toBeLessThanOrEqual(2048);expect(result.size).toBeLessThan(result.original);expect(result.size).toBeLessThanOrEqual(15*1024*1024);expect(result.type).toBe('image/jpeg');expect(result.name.endsWith('.jpg')).toBeTruthy();
|
||||
});
|
||||
test('mobile body does not overflow viewport', async ({ page }, testInfo) => {
|
||||
test.skip(testInfo.project.name!=='mobile-390'); await page.goto('/index.html', { waitUntil:'domcontentloaded' }); await page.waitForTimeout(500);
|
||||
const dims=await page.evaluate(()=>({innerWidth,scrollWidth:document.documentElement.scrollWidth,bodyWidth:document.body.scrollWidth}));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user