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

!8531 webview xts code(runJavascript&storeWebArchive)提交

Merge pull request !8531 from 张海霖/webview_01
/**
* 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 { Hypium } from '@ohos/hypium';
import testsuite from '../../test/List.test';
import Utils from '../../test/Utils';
import web_webview from '@ohos.web.webview';
let loadedUrl;
@Entry
@Component
struct Index {
controller: web_webview.WebviewController = new web_webview.WebviewController();
controller2: web_webview.WebviewController = new web_webview.WebviewController();
@State str:string="emitRunJsCallback";
@State webId:number=0;
@State webResult:string=' ';
@State proResult:string=' ';
@State webFilename:string=' ';
@State errorResult:string=' ';
@State userAgent: string = "Mozilla/5.0 (Window NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) CHrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.27";
@State pageResult:boolean=false;
@State javaScriptAccess:boolean=true;
@State fileAccess:boolean=true;
@State domStorageAccess:boolean=false
@State imageAccess:boolean=true
@State onlineImageAccess:boolean=true
@State databaseAccess:boolean=true
onPageShow(){
let valueChangeEvent={
eventId:10,
priority:events_emitter.EventPriority.LOW
}
events_emitter.on(valueChangeEvent,this.valueChangeCallBack)
}
private valueChangeCallBack=(eventData)=>{
console.info("web page valueChangeCallBack");
if(eventData != null){
console.info("valueChangeCallBack:"+ JSON.stringify(eventData));
if(eventData.data.ACTION != null){
this.str = eventData.data.ACTION;
}
}
}
build(){
Column(){
Row() {
Button("web test").key('webcomponent01').onClick(async () => {
console.info("key==>" + this.str)
switch (this.str) {
case "emitRunJsCallback": {
try {
console.info('Running testcaes emitRunJsCallback!!!')
this.controller.runJavaScript(
'testRunJavaScript()',
(error, result) => {
if (error) {
console.info(`run JavaScript error: ` + JSON.stringify(error))
return;
}
if (result) {
this.webResult = 'testRunJavaScript'
Utils.emitEvent(this.webResult, 126)
console.info(`The test() return value is: ${result}`)
}
});
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
}
case "emitRunJsPromise": {
try {
this.controller.runJavaScript('testRunJavaScript()')
.then(function (proResult) {
Utils.emitEvent(proResult, 128)
console.log('proResult: ' + proResult);
})
.catch(function (error) {
console.error("error: " + error);
})
} catch (error) {
console.error(`Errorcode: ${error.code}, Message: ${error.message}`);
}
}
}
})
}
Web({src:$rawfile('index.html'),controller:this.controller})
.javaScriptAccess(this.javaScriptAccess)
.fileAccess(this.fileAccess)
.imageAccess(this.imageAccess)
.domStorageAccess(this.domStorageAccess)
.onlineImageAccess(this.onlineImageAccess)
.databaseAccess(this.databaseAccess)
.userAgent(this.userAgent)
}
}
}
/**
* 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 { Hypium } from '@ohos/hypium';
import testsuite from '../../test/List.test';
import Utils from '../../test/Utils';
import web_webview from '@ohos.web.webview';
let loadedUrl;
@Entry
@Component
struct Index {
controller: web_webview.WebviewController = new web_webview.WebviewController();
@State str:string="emitStoreWebArchiveCallback";
@State webId:number=0;
@State webResult:string=' ';
@State proResult:string=' ';
@State webFilename:string=' ';
@State errorResult:string=' ';
@State userAgent: string = "Mozilla/5.0 (Window NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) CHrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.27";
@State pageResult:boolean=false;
@State javaScriptAccess:boolean=true;
@State fileAccess:boolean=true;
@State domStorageAccess:boolean=false
@State imageAccess:boolean=true
@State onlineImageAccess:boolean=true
@State databaseAccess:boolean=true
onPageShow(){
let valueChangeEvent={
eventId:10,
priority:events_emitter.EventPriority.LOW
}
events_emitter.on(valueChangeEvent,this.valueChangeCallBack)
}
private valueChangeCallBack=(eventData)=>{
console.info("web page valueChangeCallBack");
if(eventData != null){
console.info("valueChangeCallBack:"+ JSON.stringify(eventData));
if(eventData.data.ACTION != null){
this.str = eventData.data.ACTION;
}
}
}
build(){
Column(){
Row() {
Button("web test").key('webcomponent02').onClick( () => {
console.info("key==>" + this.str)
switch (this.str) {
case "emitStoreWebArchiveCallback": {
try {
console.info("testoooooooooooooooooooooooooooooooooooo");
this.controller.storeWebArchive("/data/storage/el2/base/", true, (error, filename) => {
if (error) {
console.info(`save web archive error: ` + JSON.stringify(error))
return;
}
if (filename != null) {
console.info(`save web archive success: ${filename}`)
this.webFilename = filename
Utils.emitEvent(this.webFilename, 130)
}
});
}catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
case "emitStoreWebArchiveCallbackFalse": {
try {
console.info("testAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
this.controller.storeWebArchive("/data/storage/el2/base/index.html.mht", false, (error, filename) => {
if (error) {
console.info(`save web archive error: ` + JSON.stringify(error))
return;
}
if (filename != null) {
console.info(`save web archive success: ${filename}`)
this.webFilename = filename
Utils.emitEvent(this.webFilename, 132)
}
});
}catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
case "emitStoreWebArchivePromise": {
try {
console.info("testBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB");
this.controller.storeWebArchive("/data/storage/el2/base/", true)
.then(filename => {
if (filename != null) {
this.webFilename = filename
Utils.emitEvent(this.webFilename, 134)
console.info(`save web archive success: ${filename}`)
}
})
.catch(error => {
console.log('error: ' + JSON.stringify(error));
})
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
case "emitStoreWebArchivePromiseFlase": {
try {
console.info("testCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC");
this.controller.storeWebArchive("/data/storage/el2/base/index.html-2.mht", false)
.then(filename => {
if (filename != null) {
this.webFilename = filename
Utils.emitEvent(this.webFilename, 136)
console.info(`save web archive success: ${filename}`)
}
})
.catch(error => {
console.log('error: ' + JSON.stringify(error));
})
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
}
})
}
Web({src:$rawfile('index.html'),controller:this.controller})
.javaScriptAccess(this.javaScriptAccess)
.fileAccess(this.fileAccess)
.imageAccess(this.imageAccess)
.domStorageAccess(this.domStorageAccess)
.onlineImageAccess(this.onlineImageAccess)
.databaseAccess(this.databaseAccess)
.userAgent(this.userAgent)
}
}
}
/**
* 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 { Hypium } from '@ohos/hypium';
import testsuite from '../../test/List.test';
import Utils from '../../test/Utils';
import web_webview from '@ohos.web.webview';
let loadedUrl;
@Entry
@Component
struct Index {
controller: web_webview.WebviewController = new web_webview.WebviewController();
@State str:string="emitStoreWebArchiveCallbackSaveFail";
@State webId:number=0;
@State webResult:string=' ';
@State proResult:string=' ';
@State webFilename:string=' ';
@State errorResult:string=' ';
@State userAgent: string = "Mozilla/5.0 (Window NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) CHrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.27";
@State pageResult:boolean=false;
@State javaScriptAccess:boolean=true;
@State fileAccess:boolean=true;
@State domStorageAccess:boolean=false
@State imageAccess:boolean=true
@State onlineImageAccess:boolean=true
@State databaseAccess:boolean=true
onPageShow(){
let valueChangeEvent={
eventId:10,
priority:events_emitter.EventPriority.LOW
}
events_emitter.on(valueChangeEvent,this.valueChangeCallBack)
}
private valueChangeCallBack=(eventData)=>{
console.info("web page valueChangeCallBack");
if(eventData != null){
console.info("valueChangeCallBack:"+ JSON.stringify(eventData));
if(eventData.data.ACTION != null){
this.str = eventData.data.ACTION;
}
}
}
build(){
Column(){
Row() {
Button("web test").key('webcomponent03').onClick(async () => {
console.info("key==>" + this.str)
switch (this.str) {
case "emitStoreWebArchiveCallbackSaveFail": {
try {
this.controller.loadUrl($rawfile('blanknull.html'))
this.controller.storeWebArchive("/data/storage/el2/base/", true, (error, filename) => {
if (error) {
console.info(`save web archive error: ` + JSON.stringify(error))
return;
}
if (filename != null) {
console.info(`save web archive success: ${filename}`)
this.webFilename = filename
Utils.emitEvent(this.webFilename, 138)
}
});
}catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
case "emitStoreWebArchivePromiseSaveFail": {
try {
this.controller.loadUrl($rawfile('blanknull.html'))
this.controller.storeWebArchive("/data/storage/el2/base/", true)
.then(filename => {
if (filename != null) {
this.webFilename = filename
Utils.emitEvent(this.webFilename, 140)
console.info(`save web archive success: ${filename}`)
}
})
.catch(error => {
console.log('error: ' + JSON.stringify(error));
})
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
}
})
}
Web({src:$rawfile('blanknull.html'),controller:this.controller})
.javaScriptAccess(this.javaScriptAccess)
.fileAccess(this.fileAccess)
.imageAccess(this.imageAccess)
.domStorageAccess(this.domStorageAccess)
.onlineImageAccess(this.onlineImageAccess)
.databaseAccess(this.databaseAccess)
.userAgent(this.userAgent)
}
}
}
/**
* 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, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
import events_emitter from '@ohos.events.emitter';
import Utils from './Utils.ets';
import router from '@system.router';
let emitKey = "emitRunJsCallback";
export default function runJavaScript() {
describe('ActsAceWebControllerTest', function () {
beforeAll(async function (done) {
let options = {
uri: "MainAbility/pages/runJavaScript"
}
try {
router.clear();
let pages = router.getState();
console.info("get runJavaScript state success " + JSON.stringify(pages));
if (!("runJavaScript" == pages.name)) {
console.info("get runJavaScript state success " + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push runJavaScript page success " + JSON.stringify(result));
}
} catch (err) {
console.error("push runJavaScript page error: " + err);
}
await Utils.sleep(2000);
done()
})
beforeEach(async function (done) {
console.info("web beforeEach start");
done();
})
afterEach(async function (done) {
console.info("ActsAceWebControllerTest 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);
console.info("ActsAceWebControllerTest afterEach end");
done();
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_001
*tc.name RunJsCallback
*tc.desic test RunJavascrit interface when choose callback mode.
*/
it('RunJsCallback',0,async function(done){
emitKey="emitRunJsPromise";
Utils.registerEvent("testRunJsCallback",'testRunJavaScript',126,done);
sendEventByKey('webcomponent01',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_002
*tc.name RunJsPromise
*tc.desic test RunJavascrit interface when choose promise mode.
*/
it('RunJsPromise',0,async function(done){
Utils.registerEvent("testRunJsPromise",'\"testRunJavaScript\"',128,done);
sendEventByKey('webcomponent01',10,'');
})
})
}
/**
* 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, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
import events_emitter from '@ohos.events.emitter';
import Utils from './Utils.ets';
import router from '@system.router';
let emitKey = "emitStoreWebArchiveCallback";
export default function storeWebArchive() {
describe('ActsAceWebControllerTest', function () {
beforeAll(async function (done) {
let options = {
uri: "MainAbility/pages/storeWebArchive"
}
try {
router.clear();
let pages = router.getState();
console.info("get storeWebArchive state success " + JSON.stringify(pages));
if (!("storeWebArchive" == pages.name)) {
console.info("get storeWebArchive state success " + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push storeWebArchive page success " + JSON.stringify(result));
}
} catch (err) {
console.error("push storeWebArchive page error: " + err);
}
await Utils.sleep(2000);
done()
})
beforeEach(async function (done) {
console.info("web beforeEach start");
done();
})
afterEach(async function (done) {
console.info("ActsAceWebControllerTest 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);
console.info("ActsAceWebViewOnWindowNewJsunitTest afterEach end");
done();
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_003
*tc.name testStoreWebArchiveCallback
*tc.desic test storeWebArchive interface when choose Callback mode and autoName parameter is ture.
*/
it('testStoreWebArchiveCallback',0,async function(done){
emitKey="emitStoreWebArchiveCallbackFalse";
Utils.registerEvent("testStoreWebArchiveCallback","/data/storage/el2/base/index.html.mht",130,done);
sendEventByKey('webcomponent02',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_004
*tc.name testStoreWebArchiveCallbackFalse
*tc.desic test storeWebArchive interface when choose Callback mode and autoName parameter is false.
*/
it('testStoreWebArchiveCallbackFalse',0,async function(done){
emitKey="emitStoreWebArchivePromise";
Utils.registerEvent("testStoreWebArchiveCallbackFalse","/data/storage/el2/base/index.html.mht",132,done);
sendEventByKey('webcomponent02',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_005
*tc.name testStoreWebArchivePromise
*tc.desic test storeWebArchive interface when choose Promise mode and autoName parameter is ture.
*/
it('testStoreWebArchivePromise',0,async function(done){
emitKey="emitStoreWebArchivePromiseFlase";
Utils.registerEvent("testStoreWebArchivePromise","/data/storage/el2/base/index.html-0.mht",134,done);
sendEventByKey('webcomponent02',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_006
*tc.name testStoreWebArchivePromiseFalse
*tc.desic test storeWebArchive interface when choose Promise mode and autoName parameter is false.
*/
it('testStoreWebArchivePromiseFalse',0,async function(done){
Utils.registerEvent("testStoreWebArchivePromiseFalse","/data/storage/el2/base/index.html-2.mht",136,done);
sendEventByKey('webcomponent02',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, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
import events_emitter from '@ohos.events.emitter';
import Utils from './Utils.ets';
import router from '@system.router';
let emitKey = "emitStoreWebArchiveCallbackSaveFail";
export default function storeWebArchiveSaveFail() {
describe('ActsAceWebControllerTest', function () {
beforeAll(async function (done) {
let options = {
uri: "MainAbility/pages/storeWebArchiveSaveFail"
}
try {
router.clear();
let pages = router.getState();
console.info("get storeWebArchiveSaveFail state success " + JSON.stringify(pages));
if (!("storeWebArchiveSaveFail" == pages.name)) {
console.info("get storeWebArchiveSaveFail state success " + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push storeWebArchiveSaveFail page success " + JSON.stringify(result));
}
} catch (err) {
console.error("push storeWebArchiveSaveFail page error: " + err);
}
await Utils.sleep(2000);
done()
})
beforeEach(async function (done) {
console.info("web beforeEach start");
done();
})
afterEach(async function (done) {
console.info("ActsAceWebControllerTest 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);
console.info("ActsAceWebControllerTest afterEach end");
done();
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_007
*tc.name testStoreWebArchiveCallback
*tc.desic test storeWebArchiveCallback interface when save file failed.
*/
it('testStoreWebArchiveCallback',0,async function(done){
emitKey="emitStoreWebArchivePromiseSaveFail";
Utils.registerEvent("testStoreWebArchiveCallback","/data/storage/el2/base/blanknull.html.mht",138,done);
sendEventByKey('webcomponent03',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_008
*tc.name testStoreWebArchivePromise
*tc.desic test storeWebArchivePromise interface when save file failed.
*/
it('testStoreWebArchivePromise',0,async function(done){
Utils.registerEvent("testStoreWebArchivePromise","/data/storage/el2/base/blanknull.html-0.mht",140,done);
sendEventByKey('webcomponent03',10,'');
})
})
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册