From 3d10c634cca73d150346102ed8a4cc9f27d0f0d8 Mon Sep 17 00:00:00 2001 From: zhijianwen Date: Mon, 25 Jul 2022 12:03:38 +0800 Subject: [PATCH] add+ Signed-off-by: zhijianwen --- .../emittertest/entry/src/main/config.json | 49 +-- .../entry/src/main/js/test/EmitterTest.js | 394 ++++++++++++++---- .../emittertest/signature/openharmony_sx.p7b | Bin 3437 -> 3441 bytes 3 files changed, 324 insertions(+), 119 deletions(-) diff --git a/notification/ces_standard/subscribeandpublish/emittertest/entry/src/main/config.json b/notification/ces_standard/subscribeandpublish/emittertest/entry/src/main/config.json index 2800c3cc4..d32d2ffff 100644 --- a/notification/ces_standard/subscribeandpublish/emittertest/entry/src/main/config.json +++ b/notification/ces_standard/subscribeandpublish/emittertest/entry/src/main/config.json @@ -24,53 +24,10 @@ "moduleName": "entry", "moduleType": "entry" }, - "defPermissions": [ + "reqPermissions": [ { - "availableScope": [], - "grantMode": "system_grant", - "name": "publish_event0800_permission" - }, - { - "availableScope": [], - "grantMode": "system_grant", - "name": "publish_event0900_subscriberPermissions" - }, - { - "availableScope": [], - "grantMode": "system_grant", - "name": "publish_event0900_publisherPermission" - }, - { - "availableScope": [], - "grantMode": "system_grant", - "name": "publish_event1000_permission" - }, - { - "availableScope": [], - "grantMode": "system_grant", - "name": "permission.COMMONEVENT_STICKY" - } - ], - "reqPermissions": [ - { - "name": "publish_event0800_permission", - "reason": "ceshi" - }, - { - "name": "publish_event0900_subscriberPermissions", - "reason": "ceshi" - }, - { - "name": "publish_event0900_publisherPermission", - "reason": "ceshi" - }, - { - "name": "publish_event1000_permission", - "reason": "ceshi" - }, - { - "name": "permission.COMMONEVENT_STICKY", - "reason": "ceshi" + "name": "ohos.permission.NOTIFICATION_CONTROLLER", + "reason": "use ohos.permission.NOTIFICATION_CONTROLLER" } ], "abilities": [ diff --git a/notification/ces_standard/subscribeandpublish/emittertest/entry/src/main/js/test/EmitterTest.js b/notification/ces_standard/subscribeandpublish/emittertest/entry/src/main/js/test/EmitterTest.js index 91c267147..f44e25577 100644 --- a/notification/ces_standard/subscribeandpublish/emittertest/entry/src/main/js/test/EmitterTest.js +++ b/notification/ces_standard/subscribeandpublish/emittertest/entry/src/main/js/test/EmitterTest.js @@ -12,98 +12,346 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import emitter from '@ohos.events.emitter' -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +import events_emitter from '@ohos.events.emitter'; +import notification from '@ohos.notification'; +import commonEvent from '@ohos.commonEvent'; +import wantAgent from '@ohos.wantAgent'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, Assert } from 'deccjsunit/index'; describe('EmitterTest', function () { - console.info("===========EmitterTest start====================>"); - - var eventData = { - data: { - "id": 1, - "content": "message", + const TAG = 'EmitterTest ===> ' + async function applyPermission() { + let appInfo = await bundle.getApplicationInfo('com.example.emittertest', 0, 100); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission]case accessTokenId is' + tokenID); + let permissionName1 = 'ohos.permission.NOTIFICATION_CONTROLLER'; + + await atManager.grantUserGrantedPermission(tokenID, permissionName1).then((result) => { + console.info('[permission]case grantUserGrantedPermission success:' + result); + }).catch((err) => { + console.info('[permission]case grantUserGrantedPermission failed:' + err); + }); + } else { + console.info('[permission]case apply permission failed,createAtManager failed'); } } - var InnerEventImmediate = { - eventId: 1, - priority: emitter.EventPriority.IMMEDIATE + const bundlel = { + bundle: 'com.example.emittertest' } - var InnerEventLow = { - eventId: 2, - priority: emitter.EventPriority.LOW + let innerEvent = { + eventId: undefined, + priority: undefined } - - function callback(data){ - console.info('callback success'); - expect(data.eventId).assertEqual("message"); + + let eventData = { + data: { + 'id': undefined, + 'content': undefined + } } - function callback01(data){ - console.info('callback success'); - expect(data.data.id).assertEqual(1); - expect(data.data.content).assertEqual("message"); + let wantAgentInfo = { + wants: [ + { + bundleName: 'com.example.emittertest', + abilityName: 'com.example.emittertest.TestAbility' + } + ], + operationType: wantAgent.OperationType.START_ABILITY, + requestCode: 0, + wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG], + extraInfo: { + key_1: 'value_1', + key_2: 'value_2', + } + } + let subscriber = undefined + beforeAll(async function() { + await applyPermission(); + await notification.enableNotification(bundlel, true, (err) => { + if (err.code) { + console.info(TAG + ': enableNotification failed! Err.code ===> ' + JSON.stringify(err.code)) + console.info(TAG + ': enableNotification failed! Err.message ===> ' + JSON.stringify(err.message)) + expect(false).assertTrue() + } else { + console.info(TAG + ': enableNotification successd!') + expect(true).assertTrue() + } + }); + console.info(TAG + 'beforeAll case'); + }) + afterEach(async function() { + await notification.cancelAll((err) => { + if (err.code) { + console.info(TAG + ': cancelAll failed! Err.code ===> ' + err.code) + console.info(TAG + ': cancelAll failed! Err.message ===> ' + err.message) + expect(false).assertTrue() + } else { + console.info(TAG + ': cancelAll successd!') + expect(true).assertTrue() + } + }) + }) + function EmitterCallback(eventData) { + console.info(TAG + 'eventData.id: ' + JSON.stringify(eventData.data.id)); + console.info(TAG + 'eventData.content: ' + JSON.stringify(eventData.data.content)); + if (eventData.data.id == 0) { + expect(eventData.data.content).assertEqual('message_0'); + } else if (eventData.data.id == 1) { + expect(eventData.data.content).assertEqual('message_1'); + } else if (eventData.data.id == 2) { + expect(eventData.data.content).assertEqual('message_2'); + } else if (eventData.data.id == 3) { + expect(eventData.data.content).assertEqual('message_3'); + } else if (eventData.data.id == 4) { + expect(eventData.data.content).assertEqual('message_4'); + } else if (eventData.data.id == 5) { + expect(eventData.data.content).assertEqual('message_5'); + } } - /* - * @tc.number : EmitterOnTest - * @tc.name : verify on : Check subscribe same on common ordered event - * @tc.desc : Check the subscriber can receive event "EmitterOnTest" type of the interface (by Promise) - */ - it('EmitterOnTest', 0, async function (done) { - console.info("===========EmitterOnTest====================>"); - emitter.on(InnerEventImmediate, callback); - done(); + it('EmitterTest_001', 0, async function (done) { + console.info(TAG + 'EmitterTest_001 start.') + innerEvent.eventId = 1 + innerEvent.priority = events_emitter.EventPriority.IDLE + + eventData.data.id = 0 + eventData.data.content = 'message_0' + + events_emitter.on(innerEvent, EmitterCallback) + events_emitter.emit(innerEvent, eventData) + eventData.data.id = 1 + eventData.data.content = 'message_1' + events_emitter.emit(innerEvent, eventData) + console.info(TAG + 'EmitterTest_001 end.') + done() }) - /* - * @tc.number : EmitterOnceTest - * @tc.name : verify once : Check subscribe same once common ordered event - * @tc.desc : Check the subscriber can receive event "EmitterOnceTest" type of the interface (by Promise) - */ - it('EmitterOnceTest', 0, async function (done){ - console.info("===========EmitterOnceTest====================>"); - emitter.once(InnerEventImmediate, callback); - done(); + it('EmitterTest_002', 0, async function (done) { + console.info(TAG + 'EmitterTest_002 start.') + innerEvent.eventId = 2 + innerEvent.priority = events_emitter.EventPriority.LOW + + eventData.data.id = 2 + eventData.data.content = 'message_2' + + events_emitter.once(innerEvent, EmitterCallback) + events_emitter.emit(innerEvent, eventData) + console.info(TAG + 'EmitterTest_002 end.') + done() }) - /* - * @tc.number : EmitterEmitTest - * @tc.name : verify emit : Check subscribe same emit common ordered event - * @tc.desc : Check the subscriber can receive event "EmitterEmitTest" type of the interface (by Promise) - */ - it('EmitterEmitTest', 0, async function (done){ - console.info("===========EmitterEmitTest====================>"); - emitter.once(InnerEventImmediate, callback01); - emitter.emit(InnerEventImmediate, eventData); - done(); + it('EmitterTest_003', 0, async function (done) { + console.info(TAG + 'EmitterTest_003 start.') + innerEvent.eventId = 3 + innerEvent.priority = events_emitter.EventPriority.HIGH + + eventData.data.id = 3 + eventData.data.content = 'message_3' + + events_emitter.once(innerEvent, EmitterCallback) + events_emitter.emit(innerEvent, eventData) + console.info(TAG + 'EmitterTest_003 end.') + done() }) - /* - * @tc.number : EmitterLowTest - * @tc.name : verify low : Check subscribe same low common ordered event - * @tc.desc : Check the subscriber can receive event "EmitterLowTest" type of the interface (by Promise) - */ - it('EmitterLowTest', 0, async function (done){ - console.info("===========EmitterLowTest====================>"); - emitter.once(InnerEventLow, callback01); - emitter.emit(InnerEventLow,eventData); - done(); + it('EmitterTest_004', 0, async function (done) { + console.info(TAG + 'EmitterTest_004 start.') + innerEvent.eventId = 4 + innerEvent.priority = events_emitter.EventPriority.IMMEDIATE + + eventData.data.id = 4 + eventData.data.content = 'message_4' + + events_emitter.once(innerEvent, EmitterCallback) + events_emitter.emit(innerEvent, eventData) + console.info(TAG + 'EmitterTest_004 end.') + done() }) - - /* - * @tc.number : EmitterOffTest - * @tc.name : verify off : Check subscribe same off common ordered event - * @tc.desc : Check the subscriber can receive event "EmitterOffTest" type of the interface (by Promise) - */ - it('EmitterOffTest', 0, async function (done){ - console.info("===========EmitterOffTest111====================>"); - emitter.once(InnerEventLow, callback01); - emitter.emit(InnerEventImmediate, eventData); - emitter.off(1); - done(); + + it('EmitterTest_005', 0, async function (done) { + console.info(TAG + 'EmitterTest_005 start.') + innerEvent.eventId = 5 + innerEvent.priority = events_emitter.EventPriority.IMMEDIATE + + eventData.data.id = 5 + eventData.data.content = 'message_5' + + events_emitter.once(innerEvent, EmitterCallback) + events_emitter.emit(innerEvent, eventData) + events_emitter.off(5) + console.info(TAG + 'EmitterTest_005 end.') + done() + }) + + it('wantAgent_trigger_001', 0, async function (done){ + await wantAgent.getWantAgent(wantAgentInfo, (err, data) => { + if (err.code) { + console.info(TAG + ': getWant failed! Err.code ===> ' + JSON.stringify(err.code)) + console.info(TAG + ': getWant failed! Err.message ===> ' + JSON.stringify(err.message)) + expect(false).assertTrue() + done() + } else { + console.info(TAG + ': getWant successd!') + console.info(TAG + ': wantAgentInfo ===> ' + JSON.stringify(data)) + expect(typeof(data)).assertEqual('object') + + let triggerInfo = { + code: 100, + want: null, + permission: null, + extraInfo: { + triggerInfo_key_1: 'triggerInfo_value_1', + triggerInfo_key_2: 'triggerInfo_value_2', + } + } + wantAgent.trigger(data, triggerInfo, (err, data) => { + console.info(TAG + ': trigger successd! CompleteData ===> ' + JSON.stringify(data)) + console.info(TAG + ': data.want.bundleName ===> ' + JSON.stringify(data.want.abilityName)) + console.info(TAG + ': data.want.abilityName ===> ' + JSON.stringify(data.want.abilityName)) + console.info(TAG + ': data.want.parameters.key_1 ===> ' + JSON.stringify(data.want.parameters.key_1)) + console.info(TAG + ': data.want.parameters.key_2 ===> ' + JSON.stringify(data.want.parameters.key_2)) + expect(data.want.bundleName).assertEqual('com.example.emittertest') + expect(data.want.abilityName).assertEqual('com.example.emittertest.TestAbility') + expect(data.want.parameters.key_1).assertEqual('value_1') + expect(data.want.parameters.key_2).assertEqual('value_2') + done() + }) + } + }) + }) + + + it('notification_publish_001', 0, async function (done){ + await notification.isNotificationEnabled(bundlel, (err, data) => { + if (err.code) { + console.info(TAG + ': isNotificationEnabled failed! Err.code ===> ' + JSON.stringify(err.code)) + console.info(TAG + ': isNotificationEnabled failed! Err.message ===> ' + JSON.stringify(err.message)) + expect(false).assertTrue() + } else { + console.info(TAG + ': isNotificationEnabled successd! Result ===> ' + JSON.stringify(data)) + expect(true).assertTrue() + } + }) + async function SubscribeCallbackData(data) { + console.info(TAG + ': data ===> ' + JSON.stringify(data)) + console.info(TAG + ': data.request.content.normal.title ===> ' + JSON.stringify(data.request.content.normal.title)) + console.info(TAG + ': data.request.content.normal.text ===> ' + JSON.stringify(data.request.content.normal.text)) + console.info(TAG + ': data.request.content.normal.additionalText ===> ' + JSON.stringify(data.request.content.normal.additionalText)) + console.info(TAG + ': data.request.actionButtons[0].title ===> ' + JSON.stringify(data.request.actionButtons[0].title)) + expect(data.request.content.normal.title).assertEqual('title'); + expect(data.request.content.normal.text).assertEqual('text'); + expect(data.request.content.normal.additionalText).assertEqual('additionalText'); + expect(data.request.content.normal.creatorBundleName).assertEqual(bundlel.bundle); + expect(data.request.content.normal.creatorPid != undefined).assertTrue() + expect(data.request.content.normal.creatorUid != undefined).assertTrue() + expect(data.request.actionButtons[0].title).assertEqual('additionalText'); + expect(data.request.actionButtons[0].extras.wantAgentInfo_key_1).assertEqual('wantAgentInfo_key_1') + expect(data.request.actionButtons[0].extras.wantAgentInfo_key_2).assertEqual('wantAgentInfo_key_2') + expect(data.request.actionButtons[0].userInput.inputKey).assertEqual('Please input at this') + expect(true).assertTrue() + + await notification.unsubscribe(NotificationSubscriber, (err) => { + if (err.code) { + console.info(TAG + ': unsubscribe failed! Err.code ===> ' + JSON.stringify(err.code)) + console.info(TAG + ': unsubscribe failed! Err.message ===> ' + JSON.stringify(err.message)) + expect(false).assertTrue() + done() + } else { + console.info(TAG + ': unsubscribe successd!') + expect(true).assertTrue() + } + }) + } + + let NotificationSubscriber = { + onConsume: SubscribeCallbackData + } + + await notification.subscribe(NotificationSubscriber, (err)=>{ + if (err.code) { + console.info(TAG + ': subscribe failed! Err.code ===> ' + JSON.stringify(err.code)) + console.info(TAG + ': subscribe failed! Err.message ===> ' + JSON.stringify(err.message)) + expect(false).assertTrue() + } else { + console.info(TAG + ': subscribe successd!') + expect(true).assertTrue() + done() + } + }) + + let wantAgentInstance = await wantAgent.getWantAgent(wantAgentInfo) + const NotificationRequest = { + content : { + contentType : notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal : { + title : 'title', + text : 'text', + additionalText : 'additionalText' + }, + }, + actionButtons: [ + { + title : 'activeButton_title', + wantAgent : wantAgentInstance, + extras : { + wantAgentInfo_key_1: 'wantAgentInfo_key_1', + wantAgentInfo_key_2: 'wantAgentInfo_key_2', + }, + userInput : { + inputKey : 'Please input at this' + } + } + ], + } + + // 发布通知 + await notification.publish(NotificationRequest, (err) => { + if (err.code) { + console.info(TAG + ': publish failed! Err.code ===> ' + JSON.stringify(err.code)) + console.info(TAG + ': publish failed! Err.message ===> ' + JSON.stringify(err.message)) + expect(false).assertTrue() + } else { + console.info(TAG + ': publish successd!') + expect(true).assertTrue() + } + }) + }) + + + it('commonEvent_subscriberInfo_001', 0, async function (done){ + let CommonEventSubscribeInfo = { + events: ['event'], + publisherPermission: '', + publisherDeviceId: '', + userId: 100, + priority: 1000 + } + + let CommonEventSubscriber = await commonEvent.createSubscriber(CommonEventSubscribeInfo) + if (CommonEventSubscriber == undefined) { + console.info(TAG + ': createSubscriber failed! Err.message ===> ' + JSON.stringify(CommonEventSubscriber)) + expect(false).assertTrue() + } + + await CommonEventSubscriber.getSubscribeInfo((err, CommonEventSubscribeInfo)=>{ + if (err.code) { + console.info(TAG + ': getSubscribeInfo failed! Err.code ===> ' + JSON.stringify(err.code)) + console.info(TAG + ': getSubscribeInfo failed! Err.message ===> ' + JSON.stringify(err.message)) + expect(false).assertTrue() + done() + } else { + console.info(TAG + ': getSubscribeInfo successd! CommonEventSubscribeInfo ===> ' + JSON.stringify(CommonEventSubscribeInfo)) + done() + } + }) + }) }) -}) diff --git a/notification/ces_standard/subscribeandpublish/emittertest/signature/openharmony_sx.p7b b/notification/ces_standard/subscribeandpublish/emittertest/signature/openharmony_sx.p7b index 9be1e98fa4c0c28ca997ed660112fa16b194f0f5..81c590bad50cc64027f1a9d070c3d0e6f10e30cc 100644 GIT binary patch delta 978 zcmZ9L&2QUu9L7oFb#zU)0|Tksq;-*YfwuX@joWyrtUtfRFVu0|Ixmg_t>ZX$632F8 zr*?x-rXW>2u~p&3sYnPRU?;=|65_&X9EK1FH251p0txL3M#= z^!ueTn9TQPW?w#J51-7(&c=@?^KV9|7LUa;^I&dfcJGjl=?Nqr1Cul7{}p4$6XYo} zK~COE?dt=t?byqj)6`QpGE1kxR(lahWmdonNG+v?!*(-zF@UZ&a9m%;TG2WBWZ{B; z;Qr$cbW2w~J$2N1<>=dmYZ#u*tzjsZTT0oEzpS==eGtX3Y(S?2h&$$H(wG)Bncb30RxVJ21lzRnI2KoyRnbPLI)nyZ9(QjQ5M3AsTB%THxxQT zc*;72BS>CAN(xn$B!&)nO774lf#4XJDbb`UY}IXfm9QFJ)6{yI{f6BQ85vdyqfjQG zC(|?@)G8RKRC&LFVi=d-wv-A8U#H->_e>Jxy3K>l&n9xyI$Si5}I2iWk^_w%~*iQ78#SU1f$tTN3ERQ#XVOY(Gr&i z)k5I5{G0?iGGKRx5UuD|xt(_E_6S;ekfZDdKM+MJHK)(P0 delta 997 zcmY+DO^D-U7{@oA&Wy9P3M&k_ml@+haK4g$O**iyZ$2hTXOcE;(~rdxVOG*){#UKcM21zchv`-jFTZqS?#Y@O+ap}KN==LoB zI6jO2^(s8kY^QITTc$kH;5``KMz#@n^8%|@C&K6^ERV-qoxbDReZ_On1UESSZ1r@o zefr?JR4$d?O=WgbY!fyucT4WNnjKlWY&MlcBK+DW>;~hr{kAsLWJiPN31~fO>6X*c zCfd*%YxaB>y1rT@2?8jo9`IQl^jNA|E=giIe-nD|m>*DR%j8Hl%JR^6`F$j>IY@M4xyPP0ynziOAvXxdNu#p_0aj%1GDM5js&! z!>?CC74NA>x-lrW%#y(3c&~TBfvJtNr>9tRwW3xJe-;7fq@tLVm|fn#jT9O=`pZw9%{w3c>u*1Ne+J>?8Gx+&scd4Aa{Y^{z@{8%9|r z16~{+xW$@jry1igY+!|aC+pa1K6I|lZ^ZYKqaeD}VPBQcj`ZVi;?nYE0+~VAqf#Ko zyuGN+ZzYzW{(m{V-m7+(Up}r3dh&|hpX!Q=)LBn*e7>3+Iwq_ zn>WNCKX|D8dHThN-(j!6fm~jCD(c}^*WwGYIE_%Tb-PHukXZZuOE*25yz-9C6O*r{ zzYDjNqrwl5-b%dqa_sp_pJr75+Xe3Xn{e{V+Ov19pMQC`eXm`*^Y-2Q&gZ{AX#DgK D`HxKH -- GitLab