未验证 提交 df6dc76d 编写于 作者: O openharmony_ci 提交者: Gitee

!8790 【OpenHarmony 4.0.7.3】【Master】【ARKUI子系统】【TOD】【rk3568】【必现】api接口,属性覆盖JsMessageType,WebMessageExt

Merge pull request !8790 from 边鑫博/master
......@@ -101,6 +101,7 @@ struct indexTwo {
},3000)
break;
}
default:
console.info("can not match case")
}
......
......@@ -426,10 +426,164 @@ export default function webJsunit() {
*tc.desic Save current page
*/
it('GetAccessibleGeolocation',0,async function(done){
emitKey="emitGetAccessibleGeolocation";
emitKey="emitJsMessExtGetString";
Utils.registerEvent("GetAccessibleGeolocation",true,451,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_039
*tc.name JsMessExtGetString
*tc.desic Save current page
*/
it('JsMessExtGetString',0,async function(done){
emitKey="emitJsMessExtGetNum";
Utils.registerEvent("JsMessExtGetString","result type:string",500,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_040
*tc.name JsMessExtGetNum
*tc.desic Save current page
*/
it('JsMessExtGetNum',0,async function(done){
emitKey="emitJsMessExtGetBoo";
Utils.registerEvent("JsMessExtGetNum","result type:number",501,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_041
*tc.name JsMessExtGetBoo
*tc.desic Save current page
*/
it('JsMessExtGetBoo',0,async function(done){
emitKey="emitJsMessExtGetArrayBuffer";
Utils.registerEvent("JsMessExtGetBoo","result type:boolean",502,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_042
*tc.name JsMessExtGetArrayBuffer
*tc.desic Save current page
*/
it('JsMessExtGetArrayBuffer',0,async function(done){
emitKey="emitJsMessExtGetArray";
Utils.registerEvent("JsMessExtGetArrayBuffer","result type:object",503,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_043
*tc.name JsMessExtGetArray
*tc.desic Save current page
*/
it('JsMessExtGetArray',0,async function(done){
emitKey="emitWebMessExtSetString";
Utils.registerEvent("JsMessExtGetArray","result type:object0",504,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_044
*tc.name WebMessExtSetString
*tc.desic Save current page
*/
it('WebMessExtSetString',0,async function(done){
emitKey="emitWebMessExtGetString";
var result="String:helloFromEts"
Utils.registerEvent("WebMessExtSetString",JSON.stringify(result),506,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_045
*tc.name WebMessExtGetString
*tc.desic Save current page
*/
it('WebMessExtGetString',0,async function(done){
emitKey="emitWebMessExtSetNumber";
Utils.registerEvent("WebMessExtGetString","result type:string",505,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_046
*tc.name WebMessExtSetNumber
*tc.desic Save current page
*/
it('WebMessExtSetNumber',0,async function(done){
emitKey="emitWebMessExtGetNumber";
var result="Number:1"
Utils.registerEvent("WebMessExtSetNumber",JSON.stringify(result),507,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_047
*tc.name WebMessExtGetNumber
*tc.desic Save current page
*/
it('WebMessExtGetNumber',0,async function(done){
emitKey="emitWebMessExtSetBoolean";
Utils.registerEvent("WebMessExtGetNumber","result type:number0",508,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_048
*tc.name WebMessExtSetBoolean
*tc.desic Save current page
*/
it('WebMessExtSetBoolean',0,async function(done){
emitKey="emitWebMessExtGetBoolean";
var result="Boolean:true"
Utils.registerEvent("WebMessExtSetBoolean",JSON.stringify(result),509,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_049
*tc.name WebMessExtGetBoolean
*tc.desic Save current page
*/
it('WebMessExtGetBoolean',0,async function(done){
emitKey="emitWebMessExtSetArray";
Utils.registerEvent("WebMessExtGetBoolean","result type:boolean",510,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_050
*tc.name WebMessExtSetArray
*tc.desic Save current page
*/
it('WebMessExtSetArray',0,async function(done){
emitKey="emitWebMessExtGetArray";
var result="Array len:1, value:apple"
Utils.registerEvent("WebMessExtSetArray",JSON.stringify(result),511,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_051
*tc.name WebMessExtGetArray
*tc.desic Save current page
*/
it('WebMessExtGetArray',0,async function(done){
emitKey="emitWebMessExtSetArrayBuffer";
Utils.registerEvent("WebMessExtGetArray","result type:object",512,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_052
*tc.name WebMessExtSetArrayBuffer
*tc.desic Save current page
*/
it('WebMessExtSetArrayBuffer',0,async function(done){
emitKey="emitWebMessExtGetArrayBuffer";
var result="ArrayBuffer:8"
Utils.registerEvent("WebMessExtSetArrayBuffer",JSON.stringify(result),513,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_053
*tc.name WebMessExtGetArrayBuffer
*tc.desic Save current page
*/
it('WebMessExtGetArrayBuffer',0,async function(done){
emitKey="emitWebMessExtGetArrayBuffer";
Utils.registerEvent("WebMessExtGetArrayBuffer","result getArrayBuffer byteLength:8",514,done);
sendEventByKey('webcomponent',10,'');
})
})
}
......@@ -70,5 +70,24 @@
let str = objName.testOne('Web')
return str
}
function getStringForJs() {
return "hello, world";
}
function getNumForJs() {
return 1;
}
function getBooForJs() {
return true;
}
function getArrayBufferForJs() {
const buffer = new ArrayBuffer(8);
const view = new Int32Array(buffer);
return view;
}
function getArrayForJs() {
const fruits = [];
fruits.push("banana", "apple", "peach");
return fruits;
}
</script>
</html>
/*
* Copyright (C) 2021 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.
*/
var h5Port;
window.addEventListener('message', function(event) {
console.info("htmlSSSSS")
if (event.data == 'init_web_messageport') {
if(event.ports[0] != null) {
h5Port = event.ports[0]; // 1. 保存从ets侧发送过来的端口
h5Port.onmessage = function(event) {
console.info("hwd In html got message");
// 2. 接收ets侧发送过来的消息.
var result = event.data;
console.info("In html got message, typeof: ", typeof(result));
console.info("In html got message, result: ", (result));
if (typeof(result) == "string") {
console.log("In html got message, String: ", result);
document.getElementById("msg").innerHTML = "String:" + result;
} else if (typeof(result) == "number") {
console.log("In html side got message, number: ", result);
document.getElementById("msg").innerHTML = "Number:" + result;
} else if (typeof(result) == "boolean") {
console.log("In html side got message, boolean: ", result);
document.getElementById("msg").innerHTML = "Boolean:" + result;
} else if (typeof(result) == "object") {
if (result instanceof ArrayBuffer) {
document.getElementById("msg2").innerHTML = "ArrayBuffer:" + result.byteLength;
console.log("In html got message, byteLength: ", result.byteLength);
} else if (result instanceof Error) {
console.log("In html error message, err:" + (result));
console.log("In html error message, typeof err:" + typeof(result));
document.getElementById("msg2").innerHTML = "Error:" + result.name + ", msg:" + result.message;
} else if (result instanceof Array) {
console.log("In html got message, Array");
console.log("In html got message, Array length:" + result.length);
console.log("In html got message, Array[0]:" + (result[0]));
console.log("In html got message, typeof Array[0]:" + typeof(result[0]));
document.getElementById("msg2").innerHTML = "Array len:" + result.length + ", value:" + result;
} else {
console.log("In html got message, not any instance of support type");
document.getElementById("msg").innerHTML = "not any instance of support type";
}
} else {
console.log("In html got message, not support type");
document.getElementById("msg").innerHTML = "not support type";
}
}
h5Port.onmessageerror = (event) => {
console.error(`hwd In html Error receiving message: ${event}`);
};
}
}
})
// 使用h5Port往ets侧发送String类型的消息.
function postStringToApp() {
if (h5Port) {
console.log("In html send string message");
h5Port.postMessage("hello");
console.log("In html send string message end");
} else {
console.error("In html h5port is null, please init first");
}
}
function postNumberToApp() {
if (h5Port) {
console.log("In html send Number message");
h5Port.postMessage(1);
console.log("In html send Number message end");
} else {
console.error("In html h5port is null, please init first");
}
}
function postBooleanToApp() {
if (h5Port) {
console.log("In html send Boolean message");
h5Port.postMessage(true);
console.log("In html send Boolean message end");
} else {
console.error("In html h5port is null, please init first");
}
}
function postArrayToApp() {
if (h5Port) {
console.log("In html send Array message");
const fruits = [];
fruits.push("apple");
h5Port.postMessage(fruits);
console.log("In html send Array message end");
} else {
console.error("In html h5port is null, please init first");
}
}
function postArrayBufferToApp() {
if (h5Port) {
console.log("In html send Buffer message");
let buffer = new ArrayBuffer(8);
h5Port.postMessage(buffer);
console.log("In html send Buffer message end");
} else {
console.error("In html h5port is null, please init first");
}
}
function postErrorToApp() {
if (h5Port) {
console.log("In html send error message");
let err = {name:"cuowu",message:"cuowu"};
h5Port.postMessage(err);
console.log("In html send error message end");
} else {
console.error("In html h5port is null, please init first");
}
}
function postStringToHtml() {
var a=document.getElementById("msg").innerText
return a
}
function postNumberToHtml() {
var a=document.getElementById("msg").innerText
return a
}
function postBooleanToHtml() {
var a=document.getElementById("msg").innerText
return a
}
function postArrayToHtml() {
var a=document.getElementById("msg2").innerText
return a
}
function postArrayBufferToHtml() {
var a=document.getElementById("msg2").innerText
return a
}
function postErrorToHtml() {
var a=document.getElementById("msg2").innerText
return a
}
\ No newline at end of file
<!--index.html-->
<!DOCTYPE html>
<html lang="en-gb">
<head>
<title>WebView MessagePort Demo</title>
</head>
<body>
<h1>Html5 Send and Receive Message</h1>
<h3 id="msg">Receive string:</h3>
<h3 id="msg2">Receive arraybuffer:</h3>
<div style="font-size: 10pt; text-align: center;">
<input type="button" value="Send String" onclick="postStringToApp();" /><br/>
</div>
</body>
<script src="index.js"></script>
</html>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册