提交 3d10c634 编写于 作者: Z zhijianwen

add+

Signed-off-by: Nzhijianwen <zhijianwen@huawei.com>
上级 422b7f8e
...@@ -24,53 +24,10 @@ ...@@ -24,53 +24,10 @@
"moduleName": "entry", "moduleName": "entry",
"moduleType": "entry" "moduleType": "entry"
}, },
"defPermissions": [ "reqPermissions": [
{ {
"availableScope": [], "name": "ohos.permission.NOTIFICATION_CONTROLLER",
"grantMode": "system_grant", "reason": "use ohos.permission.NOTIFICATION_CONTROLLER"
"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"
} }
], ],
"abilities": [ "abilities": [
......
...@@ -12,98 +12,346 @@ ...@@ -12,98 +12,346 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import emitter from '@ohos.events.emitter' import events_emitter from '@ohos.events.emitter';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' 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 () { describe('EmitterTest', function () {
console.info("===========EmitterTest start====================>"); const TAG = 'EmitterTest ===> '
async function applyPermission() {
var eventData = { let appInfo = await bundle.getApplicationInfo('com.example.emittertest', 0, 100);
data: { let atManager = abilityAccessCtrl.createAtManager();
"id": 1, if (atManager != null) {
"content": "message", 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 = { const bundlel = {
eventId: 1, bundle: 'com.example.emittertest'
priority: emitter.EventPriority.IMMEDIATE
} }
var InnerEventLow = { let innerEvent = {
eventId: 2, eventId: undefined,
priority: emitter.EventPriority.LOW priority: undefined
} }
function callback(data){ let eventData = {
console.info('callback success'); data: {
expect(data.eventId).assertEqual("message"); 'id': undefined,
'content': undefined
}
} }
function callback01(data){ let wantAgentInfo = {
console.info('callback success'); wants: [
expect(data.data.id).assertEqual(1); {
expect(data.data.content).assertEqual("message"); 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');
}
} }
/* it('EmitterTest_001', 0, async function (done) {
* @tc.number : EmitterOnTest console.info(TAG + 'EmitterTest_001 start.')
* @tc.name : verify on : Check subscribe same on common ordered event innerEvent.eventId = 1
* @tc.desc : Check the subscriber can receive event "EmitterOnTest" type of the interface (by Promise) innerEvent.priority = events_emitter.EventPriority.IDLE
*/
it('EmitterOnTest', 0, async function (done) { eventData.data.id = 0
console.info("===========EmitterOnTest====================>"); eventData.data.content = 'message_0'
emitter.on(InnerEventImmediate, callback);
done(); 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()
}) })
/* it('EmitterTest_002', 0, async function (done) {
* @tc.number : EmitterOnceTest console.info(TAG + 'EmitterTest_002 start.')
* @tc.name : verify once : Check subscribe same once common ordered event innerEvent.eventId = 2
* @tc.desc : Check the subscriber can receive event "EmitterOnceTest" type of the interface (by Promise) innerEvent.priority = events_emitter.EventPriority.LOW
*/
it('EmitterOnceTest', 0, async function (done){ eventData.data.id = 2
console.info("===========EmitterOnceTest====================>"); eventData.data.content = 'message_2'
emitter.once(InnerEventImmediate, callback);
done(); events_emitter.once(innerEvent, EmitterCallback)
events_emitter.emit(innerEvent, eventData)
console.info(TAG + 'EmitterTest_002 end.')
done()
}) })
/* it('EmitterTest_003', 0, async function (done) {
* @tc.number : EmitterEmitTest console.info(TAG + 'EmitterTest_003 start.')
* @tc.name : verify emit : Check subscribe same emit common ordered event innerEvent.eventId = 3
* @tc.desc : Check the subscriber can receive event "EmitterEmitTest" type of the interface (by Promise) innerEvent.priority = events_emitter.EventPriority.HIGH
*/
it('EmitterEmitTest', 0, async function (done){ eventData.data.id = 3
console.info("===========EmitterEmitTest====================>"); eventData.data.content = 'message_3'
emitter.once(InnerEventImmediate, callback01);
emitter.emit(InnerEventImmediate, eventData); events_emitter.once(innerEvent, EmitterCallback)
done(); events_emitter.emit(innerEvent, eventData)
console.info(TAG + 'EmitterTest_003 end.')
done()
}) })
/* it('EmitterTest_004', 0, async function (done) {
* @tc.number : EmitterLowTest console.info(TAG + 'EmitterTest_004 start.')
* @tc.name : verify low : Check subscribe same low common ordered event innerEvent.eventId = 4
* @tc.desc : Check the subscriber can receive event "EmitterLowTest" type of the interface (by Promise) innerEvent.priority = events_emitter.EventPriority.IMMEDIATE
*/
it('EmitterLowTest', 0, async function (done){ eventData.data.id = 4
console.info("===========EmitterLowTest====================>"); eventData.data.content = 'message_4'
emitter.once(InnerEventLow, callback01);
emitter.emit(InnerEventLow,eventData); events_emitter.once(innerEvent, EmitterCallback)
done(); events_emitter.emit(innerEvent, eventData)
console.info(TAG + 'EmitterTest_004 end.')
done()
}) })
/* it('EmitterTest_005', 0, async function (done) {
* @tc.number : EmitterOffTest console.info(TAG + 'EmitterTest_005 start.')
* @tc.name : verify off : Check subscribe same off common ordered event innerEvent.eventId = 5
* @tc.desc : Check the subscriber can receive event "EmitterOffTest" type of the interface (by Promise) innerEvent.priority = events_emitter.EventPriority.IMMEDIATE
*/
it('EmitterOffTest', 0, async function (done){ eventData.data.id = 5
console.info("===========EmitterOffTest111====================>"); eventData.data.content = 'message_5'
emitter.once(InnerEventLow, callback01);
emitter.emit(InnerEventImmediate, eventData); events_emitter.once(innerEvent, EmitterCallback)
emitter.off(1); events_emitter.emit(innerEvent, eventData)
done(); 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()
}
})
})
}) })
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册