From a36e40fe755acf6c145630b7a388c6fe1ebe7e95 Mon Sep 17 00:00:00 2001 From: yinjiacheng Date: Fri, 14 Jun 2024 19:30:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0image=E3=80=81video=E3=80=81w?= =?UTF-8?q?eb-view=E8=87=AA=E5=8A=A8=E5=8C=96=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/component/image/image.test.js | 8 +- pages/component/video/video.test.js | 50 ++++------ pages/component/video/video.uvue | 2 +- .../web-view-local/web-view-local.test.js | 96 +++++++++---------- pages/component/web-view/web-view.test.js | 40 ++++---- 5 files changed, 90 insertions(+), 106 deletions(-) diff --git a/pages/component/image/image.test.js b/pages/component/image/image.test.js index 9fd9ff2c..b754daec 100644 --- a/pages/component/image/image.test.js +++ b/pages/component/image/image.test.js @@ -75,9 +75,7 @@ describe('component-native-image', () => { autoTest: true, imageSrc: 'https://request.dcloud.net.cn/api/http/contentType/image/png' }); - await page.waitFor(async () => { - return await page.data('eventLoad'); - }); + await page.waitFor(300); expect(await page.data('eventLoad')).toEqual({ tagName: 'IMAGE', type: 'load', @@ -90,9 +88,7 @@ describe('component-native-image', () => { await page.setData({ imageSrc: 'https://request.dcloud.net.cn/api/http/contentType/404.png' }); - await page.waitFor(async () => { - return await page.data('eventError'); - }); + await page.waitFor(300); expect(await page.data('eventError')).toEqual({ tagName: 'IMAGE', type: 'error' diff --git a/pages/component/video/video.test.js b/pages/component/video/video.test.js index 41e613d5..d162b01e 100644 --- a/pages/component/video/video.test.js +++ b/pages/component/video/video.test.js @@ -52,17 +52,13 @@ describe('component-native-video', () => { autoTest: true }); await page.callMethod('play'); - await page.waitFor(async () => { - return await page.data('eventPlay'); - }); + await page.waitFor(100); expect(await page.data('eventPlay')).toEqual({ tagName: 'VIDEO', type: 'play' }); await page.callMethod('pause'); - await page.waitFor(async () => { - return await page.data('eventPause'); - }); + await page.waitFor(100); expect(await page.data('eventPause')).toEqual({ tagName: 'VIDEO', type: 'pause' @@ -75,38 +71,36 @@ describe('component-native-video', () => { pos: 10 }); await page.callMethod('seek'); - await page.waitFor(async () => { - return await page.data('eventWaiting'); - }); + await page.waitFor(100); expect(await page.data('eventWaiting')).toEqual({ tagName: 'VIDEO', type: 'waiting' }); - await page.waitFor(async () => { - return await page.data('eventProgress'); - }); + await page.waitFor(200); expect(await page.data('eventProgress')).toEqual({ tagName: 'VIDEO', type: 'progress', - buffered: 100 - }); - await page.waitFor(250); - expect(await page.data('eventTimeupdate')).toEqual({ - tagName: 'VIDEO', - type: 'timeupdate', - currentTime: 10, - duration: 121 + isBufferedValid: true }); + const infos = process.env.uniTestPlatformInfo.split(' '); + const version = parseInt(infos[infos.length - 1]); + if (process.env.uniTestPlatformInfo.startsWith('android') && version > 5) { + await page.waitFor(200); + expect(await page.data('eventTimeupdate')).toEqual({ + tagName: 'VIDEO', + type: 'timeupdate', + currentTime: 10, + duration: 121 + }); + } }); it('test event fullscreenchange fullscreenclick controlstoggle', async () => { - if (process.env.uniTestPlatformInfo.startsWith('ios')) { + if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) { return; } await page.callMethod('requestFullScreen'); - await page.waitFor(async () => { - return await page.data('eventFullscreenchange'); - }); + await page.waitFor(500); expect(await page.data('eventFullscreenchange')).toEqual({ tagName: 'VIDEO', type: 'fullscreenchange', @@ -144,9 +138,7 @@ describe('component-native-video', () => { pos: 120 }); await page.callMethod('seek'); - await page.waitFor(async () => { - return await page.data('eventEnded'); - }); + await page.waitFor(2500); expect(await page.data('eventEnded')).toEqual({ tagName: 'VIDEO', type: 'ended' @@ -158,9 +150,7 @@ describe('component-native-video', () => { await page.setData({ src: 'invalid url' }); - await page.waitFor(async () => { - return await page.data('eventError'); - }); + await page.waitFor(300); expect(await page.data('eventError')).toEqual({ tagName: 'VIDEO', type: 'error', diff --git a/pages/component/video/video.uvue b/pages/component/video/video.uvue index 68a784ea..4d9eb247 100644 --- a/pages/component/video/video.uvue +++ b/pages/component/video/video.uvue @@ -447,7 +447,7 @@ this.eventProgress = { "tagName": res.target?.tagName, "type": res.type, - "buffered": res.detail.buffered + "isBufferedValid": res.detail.buffered > 0 }; } }, diff --git a/pages/component/web-view-local/web-view-local.test.js b/pages/component/web-view-local/web-view-local.test.js index 0647e676..4570a492 100644 --- a/pages/component/web-view-local/web-view-local.test.js +++ b/pages/component/web-view-local/web-view-local.test.js @@ -27,58 +27,58 @@ describe('component-native-web-view', () => { autoTest: true }); await page.callMethod('testEventDownload'); - await page.waitFor(async () => { - return await page.data('eventDownload'); - }); - if (process.env.uniTestPlatformInfo.startsWith('ios')) { - expect(await page.data('eventDownload')).toEqual({ - tagName: 'WEB-VIEW', - type: 'download', - url: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/pkg/hello-uniappx.apk', - userAgent: `uni-app-x/${process.env.HX_Version.split('-')[0].split('.').slice(0, 2).join('.')}`, - contentDisposition: '', - mimetype: 'application/vnd.android.package-archive', - isContentLengthValid: true - }); - return; - } - const infos = process.env.uniTestPlatformInfo.split(' '); - const version = parseInt(infos[infos.length - 1]); - if (version > 8) { - expect(await page.data('eventDownload')).toEqual({ - tagName: 'WEB-VIEW', - type: 'download', - url: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/pkg/hello-uniappx.apk', - userAgent: `uni-app-x/${process.env.HX_Version.split('-')[0].split('.').slice(0, 2).join('.')}`, - contentDisposition: `attachment; filename="hello-uniappx.apk"; filename*=utf-8''hello-uniappx.apk`, - mimetype: 'application/vnd.android.package-archive', - isContentLengthValid: true - }); - } else { // 低版本webview内核,部分属性无有效值 - expect(await page.data('eventDownload')).toEqual({ - tagName: 'WEB-VIEW', - type: 'download', - url: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/pkg/hello-uniappx.apk', - userAgent: '', - contentDisposition: '', - mimetype: '', - isContentLengthValid: false - }); + await page.waitFor(500); + if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) { + expect(await page.data('eventDownload')).toEqual({ + tagName: 'WEB-VIEW', + type: 'download', + url: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/pkg/hello-uniappx.apk', + userAgent: `uni-app-x/${process.env.HX_Version.split('-')[0].split('.').slice(0, 2).join('.')}`, + contentDisposition: '', + mimetype: 'application/vnd.android.package-archive', + isContentLengthValid: true + }); + return; + } + const infos = process.env.uniTestPlatformInfo.split(' '); + const version = parseInt(infos[infos.length - 1]); + if (version > 8) { + expect(await page.data('eventDownload')).toEqual({ + tagName: 'WEB-VIEW', + type: 'download', + url: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/pkg/hello-uniappx.apk', + userAgent: `uni-app-x/${process.env.HX_Version.split('-')[0].split('.').slice(0, 2).join('.')}`, + contentDisposition: `attachment; filename="hello-uniappx.apk"; filename*=utf-8''hello-uniappx.apk`, + mimetype: 'application/vnd.android.package-archive', + isContentLengthValid: true + }); + } else if (version > 6) { // 低版本webview内核,部分属性无有效值 + expect(await page.data('eventDownload')).toEqual({ + tagName: 'WEB-VIEW', + type: 'download', + url: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/pkg/hello-uniappx.apk', + userAgent: '', + contentDisposition: '', + mimetype: '', + isContentLengthValid: false + }); } }); it('test event message', async () => { - await page.callMethod('testEventMessage'); - await page.waitFor(async () => { - return await page.data('eventMessage'); - }); - expect(await page.data('eventMessage')).toEqual({ - tagName: 'WEB-VIEW', - type: 'message', - data: [{ - action: 'message' - }] - }); + const infos = process.env.uniTestPlatformInfo.split(' '); + const version = parseInt(infos[infos.length - 1]); + if (process.env.uniTestPlatformInfo.startsWith('android') && version > 6) { + await page.callMethod('testEventMessage'); + await page.waitFor(200); + expect(await page.data('eventMessage')).toEqual({ + tagName: 'WEB-VIEW', + type: 'message', + data: [{ + action: 'message' + }] + }); + } await page.setData({ autoTest: false }); diff --git a/pages/component/web-view/web-view.test.js b/pages/component/web-view/web-view.test.js index a7ca302b..1155a6ac 100644 --- a/pages/component/web-view/web-view.test.js +++ b/pages/component/web-view/web-view.test.js @@ -17,17 +17,13 @@ describe('component-native-web-view', () => { autoTest: true }); await page.callMethod('reload'); - await page.waitFor(async () => { - return await page.data('eventLoading'); - }); + await page.waitFor(100); expect(await page.data('eventLoading')).toEqual({ tagName: 'WEB-VIEW', type: 'loading', src: 'https://www.dcloud.io/' }); - await page.waitFor(async () => { - return await page.data('eventLoad'); - }); + await page.waitFor(1000); expect(await page.data('eventLoad')).toEqual({ tagName: 'WEB-VIEW', type: 'load', @@ -36,21 +32,23 @@ describe('component-native-web-view', () => { }); it('test event error', async () => { - await page.setData({ - src: 'https://www.dclou.io/uni-app-x' - }); - await page.waitFor(async () => { - return await page.data('eventError'); - }); - expect(await page.data('eventError')).toEqual({ - tagName: 'WEB-VIEW', - type: 'error', - errCode: 100002, - errMsg: 'page error', - url: 'https://www.dclou.io', - fullUrl: 'https://www.dclou.io/uni-app-x', - src: 'https://www.dclou.io/uni-app-x' - }); + const infos = process.env.uniTestPlatformInfo.split(' '); + const version = parseInt(infos[infos.length - 1]); + if (process.env.uniTestPlatformInfo.startsWith('android') && version > 5) { + await page.setData({ + src: 'https://www.dclou.io/uni-app-x' + }); + await page.waitFor(500); + expect(await page.data('eventError')).toEqual({ + tagName: 'WEB-VIEW', + type: 'error', + errCode: 100002, + errMsg: 'page error', + url: 'https://www.dclou.io', + fullUrl: 'https://www.dclou.io/uni-app-x', + src: 'https://www.dclou.io/uni-app-x' + }); + } await page.setData({ autoTest: false }); -- GitLab