1bc03f14fSopenharmony_ci/* 2bc03f14fSopenharmony_ci * Copyright (C) 2022-2023 Huawei Device Co., Ltd. 3bc03f14fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the 'License'); 4bc03f14fSopenharmony_ci * you may not use this file except in compliance with the License. 5bc03f14fSopenharmony_ci * You may obtain a copy of the License at 6bc03f14fSopenharmony_ci * 7bc03f14fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8bc03f14fSopenharmony_ci * 9bc03f14fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10bc03f14fSopenharmony_ci * distributed under the License is distributed on an 'AS IS' BASIS, 11bc03f14fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12bc03f14fSopenharmony_ci * See the License for the specific language governing permissions and 13bc03f14fSopenharmony_ci * limitations under the License. 14bc03f14fSopenharmony_ci */ 15bc03f14fSopenharmony_ci// @ts-nocheck 16bc03f14fSopenharmony_ciimport {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' 17bc03f14fSopenharmony_ciimport pasteboard from '@ohos.pasteboard' 18bc03f14fSopenharmony_ciimport image from '@ohos.multimedia.image' 19bc03f14fSopenharmony_ci 20bc03f14fSopenharmony_cidescribe('PasteBoardPerfJSTest', function () { 21bc03f14fSopenharmony_ci beforeAll(async function () { 22bc03f14fSopenharmony_ci console.info('beforeAll'); 23bc03f14fSopenharmony_ci }) 24bc03f14fSopenharmony_ci 25bc03f14fSopenharmony_ci afterAll(async function () { 26bc03f14fSopenharmony_ci console.info('afterAll'); 27bc03f14fSopenharmony_ci }) 28bc03f14fSopenharmony_ci 29bc03f14fSopenharmony_ci const BASE_CONUT = 100; 30bc03f14fSopenharmony_ci const htmlText = '<html><head></head><body>Hello!</body></html>'; 31bc03f14fSopenharmony_ci 32bc03f14fSopenharmony_ci 33bc03f14fSopenharmony_ci /** 34bc03f14fSopenharmony_ci * @tc.name clearData_Promise_performance_test_001 35bc03f14fSopenharmony_ci * @tc.desc clearData interface promise performance test 36bc03f14fSopenharmony_ci * @tc.type PERF 37bc03f14fSopenharmony_ci * @tc.require I5YP4X 38bc03f14fSopenharmony_ci */ 39bc03f14fSopenharmony_ci it('clearData_Promise_performance_test_001', 0, async function (done) { 40bc03f14fSopenharmony_ci let systemPasteboard = pasteboard.getSystemPasteboard(); 41bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 42bc03f14fSopenharmony_ci clearDataPromisePerfTest(0); 43bc03f14fSopenharmony_ci 44bc03f14fSopenharmony_ci function clearDataPromisePerfTest(index) { 45bc03f14fSopenharmony_ci systemPasteboard.clearData().then(() => { 46bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 47bc03f14fSopenharmony_ci clearDataPromisePerfTest(index + 1); 48bc03f14fSopenharmony_ci } else { 49bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, "clearData_Promise_performance_test_001 averageTime:"); 50bc03f14fSopenharmony_ci done(); 51bc03f14fSopenharmony_ci } 52bc03f14fSopenharmony_ci }); 53bc03f14fSopenharmony_ci } 54bc03f14fSopenharmony_ci }) 55bc03f14fSopenharmony_ci 56bc03f14fSopenharmony_ci /** 57bc03f14fSopenharmony_ci * @tc.name clear_Promise_performance_test_001 58bc03f14fSopenharmony_ci * @tc.desc clear interface promise performance test 59bc03f14fSopenharmony_ci * @tc.type PERF 60bc03f14fSopenharmony_ci * @tc.require I5YP4X 61bc03f14fSopenharmony_ci */ 62bc03f14fSopenharmony_ci it('clear_Promise_performance_test_001', 0, async function (done) { 63bc03f14fSopenharmony_ci let systemPasteboard = pasteboard.getSystemPasteboard(); 64bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 65bc03f14fSopenharmony_ci clearPromisePerfTest(0); 66bc03f14fSopenharmony_ci 67bc03f14fSopenharmony_ci function clearPromisePerfTest(index) { 68bc03f14fSopenharmony_ci systemPasteboard.clearData().then(() => { 69bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 70bc03f14fSopenharmony_ci clearPromisePerfTest(index + 1); 71bc03f14fSopenharmony_ci } else { 72bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, "clear_Promise_performance_test_001 averageTime:"); 73bc03f14fSopenharmony_ci done(); 74bc03f14fSopenharmony_ci } 75bc03f14fSopenharmony_ci }); 76bc03f14fSopenharmony_ci } 77bc03f14fSopenharmony_ci }) 78bc03f14fSopenharmony_ci 79bc03f14fSopenharmony_ci /** 80bc03f14fSopenharmony_ci * @tc.name setData_Promise_performance_test_001 81bc03f14fSopenharmony_ci * @tc.desc setData interface promise performance test 82bc03f14fSopenharmony_ci * @tc.type PERF 83bc03f14fSopenharmony_ci * @tc.require I5YP4X 84bc03f14fSopenharmony_ci */ 85bc03f14fSopenharmony_ci it('setData_Promise_performance_test_001', 0, async function (done) { 86bc03f14fSopenharmony_ci let systemPasteboard = pasteboard.getSystemPasteboard(); 87bc03f14fSopenharmony_ci let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_HTML, htmlText); 88bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 89bc03f14fSopenharmony_ci setDataPromisePerfTest(0); 90bc03f14fSopenharmony_ci 91bc03f14fSopenharmony_ci function setDataPromisePerfTest(index) { 92bc03f14fSopenharmony_ci systemPasteboard.setData(pasteData).then(() => { 93bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 94bc03f14fSopenharmony_ci setDataPromisePerfTest(index + 1); 95bc03f14fSopenharmony_ci } else { 96bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, "setData_Promise_performance_test_001 averageTime:"); 97bc03f14fSopenharmony_ci done(); 98bc03f14fSopenharmony_ci } 99bc03f14fSopenharmony_ci }); 100bc03f14fSopenharmony_ci } 101bc03f14fSopenharmony_ci }) 102bc03f14fSopenharmony_ci 103bc03f14fSopenharmony_ci /** 104bc03f14fSopenharmony_ci * @tc.name setPasteData_Promise_performance_test_001 105bc03f14fSopenharmony_ci * @tc.desc setPasteData interface promise performance test 106bc03f14fSopenharmony_ci * @tc.type PERF 107bc03f14fSopenharmony_ci * @tc.require I5YP4X 108bc03f14fSopenharmony_ci */ 109bc03f14fSopenharmony_ci it('setPasteData_Promise_performance_test_001', 0, async function (done) { 110bc03f14fSopenharmony_ci let systemPasteboard = pasteboard.getSystemPasteboard(); 111bc03f14fSopenharmony_ci let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_HTML, htmlText); 112bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 113bc03f14fSopenharmony_ci setPasteDataPromisePerfTest(0); 114bc03f14fSopenharmony_ci 115bc03f14fSopenharmony_ci function setPasteDataPromisePerfTest(index) { 116bc03f14fSopenharmony_ci systemPasteboard.setPasteData(pasteData).then(() => { 117bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 118bc03f14fSopenharmony_ci setPasteDataPromisePerfTest(index + 1); 119bc03f14fSopenharmony_ci } else { 120bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, "setPasteData_Promise_performance_test_001 averageTime:"); 121bc03f14fSopenharmony_ci done(); 122bc03f14fSopenharmony_ci } 123bc03f14fSopenharmony_ci }); 124bc03f14fSopenharmony_ci } 125bc03f14fSopenharmony_ci }) 126bc03f14fSopenharmony_ci 127bc03f14fSopenharmony_ci /** 128bc03f14fSopenharmony_ci * @tc.name hasData_Promise_performance_test_001 129bc03f14fSopenharmony_ci * @tc.desc hasData interface promise performance test 130bc03f14fSopenharmony_ci * @tc.type PERF 131bc03f14fSopenharmony_ci * @tc.require I5YP4X 132bc03f14fSopenharmony_ci */ 133bc03f14fSopenharmony_ci it('hasData_Promise_performance_test_001', 0, async function (done) { 134bc03f14fSopenharmony_ci let systemPasteboard = pasteboard.getSystemPasteboard(); 135bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 136bc03f14fSopenharmony_ci hasDataPromisePerfTest(0); 137bc03f14fSopenharmony_ci 138bc03f14fSopenharmony_ci function hasDataPromisePerfTest(index) { 139bc03f14fSopenharmony_ci systemPasteboard.hasData().then(() => { 140bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 141bc03f14fSopenharmony_ci hasDataPromisePerfTest(index + 1); 142bc03f14fSopenharmony_ci } else { 143bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, "hasData_Promise_performance_test_001 averageTime:"); 144bc03f14fSopenharmony_ci done(); 145bc03f14fSopenharmony_ci } 146bc03f14fSopenharmony_ci }); 147bc03f14fSopenharmony_ci } 148bc03f14fSopenharmony_ci }) 149bc03f14fSopenharmony_ci 150bc03f14fSopenharmony_ci /** 151bc03f14fSopenharmony_ci * @tc.name hasPasteData_Promise_performance_test_001 152bc03f14fSopenharmony_ci * @tc.desc hasPasteData interface promise performance test 153bc03f14fSopenharmony_ci * @tc.type PERF 154bc03f14fSopenharmony_ci * @tc.require I5YP4X 155bc03f14fSopenharmony_ci */ 156bc03f14fSopenharmony_ci it('hasPasteData_Promise_performance_test_001', 0, async function (done) { 157bc03f14fSopenharmony_ci let systemPasteboard = pasteboard.getSystemPasteboard(); 158bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 159bc03f14fSopenharmony_ci hasPasteDataPromisePerfTest(0); 160bc03f14fSopenharmony_ci 161bc03f14fSopenharmony_ci function hasPasteDataPromisePerfTest(index) { 162bc03f14fSopenharmony_ci systemPasteboard.hasPasteData().then(() => { 163bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 164bc03f14fSopenharmony_ci hasPasteDataPromisePerfTest(index + 1); 165bc03f14fSopenharmony_ci } else { 166bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, "hasPasteData_Promise_performance_test_001 averageTime:"); 167bc03f14fSopenharmony_ci done(); 168bc03f14fSopenharmony_ci } 169bc03f14fSopenharmony_ci }); 170bc03f14fSopenharmony_ci } 171bc03f14fSopenharmony_ci }) 172bc03f14fSopenharmony_ci 173bc03f14fSopenharmony_ci /** 174bc03f14fSopenharmony_ci * @tc.name getData_Promise_performance_test_001 175bc03f14fSopenharmony_ci * @tc.desc getData interface promise performance test 176bc03f14fSopenharmony_ci * @tc.type PERF 177bc03f14fSopenharmony_ci * @tc.require I5YP4X 178bc03f14fSopenharmony_ci */ 179bc03f14fSopenharmony_ci it('getData_Promise_performance_test_001', 0, async function (done) { 180bc03f14fSopenharmony_ci let systemPasteboard = pasteboard.getSystemPasteboard(); 181bc03f14fSopenharmony_ci let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_HTML, htmlText); 182bc03f14fSopenharmony_ci await systemPasteboard.clearData(); 183bc03f14fSopenharmony_ci await systemPasteboard.setData(pasteData); 184bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 185bc03f14fSopenharmony_ci getDataPromisePerfTest(0); 186bc03f14fSopenharmony_ci 187bc03f14fSopenharmony_ci function getDataPromisePerfTest(index) { 188bc03f14fSopenharmony_ci systemPasteboard.getData().then(() => { 189bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 190bc03f14fSopenharmony_ci getDataPromisePerfTest(index + 1); 191bc03f14fSopenharmony_ci } else { 192bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, "getData_Promise_performance_test_001 averageTime:"); 193bc03f14fSopenharmony_ci done(); 194bc03f14fSopenharmony_ci } 195bc03f14fSopenharmony_ci }); 196bc03f14fSopenharmony_ci } 197bc03f14fSopenharmony_ci }) 198bc03f14fSopenharmony_ci 199bc03f14fSopenharmony_ci /** 200bc03f14fSopenharmony_ci * @tc.name getPasteData_Promise_performance_test_001 201bc03f14fSopenharmony_ci * @tc.desc getPasteData interface promise performance test 202bc03f14fSopenharmony_ci * @tc.type PERF 203bc03f14fSopenharmony_ci * @tc.require I5YP4X 204bc03f14fSopenharmony_ci */ 205bc03f14fSopenharmony_ci it('getPasteData_Promise_performance_test_001', 0, async function (done) { 206bc03f14fSopenharmony_ci let systemPasteboard = pasteboard.getSystemPasteboard(); 207bc03f14fSopenharmony_ci let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_HTML, htmlText); 208bc03f14fSopenharmony_ci await systemPasteboard.clearData(); 209bc03f14fSopenharmony_ci await systemPasteboard.setData(pasteData); 210bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 211bc03f14fSopenharmony_ci getPasteDataPromisePerfTest(0); 212bc03f14fSopenharmony_ci 213bc03f14fSopenharmony_ci function getPasteDataPromisePerfTest(index) { 214bc03f14fSopenharmony_ci systemPasteboard.getData().then(() => { 215bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 216bc03f14fSopenharmony_ci getPasteDataPromisePerfTest(index + 1); 217bc03f14fSopenharmony_ci } else { 218bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, "getPasteData_Promise_performance_test_001 averageTime:"); 219bc03f14fSopenharmony_ci done(); 220bc03f14fSopenharmony_ci } 221bc03f14fSopenharmony_ci }); 222bc03f14fSopenharmony_ci } 223bc03f14fSopenharmony_ci }) 224bc03f14fSopenharmony_ci 225bc03f14fSopenharmony_ci /** 226bc03f14fSopenharmony_ci * @tc.name convertToText_Promise_performance_test_001 227bc03f14fSopenharmony_ci * @tc.desc convertToText interface promise performance test 228bc03f14fSopenharmony_ci * @tc.type PERF 229bc03f14fSopenharmony_ci * @tc.require I5YP4X 230bc03f14fSopenharmony_ci */ 231bc03f14fSopenharmony_ci it('convertToText_Promise_performance_test_001', 0, async function (done) { 232bc03f14fSopenharmony_ci let pasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_HTML, htmlText); 233bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 234bc03f14fSopenharmony_ci convertToTextPromisePerfTest(0); 235bc03f14fSopenharmony_ci 236bc03f14fSopenharmony_ci function convertToTextPromisePerfTest(index) { 237bc03f14fSopenharmony_ci pasteDataRecord.convertToText().then(() => { 238bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 239bc03f14fSopenharmony_ci convertToTextPromisePerfTest(index + 1); 240bc03f14fSopenharmony_ci } else { 241bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, "convertToText_Promise_performance_test_001 averageTime:"); 242bc03f14fSopenharmony_ci done(); 243bc03f14fSopenharmony_ci } 244bc03f14fSopenharmony_ci }); 245bc03f14fSopenharmony_ci } 246bc03f14fSopenharmony_ci }) 247bc03f14fSopenharmony_ci 248bc03f14fSopenharmony_ci /** 249bc03f14fSopenharmony_ci * @tc.name convertToTextV9_Promise_performance_test_001 250bc03f14fSopenharmony_ci * @tc.desc convertToTextV9 interface promise performance test 251bc03f14fSopenharmony_ci * @tc.type PERF 252bc03f14fSopenharmony_ci * @tc.require I5YP4X 253bc03f14fSopenharmony_ci */ 254bc03f14fSopenharmony_ci it('convertToTextV9_Promise_performance_test_001', 0, async function (done) { 255bc03f14fSopenharmony_ci let pasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_HTML, htmlText); 256bc03f14fSopenharmony_ci let startTime = new Date().getTime(); 257bc03f14fSopenharmony_ci convertToTextV9PromisePerfTest(0); 258bc03f14fSopenharmony_ci 259bc03f14fSopenharmony_ci function convertToTextV9PromisePerfTest(index) { 260bc03f14fSopenharmony_ci pasteDataRecord.convertToTextV9().then(() => { 261bc03f14fSopenharmony_ci if (index < BASE_CONUT) { 262bc03f14fSopenharmony_ci convertToTextV9PromisePerfTest(index + 1); 263bc03f14fSopenharmony_ci } else { 264bc03f14fSopenharmony_ci computeAverageTime(startTime, BASE_CONUT, "convertToTextV9_Promise_performance_test_001 averageTime:"); 265bc03f14fSopenharmony_ci done(); 266bc03f14fSopenharmony_ci } 267bc03f14fSopenharmony_ci }); 268bc03f14fSopenharmony_ci } 269bc03f14fSopenharmony_ci }) 270bc03f14fSopenharmony_ci 271bc03f14fSopenharmony_ci function computeAverageTime(startTime, baseCount, message) { 272bc03f14fSopenharmony_ci let endTime = new Date().getTime(); 273bc03f14fSopenharmony_ci let averageTime = ((endTime - startTime) * 1000) / baseCount; 274bc03f14fSopenharmony_ci console.info(message + averageTime); 275bc03f14fSopenharmony_ci } 276bc03f14fSopenharmony_ci 277bc03f14fSopenharmony_ci}); 278