提交 ea2c699b 编写于 作者: Y yupeng

beta2_fugai

Signed-off-by: Nyupeng <yupeng78@huawei.com>
上级 b5ba24f3
......@@ -28,6 +28,7 @@ struct Index {
@State outputStr: string = ''
@State playing: boolean = false
@State str:string="emitOnLoadIntercept"
@State arrid:number = 0
onPageShow(){
let valueChangeEvent={
eventId:10,
......@@ -62,6 +63,10 @@ struct Index {
this.controller.loadUrl("https://www.baidu.com/")
break;
}
case "emitOnControllerAttached":{
Utils.emitEvent(this.arrid,7)
break;
}
default:
console.info("can not match case")
......@@ -82,6 +87,65 @@ struct Index {
console.log('getErrorInfo:' + event.error.getErrorInfo())
Utils.emitEvent(event.error.getErrorInfo(),3)
})
.onScreenCaptureRequest((event) => {
AlertDialog.show({
title: 'title: ' + event.handler.getOrigin(),
message: 'text',
primaryButton: {
value: 'deny',
action: () => {
event.handler.deny()
}
},
secondaryButton: {
value: 'onConfirm',
action: () => {
event.handler.grant({ captureMode: WebCaptureMode.HOME_SCREEN })
}
},
cancel: () => {
event.handler.deny()
}
})
})
.onControllerAttached(() => {
try {
this.arrid = this.controller.getWebId();
console.log("id++++++: " + this.arrid);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
.onOverScroll((event) => {
console.info("x = " + event.xOffset)
console.info("y = " + event.yOffset)
})
.onClientAuthenticationRequest((event) => {
AlertDialog.show({
title: 'onClientAuthenticationRequest',
message: 'text',
primaryButton: {
value: 'confirm',
action: () => {
event.handler.confirm("/system/etc/user.pk8", "/system/etc/chain-user.pem")
}
},
secondaryButton: {
value: 'cancel',
action: () => {
event.handler.cancel()
}
},
cancel: () => {
event.handler.ignore()
}
})
})
}
}
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
......@@ -15,6 +16,7 @@
import events_emitter from '@ohos.events.emitter';
import Utils from '../../test/Utils';
import web_webview from '@ohos.web.webview';
import UIAbility from '@ohos.app.ability.UIAbility';
function Uint8ArrayToString(dataArray) {
var dataString = ''
......@@ -40,7 +42,9 @@ function ParseX509CertInfo(x509CertArray) {
@Entry
@Component
struct Second {
@State outputStr: string = ''
@State outputStr: string = ''
@State firsttime:number = 0
@State arr: Array<number> = [0, 0]
webviewCtl: web_webview.WebviewController = new web_webview.WebviewController();
@State str:string="emitGetCertificate"
onPageShow(){
......@@ -78,13 +82,61 @@ struct Second {
}
break;
}
case "emitPrefetchPage": {
try {
this.webviewCtl.removeCache(true)
this.webviewCtl.loadUrl('https://www.huawei.com')
if (this.arr.length > 2) {
this.webviewCtl.removeCache(true)
}
this.webviewCtl.prefetchPage('https://www.huawei.com');
this.webviewCtl.loadUrl('https://www.huawei.com')
setTimeout(()=>{
if (this.arr.length > 3) {
if (this.arr[3]-this.arr[2] < 0) {
Utils.emitEvent("success",6)
}
}
},2000)
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
case "emitPrepareForPageLoad": {
try {
this.webviewCtl.removeCache(true)
this.webviewCtl.loadUrl('https://www.jd.com/')
if (this.arr.length > 4) {
this.webviewCtl.removeCache(true)
}
web_webview.WebviewController.prepareForPageLoad("https://www.jd.com/", true, 6);
this.webviewCtl.loadUrl('https://www.jd.com/')
setTimeout(()=>{
if (this.arr.length > 5) {
if (this.arr[5]-this.arr[4] < 0) {
Utils.emitEvent("success",8)
}
}
},2000)
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
default:
console.info("can not match case");
}
})
}
Web({ src: 'https://www.example.com', controller: this.webviewCtl })
Web({ src: 'www.baidu.com', controller: this.webviewCtl })
.fileAccess(true)
.javaScriptAccess(true)
.domStorageAccess(true)
......@@ -92,6 +144,13 @@ struct Second {
.onPageEnd((e) => {
this.outputStr = 'onPageEnd : url = ' + e.url
})
.onFirstContentfulPaint(event => {
console.log("onFirstContentfulPaint:" + "[navigationStartTick]:" +
event.navigationStartTick + ", [firstContentfulPaintMs]:" +
event.firstContentfulPaintMs)
this.firsttime = event.firstContentfulPaintMs - event.navigationStartTick/1000
this.arr.push(this.firsttime)
})
}
}
}
\ No newline at end of file
......@@ -45,14 +45,22 @@ export default function webJsunit() {
done();
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_002
*tc.number SUB_ACE_BASIC_ETS_API_001
*tc.name OnLoadIntercept *tc.desic Injects the JavaScript object into window and invoke the function in window
*/
it('OnLoadIntercept',0,async function(done){
emitKey="emitOnLoadIntercept";
emitKey="emitOnControllerAttached";
Utils.registerEvent("OnLoadIntercept","https://www.baidu.com/",2,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_002
*tc.name OnControllerAttached *tc.desic Injects the JavaScript object into window and invoke the function in window
*/
it('OnControllerAttached',0,async function(done){
emitKey="emitOnControllerAttached";
Utils.registerEvent("OnControllerAttached",1,7,done);
sendEventByKey('webcomponent',10,'');
})
})
}
......@@ -70,9 +70,29 @@ export default function webTwoJsunit() {
*tc.desic Sets allow the Web access overview mode
*/
it('GetCertificate',0,async function(done){
emitKey="emitOverviewModeAccessFalse";
emitKey="emitGetCertificate";
Utils.registerEvent("GetCertificate","getCertificate success: len = 0",4,done);
sendEventByKey('webcomponenttwo',10,'');
})
///*
// *tc.number SUB_ACE_BASIC_ETS_API_002
// *tc.name PrefetchPage
// *tc.desic Sets allow the Web access overview mode
// */
//it('PrefetchPage',0,async function(done){
// emitKey="emitPrepareForPageLoad";
// Utils.registerEvent("PrefetchPage","success",6,done);
// sendEventByKey('webcomponenttwo',10,'');
//})
///*
// *tc.number SUB_ACE_BASIC_ETS_API_003
// *tc.name PrepareForPageLoad
// *tc.desic Sets allow the Web access overview mode
// */
//it('PrepareForPageLoad',0,async function(done){
// emitKey="emitPrepareForPageLoad";
// Utils.registerEvent("PrepareForPageLoad","success",8,done);
// sendEventByKey('webcomponenttwo',10,'');
//})
})
}
\ No newline at end of file
<!-- index.html -->
<!DOCTYPE html>
<html>
<body>
<p>Hello World</p>
</body>
</html>
\ No newline at end of file
......@@ -113,7 +113,6 @@ struct webViewContMessageError {
this.ports[1].postMessageEvent("post message from ets to html5");
} catch (error) {
console.error(`emitPostMessageEventUnPortErr ErrorCode: ${error.code}, Message: ${error.message}`);
this.errorCode = error.code
this.errorMsg = error.message
}
this.controller.runJavaScript("test()",(res) => {
......@@ -122,6 +121,7 @@ struct webViewContMessageError {
})
break;
}
}
})
}
......
/**
* Copyright (c) 2023 iSoftStone Information Technology (Group) 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
import UIAbility from '@ohos.app.ability.UIAbility';
import { Hypium } from '@ohos/hypium';
import testsuite from '../../test/List.test';
import Utils from '../../test/Utils';
import web_webview from '@ohos.web.webview';
@Entry
@Component
struct webViewContPageAndprepareForPageLoadErrorOne {
controller20: web_webview.WebviewController = new web_webview.WebviewController();
ports: web_webview.WebMessagePort[];
msgPort: web_webview.WebMessagePort[] = null;
@State str:string="emitPrefetchPageErr";
@State errorCode: string = '0';
onPageShow(){
let valueChangeEvent={
eventId:10,
priority:events_emitter.EventPriority.LOW
}
events_emitter.on(valueChangeEvent,this.valueChangeCallBack)
}
private valueChangeCallBack=(eventData)=>{
console.info("webViewContPageAndprepareForPageLoadErrorOne page valueChangeCallBack");
if(eventData != null){
console.info("valueChangeCallBack:"+ JSON.stringify(eventData));
if(eventData.data.ACTION != null){
this.str = eventData.data.ACTION;
}
}
}
private jsObj={
test:(res)=>{
Utils.emitEvent(res,102);
},
toString:(str)=>{
console.info("ets toString:"+String(str));
},
register:(res)=>{
Utils.emitEvent(res,86);
return "web222"
}
}
aboutToAppear(){
let abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
let abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
build(){
Column(){
Row() {
Button("messageEventErrorTest").key('webViewContPageAndprepareForPageLoadErrorOne').onClick(() => {
console.info("key==>" + this.str)
switch (this.str) {
case "emitPrefetchPageErr": {
try {
this.controller20.prefetchPage('百度');
console.info("---666---444---8888")
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
this.errorCode = error.code
console.info("789+++987"+this.errorCode)
Utils.emitEvent(this.errorCode, 900)
}
break;
}
}
})
}
}
}
}
\ No newline at end of file
/**
* Copyright (c) 2023 iSoftStone Information Technology (Group) 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
import UIAbility from '@ohos.app.ability.UIAbility';
import { Hypium } from '@ohos/hypium';
import testsuite from '../../test/List.test';
import Utils from '../../test/Utils';
import web_webview from '@ohos.web.webview';
@Entry
@Component
struct webViewContPageAndprepareForPageLoadErrorTwo {
controller: web_webview.WebviewController = new web_webview.WebviewController();
ports: web_webview.WebMessagePort[];
msgPort: web_webview.WebMessagePort[] = null;
@State javaScriptAccess:boolean=true;
@State fileAccess:boolean=true;
@State domStorageAccess:boolean=false;
@State imageAccess:boolean=true;
@State onlineImageAccess:boolean=true;
@State databaseAccess:boolean=true;
@State zoomAccess:boolean=false;
@State str:string="emitPostMessageInitErr";
@State errorCode: string = '0';
onPageShow(){
let valueChangeEvent={
eventId:10,
priority:events_emitter.EventPriority.LOW
}
events_emitter.on(valueChangeEvent,this.valueChangeCallBack)
}
private valueChangeCallBack=(eventData)=>{
console.info("webViewContPageAndprepareForPageLoadErrorTwo page valueChangeCallBack");
if(eventData != null){
console.info("valueChangeCallBack:"+ JSON.stringify(eventData));
if(eventData.data.ACTION != null){
this.str = eventData.data.ACTION;
}
}
}
private jsObj={
test:(res)=>{
Utils.emitEvent(res,102);
},
toString:(str)=>{
console.info("ets toString:"+String(str));
},
register:(res)=>{
Utils.emitEvent(res,86);
return "web222"
}
}
aboutToAppear(){
let abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
let abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
build(){
Column(){
Row() {
Button("messageEventErrorTest").key('webViewContPageAndprepareForPageLoadErrorTwo').onClick(() => {
console.info("key==>" + this.str)
switch (this.str) {
case "emitPrefetchPageErr": {
try {
this.controller.prefetchPage('华为');
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
this.errorCode = error.code
console.info("123+++321"+this.errorCode)
Utils.emitEvent(this.errorCode, 903)
}
break;
}
case "emitPrepareForPageLoadErr": {
try {
web_webview.WebviewController.prepareForPageLoad("华为", true, 6);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
this.errorCode = error.code
console.info("456+++654"+this.errorCode)
Utils.emitEvent(this.errorCode, 904)
}
break;
}
case "emitPrepareForPageLoadErrTwo": {
try {
web_webview.WebviewController.prepareForPageLoad("huawei", true, 7);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
this.errorCode = error.code
console.info("4566+++6546"+this.errorCode)
Utils.emitEvent(this.errorCode, 905)
}
break;
}
}
})
}
Web({src:'www.example.com',controller:this.controller})
.javaScriptAccess(this.javaScriptAccess)
.fileAccess(this.fileAccess)
.imageAccess(this.imageAccess)
.domStorageAccess(this.domStorageAccess)
.onlineImageAccess(this.onlineImageAccess)
.databaseAccess(this.databaseAccess)
.zoomAccess(this.zoomAccess)
}
}
}
\ No newline at end of file
......@@ -21,6 +21,8 @@ import webViewContGetUrlAndOthersError from './webViewContGetUrlAndOthersError.t
import webViewContCookieToGeoLocationError from './webViewContCookieToGeoLocationError.test'
import webViewContJsMessageExtReturnError from './webViewContJsMessageExtReturnError.test'
import webViewContWebMessageExtReturnError from './webViewContWebMessageExtReturnError.test'
import webViewContPageAndprepareForPageLoadErrorOne from './webViewContPageAndprepareForPageLoadErrorOne.test'
import webViewContPageAndprepareForPageLoadErrorTwo from './webViewContPageAndprepareForPageLoadErrorTwo.test'
export default function testsuite() {
webViewContMessageError()
......@@ -32,4 +34,7 @@ export default function testsuite() {
webViewContCookieToGeoLocationError()
webViewContJsMessageExtReturnError()
webViewContWebMessageExtReturnError()
//webViewContPageAndprepareForPageLoadErrorOne()
//webViewContPageAndprepareForPageLoadErrorTwo()
}
\ No newline at end of file
/**
* Copyright (c) 2023 iSoftStone Information Technology (Group) 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 {describe, beforeEach, afterEach, it, expect, beforeAll} from "@ohos/hypium";
import events_emitter from '@ohos.events.emitter';
import Utils from './Utils.ets';
import router from '@system.router';
let emitKey = "emitPrefetchPageErr";
export default function webViewContPageAndprepareForPageLoadErrorOne() {
describe('ActsAceWebDevWebViewContPageAndPrepareForPageLoadErrorOneTest', function () {
beforeAll(async function (done) {
let options = {
uri: 'MainAbility/pages/webViewContPageAndprepareForPageLoadErrorOne',
}
try {
router.clear();
let pages = router.getState();
console.info("get webViewContPageAndprepareForPageLoadErrorOne state success " + JSON.stringify(pages));
if (!("webViewContPageAndprepareForPageLoadErrorOne" == pages.name)) {
console.info("get webViewContPageAndprepareForPageLoadErrorOne state success " + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push webViewContPageAndprepareForPageLoadErrorOne page success " + JSON.stringify(result));
}
} catch (err) {
console.error("push webViewContPageAndprepareForPageLoadErrorOne page error: " + err);
}
done()
});
beforeEach(async function (done) {
await Utils.sleep(2000);
console.info("webViewContPageAndprepareForPageLoadErrorOne beforeEach start");
done();
})
afterEach(async function (done) {
console.info("webViewContPageAndprepareForPageLoadErrorOne afterEach start:"+emitKey);
try {
let backData = {
data: {
"ACTION": emitKey
}
}
let backEvent = {
eventId:10,
priority:events_emitter.EventPriority.LOW
}
console.info("start send emitKey");
events_emitter.emit(backEvent, backData);
} catch (err) {
console.info("emit emitKey err: " + JSON.stringify(err));
}
await Utils.sleep(2000);
done();
})
/*
*tc.number SUB_ACE_BASIC_ETS_WEBVIEWERROR_0100
*tc.name testPostMessageInitErr
*tc.desc test interface of postMessage with not been associated with specific Web Components
*/
it('PrefetchPageErr',0,async function(done){
emitKey="emitPrepareForPageLoadErr";
Utils.registerEvent("PrefetchPageErr","17100001",900,done);
sendEventByKey('webViewContPageAndprepareForPageLoadErrorOne',10,'');
})
})
}
\ No newline at end of file
/**
* Copyright (c) 2023 iSoftStone Information Technology (Group) 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 {describe, beforeEach, afterEach, it, expect, beforeAll} from "@ohos/hypium";
import events_emitter from '@ohos.events.emitter';
import Utils from './Utils.ets';
import router from '@system.router';
let emitKey = "emitPrefetchPageErr";
export default function webViewContPageAndprepareForPageLoadErrorTwo() {
describe('ActsAceWebDevWebViewContPageAndPrepareForPageLoadErrorTwoTest', function () {
beforeAll(async function (done) {
let options = {
uri: 'MainAbility/pages/webViewContPageAndprepareForPageLoadErrorTwo',
}
try {
router.clear();
let pages = router.getState();
console.info("get webViewContPageAndprepareForPageLoadErrorTwo state success " + JSON.stringify(pages));
if (!("webViewContPageAndprepareForPageLoadErrorTwo" == pages.name)) {
console.info("get webViewContPageAndprepareForPageLoadErrorTwo state success " + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push webViewContPageAndprepareForPageLoadErrorTwo page success " + JSON.stringify(result));
}
} catch (err) {
console.error("push webViewContPageAndprepareForPageLoadErrorTwo page error: " + err);
}
done()
});
beforeEach(async function (done) {
await Utils.sleep(2000);
console.info("webViewContPageAndprepareForPageLoadErrorTwo beforeEach start");
done();
})
afterEach(async function (done) {
console.info("webViewContPageAndprepareForPageLoadErrorTwo afterEach start:"+emitKey);
try {
let backData = {
data: {
"ACTION": emitKey
}
}
let backEvent = {
eventId:10,
priority:events_emitter.EventPriority.LOW
}
console.info("start send emitKey");
events_emitter.emit(backEvent, backData);
} catch (err) {
console.info("emit emitKey err: " + JSON.stringify(err));
}
await Utils.sleep(2000);
done();
})
/*
*tc.number SUB_ACE_BASIC_ETS_WEBVIEWERROR_0100
*tc.name testPostMessageInitErr
*tc.desc test interface of postMessage with not been associated with specific Web Components
*/
it('PrefetchPageErr',0,async function(done){
emitKey="emitPrepareForPageLoadErr";
Utils.registerEvent("PrefetchPageErr","17100002",903,done);
sendEventByKey('webViewContPageAndprepareForPageLoadErrorTwo',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_WEBVIEWERROR_0200
*tc.name testPostMessageEventPortClose
*tc.desc test interface of postMessageEvent with WebMessagePort been closed by ets
*/
it('PrepareForPageLoadErr',0,async function(done){
emitKey="emitPrepareForPageLoadErrTwo";
Utils.registerEvent("PrepareForPageLoadErr","17100002",904,done);
sendEventByKey('webViewContPageAndprepareForPageLoadErrorTwo',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_WEBVIEWERROR_0200
*tc.name testPostMessageEventPortClose
*tc.desc test interface of postMessageEvent with WebMessagePort been closed by ets
*/
it('PrepareForPageLoadErrTwo',0,async function(done){
emitKey="emitPrepareForPageLoadErrTwo";
Utils.registerEvent("PrepareForPageLoadErrTwo","171000013",905,done);
sendEventByKey('webViewContPageAndprepareForPageLoadErrorTwo',10,'');
})
})
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册