diff --git a/web/web_multi_media/video_hosting/video_hosting_three/entry/src/ohosTest/ets/test/Utils.ets b/web/web_multi_media/video_hosting/video_hosting_three/entry/src/ohosTest/ets/test/Utils.ets index 28ce2ac4f36a2fd14c4a5094cd82289f8b1654f1..fb994823331bd96664c54779d5de29f6b3072034 100644 --- a/web/web_multi_media/video_hosting/video_hosting_three/entry/src/ohosTest/ets/test/Utils.ets +++ b/web/web_multi_media/video_hosting/video_hosting_three/entry/src/ohosTest/ets/test/Utils.ets @@ -124,7 +124,7 @@ export default class Utils { eventId: eventId, priority: events_emitter.EventPriority.LOW } - events_emitter.on(innerEvent, callBack) + events_emitter.once(innerEvent, callBack) } catch (err) { console.info(`[${testCaseName}] err:` + JSON.stringify(err)); } diff --git a/web/web_multi_media/video_hosting/video_hosting_three/entry/src/ohosTest/ets/test/WaitTest.test.ets b/web/web_multi_media/video_hosting/video_hosting_three/entry/src/ohosTest/ets/test/WaitTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eca5f086d3302dbfe06a78abfeb52efad818b41 --- /dev/null +++ b/web/web_multi_media/video_hosting/video_hosting_three/entry/src/ohosTest/ets/test/WaitTest.test.ets @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +import events_emitter from '@ohos.events.emitter'; +import { Driver, ON } from '@ohos.UiTest'; +import { BusinessError } from '@kit.BasicServicesKit'; + +function sleep(time: number) { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve('ok') + }, time) + }).then(() => { + console.info(`debug wait for sleep ${time} over...`) + } ) +} + +function emitEvent(actualValue: T, eventId: number) { + try { + let backData: events_emitter.EventData = { + data: { + 'ACTION': actualValue + } + } + let backEvent: events_emitter.InnerEvent = { + eventId: eventId, + priority: events_emitter.EventPriority.LOW + } + console.info('webFlag start to emit action state debug wait for'); + events_emitter.emit(backEvent, backData); + } catch (err) { + console.info('webFlag emit action state debug wait for err: ' + JSON.stringify(err)); + } +} + +export async function waitForAssert( + stateGetter:() => T, + check:(v1: T, v2: U) => boolean, + expectValue: U, + eventId: number, + testsuite: string, + interval=3000, + tryTime=20): Promise{ + let nums = 0; + let isSuccess = false; + while(nums < tryTime) { + const currentValue = await new Promise((done) => { + setTimeout(()=>done(stateGetter()), 0); + }); + console.log(testsuite + ' debug wait for ' + nums + ' times, currentValue:' + currentValue + + ', expectValue:' + expectValue); + if (check(currentValue, expectValue)) { + console.log(testsuite + ' debug wait for success ' + nums + ' times, currentValue:' + currentValue + + ', expectValue: ' + expectValue); + isSuccess = true; + emitEvent(expectValue, eventId); + return currentValue; + } + nums++; + await sleep(interval); + } + if (!isSuccess) { + console.log(testsuite + ' debug wait for failed'); + } + const currentValue = await new Promise((result)=>{ + setTimeout(()=> result(stateGetter()), 0); + }); + console.log(testsuite + ' debug wait for failed, currentValue:' + currentValue + ', expectValue:' + expectValue); + emitEvent(currentValue, eventId); + return currentValue; +} + +export async function waitForExist ( + stateGetter: () => T, + testsuite: string, + expectValue: string | number | null = null, + interval=3000, + tryTime=20 +):Promise{ + let nums = 0; + let isSuccess = false; + while (nums < tryTime) { + const currentValue = await new Promise((done) => { + setTimeout(()=>done(stateGetter()), 0); + }) + console.log(testsuite + ' debug wait for exist' + nums + ' times, currentValue: ' + currentValue + + ',expectValue ' + expectValue) + + if (expectValue == null) { + if (currentValue != null) { + console.log(testsuite + ' debug wait for success exist'); + isSuccess = true; + return currentValue + } + } else { + if (currentValue == expectValue) { + console.log(testsuite + ' debug wait for success exist'); + isSuccess = true; + return currentValue + } + } + nums++; + await sleep(interval); + } + if (!isSuccess) { + console.log(testsuite + ' debug wait for failed') + } + const currentValue = await new Promise((result) => { + setTimeout(() => result(stateGetter()), 0); + }); + console.log(testsuite + ' debug wait for failed exist ' + currentValue); + return currentValue; +} + +export async function waitForComponents(componentName:string, interval=10000) { + let driver: Driver = Driver.create(); + let component = await driver.waitForComponent(ON.id(componentName), interval); + console.info('waitForComponent', componentName, '==>'); + return component; +} \ No newline at end of file diff --git a/web/web_multi_media/video_hosting/video_hosting_three/entry/src/ohosTest/ets/test/webViewNativeMediaPlayerHandler.test.ets b/web/web_multi_media/video_hosting/video_hosting_three/entry/src/ohosTest/ets/test/webViewNativeMediaPlayerHandler.test.ets index 4ff55bb59a373dbdfc1034fa6af66074935090bc..f5dbe05c022553dbcbb00f33812bce66448f0d9e 100644 --- a/web/web_multi_media/video_hosting/video_hosting_three/entry/src/ohosTest/ets/test/webViewNativeMediaPlayerHandler.test.ets +++ b/web/web_multi_media/video_hosting/video_hosting_three/entry/src/ohosTest/ets/test/webViewNativeMediaPlayerHandler.test.ets @@ -18,6 +18,8 @@ import Utils from './Utils'; import router from '@ohos.router'; import emitter from '@ohos.events.emitter'; import { accessibility, config } from '@kit.AccessibilityKit'; +import { waitForComponents } from './WaitTest.test'; + const CAPACITY: accessibility.Capability[] = ['retrieve', 'gesture']; const BUNDLE_NAME = 'com.example.myaccessibilityapp/AccessibilityExtAbility'; // @ts-nocheck @@ -30,27 +32,25 @@ export default function webViewNativeMediaPlayerHandler() { } try { - await Utils.sleep(1000); router.clear(); let pages = router.getState(); if (!("webViewNativeMediaPlayerHandler" == pages.name)) { let result = await router.pushUrl(options); - await Utils.sleep(1000); console.info("push webViewNativeMediaPlayerHandler state success " + JSON.stringify(result)); } } catch (err) { console.error("push webViewNativeMediaPlayerHandler page error:" + err); } + await waitForComponents("webViewNativeMediaPlayerHandler"); done() }); - + beforeEach(async (done: Function) => { config.enableAbility(BUNDLE_NAME, CAPACITY).then(() => { console.info(`enable success`); - }).catch((err: object) => { + }).catch((err: object) => { console.error(`failed to enable, ${err}`); }) - await Utils.sleep(2000); console.info("webViewNativeMediaPlayerHandler beforeEach start"); done(); }) @@ -63,25 +63,32 @@ export default function webViewNativeMediaPlayerHandler() { * @tc.type : Function * @tc.level : Level 0 */ - it('testWebViewNativeMediaPlayerHandlePlaybackRateChanged', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async (done: Function) => { - let emitKey = "emitWebViewNativeMediaPlayerHandlePlaybackRateChanged"; - Utils.emitEvent(emitKey, 10) - Utils.registerEvent("testWebViewNativeMediaPlayerHandlePlaybackRateChanged", true, 1304, done); - sendEventByKey('webViewNativeMediaPlayerHandler', 10, ''); - }) + it('testWebViewNativeMediaPlayerHandlePlaybackRateChanged', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, + async (done: Function) => { + let emitKey = "emitWebViewNativeMediaPlayerHandlePlaybackRateChanged"; + Utils.emitEvent(emitKey, 300200) + Utils.registerBaseEvent("testWebViewNativeMediaPlayerHandlePlaybackRateChanged", true, 300250, done, + (backData: events_emitter.EventData, expected: Object) => { + expect(backData?.data?.ACTION).assertEqual(expected); + }); + sendEventByKey('webViewNativeMediaPlayerHandler', 10, ''); + }) /* * @tc.number : SUB_ACE_WEB_handleTimeUpdate_API_0002 * @tc.name : testWebViewNativeMediaPlayerHandleTimeUpdate + * @tc.level : Level 1 * @tc.desc : test handleTimeUpdate * @tc.size_t : MediumTest * @tc.type : Function - * @tc.level : Level 1 - */ + **/ it('testWebViewNativeMediaPlayerHandleTimeUpdate', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { let emitKey = "emitWebViewNativeMediaPlayerHandleTimeUpdate"; - Utils.emitEvent(emitKey, 10) - Utils.registerEvent("testWebViewNativeMediaPlayerHandleTimeUpdate", true, 1300, done); + Utils.emitEvent(emitKey, 300200) + Utils.registerBaseEvent("testWebViewNativeMediaPlayerHandleTimeUpdate", true, 300210, done, + (backData: events_emitter.EventData, expected: Object) => { + expect(backData?.data?.ACTION).assertEqual(expected); + }); sendEventByKey('webViewNativeMediaPlayerHandler', 10, ''); }) @@ -95,8 +102,11 @@ export default function webViewNativeMediaPlayerHandler() { */ it('testWebViewNativeMediaPlayerHandleBufferedEndTimeChanged', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { let emitKey = "emitWebViewNativeMediaPlayerHandleBufferedEndTimeChanged"; - Utils.emitEvent(emitKey, 10) - Utils.registerEvent("testWebViewNativeMediaPlayerHandleBufferedEndTimeChanged", true, 1301, done); + Utils.emitEvent(emitKey, 300200) + Utils.registerBaseEvent("testWebViewNativeMediaPlayerHandleBufferedEndTimeChanged", true, 300220, done, + (backData: events_emitter.EventData, expected: Object) => { + expect(backData?.data?.ACTION).assertEqual(expected); + }); sendEventByKey('webViewNativeMediaPlayerHandler', 10, ''); }) @@ -110,8 +120,11 @@ export default function webViewNativeMediaPlayerHandler() { */ it('testWebViewNativeMediaPlayerHandleDurationChanged', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { let emitKey = "emitWebViewNativeMediaPlayerHandleDurationChanged"; - Utils.emitEvent(emitKey, 10) - Utils.registerEvent("testWebViewNativeMediaPlayerHandleDurationChanged", true, 1302, done); + Utils.emitEvent(emitKey, 300200) + Utils.registerBaseEvent("testWebViewNativeMediaPlayerHandleDurationChanged", true, 300230, done, + (backData: events_emitter.EventData, expected: Object) => { + expect(backData?.data?.ACTION).assertEqual(expected); + }); sendEventByKey('webViewNativeMediaPlayerHandler', 10, ''); }) @@ -125,8 +138,11 @@ export default function webViewNativeMediaPlayerHandler() { */ it('testWebViewNativeMediaPlayerHandleVideoSizeChanged', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { let emitKey = "emitWebViewNativeMediaPlayerHandleVideoSizeChanged"; - Utils.emitEvent(emitKey, 10) - Utils.registerEvent("testWebViewNativeMediaPlayerHandleVideoSizeChanged", true, 1303, done); + Utils.emitEvent(emitKey, 300200) + Utils.registerBaseEvent("testWebViewNativeMediaPlayerHandleVideoSizeChanged", true, 300240, done, + (backData: events_emitter.EventData, expected: Object) => { + expect(backData?.data?.ACTION).assertEqual(expected); + }); sendEventByKey('webViewNativeMediaPlayerHandler', 10, ''); }) @@ -140,8 +156,11 @@ export default function webViewNativeMediaPlayerHandler() { */ it('testWebViewNativeMediaPlayerHandleSeeking', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { let emitKey = "emitWebViewNativeMediaPlayerHandleSeeking"; - Utils.emitEvent(emitKey, 10) - Utils.registerEvent("testWebViewNativeMediaPlayerHandleSeeking", true, 1305, done); + Utils.emitEvent(emitKey, 300200) + Utils.registerBaseEvent("testWebViewNativeMediaPlayerHandleSeeking", true, 300320, done, + (backData: events_emitter.EventData, expected: Object) => { + expect(backData?.data?.ACTION).assertEqual(expected); + }); sendEventByKey('webViewNativeMediaPlayerHandler', 10, ''); }) @@ -155,8 +174,11 @@ export default function webViewNativeMediaPlayerHandler() { */ it('testWebViewNativeMediaPlayerHandleSeekFinished', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { let emitKey = "emitWebViewNativeMediaPlayerHandleSeekFinished"; - Utils.emitEvent(emitKey, 10) - Utils.registerEvent("testWebViewNativeMediaPlayerHandleSeekFinished", true, 1306, done); + Utils.emitEvent(emitKey, 300200) + Utils.registerBaseEvent("testWebViewNativeMediaPlayerHandleSeekFinished", true, 300260, done, + (backData: events_emitter.EventData, expected: Object) => { + expect(backData?.data?.ACTION).assertEqual(expected); + }); sendEventByKey('webViewNativeMediaPlayerHandler', 10, ''); }) @@ -170,8 +192,11 @@ export default function webViewNativeMediaPlayerHandler() { */ it('testWebViewNativeMediaPlayerHandleVolumeChanged', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { let emitKey = "emitWebViewNativeMediaPlayerHandleVolumeChanged"; - Utils.emitEvent(emitKey, 10) - Utils.registerEvent("testWebViewNativeMediaPlayerHandleVolumeChanged", true, 1307, done); + Utils.emitEvent(emitKey, 300200) + Utils.registerBaseEvent("testWebViewNativeMediaPlayerHandleVolumeChanged", true, 300270, done, + (backData: events_emitter.EventData, expected: Object) => { + expect(backData?.data?.ACTION).assertEqual(expected); + }); sendEventByKey('webViewNativeMediaPlayerHandler', 10, ''); }) @@ -186,8 +211,11 @@ export default function webViewNativeMediaPlayerHandler() { */ it('testWebViewNativeMediaPlayerHandleEnded', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { let emitKey = "emitWebViewNativeMediaPlayerHandleEnded"; - Utils.emitEvent(emitKey, 10) - Utils.registerEvent("testWebViewNativeMediaPlayerHandleEnded", true, 1308, done); + Utils.emitEvent(emitKey, 300200) + Utils.registerBaseEvent("testWebViewNativeMediaPlayerHandleEnded", true, 300280, done, + (backData: events_emitter.EventData, expected: Object) => { + expect(backData?.data?.ACTION).assertEqual(expected); + }); sendEventByKey('webViewNativeMediaPlayerHandler', 10, ''); }) @@ -201,8 +229,11 @@ export default function webViewNativeMediaPlayerHandler() { */ it('testWebViewNativeMediaPlayerHandleError', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { let emitKey = "emitWebViewNativeMediaPlayerHandleError"; - Utils.emitEvent(emitKey, 10) - Utils.registerEvent("testWebViewNativeMediaPlayerHandleError", true, 1309, done); + Utils.emitEvent(emitKey, 300200) + Utils.registerBaseEvent("testWebViewNativeMediaPlayerHandleError", true, 300290, done, + (backData: events_emitter.EventData, expected: Object) => { + expect(backData?.data?.ACTION).assertEqual(expected); + }); sendEventByKey('webViewNativeMediaPlayerHandler', 10, ''); }) @@ -217,8 +248,11 @@ export default function webViewNativeMediaPlayerHandler() { */ it('testWebViewNativeMediaSetSeekTwo', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { let emitKey = "emitWebViewNativeVideoSetSeek"; - Utils.emitEvent(emitKey, 10) - Utils.registerEvent("testWebViewNativeMediaSetSeek", true, 1293, done); + Utils.emitEvent(emitKey,300200) + Utils.registerBaseEvent("testWebViewNativeMediaSetSeek", true, 300330, done, + (backData: events_emitter.EventData, expected: Object) => { + expect(backData?.data?.ACTION).assertEqual(expected); + }); sendEventByKey('webViewNativeMediaPlayerHandler', 10, ''); }) @@ -233,8 +267,11 @@ export default function webViewNativeMediaPlayerHandler() { */ it('testWebViewNativeMediaSetVolumeTwo', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { let emitKey = "emitWebViewNativeMediaSetVolume"; - Utils.emitEvent(emitKey, 10) - Utils.registerEvent("testWebViewNativeMediaSetVolume", true, 1290, done); + Utils.emitEvent(emitKey, 300200) + Utils.registerBaseEvent("testWebViewNativeMediaSetVolume", true, 300340, done, + (backData: events_emitter.EventData, expected: Object) => { + expect(backData?.data?.ACTION).assertEqual(expected); + }); sendEventByKey('webViewNativeMediaPlayerHandler', 10, ''); }) @@ -248,8 +285,11 @@ export default function webViewNativeMediaPlayerHandler() { */ it('testWebViewNativeMediaMediaInfoTwo', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, async (done: Function) => { let emitKey="emitWebViewNativeMediaMediaInfo" - Utils.emitEvent(emitKey,10) - Utils.registerEvent("testWebViewNativeMediaMediaInfo", true, 1289, done); + Utils.emitEvent(emitKey,300200) + Utils.registerBaseEvent("testWebViewNativeMediaMediaInfo", true, 300350, done, + (backData: events_emitter.EventData, expected: Object) => { + expect(backData?.data?.ACTION).assertEqual(expected); + }); sendEventByKey('webViewNativeMediaPlayerHandler', 10, ''); }) }) diff --git a/web/web_multi_media/video_hosting/video_hosting_three/entry/src/ohosTest/ets/testability/pages/webViewNativeMediaPlayerHandler.ets b/web/web_multi_media/video_hosting/video_hosting_three/entry/src/ohosTest/ets/testability/pages/webViewNativeMediaPlayerHandler.ets index 3294d793fa172653a1178769555d3230166479a8..a4a492d246fa01f8d4bdef8f0d433a89247be9f6 100644 --- a/web/web_multi_media/video_hosting/video_hosting_three/entry/src/ohosTest/ets/testability/pages/webViewNativeMediaPlayerHandler.ets +++ b/web/web_multi_media/video_hosting/video_hosting_three/entry/src/ohosTest/ets/testability/pages/webViewNativeMediaPlayerHandler.ets @@ -24,6 +24,7 @@ import Utils from '../../test/Utils'; import JSON from '@ohos.util.json'; import connection from '@ohos.net.connection'; import router from '@ohos.router'; +import { waitForExist } from '../../test/WaitTest.test'; interface AVPlayerListener { onPlaying() : void @@ -231,7 +232,7 @@ class AVPlayerDemo { return result; } play() { - let commandName = 'play'; + let commandName = '"play"'; let checkResult = this.checkCommand(commandName, 'pause'); if (checkResult.ignore) { console.log('AVPlayer ${commandName} ignored.'); @@ -251,7 +252,7 @@ class AVPlayerDemo { } pause() { let commandName = 'pause'; - let checkResult = this.checkCommand(commandName, 'play'); + let checkResult = this.checkCommand(commandName, '"play"'); console.log('checkResult: ${JSON.stringify(checkResult)}'); if (checkResult.ignore) { console.log('AVPlayer ${commandName} ignored.'); @@ -324,66 +325,66 @@ class NativeMediaPlayerHandlerImpl implements webview.NativeMediaPlayerHandler{ } handleStatusChanged(status: webview.PlaybackStatus): void { console.log("handle PlaybackStatus:") - Utils.emitEvent(true, 1312) + Utils.emitEvent(true, 300310) this.rawHandler.handleStatusChanged(status) } handleVolumeChanged(volume: number): void { console.log("handle volume change :" + volume) if(volume == 0.5) { - Utils.emitEvent(true, 1307) + Utils.emitEvent(true, 300270) } this.rawHandler.handleVolumeChanged(volume) } handleMutedChanged(muted: boolean): void { console.log("handle muted:" + muted) - Utils.emitEvent(true, 1316) + Utils.emitEvent(true, 300300) this.rawHandler.handleMutedChanged(muted) } handlePlaybackRateChanged(playbackRate: number): void { console.log("handle playbackRate:" + playbackRate) if(playbackRate == media.PlaybackSpeed.SPEED_FORWARD_2_00_X) { - Utils.emitEvent(true, 1304) + Utils.emitEvent(true, 300250) } this.rawHandler.handlePlaybackRateChanged(playbackRate) } handleDurationChanged(duration: number): void { console.log("handle duration :" + duration) - Utils.emitEvent(true, 1302) + Utils.emitEvent(true, 300230) this.rawHandler.handleDurationChanged(duration) } handleTimeUpdate(currentPlayTime: number): void { console.log("handle currentPlayTime :" + currentPlayTime) - Utils.emitEvent(true, 1300) + Utils.emitEvent(true, 300210) this.rawHandler.handleTimeUpdate(currentPlayTime) } handleBufferedEndTimeChanged(bufferedEndTime: number): void { console.log("handle bufferedEndTime :" + bufferedEndTime) - Utils.emitEvent(true, 1301) + Utils.emitEvent(true, 300220) this.rawHandler.handleBufferedEndTimeChanged(bufferedEndTime) } handleEnded(): void { console.log("handle end:") - Utils.emitEvent(true, 1308) + Utils.emitEvent(true, 300280) this.rawHandler.handleEnded() } handleNetworkStateChanged(state: webview.NetworkState): void { console.log("handleNetworkStateChanged before:" + state) - Utils.emitEvent(true, 1315) + Utils.emitEvent(true, 300360) console.log("handleNetworkStateChanged dfdf:" + state) this.rawHandler.handleNetworkStateChanged(state) } handleReadyStateChanged(state: webview.ReadyState): void { console.log("handleReadyStateChanged :" + state) - Utils.emitEvent(true, 1310) + Utils.emitEvent(true, 300370) this.rawHandler.handleReadyStateChanged(state) } @@ -394,25 +395,25 @@ class NativeMediaPlayerHandlerImpl implements webview.NativeMediaPlayerHandler{ handleSeeking(): void { console.log("handleSeeking:") - Utils.emitEvent(true, 1305) + Utils.emitEvent(true, 300320) this.rawHandler.handleSeeking() } handleSeekFinished(): void { console.log("handleSeekFinished:") - Utils.emitEvent(true, 1306) + Utils.emitEvent(true, 300260) this.rawHandler.handleSeekFinished() } handleError(error: webview.MediaError, errorMessage: string): void { console.log("handleError:" + "mediaError" + errorMessage + ":" + errorMessage) - Utils.emitEvent(true, 1309) + Utils.emitEvent(true, 300290) this.rawHandler.handleError(error,errorMessage) } handleVideoSizeChanged(width: number, height: number): void { console.log("handleVideoSizeChanged:") - Utils.emitEvent(true, 1303) + Utils.emitEvent(true, 300240) this.rawHandler.handleVideoSizeChanged(width,height) } } @@ -849,10 +850,14 @@ struct WebComponent { componentOverlay: false } @State emitKey: string = "emitWebViewNativeMediaPlayerHandleTimeUpdate"; + @State isReceive: number = -1; + @State isPageEnd: number = -1; + @State isEnd: number = -1; + @State checkResult: string = ''; onPageShow() { let valueChangeEvent: events_emitter.InnerEvent = { - eventId: 10, + eventId: 300200, priority: events_emitter.EventPriority.LOW } events_emitter.on(valueChangeEvent, this.valueChangeCallBack) @@ -863,6 +868,7 @@ struct WebComponent { console.info("valueChangeCallBack:" + JSON.stringify(eventData)); if (eventData.data != null && eventData.data.ACTION != null) { this.emitKey = eventData.data.ACTION; + this.isReceive = 0; } } } @@ -870,9 +876,13 @@ struct WebComponent { Column() { Row() { Button("web click").key('webViewNativeMediaPlayerHandler').onClick(async () => { - console.info("key==>" + this.emitKey) + console.info('key==>' + this.emitKey) + await waitForExist(()=>this.isReceive, this.emitKey + 'IsReceive', 0); + await waitForExist(()=>this.isPageEnd, this.emitKey + 'IsPageEnd', 0); + this.isReceive = -1; + this.isPageEnd =-1; this.controller.refresh() - await Utils.sleep(1000) + await waitForExist(()=>this.isPageEnd, this.emitKey + 'IsPageEnd', 0,1000); this.controller.runJavaScript("buttonPlay()", (error, result) => { console.error('The play() return error is: ${error}'); console.log('The play() return value is: ${result}'); @@ -881,108 +891,114 @@ struct WebComponent { case "emitWebViewNativeMediaPlayerHandleTimeUpdate": { try { console.log('emitWebViewNativeMediaPlayerHandleTimeUpdate==>') - await Utils.sleep(1000) + this.checkResult = ''; this.controller.runJavaScript("setSeek()", (error, result) => { + this.checkResult = result; console.log('The playerHandleTimeUpdate() return value is: ${result}'); }) - await Utils.sleep(1500) - Utils.emitEvent(true,1300) + await waitForExist(()=>this.checkResult, this.emitKey, '"setSeek"'); + Utils.emitEvent(true,300210) } catch (error) { - Utils.emitEvent('error',1300) + Utils.emitEvent('error',300210) } break; } case "emitWebViewNativeMediaPlayerHandleBufferedEndTimeChanged": { try { console.log('emitWebViewNativeMediaPlayerHandleBufferedEndTimeChanged==>') - await Utils.sleep(1000) + this.checkResult = ''; this.controller.runJavaScript("setSeek()", (error, result) => { + this.checkResult = result; console.log('The playerHandleTimeUpdate() return value is: ${result}'); }) - await Utils.sleep(1500) - Utils.emitEvent(true,1301) + await waitForExist(()=>this.checkResult, this.emitKey, '"setSeek"'); + Utils.emitEvent(true,300220) } catch (error) { - Utils.emitEvent('error',1301) + Utils.emitEvent('error',300220) } break; } case "emitWebViewNativeMediaPlayerHandleDurationChanged": { try { console.log('emitWebViewNativeMediaPlayerHandleDurationChanged==>') - await Utils.sleep(1500) - Utils.emitEvent(true,1302) + Utils.emitEvent(true,300230) } catch (error) { - Utils.emitEvent('error',1302) + Utils.emitEvent('error',300230) } break; } case "emitWebViewNativeMediaPlayerHandleVideoSizeChanged": { try { console.log('emitWebViewNativeMediaPlayerHandleVideoSizeChanged==>') - await Utils.sleep(1000) + this.checkResult = ''; this.controller.runJavaScript("resize()", (error, result) => { + this.checkResult = result; console.log('The resize() return value is: ${result}'); }) - await Utils.sleep(1500) - Utils.emitEvent(true,1303) + await waitForExist(()=>this.checkResult, this.emitKey, '"resizeDom"'); + Utils.emitEvent(true,300240) } catch (error) { - Utils.emitEvent('error',1303) + Utils.emitEvent('error',300240) } break; } case "emitWebViewNativeMediaPlayerHandlePlaybackRateChanged": { try { console.log('emitWebViewNativeMediaPlayerHandlePlaybackRateChanged==>') - await Utils.sleep(1000) + this.checkResult = ''; this.controller.runJavaScript("setPlayBackRate()", (error, result) => { + this.checkResult = result; console.log('The setPlayBackRate() return value is: ${result}'); }) - await Utils.sleep(2000) - Utils.emitEvent(true,1304) + await waitForExist(()=>this.checkResult, this.emitKey, '"setPlayBackRate"'); + Utils.emitEvent(true,300250) } catch (error) { - Utils.emitEvent('error',1304) + Utils.emitEvent('error',300250) } break; } case "emitWebViewNativeMediaPlayerHandleSeeking": { try { console.log('emitWebViewNativeMediaPlayerHandleSeeking==>') - await Utils.sleep(1000) + this.checkResult = ''; this.controller.runJavaScript("setSeek()", (error, result) => { + this.checkResult = result; console.log('The playerHandleTimeUpdate() return value is: ${result}'); }) - await Utils.sleep(1500) - Utils.emitEvent(true,1305) + await waitForExist(()=>this.checkResult, this.emitKey, '"setSeek"'); + Utils.emitEvent(true,300320) } catch (error) { - Utils.emitEvent('error',1305) + Utils.emitEvent('error',300320) } break; } case "emitWebViewNativeMediaPlayerHandleSeekFinished": { try { console.log('emitWebViewNativeMediaPlayerHandleSeekFinished==>') - await Utils.sleep(1000) + this.checkResult = ''; this.controller.runJavaScript("setSeek()", (error, result) => { + this.checkResult = result; console.log('The playerHandleTimeUpdate() return value is: ${result}'); }) - await Utils.sleep(1000) - Utils.emitEvent(true,1306) + await waitForExist(()=>this.checkResult, this.emitKey, '"setSeek"'); + Utils.emitEvent(true,300260) } catch (error) { - Utils.emitEvent('error',1306) + Utils.emitEvent('error',300260) } break; } case "emitWebViewNativeMediaPlayerHandleVolumeChanged": { try { console.log('emitWebViewNativeMediaPlayerHandleVolumeChanged==>') - await Utils.sleep(1000) + this.checkResult = ''; this.controller.runJavaScript("setVolume()", (error, result) => { + this.checkResult = result; console.log('The setVolume() return value is: ${result}'); }) - await Utils.sleep(2000) - Utils.emitEvent(true,1307) + await waitForExist(()=>this.checkResult, this.emitKey, '"volume h5"'); + Utils.emitEvent(true,300270) } catch (error) { - Utils.emitEvent('error',1307) + Utils.emitEvent('error',300270) } break; } @@ -994,9 +1010,9 @@ struct WebComponent { console.log('The jumpToEnd() return value is: ${result}'); }) await Utils.sleep(2000) - Utils.emitEvent(true,1308) + Utils.emitEvent(true,300280) } catch (error) { - Utils.emitEvent('error',1308) + Utils.emitEvent('error',300280) } break; } @@ -1004,104 +1020,122 @@ struct WebComponent { try { this.controller.loadUrl($rawfile("nativeMediaError2.html")) await Utils.sleep(1500) - Utils.emitEvent(true,1309) + Utils.emitEvent(true,300290) } catch (error) { - Utils.emitEvent('error',1309) + Utils.emitEvent('error',300290) } break; } case "emitWebViewNativeMediaPlayerHandleStatusChanged": { try { console.log('emitWebViewNativeMediaPlayerHandleStatusChanged==>') + this.checkResult = ''; this.controller.runJavaScript("buttonPause()", (error, result) => { + this.checkResult = result; console.log('The pause() return value is: ${result}'); }) - await Utils.sleep(1000) + await waitForExist(()=>this.checkResult, this.emitKey, '"pause"'); this.controller.runJavaScript("buttonPlay()", (error, result) => { - console.log('The pause() return value is: ${result}'); + this.checkResult = result; + console.log('The buttonPlay() return value is: ${result}'); }) - await Utils.sleep(1500) - Utils.emitEvent(true,1312) + await waitForExist(()=>this.checkResult, this.emitKey, '"play"'); + Utils.emitEvent(true,300310) } catch (error) { - Utils.emitEvent('error',1312) + Utils.emitEvent('error',300310) } break; } case "emitWebViewNativeMediaPlayerHandleMutedChanged": { try { console.log('emitWebViewNativeMediaPlayerHandleMutedChanged==>') - await Utils.sleep(1000) + this.checkResult = ''; this.controller.runJavaScript("buttonPlay()", (error, result) => { - console.log('The pause() return value is: ${result}'); + this.checkResult = result; + console.log('The buttonPlay() return value is: ${result}'); }) - await Utils.sleep(1000) + await waitForExist(()=>this.checkResult, this.emitKey, '"play"'); this.controller.runJavaScript("setMutedFalse()", (error, result) => { + this.checkResult = result; console.log('The setMutedFalse() return value is: ${result}'); }) - await Utils.sleep(1500) - Utils.emitEvent(true,1316) + await waitForExist(()=>this.checkResult, this.emitKey, '"setMuted"'); + Utils.emitEvent(true,300300) } catch (error) { - Utils.emitEvent('error',1316) + Utils.emitEvent('error',300300) } break; } case "emitWebViewNativeVideoSetSeek": { try { console.log('emitWebViewNativeVideoSetSeek==>') + this.checkResult = ''; + this.isPageEnd = -1; this.controller.loadUrl($rawfile('nativeMediaSetSeek.html')) - await Utils.sleep(1000) + await waitForExist(()=>this.isPageEnd, this.emitKey + 'isPageEnd',0) this.controller.runJavaScript("buttonPlay()", (error, result) => { - console.error('The play(0 return error is: ${error}'); - console.log('The play(0 return value is: ${result}'); + this.checkResult = result; + console.error('The buttonPlay() return error is: ${error}'); + console.log('The buttonPlay() return value is: ${result}'); }) - await Utils.sleep(1000) + await waitForExist(()=>this.checkResult, this.emitKey, '"play"'); this.controller.runJavaScript("setSeek()", (error, result) => { - console.log('The setSeek(0 return value is: ${result}'); + this.checkResult = result; + console.log('The setSeek() return value is: ${result}'); }) - await Utils.sleep(2000) - Utils.emitEvent(true, 1293) + await waitForExist(()=>this.checkResult, this.emitKey, '"setSeek"'); + Utils.emitEvent(true, 300330) } catch (error) { - Utils.emitEvent('error',1293) + Utils.emitEvent('error',300330) } break; } case "emitWebViewNativeMediaSetVolume": { try { - this.controller.loadUrl($rawfile('nativeMediaSetVolume.html')) console.log('emitWebViewNativeMediaSetVolume==>') - await Utils.sleep(1000) + this.checkResult = ''; + this.isPageEnd = -1; + this.controller.loadUrl($rawfile('nativeMediaSetVolume.html')) + await waitForExist(()=>this.isPageEnd, this.emitKey + 'isPageEnd',0) this.controller.runJavaScript("buttonPlay()", (error, result) => { - console.error('The play(0 return error is: ${error}'); - console.log('The play(0 return value is: ${result}'); + this.checkResult = result; + console.error('The buttonPlay() return error is: ${error}'); + console.log('The buttonPlay() return value is: ${result}'); }) - await Utils.sleep(1000) + await waitForExist(()=>this.checkResult, this.emitKey, '"play"'); this.controller.runJavaScript("setVolume()", (error, result) => { - console.log('The setVolume(0 return value is: ${result}'); + this.checkResult = result; + console.log('The setVolume() return value is: ${result}'); }) - await Utils.sleep(2000) - Utils.emitEvent(true, 1290) + await waitForExist(()=>this.checkResult, this.emitKey, '"volume h5"'); + Utils.emitEvent(true, 300340) } catch (error) { - Utils.emitEvent('error',1290) + Utils.emitEvent('error',300340) } break; } case "emitWebViewNativeMediaMediaInfo": { try { - this.controller.loadUrl($rawfile('nativeMediaInfo.html')) console.log('emitWebViewNativeMediaMediaInfo==>') + this.checkResult = ''; + this.isPageEnd = -1; + this.controller.loadUrl($rawfile('nativeMediaInfo.html')) + await waitForExist(()=>this.isPageEnd, this.emitKey + 'IsPageEnd',0,1000); this.controller.runJavaScript("buttonLoad()", (error, result) => { - console.log('The load() return value is: ${result}'); + this.checkResult = '' + result; + console.log('The buttonLoad() return value is: ${result}'); }) - await Utils.sleep(1000) + await waitForExist(()=>this.checkResult, this.emitKey, 'true'); this.controller.runJavaScript("buttonPlay()", (error, result) => { + this.checkResult = result; console.error('The play() return error is: ${error}'); console.log('The play() return value is: ${result}'); }) - await Utils.sleep(2000) - Utils.emitEvent(true, 1289) + await waitForExist(()=>this.checkResult, this.emitKey, '"play"'); + Utils.emitEvent(true, 300350) } catch (error) { - Utils.emitEvent('error',1289) + Utils.emitEvent('error',300350) } break; } @@ -1173,6 +1207,9 @@ struct WebComponent { console.log('[BrowserShell] postTouchEvent, ret[${ret}], touchEvent[${JSON.stringify(event.touchEvent)}]'); event.result?.setGestureEventResult(true); }) + .onPageEnd(()=>{ + this.isPageEnd = 0; + }) if (this.pageParams.componentOverlay && this.show_native_media_player) { NodeContainer(this.node_controller) .width(this.node_width)