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

!8967 test:add webstorage testcase

Merge pull request !8967 from 李伟明/webview
......@@ -32,7 +32,7 @@ struct OnWindowNew {
@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 javaScriptAccess:boolean=true;
@State fileAccess:boolean=true;
@State domStorageAccess:boolean=false;
@State domStorageAccess:boolean=true;
@State imageAccess:boolean=true;
@State onlineImageAccess:boolean=true;
@State databaseAccess:boolean=true;
......@@ -153,6 +153,26 @@ struct OnWindowNew {
}
break;
}
case "emitGetOriginsPromiseLoadLocalHtml01": {
let length = -1;
try {
this.controller.loadUrl($rawfile('getOrigins.html'));
web_webview.WebStorage.getOrigins()
.then(origins => {
console.log(`getOrigins call`);
if (origins) {
length = origins.length;
console.log(`length is: ${length}`);
}
console.log(`getOrigins call end`);
Utils.emitEvent(length, 7166);
})
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
Utils.emitEvent(length, 7166);
}
break;
}
}
})
}
......
......@@ -19,6 +19,7 @@ import webViewOnErrorReceive03Jsunit from './WebViewOnErrorReceive03Jsunit.test'
import webViewHasImageJsunit from './webViewHasImageJsunit.test'
import webViewSrollToJsunit from './webViewSrollToJsunit.test'
import webViewSrollByJsunit from './webViewSrollByJsunit.test'
import WebViewWebStorageJsunit from './WebViewWebStorageJsunit.test'
export default function testsuite() {
webViewControllerJsunit()
webViewOnWindowNewJsunit()
......@@ -27,4 +28,5 @@ export default function testsuite() {
webViewHasImageJsunit()
webViewSrollToJsunit()
webViewSrollByJsunit()
WebViewWebStorageJsunit()
}
\ No newline at end of file
......@@ -148,9 +148,21 @@ export default function webViewOnWindowNewJsunit() {
*tc.desc test api blockNetWork set to false by load online website
*/
it('testBlockNetWorkFalse',0,async function(done){
emitKey="emitGetOriginsPromiseLoadLocalHtml01";
let title = "www.weibo.com";
Utils.registerEvent("testBlockNetWorkFalse", title, 7114, done);
sendEventByKey('onWindowNew', 10, '');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_0100
*tc.name testGetOriginsPromiseLoadLocalHtml01
*tc.desc test api GetOrigins promise mode by load loacal html
*/
it('testGetOriginsPromiseLoadLocalHtml01', 0, async function(done){
emitKey = 'emitGetOriginsPromiseLoadLocalHtml01';
let length = 1;
Utils.registerEvent("testGetOriginsPromiseLoadLocalHtml01", length, 7166, done);
sendEventByKey('onWindowNew', 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 } from "@ohos/hypium";
import events_emitter from '@ohos.events.emitter';
import Utils from './Utils.ets';
import router from '@system.router';
let emitKey = 'emitGetOriginsCallbackLoadWebkit';
export default function WebViewWebStorageJsunit() {
describe('actsAceWebViewWebStorageJsunit', function () {
beforeEach(async function (done) {
let options = {
uri: "MainAbility/pages/webStorage"
}
try {
router.clear();
let pages = router.getState();
console.info("get webStorage state success " + JSON.stringify(pages));
if (!("webStorage" == pages.name)) {
console.info("get webStorage state success " + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push webStorage page success " + JSON.stringify(result));
}
} catch (err) {
console.error("push webStorage page error: " + err);
}
await Utils.sleep(2000);
done()
})
afterEach(async function (done) {
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_API_GETORIGINS_0100
*tc.name testGetOriginsCallbackLoadWebkit01
*tc.desc test api getOrigins callback mode by checking the value 0f Origins[0].origin when load website which
* address is 'https://webkit.org/demos/sticky-notes/index.html'
*/
it('testGetOriginsCallbackLoadWebkit01', 0, async function(done){
emitKey = 'emitGetOriginsCallbackLoadWebkit02';
let origin = 'https://webkit.org/';
Utils.registerEvent("testGetOriginsCallbackLoadWebkit01", origin, 7136, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_0200
*tc.name testGetOriginsCallbackLoadWebkit02
*tc.desc test api getOrigins callback mode by checking the value 0f Origins[0].usage when load website which
* address is 'https://webkit.org/demos/sticky-notes/index.html'
*/
it('testGetOriginsCallbackLoadWebkit02', 0, async function(done){
emitKey = 'emitGetOriginsCallbackLoadWebkit03';
let usage = 24576;
Utils.registerEvent("testGetOriginsCallbackLoadWebkit02", usage, 7138, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_0300
*tc.name testGetOriginsCallbackLoadWebkit03
*tc.desc test api getOrigins callback mode by the value 0f checking Origins[0].quote when load website which
* address is 'https://webkit.org/demos/sticky-notes/index.html'
*/
it('testGetOriginsCallbackLoadWebkit03', 0, async function(done){
emitKey = 'emitGetOriginsPromiseLoadWebkit01';
let quota = 4054614016;
Utils.registerEvent("testGetOriginsCallbackLoadWebkit03", quota.toString(), 7140, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_0400
*tc.name testGetOriginsPromiseLoadWebkit01
*tc.desc test api getOrigins promise mode by checking the value 0f Origins[0].origin when load website which address
* is 'https://webkit.org/demos/sticky-notes/index.html'
*/
it('testGetOriginsPromiseLoadWebkit01', 0, async function(done){
emitKey = 'emitGetOriginsPromiseLoadWebkit02';
let origin = 'https://webkit.org/';
Utils.registerEvent("testGetOriginsPromiseLoadWebkit01", origin, 7142, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_0500
*tc.name testGetOriginsPromiseLoadWebkit02
*tc.desc test api getOrigins promise mode by checking the value 0f Origins[0].usage when load website which address
* is 'https://webkit.org/demos/sticky-notes/index.html'
*/
it('testGetOriginsPromiseLoadWebkit02', 0, async function(done){
emitKey = 'emitGetOriginsPromiseLoadWebkit03';
let usage = 24576;
Utils.registerEvent("testGetOriginsPromiseLoadWebkit02", usage, 7144, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_0600
*tc.name testGetOriginsPromiseLoadWebkit03
*tc.desc test api getOrigins promise mode by the value 0f checking Origins[0].quote when load website which address
* is 'https://webkit.org/demos/sticky-notes/index.html'
*/
it('testGetOriginsPromiseLoadWebkit03', 0, async function(done){
emitKey = 'emitGetOriginsCallbackLoadBaidu01';
let quota = 4054614016;
Utils.registerEvent("testGetOriginsPromiseLoadWebkit03", quota.toString(), 7146, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_0700
*tc.name testGetOriginsCallbackLoadBaidu01
*tc.desc test api getOrigins callback mode by checking the length of origins when load website which address
* is 'https://www.baidu.com'
*/
it('testGetOriginsCallbackLoadBaidu01', 0, async function(done){
emitKey = 'emitGetOriginsCallbackLoadBaidu02';
let length = 1;
Utils.registerEvent("testGetOriginsCallbackLoadBaidu01", length, 7148, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_0800
*tc.name testGetOriginsLoadBaidu02
*tc.desc test api getOrigins callback mode by checking the value 0f Origins[0].usage when load website which address
* is 'https://www.baidu.com'
*/
it('testGetOriginsCallbackLoadBaidu02', 0, async function(done){
emitKey = 'emitGetOriginsCallbackLoadBaidu03';
let usage = 24576;
Utils.registerEvent("testGetOriginsCallbackLoadBaidu02", usage, 7150, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_0900
*tc.name testGetOriginsCallbackLoadBaidu03
*tc.desc test api getOrigins callback mode by checking the value 0f Origins[0].quota when load website which address
* is 'https://www.baidu.com'
*/
it('testGetOriginsCallbackLoadBaidu03', 0, async function(done){
emitKey = 'emitGetOriginsPromiseLoadBaidu01';
let quota = 4054614016;
Utils.registerEvent("testGetOriginsCallbackLoadBaidu03", quota.toString(), 7152, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_1000
*tc.name testGetOriginsPromiseLoadBaidu01
*tc.desc test api getOrigins Promise mode by checking the length of origins when load website which address
* is 'https://www.baidu.com'
*/
it('testGetOriginsPromiseLoadBaidu01', 0, async function(done){
emitKey = 'emitGetOriginsPromiseLoadBaidu02';
let length = 1;
Utils.registerEvent("testGetOriginsPromiseLoadBaidu01", length, 7154, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_1100
*tc.name testGetOriginsPromiseLoadBaidu02
*tc.desc test api getOrigins Promise mode by checking the value 0f Origins[0].usage when load website which address
* is 'https://www.baidu.com'
*/
it('testGetOriginsPromiseLoadBaidu02', 0, async function(done){
emitKey = 'emitGetOriginsPromiseLoadBaidu03';
let usage = 24576;
Utils.registerEvent("testGetOriginsPromiseLoadBaidu02", usage, 7156, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_1200
*tc.name testGetOriginsPromiseLoadBaidu03
*tc.desc test api getOrigins Promise mode by checking the value 0f Origins[0].quota when load website which address
* is 'https://www.baidu.com'
*/
it('testGetOriginsPromiseLoadBaidu03', 0, async function(done){
emitKey = 'emitGetOriginsCallbackLoadLocalHtml01';
let quota = 4054614016;
Utils.registerEvent("testGetOriginsPromiseLoadBaidu03", quota.toString(), 7158, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_1300
*tc.name testGetOriginsCallbackLoadLocalHtml01
*tc.desc test api getOrigins callback mode by checking the length of origins when load local html
*/
it('testGetOriginsCallbackLoadLocalHtml01', 0, async function(done){
emitKey = 'emitGetOriginsCallbackLoadLocalHtml02';
let length = 1;
Utils.registerEvent("testGetOriginsCallbackLoadLocalHtml01", length, 7160, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_1400
*tc.name testGetOriginsLoadCallbackLocalHtml02
*tc.desc test api getOrigins callback mode by checking the value 0f Origins[0].usage when load local html
*/
it('testGetOriginsLoadCallbackLocalHtml02', 0, async function(done){
emitKey = 'emitGetOriginsCallbackLoadLocalHtml03';
let usage = 24576;
Utils.registerEvent("testGetOriginsLoadCallbackLocalHtml02", usage, 7162, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_1500
*tc.name testGetOriginsCallbackLoadLocalHtml03
*tc.desc test api getOrigins callback mode by checking the value 0f Origins[0].quota when load local html
*/
it('testGetOriginsCallbackLoadLocalHtml03', 0, async function(done){
emitKey = 'emitGetOriginsPromiseLoadLocalHtml02';
let quota = 4054614016;
Utils.registerEvent("testGetOriginsCallbackLoadLocalHtml03", quota.toString(), 7164, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_1600
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_1700
*tc.name testGetOriginsPromiseLoadLocalHtml02
*tc.desc test api getOrigins callback mode by checking the value 0f Origins[0].usage when load local html
*/
it('testGetOriginsLoadPromiseLocalHtml02', 0, async function(done){
emitKey = 'emitGetOriginsPromiseLoadLocalHtml03';
let usage = 24576;
Utils.registerEvent("testGetOriginsPromiseLoadLocalHtml02", usage, 7168, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_1800
*tc.name testGetOriginsPromiseLoadLocalHtml03
*tc.desc test api getOrigins Promise mode by checking the value 0f Origins[0].quota when load local html
*/
it('testGetOriginsPromiseLoadLocalHtml03', 0, async function(done){
emitKey = 'emitDeleteOrigin';
let quota = 4054614016;
Utils.registerEvent("testGetOriginsPromiseLoadLocalHtml03", quota.toString(), 7170, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_1900
*tc.name testDeleteOrigin
*tc.desc test api deleteOrigin by checking the value 0f getOriginUsage when delete 'resource://rawfile/'
*/
it('testDeleteOrigin', 0, async function(done){
emitKey = 'emitDeleteAllData';
let usage = 0;
Utils.registerEvent("testDeleteOrigin", usage, 7172, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_2000
*tc.name testDeleteAllData
*tc.desc test api deleteAllData by checking the value 0f getOriginUsage when delete 'resource://rawfile/'
*/
it('testDeleteAllData', 0, async function(done){
emitKey = 'emitGetOriginQuotaCallback';
let usage = 0;
Utils.registerEvent("testDeleteAllData", usage, 7174, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_2100
*tc.name testGetOriginQuotaCallback
*tc.desc test api getOriginQuota callbcak mode by load loacal html
*/
it('testGetOriginQuotaCallback', 0, async function(done){
emitKey = 'emitGetOriginQuotaPromise';
let quota = 4054614016;
Utils.registerEvent("testGetOriginQuotaCallback", quota.toString(), 7176, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_2200
*tc.name testGetOriginQuotaPromise
*tc.desc test api getOriginQuota callbcak mode by load loacal html
*/
it('testGetOriginQuotaPromise', 0, async function(done){
emitKey = 'emitGetOriginUsageCallback';
let quota = 4054614016;
Utils.registerEvent("testGetOriginQuotaPromise", quota.toString(), 7178, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_2300
*tc.name testGetOriginUsageCallback
*tc.desc test api getOriginUsage callbcak mode by load loacal html
*/
it('testGetOriginUsageCallback', 0, async function(done){
emitKey = 'emitGetOriginUsagePromise';
let usage = 24576;
Utils.registerEvent("testGetOriginUsageCallback", usage, 7180, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_GETORIGINS_2400
*tc.name testGetOriginUsagePromise
*tc.desc test api getOriginUsage callbcak mode by load loacal html
*/
it('testGetOriginUsagePromise', 0, async function(done){
emitKey = 'emitGetOriginsDomStorageAccessFalse';
let usage = 24576;
Utils.registerEvent("testGetOriginUsagePromise", usage, 7182, done);
sendEventByKey('webStorage',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_0900
*tc.name testGetOriginsDomStorageAccessFalse
*tc.desc test api blockNetWork set to false by load online website
*/
it('testGetOriginsDomStorageAccessFalse',0,async function(done){
let quota = 4054614016;
Utils.registerEvent("testGetOriginsDomStorageAccessFalse", quota.toString(), 7184, done);
sendEventByKey('webStorage', 10, '');
})
})
}
\ No newline at end of file
......@@ -6,6 +6,7 @@
"MainAbility/pages/onErrorReceive03",
"MainAbility/pages/webViewHasImage",
"MainAbility/pages/webViewScrollTo",
"MainAbility/pages/webViewScrollBy"
"MainAbility/pages/webViewScrollBy",
"MainAbility/pages/webStorage"
]
}
\ No newline at end of file
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript">
var db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
var msg;
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)');
tx.executeSql('INSERT INTO LOGS (id, log) VALUES (1, "W3Cschool教程")');
tx.executeSql('INSERT INTO LOGS (id, log) VALUES (2, "www.w3cschool.cn")');
msg = '<p>数据表已创建,且插入了两条数据。</p>';
document.querySelector('#status').innerHTML = msg;
});
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM LOGS', [], function (tx, results) {
var len = results.rows.length, i;
msg = "<p>查询记录条数: " + len + "</p>";
document.querySelector('#status').innerHTML += msg;
for (i = 0; i < len; i++){
msg = "<p><b>" + results.rows.item(i).log + "</b></p>";
document.querySelector('#status').innerHTML += msg;
}
}, null);
});
</script>
</head>
<body>
<div id="status" name="status">状态信息</div>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册