From e830485ff951cff1b378c64e46c96da9a45f6653 Mon Sep 17 00:00:00 2001 From: zhangxinyue Date: Fri, 23 Sep 2022 13:24:04 +0800 Subject: [PATCH] add new Signed-off-by: zhangxinyue --- .../src/main/ets/MainAbility/pages/web.ets | 140 +++++++++++++++++- .../src/main/ets/test/WebJsunit.test.ets | 128 +++++++++++++--- 2 files changed, 241 insertions(+), 27 deletions(-) diff --git a/arkui/ace_ets_web_dev_two/entry/src/main/ets/MainAbility/pages/web.ets b/arkui/ace_ets_web_dev_two/entry/src/main/ets/MainAbility/pages/web.ets index 3d230c746..254d1fc6c 100644 --- a/arkui/ace_ets_web_dev_two/entry/src/main/ets/MainAbility/pages/web.ets +++ b/arkui/ace_ets_web_dev_two/entry/src/main/ets/MainAbility/pages/web.ets @@ -27,6 +27,7 @@ struct Index { responseweb: WebResourceResponse = new WebResourceResponse() @State str:string="emitStoreWebArchive" @State text:string="" + @State num:number=0 @State textRatio:number=100 @State zoomAccessValue:boolean=true host: string = "www.spincast.org" @@ -79,14 +80,14 @@ struct Index { let level = event.message.getMessageLevel() let msg = event.message.getMessage() let lineNumber = event.message.getLineNumber().toString() - let sourceId = event.message.getSourceId() console.log("lineNumber:" + lineNumber) setTimeout(()=>{ Utils.emitEvent(lineNumber,420) },3000) setTimeout(()=>{ + let sourceId = event.message.getSourceId() Utils.emitEvent(sourceId,422) - },3000) + },5000) return false }) .onSearchResultReceive(ret=>{ @@ -215,6 +216,139 @@ struct Index { },3000); break ; } + case "emitGetOriginUsage":{ + this.controller.loadUrl({url:"file:///data/storage/el1/bundle/phone/resources/rawfile/webstorage.html"}) + setTimeout(()=>{ + web_webview.WebStorage.getOriginUsage("file:///data/storage/el1/bundle/phone/resources/rawfile/webstorage.html",(error,result)=>{ + if (error) { + console.log('error:' + error); + return; + } + this.text = result.toString(); + console.log("usage is:" + this.text) + }) + setTimeout(()=>{ + Utils.emitEvent(this.text,432) + },3000) + },3000) + break; + } + case "emitGetOriginUsagePromise":{ + this.controller.loadUrl({url:"file:///data/storage/el1/bundle/phone/resources/rawfile/webstorage.html"}) + setTimeout(()=>{ + web_webview.WebStorage.getOriginUsage("file:///data/storage/el1/bundle/phone/resources/rawfile/webstorage.html") + .then(usage=>{ + console.log('usage: '+usage) + setTimeout(()=>{ + Utils.emitEvent(usage.toString(),447) + },3000) + }) + .catch(error=>{ + console.log('error: '+error) + }) + },3000) + break; + } + case "emitGetOriginQuota":{ + web_webview.WebStorage.getOriginQuota("file:///data/storage/el1/bundle/phone/resources/rawfile/webstorage.html",(error,result)=>{ + if (error) { + console.log('error:' + error); + return; + } + this.text = result.toString(); + console.log("usage is:" + this.text) + }) + setTimeout(()=>{ + Utils.emitEvent(this.text,434) + },3000) + break; + } + case "emitGetOriginQuotaPromise":{ + setTimeout(()=>{ + web_webview.WebStorage.getOriginQuota("file:///data/storage/el1/bundle/phone/resources/rawfile/webstorage.html") + .then(quota=>{ + console.log('usage: '+quota) + setTimeout(()=>{ + Utils.emitEvent(quota.toString(),448) + },3000) + }) + .catch(error=>{ + console.log('error: '+error) + }) + },3000) + break; + } + case "emitGetOrigins":{ + web_webview.WebStorage.getOrigins((error, origins) => { + if (error) { + console.log('error: ' + error); + return; + } + this.text = origins[0].origin.toString(); + var us = origins[0].usage; + var qu = origins[0].quota; + console.log("usage is:" + this.text) + }) + setTimeout(()=>{ + Utils.emitEvent(this.text,436) + },3000) + break; + } + case "emitGetOriginsPromise":{ + setTimeout(()=>{ + web_webview.WebStorage.getOrigins() + .then(origins=>{ + for (let i = 0; i < origins.length; i++) { + console.log('origin: ' + origins[i].origin); + console.log('usage: ' + origins[i].usage); + console.log('quota: ' + origins[i].quota); + } + setTimeout(()=>{ + Utils.emitEvent(origins[0].origin,449) + },3000) + }) + .catch(error=>{ + console.log('error: '+error) + }) + },3000) + this.controller.loadUrl({url:"file:///data/storage/el1/bundle/phone/resources/rawfile/index.html"}) + break; + } + case "emitDeleteOrigin":{ + web_webview.WebStorage.deleteOrigin("file:///data/storage/el1/bundle/phone/resources/rawfile/webstorage.html") + setTimeout(()=>{ + web_webview.WebStorage.getOriginUsage("file:///data/storage/el1/bundle/phone/resources/rawfile/webstorage.html",(error, usage) => { + if (error) { + console.log('error: ' + error); + return; + } + this.num = usage + console.log("usage is:" + this.num) + setTimeout(()=>{ + Utils.emitEvent(this.num,438) + },4000) + }) + },3000) + + break; + } + case "emitDeleteAllData":{ + web_webview.WebStorage.deleteAllData() + setTimeout(()=>{ + web_webview.WebStorage.getOriginUsage("file:///data/storage/el1/bundle/phone/resources/rawfile/webstorage.html",(error, usage) => { + if (error) { + console.log('error: ' + error); + return; + } + this.num = usage + console.log("usage is:" + this.num) + setTimeout(()=>{ + Utils.emitEvent(this.num,440) + },4000) + }) + },3000) + break; + } case "emitSaveHttpAuthCredentials":{ web_webview.WebDataBase.saveHttpAuthCredentials(this.host, this.realm, "Stromgol", "Laroche"); setTimeout(()=>{ @@ -253,4 +387,4 @@ struct Index { } } } -} +} \ No newline at end of file diff --git a/arkui/ace_ets_web_dev_two/entry/src/main/ets/test/WebJsunit.test.ets b/arkui/ace_ets_web_dev_two/entry/src/main/ets/test/WebJsunit.test.ets index deea6fda9..9085a13da 100644 --- a/arkui/ace_ets_web_dev_two/entry/src/main/ets/test/WebJsunit.test.ets +++ b/arkui/ace_ets_web_dev_two/entry/src/main/ets/test/WebJsunit.test.ets @@ -120,28 +120,8 @@ export default function webJsunit() { *tc.desic return whether there exits cookie */ it('existCookie',0,async function(done){ - emitKey="emitOnConsole"; - Utils.registerEvent("existCookie",false,414,done); - sendEventByKey('webcomponent',10,''); - }) - /* - *tc.number SUB_ACE_BASIC_ETS_API_076 - *tc.name getLineNumber - *tc.desic return the number of console message lines - */ - it('getLineNumber',0,async function(done){ - emitKey="emitOnConsole"; - Utils.registerEvent("getLineNumber","51",420,done); - sendEventByKey('webcomponent',10,''); - }) - /* - *tc.number SUB_ACE_BASIC_ETS_API_077 - *tc.name getSourceId - *tc.desic return the source url - */ - it('getSourceId',0,async function(done){ emitKey="emitLoaData"; - Utils.registerEvent("getSourceId","file:///data/storage/el1/bundle/phone/resources/rawfile/index.html",422,done); + Utils.registerEvent("existCookie",false,414,done); sendEventByKey('webcomponent',10,''); }) /* @@ -160,10 +140,60 @@ export default function webJsunit() { *tc.desic set whether it is allowed to zoom */ it('zoomAccess',0,async function(done){ - emitKey="emitSaveHttpAuthCredentials"; + emitKey="emitGetOriginUsage"; Utils.registerEvent("zoomAccess",false,428,done); sendEventByKey('webcomponent',10,''); }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_082 + *tc.name getOriginUsage + *tc.desic get origin usage + */ + it('getOriginUsage',0,async function(done){ + emitKey="emitGetOriginQuota"; + Utils.registerEvent("getOriginUsage","24576",432,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_083 + *tc.name getOriginQuota + *tc.desic get origin storage + */ + it('getOriginQuota',0,async function(done){ + emitKey="emitGetOrigins"; + Utils.registerEvent("getOriginQuota","2575722086",434,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_084 + *tc.name getOrigins + *tc.desic get origins + */ + it('getOrigins',0,async function(done){ + emitKey="emitDeleteOrigin"; + Utils.registerEvent("getOrigins","file:///",436,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_085 + *tc.name deleteOrigin + *tc.desic delete specific url usage + */ + it('deleteOrigin',0,async function(done){ + emitKey="emitDeleteAllData"; + Utils.registerEvent("deleteOrigin",0,438,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_086 + *tc.name deleteAllData + *tc.desic delete all data + */ + it('deleteAllData',0,async function(done){ + emitKey="emitSaveHttpAuthCredentials"; + Utils.registerEvent("deleteAllData",0,440,done); + sendEventByKey('webcomponent',10,''); + }) /* *tc.number SUB_ACE_BASIC_ETS_API_087 *tc.name saveHttpAuthCredentials @@ -190,10 +220,60 @@ export default function webJsunit() { *tc.desic delete credentials */ it('deleteHttpAuthCredentials',0,async function(done){ - emitKey="emitSearchAllAsync"; + emitKey="emitGetOriginUsagePromise"; Utils.registerEvent("deleteHttpAuthCredentials",false,446,done); sendEventByKey('webcomponent',10,''); }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_090 + *tc.name getOriginUsagePromise + *tc.desic promise method + */ + it('getOriginUsagePromise',0,async function(done){ + emitKey="emitGetOriginQuotaPromise"; + Utils.registerEvent("getOriginUsagePromise",'24576',447,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_091 + *tc.name getOriginQuotaPromise + *tc.desic promise method + */ + it('getOriginQuotaPromise',0,async function(done){ + emitKey="emitGetOriginsPromise"; + Utils.registerEvent("getOriginQuotaPromise",'2575722086',448,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_092 + *tc.name getOriginsPromise + *tc.desic promise method + */ + it('getOriginsPromise',0,async function(done){ + emitKey="emitOnConsole"; + Utils.registerEvent("getOriginsPromise",'file:///',449,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_077 + *tc.name getSourceId + *tc.desic return the source url + */ + it('getSourceId',0,async function(done){ + emitKey="emitOnConsole"; + Utils.registerEvent("getSourceId","file:///data/storage/el1/bundle/phone/resources/rawfile/index.html",422,done); + sendEventByKey('webcomponent',10,''); + }) + /* + *tc.number SUB_ACE_BASIC_ETS_API_076 + *tc.name getLineNumber + *tc.desic return the number of console message lines + */ + it('getLineNumber',0,async function(done){ + emitKey="emitSearchAllAsync"; + Utils.registerEvent("getLineNumber","51",420,done); + sendEventByKey('webcomponent',10,''); + }) /* *tc.number SUB_ACE_BASIC_ETS_API_079 *tc.name searchAllAsync @@ -205,4 +285,4 @@ export default function webJsunit() { sendEventByKey('webcomponent',10,''); }) }) -} +} \ No newline at end of file -- GitLab