提交 554faa70 编写于 作者: W wang-xupeng2

add api

Signed-off-by: Nwang-xupeng2 <wangxupeng2@huawei.com>
上级 006d1169
...@@ -11,10 +11,10 @@ ...@@ -11,10 +11,10 @@
"distributedNotificationEnabled": true, "distributedNotificationEnabled": true,
"keepAlive": true, "keepAlive": true,
"singleUser": true, "singleUser": true,
"minAPIVersion": 9, "minAPIVersion": 10,
"targetAPIVersion": 9, "targetAPIVersion": 10,
"car": { "car": {
"apiCompatibleVersion": 9, "apiCompatibleVersion": 10,
"singleUser": false "singleUser": false
} }
} }
......
...@@ -18,17 +18,22 @@ import { Hypium } from '@ohos/hypium'; ...@@ -18,17 +18,22 @@ import { Hypium } from '@ohos/hypium';
import testsuite from '../../test/List.test'; import testsuite from '../../test/List.test';
import Utils from '../../test/Utils'; import Utils from '../../test/Utils';
import web_webview from '@ohos.web.webview'; import web_webview from '@ohos.web.webview';
import fileio from '@ohos.fileio';
let loadedUrl; let loadedUrl;
@Entry @Entry
@Component @Component
struct Index { struct Index {
controller: web_webview.WebviewController = new web_webview.WebviewController(); controller: web_webview.WebviewController = new web_webview.WebviewController();
controllerTwo: web_webview.WebviewController = new web_webview.WebviewController(); controllerTwo: web_webview.WebviewController = new web_webview.WebviewController();
scheme1: web_webview.WebCustomScheme = {schemeName: "name1", isSupportCORS: true, isSupportFetch: true}
responseweb: WebResourceResponse = new WebResourceResponse() responseweb: WebResourceResponse = new WebResourceResponse()
@State str:string="emitLoadUrl" @State str:string="emitLoadUrl"
@State text:boolean=false @State text:boolean=false
@State num:number=0 @State num:number=0
@State mode: WebDarkMode = WebDarkMode.Off
@State mode1: WebDarkMode = WebDarkMode.On
@State mode2: WebDarkMode = WebDarkMode.Auto
ports: web_webview.WebMessagePort[];
testObj = { testObj = {
testOne: (data) => { testOne: (data) => {
Utils.emitEvent(data,13) Utils.emitEvent(data,13)
...@@ -62,6 +67,14 @@ struct Index { ...@@ -62,6 +67,14 @@ struct Index {
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!') console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
try{
web_webview.once("webInited",()=>{
web_webview.WebCookieManager.setCookie("https://www.huawei.com", "a=b");
})
}catch(error){
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
} }
build(){ build(){
Column(){ Column(){
...@@ -406,6 +419,113 @@ struct Index { ...@@ -406,6 +419,113 @@ struct Index {
} }
break; break;
} }
case "emitOnce":{
try {
let re = web_webview.WebCookieManager.getCookie("https://www.huawei.com")
Utils.emitEvent(re, 31)
console.log("result: " + re);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
case "emitGetItemAtIndex":{
try {
let res = this.controller.getBackForwardEntries()
let item =res.getItemAtIndex(0)
Utils.emitEvent(item.title, 32)
console.log("result: " + item.title);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
case "emitSlideScroll":{
try {
this.controller.slideScroll(10, 10);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
try {
let state = this.controller.serializeWebState();
let path = globalThis.AbilityContext.cacheDir;
path += '/WebState';
let fd = fileio.openSync(path, 0o2 | 0o100, 0o666);
fileio.writeSync(fd, state.buffer);
fileio.closeSync(fd);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
try {
let path = globalThis.AbilityContext.cacheDir;
path += '/WebState';
let fd = fileio.openSync(path, 0o002, 0o666);
let stat = fileio.fstatSync(fd);
let size = stat.size;
let buf = new ArrayBuffer(size);
fileio.read(fd, buf, (err, data) => {
if (data) {
this.controller.restoreWebState(new Uint8Array(data.buffer));
}
fileio.closeSync(fd);
});
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
try {
this.ports = this.controller.createWebMessagePorts();
this.ports[1].onMessageEvent((msg) => {
if (typeof(msg) == "string") {
console.log("received string message from html5, string is:" + msg);
} else if (typeof(msg) == "object") {
if (msg instanceof ArrayBuffer) {
console.log("received arraybuffer from html5, length is:" + msg.byteLength);
} else {
console.log("not support");
}
} else {
console.log("not support");
}
})
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
case "emitContextMenuMediaType":{
try {
let con = ContextMenuMediaType.Image
Utils.emitEvent(con, 33)
console.log("result: " + con);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
case "emitContextMenuInputFieldType":{
try {
Utils.emitEvent(ContextMenuInputFieldType.PlainText, 34)
Utils.emitEvent(ContextMenuInputFieldType.Telephone, 35)
Utils.emitEvent(ContextMenuInputFieldType.Other, 36)
console.log("result: " + ContextMenuInputFieldType.PlainText);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
case "emitContextMenuEditStateFlags":{
try {
Utils.emitEvent(ContextMenuEditStateFlags.NONE, 37)
Utils.emitEvent(ContextMenuEditStateFlags.CAN_CUT, 38)
Utils.emitEvent(ContextMenuEditStateFlags.CAN_COPY, 39)
Utils.emitEvent(ContextMenuEditStateFlags.CAN_PASTE, 40)
Utils.emitEvent(ContextMenuEditStateFlags.CAN_SELECT_ALL, 41)
console.log("result: " + ContextMenuEditStateFlags.CAN_SELECT_ALL);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
default: default:
console.info("can not match case") console.info("can not match case")
} }
...@@ -415,6 +535,10 @@ struct Index { ...@@ -415,6 +535,10 @@ struct Index {
.mediaPlayGestureAccess(true) .mediaPlayGestureAccess(true)
.javaScriptAccess(true) .javaScriptAccess(true)
.zoomAccess(this.text) .zoomAccess(this.text)
.onDataResubmitted((event) => {
console.log('onDataResubmitted')
event.handler.resend();
})
.onSearchResultReceive(ret=>{ .onSearchResultReceive(ret=>{
var searchResult = ret.activeMatchOrdinal.toString() + var searchResult = ret.activeMatchOrdinal.toString() +
ret.numberOfMatches.toString() ret.numberOfMatches.toString()
...@@ -423,6 +547,30 @@ struct Index { ...@@ -423,6 +547,30 @@ struct Index {
Utils.emitEvent(searchResult,16) Utils.emitEvent(searchResult,16)
},3000) },3000)
}) })
.onContextMenuShow((event) => {
console.info(event.param.getMediaType() + event.param.getSelectionText() + event.param.getSourceType())
console.info(event.param.getInputFieldType().toString())
console.info(event.param.isEditable().toString())
console.info(event.param.getEditStateFlags().toString())
event.result.paste()
event.result.cut()
return true
})
.onHttpErrorReceive((event) => {
event.response.setResponseIsReady(true)
})
.darkMode(this.mode)
.forceDarkAccess(false)
.webSerifFont('serif')
.webFixedFont('fixed')
.webSansSerifFont('serif')
.minLogicalFontSize(1)
.horizontalScrollBarAccess(true)
.verticalScrollBarAccess(true)
.onTouchIconUrlReceived((event) => {
console.log('onTouchIconUrlReceived:' + JSON.stringify(event))
})
.pinchSmooth(true)
} }
} }
......
...@@ -340,9 +340,65 @@ export default function webJsunit() { ...@@ -340,9 +340,65 @@ export default function webJsunit() {
*tc.desic Save current page *tc.desic Save current page
*/ */
it('GetUrl',0,async function(done){ it('GetUrl',0,async function(done){
emitKey="emitGetUrl"; emitKey="emitOnce";
Utils.registerContainEvent("GetUrl","17100001",30,done); Utils.registerContainEvent("GetUrl","17100001",30,done);
sendEventByKey('webcomponent',10,''); sendEventByKey('webcomponent',10,'');
}) })
/*
*tc.number SUB_ACE_BASIC_ETS_API_031
*tc.name Once
*tc.desic Save current page
*/
it('Once',0,async function(done){
emitKey="emitGetItemAtIndex";
Utils.registerContainEvent("Once","a=b",31,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_032
*tc.name GetItemAtIndex
*tc.desic Save current page
*/
it('GetItemAtIndex',0,async function(done){
emitKey="emitContextMenuMediaType";
Utils.registerEvent("GetItemAtIndex","index",32,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_033
*tc.name ContextMenuMediaType
*tc.desic Save current page
*/
it('ContextMenuMediaType',0,async function(done){
emitKey="emitContextMenuInputFieldType";
Utils.registerEvent("ContextMenuMediaType",1,33,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_034
*tc.name ContextMenuInputFieldType
*tc.desic Save current page
*/
it('ContextMenuInputFieldType',0,async function(done){
emitKey="emitContextMenuEditStateFlags";
Utils.registerEvent("ContextMenuInputFieldType",1,34,done);
Utils.registerEvent("ContextMenuInputFieldType",4,35,done);
Utils.registerEvent("ContextMenuInputFieldType",5,36,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_035
*tc.name ContextMenuEditStateFlags
*tc.desic Save current page
*/
it('ContextMenuEditStateFlags',0,async function(done){
emitKey="emitContextMenuEditStateFlags";
Utils.registerEvent("ContextMenuEditStateFlags",0,37,done);
Utils.registerEvent("ContextMenuEditStateFlags",1,38,done);
Utils.registerEvent("ContextMenuEditStateFlags",2,39,done);
Utils.registerEvent("ContextMenuEditStateFlags",4,40,done);
Utils.registerEvent("ContextMenuEditStateFlags",8,41,done);
sendEventByKey('webcomponent',10,'');
})
}) })
} }
\ No newline at end of file
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
"uiSyntax": "ets", "uiSyntax": "ets",
"pages": "$profile:main_pages", "pages": "$profile:main_pages",
"metadata": [ "metadata": [
{ {
"name": "ArkTSPartialUpdate", "name": "ArkTSPartialUpdate",
"value": "false" "value": "true"
} }
], ],
"abilities": [{ "abilities": [{
"name": "com.example.myapplication.MainAbility", "name": "com.example.myapplication.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts", "srcEntrance": "./ets/MainAbility/MainAbility.ts",
...@@ -46,4 +46,4 @@ ...@@ -46,4 +46,4 @@
} }
] ]
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册