Bug 1189998, Part 3 - Update consolidated Push tests. r=mt

--HG--
extra : commitid : 14SSmeaQP4S
extra : rebase_source : 16e10ef52149e6002d5196595662bef45a00205f
This commit is contained in:
Kit Cambridge 2015-12-08 15:41:57 -05:00
parent 2aac6b9fea
commit a15219cdc8
38 changed files with 540 additions and 144 deletions

View File

@ -1074,7 +1074,7 @@ this.PushService = {
Services.telemetry.getHistogramById("PUSH_API_SUBSCRIBE_FAILED").add()
if (!reply.error) {
console.warn("onRegisterError: Called without valid error message!",
reply.error);
reply);
throw new Error("Registration error");
}
throw reply.error;

View File

@ -17,17 +17,14 @@ Cu.import('resource://gre/modules/ObjectUtils.jsm');
const serviceExports = Cu.import('resource://gre/modules/PushService.jsm', {});
const servicePrefs = new Preferences('dom.push.');
XPCOMUtils.defineLazyServiceGetter(
this,
"PushNotificationService",
"@mozilla.org/push/NotificationService;1",
"nsIPushNotificationService"
);
const DEFAULT_TIMEOUT = 5000;
const WEBSOCKET_CLOSE_GOING_AWAY = 1001;
var isParent = Cc['@mozilla.org/xre/runtime;1']
.getService(Ci.nsIXULRuntime).processType ==
Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
// Stop and clean up after the PushService.
Services.obs.addObserver(function observe(subject, topic, data) {
Services.obs.removeObserver(observe, topic, false);
@ -439,3 +436,114 @@ MockMobileNetworkInfo.prototype = {
return 'network-active-changed';
}
};
var setUpServiceInParent = Task.async(function* (service, db) {
if (!isParent) {
return;
}
let userAgentID = 'ce704e41-cb77-4206-b07b-5bf47114791b';
setPrefs({
userAgentID: userAgentID,
});
yield db.put({
channelID: '6e2814e1-5f84-489e-b542-855cc1311f09',
pushEndpoint: 'https://example.org/push/get',
scope: 'https://example.com/get/ok',
originAttributes: '',
version: 1,
pushCount: 10,
lastPush: 1438360548322,
quota: 16,
});
yield db.put({
channelID: '3a414737-2fd0-44c0-af05-7efc172475fc',
pushEndpoint: 'https://example.org/push/unsub',
scope: 'https://example.com/unsub/ok',
originAttributes: '',
version: 2,
pushCount: 10,
lastPush: 1438360848322,
quota: 4,
});
yield db.put({
channelID: 'ca3054e8-b59b-4ea0-9c23-4a3c518f3161',
pushEndpoint: 'https://example.org/push/stale',
scope: 'https://example.com/unsub/fail',
originAttributes: '',
version: 3,
pushCount: 10,
lastPush: 1438362348322,
quota: 1,
});
service.init({
serverURI: 'wss://push.example.org/',
networkInfo: new MockDesktopNetworkInfo(),
db: makeStub(db, {
put(prev, record) {
if (record.scope == 'https://example.com/sub/fail') {
return Promise.reject('synergies not aligned');
}
return prev.call(this, record);
},
delete: function(prev, channelID) {
if (channelID == 'ca3054e8-b59b-4ea0-9c23-4a3c518f3161') {
return Promise.reject('splines not reticulated');
}
return prev.call(this, channelID);
},
getByIdentifiers(prev, identifiers) {
if (identifiers.scope == 'https://example.com/get/fail') {
return Promise.reject('qualia unsynchronized');
}
return prev.call(this, identifiers);
},
}),
makeWebSocket(uri) {
return new MockWebSocket(uri, {
onHello(request) {
this.serverSendMsg(JSON.stringify({
messageType: 'hello',
uaid: userAgentID,
status: 200,
}));
},
onRegister(request) {
this.serverSendMsg(JSON.stringify({
messageType: 'register',
uaid: userAgentID,
channelID: request.channelID,
status: 200,
pushEndpoint: 'https://example.org/push/' + request.channelID,
}));
},
});
},
});
});
var tearDownServiceInParent = Task.async(function* (db) {
if (!isParent) {
return;
}
let record = yield db.getByIdentifiers({
scope: 'https://example.com/sub/ok',
originAttributes: '',
});
ok(record.pushEndpoint.startsWith('https://example.org/push'),
'Wrong push endpoint in subscription record');
record = yield db.getByIdentifiers({
scope: 'https://example.net/scope/1',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: 1, inBrowser: true }),
});
ok(record.pushEndpoint.startsWith('https://example.org/push'),
'Wrong push endpoint in app record');
record = yield db.getByKeyID('3a414737-2fd0-44c0-af05-7efc172475fc');
ok(!record, 'Unsubscribed record should not exist');
});

View File

@ -42,7 +42,7 @@ add_task(function* test_unregister_success() {
}
});
yield PushNotificationService.clearAll();
yield PushService._clearAll();
let record = yield db.getByKeyID(channelID);
ok(!record, 'Unregister did not remove record');
});

View File

@ -16,10 +16,10 @@ let clearForPattern = Task.async(function* (testRecords, pattern) {
let originSuffix = ChromeUtils.originAttributesToSuffix(
test.originAttributes);
let registration = yield PushNotificationService.registration(
test.scope,
originSuffix
);
let registration = yield PushService.registration({
scope: test.scope,
originAttributes: originSuffix,
});
let url = test.scope + originSuffix;
@ -118,10 +118,11 @@ add_task(function* test_webapps_cleardata() {
});
yield Promise.all(testRecords.map(test =>
PushNotificationService.register(
test.scope,
ChromeUtils.originAttributesToSuffix(test.originAttributes)
)
PushService.register({
scope: test.scope,
originAttributes: ChromeUtils.originAttributesToSuffix(
test.originAttributes),
})
));
// Removes records for all scopes with the same app ID. Excludes records

View File

@ -75,7 +75,8 @@ add_task(function* test_pushNotifications() {
x: '8J3iA1CSPBFqHrUul0At3NkosudTlQDAPO1Dn-HRCxM',
y: '26jk0IFbqcK6-JxhHAm-rsHEwy0CyVJjtnfOcqc1tgA'
},
originAttributes: ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
quota: Infinity,
}, {
subscriptionUri: serverURL + '/pushNotifications/subscription2',
@ -92,7 +93,8 @@ add_task(function* test_pushNotifications() {
x: '-dbJSjvIye4yXIq0RG4t9YTxrT1212MdJbaWkL38GpE',
y: '5TZ1rK8Ldih6ljyxVwnBA-nygQHGRpEmu1jV5K8437E'
},
originAttributes: ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
quota: Infinity,
}, {
subscriptionUri: serverURL + '/pushNotifications/subscription3',
@ -109,7 +111,8 @@ add_task(function* test_pushNotifications() {
x: 'OFQchNJ5WtZjJsWdvvKVVMIMMs91BYyl_yBeFxbC9po',
y: 'Ja6n3YH8TOcH8narDF6t8mKVvg2ioLW-8MH5O4dzGcI'
},
originAttributes: ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
quota: Infinity,
}];

View File

@ -22,13 +22,13 @@ add_task(function* test_expiration_origin_threshold() {
let db = PushServiceWebSocket.newPushDB();
do_register_cleanup(() => {
db.drop().then(_ => db.close())
PushService._notificationForOriginClosed("https://example.com");
PushService.notificationForOriginClosed("https://example.com");
});
// Simulate a notification being shown for the origin,
// this should relax the quota and allow as many push messages
// as we want.
PushService._notificationForOriginShown("https://example.com");
PushService.notificationForOriginShown("https://example.com");
yield db.put({
channelID: 'f56645a9-1f32-4655-92ad-ddc37f6d54fb',
@ -55,7 +55,7 @@ add_task(function* test_expiration_origin_threshold() {
let updates = 0;
let notifyPromise = promiseObserverNotification('push-notification', (subject, data) => {
dump(updates++);
updates++;
return updates == numMessages;
});

View File

@ -55,18 +55,20 @@ add_task(function* test_reconnect_retry() {
}
});
let registration = yield PushNotificationService.register(
'https://example.com/page/1',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })
);
let registration = yield PushService.register({
scope: 'https://example.com/page/1',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
});
let retryEndpoint = 'https://example.org/push/' + channelID;
equal(registration.pushEndpoint, retryEndpoint, 'Wrong endpoint for retried request');
equal(registration.endpoint, retryEndpoint, 'Wrong endpoint for retried request');
registration = yield PushNotificationService.register(
'https://example.com/page/2',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })
);
notEqual(registration.pushEndpoint, retryEndpoint, 'Wrong endpoint for new request')
registration = yield PushService.register({
scope: 'https://example.com/page/2',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
});
notEqual(registration.endpoint, retryEndpoint, 'Wrong endpoint for new request')
equal(registers, 3, 'Wrong registration count');
});

View File

@ -82,15 +82,19 @@ add_task(function* test1() {
db
});
let newRecord = yield PushNotificationService.register(
'https://example.com/retry5xxCode',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })
);
let originAttributes = ChromeUtils.originAttributesToSuffix({
appId: Ci.nsIScriptSecurityManager.NO_APP_ID,
inBrowser: false,
});
let newRecord = yield PushService.register({
scope: 'https://example.com/retry5xxCode',
originAttributes: originAttributes,
});
var subscriptionUri = serverURL + '/subscription';
var pushEndpoint = serverURL + '/pushEndpoint';
var pushReceiptEndpoint = serverURL + '/receiptPushEndpoint';
equal(newRecord.pushEndpoint, pushEndpoint,
equal(newRecord.endpoint, pushEndpoint,
'Wrong push endpoint in registration record');
equal(newRecord.pushReceiptEndpoint, pushReceiptEndpoint,

View File

@ -47,12 +47,15 @@ add_task(function* test_register_case() {
});
let newRecord = yield waitForPromise(
PushNotificationService.register('https://example.net/case',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })),
PushService.register({
scope: 'https://example.net/case',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
}),
DEFAULT_TIMEOUT,
'Mixed-case register response timed out'
);
equal(newRecord.pushEndpoint, 'https://example.com/update/case',
equal(newRecord.endpoint, 'https://example.com/update/case',
'Wrong push endpoint in registration record');
let record = yield db.getByPushEndpoint('https://example.com/update/case');

View File

@ -46,9 +46,11 @@ add_task(function* test_pushSubscriptionNoConnection() {
});
yield rejects(
PushNotificationService.register(
'https://example.net/page/invalid-response',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })),
PushService.register({
scope: 'https://example.net/page/invalid-response',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
}),
'Expected error for not being able to establish connecion.'
);
@ -84,9 +86,11 @@ add_task(function* test_pushSubscriptionMissingLocation() {
});
yield rejects(
PushNotificationService.register(
'https://example.net/page/invalid-response',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })),
PushService.register({
scope: 'https://example.net/page/invalid-response',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
}),
'Expected error for the missing location header.'
);
@ -108,9 +112,11 @@ add_task(function* test_pushSubscriptionMissingLink() {
});
yield rejects(
PushNotificationService.register(
'https://example.net/page/invalid-response',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })),
PushService.register({
scope: 'https://example.net/page/invalid-response',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
}),
'Expected error for the missing link header.'
);
@ -132,9 +138,11 @@ add_task(function* test_pushSubscriptionMissingLink1() {
});
yield rejects(
PushNotificationService.register(
'https://example.net/page/invalid-response',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })),
PushService.register({
scope: 'https://example.net/page/invalid-response',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
}),
'Expected error for the missing push endpoint.'
);
@ -156,9 +164,11 @@ add_task(function* test_pushSubscriptionLocationBogus() {
});
yield rejects(
PushNotificationService.register(
'https://example.net/page/invalid-response',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })),
PushService.register({
scope: 'https://example.net/page/invalid-response',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
}),
'Expected error for the bogus location'
);
@ -180,9 +190,11 @@ add_task(function* test_pushSubscriptionNot2xxCode() {
});
yield rejects(
PushNotificationService.register(
'https://example.net/page/invalid-response',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })),
PushService.register({
scope: 'https://example.net/page/invalid-response',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
}),
'Expected error for not 201 responce code.'
);

View File

@ -76,9 +76,11 @@ add_task(function* test_register_flush() {
}
});
let newRecord = yield PushNotificationService.register(
'https://example.com/page/2', '');
equal(newRecord.pushEndpoint, 'https://example.org/update/2',
let newRecord = yield PushService.register({
scope: 'https://example.com/page/2',
originAttributes: '',
});
equal(newRecord.endpoint, 'https://example.org/update/2',
'Wrong push endpoint in record');
let {data: scope} = yield waitForPromise(notifyPromise, DEFAULT_TIMEOUT,

View File

@ -48,8 +48,11 @@ add_task(function* test_register_invalid_channel() {
});
yield rejects(
PushNotificationService.register('https://example.com/invalid-channel',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })),
PushService.register({
scope: 'https://example.com/invalid-channel',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
}),
'Expected error for invalid channel ID'
);

View File

@ -49,9 +49,11 @@ add_task(function* test_register_invalid_endpoint() {
});
yield rejects(
PushNotificationService.register(
'https://example.net/page/invalid-endpoint',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })),
PushService.register({
scope: 'https://example.net/page/invalid-endpoint',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
}),
'Expected error for invalid endpoint'
);

View File

@ -49,8 +49,11 @@ add_task(function* test_register_invalid_json() {
});
yield rejects(
PushNotificationService.register('https://example.net/page/invalid-json',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })),
PushService.register({
scope: 'https://example.net/page/invalid-json',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
}),
'Expected error for invalid JSON response'
);

View File

@ -53,8 +53,11 @@ add_task(function* test_register_no_id() {
});
yield rejects(
PushNotificationService.register('https://example.com/incomplete',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })),
PushService.register({
scope: 'https://example.com/incomplete',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
}),
'Expected error for incomplete register response'
);

View File

@ -45,14 +45,16 @@ add_task(function* test_register_request_queue() {
}
});
let firstRegister = PushNotificationService.register(
'https://example.com/page/1',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })
);
let secondRegister = PushNotificationService.register(
'https://example.com/page/1',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })
);
let firstRegister = PushService.register({
scope: 'https://example.com/page/1',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
});
let secondRegister = PushService.register({
scope: 'https://example.com/page/1',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
});
yield waitForPromise(Promise.all([
rejects(firstRegister, 'Should time out the first request'),

View File

@ -75,8 +75,11 @@ add_task(function* test_register_rollback() {
// Should return a rejected promise if storage fails.
yield rejects(
PushNotificationService.register('https://example.com/storage-error',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })),
PushService.register({
scope: 'https://example.com/storage-error',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
}),
'Expected error for unregister database failure'
);

View File

@ -56,11 +56,12 @@ add_task(function* test_register_success() {
}
});
let newRecord = yield PushNotificationService.register(
'https://example.org/1',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })
);
equal(newRecord.pushEndpoint, 'https://example.com/update/1',
let newRecord = yield PushService.register({
scope: 'https://example.org/1',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
});
equal(newRecord.endpoint, 'https://example.com/update/1',
'Wrong push endpoint in registration record');
let record = yield db.getByKeyID(channelID);
@ -68,6 +69,6 @@ add_task(function* test_register_success() {
'Wrong channel ID in database record');
equal(record.pushEndpoint, 'https://example.com/update/1',
'Wrong push endpoint in database record');
equal(record.quota, Infinity,
equal(record.quota, 16,
'Wrong quota in database record');
});

View File

@ -56,15 +56,16 @@ add_task(function* test_pushSubscriptionSuccess() {
db
});
let newRecord = yield PushNotificationService.register(
'https://example.org/1',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })
);
let newRecord = yield PushService.register({
scope: 'https://example.org/1',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
});
var subscriptionUri = serverURL + '/pushSubscriptionSuccesss';
var pushEndpoint = serverURL + '/pushEndpointSuccess';
var pushReceiptEndpoint = serverURL + '/receiptPushEndpointSuccess';
equal(newRecord.pushEndpoint, pushEndpoint,
equal(newRecord.endpoint, pushEndpoint,
'Wrong push endpoint in registration record');
equal(newRecord.pushReceiptEndpoint, pushReceiptEndpoint,
@ -95,15 +96,16 @@ add_task(function* test_pushSubscriptionMissingLink2() {
db
});
let newRecord = yield PushNotificationService.register(
'https://example.org/no_receiptEndpoint',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })
);
let newRecord = yield PushService.register({
scope: 'https://example.org/no_receiptEndpoint',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
});
var subscriptionUri = serverURL + '/subscriptionMissingLink2';
var pushEndpoint = serverURL + '/pushEndpointMissingLink2';
var pushReceiptEndpoint = '';
equal(newRecord.pushEndpoint, pushEndpoint,
equal(newRecord.endpoint, pushEndpoint,
'Wrong push endpoint in registration record');
equal(newRecord.pushReceiptEndpoint, pushReceiptEndpoint,

View File

@ -75,8 +75,11 @@ add_task(function* test_register_timeout() {
});
yield rejects(
PushNotificationService.register('https://example.net/page/timeout',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })),
PushService.register({
scope: 'https://example.net/page/timeout',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
}),
'Expected error for request timeout'
);

View File

@ -59,8 +59,11 @@ add_task(function* test_register_wrong_id() {
});
yield rejects(
PushNotificationService.register('https://example.com/mismatched',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })),
PushService.register({
scope: 'https://example.com/mismatched',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
}),
'Expected error for mismatched register reply'
);

View File

@ -53,8 +53,11 @@ add_task(function* test_register_wrong_type() {
});
yield rejects(
PushNotificationService.register('https://example.com/mistyped',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })),
PushService.register({
scope: 'https://example.com/mistyped',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
}),
'Expected error for non-string channel ID'
);

View File

@ -31,8 +31,11 @@ add_task(function* test_registrations_error() {
});
yield rejects(
PushNotificationService.registration('https://example.net/1',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })),
PushService.registration({
scope: 'https://example.net/1',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
}),
function(error) {
return error == 'Database error';
},

View File

@ -25,8 +25,11 @@ add_task(function* test_registrations_error() {
});
yield rejects(
PushNotificationService.registration('https://example.net/1',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })),
PushService.registration({
scope: 'https://example.net/1',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
}),
function(error) {
return error == 'Database error';
},

View File

@ -20,7 +20,7 @@ add_task(function* test_registration_missing_scope() {
}
});
yield rejects(
PushNotificationService.registration('', ''),
PushService.registration({ scope: '', originAttributes: '' }),
'Record missing page and manifest URLs'
);
});

View File

@ -23,8 +23,10 @@ add_task(function* test_registration_none() {
}
});
let registration = yield PushNotificationService.registration(
'https://example.net/1',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }));
let registration = yield PushService.registration({
scope: 'https://example.net/1',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
});
ok(!registration, 'Should not open a connection without registration');
});

View File

@ -27,14 +27,16 @@ add_task(function* test_registration_success() {
channelID: 'f6edfbcd-79d6-49b8-9766-48b9dcfeff0f',
pushEndpoint: 'https://example.com/update/same-manifest/2',
scope: 'https://example.net/b',
originAttributes: ChromeUtils.originAttributesToSuffix({ appId: 42 }),
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: 42 }),
version: 10,
quota: Infinity,
}, {
channelID: 'b1cf38c9-6836-4d29-8a30-a3e98d59b728',
pushEndpoint: 'https://example.org/update/different-manifest',
scope: 'https://example.org/c',
originAttributes: ChromeUtils.originAttributesToSuffix({ appId: 42, inBrowser: true }),
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: 42, inBrowser: true }),
version: 15,
quota: Infinity,
}];
@ -68,10 +70,12 @@ add_task(function* test_registration_success() {
'Timed out waiting for handshake'
);
let registration = yield PushNotificationService.registration(
'https://example.net/a', '');
let registration = yield PushService.registration({
scope: 'https://example.net/a',
originAttributes: '',
});
equal(
registration.pushEndpoint,
registration.endpoint,
'https://example.com/update/same-manifest/1',
'Wrong push endpoint for scope'
);

View File

@ -42,21 +42,24 @@ add_task(function* test_pushNotifications() {
pushEndpoint: serverURL + '/pushEndpointA',
pushReceiptEndpoint: serverURL + '/pushReceiptEndpointA',
scope: 'https://example.net/a',
originAttributes: ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
quota: Infinity,
}, {
subscriptionUri: serverURL + '/subscriptionB',
pushEndpoint: serverURL + '/pushEndpointB',
pushReceiptEndpoint: serverURL + '/pushReceiptEndpointB',
scope: 'https://example.net/b',
originAttributes: ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
quota: Infinity,
}, {
subscriptionUri: serverURL + '/subscriptionC',
pushEndpoint: serverURL + '/pushEndpointC',
pushReceiptEndpoint: serverURL + '/pushReceiptEndpointC',
scope: 'https://example.net/c',
originAttributes: ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
quota: Infinity,
}];
@ -69,11 +72,13 @@ add_task(function* test_pushNotifications() {
db
});
let registration = yield PushNotificationService.registration(
'https://example.net/a',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }));
let registration = yield PushService.registration({
scope: 'https://example.net/a',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
});
equal(
registration.pushEndpoint,
registration.endpoint,
serverURL + '/pushEndpointA',
'Wrong push endpoint for scope'
);

View File

@ -0,0 +1,171 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
'use strict';
const {PushDB, PushService, PushServiceWebSocket} = serviceExports;
var db, service;
function run_test() {
service = Cc['@mozilla.org/push/Service;1']
.getService(Ci.nsIPushService);
if (isParent) {
do_get_profile();
}
run_next_test();
}
if (isParent) {
add_test(function setUp() {
db = PushServiceWebSocket.newPushDB();
do_register_cleanup(() => {return db.drop().then(_ => db.close());});
setUpServiceInParent(PushService, db).then(run_next_test, run_next_test);
});
}
add_test(function test_subscribe_success() {
do_test_pending();
service.subscribe(
'https://example.com/sub/ok',
Services.scriptSecurityManager.getSystemPrincipal(),
(result, subscription) => {
ok(Components.isSuccessCode(result), 'Error creating subscription');
ok(subscription.endpoint.startsWith('https://example.org/push'), 'Wrong endpoint prefix');
equal(subscription.pushCount, 0, 'Wrong push count');
equal(subscription.lastPush, 0, 'Wrong last push time');
do_test_finished();
run_next_test();
}
);
});
add_test(function test_subscribe_error() {
do_test_pending();
service.subscribe(
'https://example.com/sub/fail',
Services.scriptSecurityManager.getSystemPrincipal(),
(result, subscription) => {
ok(!Components.isSuccessCode(result), 'Expected error creating subscription');
strictEqual(subscription, null, 'Unexpected subscription');
do_test_finished();
run_next_test();
}
);
});
add_test(function test_getSubscription_exists() {
do_test_pending();
service.getSubscription(
'https://example.com/get/ok',
Services.scriptSecurityManager.getSystemPrincipal(),
(result, subscription) => {
ok(Components.isSuccessCode(result), 'Error getting subscription');
equal(subscription.endpoint, 'https://example.org/push/get', 'Wrong endpoint');
equal(subscription.pushCount, 10, 'Wrong push count');
equal(subscription.lastPush, 1438360548322, 'Wrong last push');
do_test_finished();
run_next_test();
}
);
});
add_test(function test_getSubscription_missing() {
do_test_pending();
service.getSubscription(
'https://example.com/get/missing',
Services.scriptSecurityManager.getSystemPrincipal(),
(result, subscription) => {
ok(Components.isSuccessCode(result), 'Error getting nonexistent subscription');
strictEqual(subscription, null, 'Nonexistent subscriptions should return null');
do_test_finished();
run_next_test();
}
);
});
add_test(function test_getSubscription_error() {
do_test_pending();
service.getSubscription(
'https://example.com/get/fail',
Services.scriptSecurityManager.getSystemPrincipal(),
(result, subscription) => {
ok(!Components.isSuccessCode(result), 'Expected error getting subscription');
strictEqual(subscription, null, 'Unexpected subscription');
do_test_finished();
run_next_test();
}
);
});
add_test(function test_unsubscribe_success() {
do_test_pending();
service.unsubscribe(
'https://example.com/unsub/ok',
Services.scriptSecurityManager.getSystemPrincipal(),
(result, success) => {
ok(Components.isSuccessCode(result), 'Error unsubscribing');
strictEqual(success, true, 'Expected successful unsubscribe');
do_test_finished();
run_next_test();
}
);
});
add_test(function test_unsubscribe_nonexistent() {
do_test_pending();
service.unsubscribe(
'https://example.com/unsub/ok',
Services.scriptSecurityManager.getSystemPrincipal(),
(result, success) => {
ok(Components.isSuccessCode(result), 'Error removing nonexistent subscription');
strictEqual(success, false, 'Nonexistent subscriptions should return false');
do_test_finished();
run_next_test();
}
);
});
add_test(function test_unsubscribe_error() {
do_test_pending();
service.unsubscribe(
'https://example.com/unsub/fail',
Services.scriptSecurityManager.getSystemPrincipal(),
(result, success) => {
ok(!Components.isSuccessCode(result), 'Expected error unsubscribing');
strictEqual(success, false, 'Unexpected successful unsubscribe');
do_test_finished();
run_next_test();
}
);
});
add_test(function test_subscribe_principal() {
let principal = Services.scriptSecurityManager.getAppCodebasePrincipal(
Services.io.newURI('https://example.net/app/1', null, null),
1, /* appId */
true /* browserOnly */
);
service.subscribe('https://example.net/scope/1', principal, (result, subscription) => {
ok(Components.isSuccessCode(result), 'Error creating subscription');
ok(subscription.endpoint.startsWith('https://example.org/push'),
'Wrong push endpoint in app subscription');
run_next_test();
});
});
if (isParent) {
add_test(function tearDown() {
tearDownServiceInParent(db).then(run_next_test, run_next_test);
});
}

View File

@ -0,0 +1,24 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
'use strict';
const {PushDB, PushService, PushServiceWebSocket} = serviceExports;
function run_test() {
do_get_profile();
run_next_test();
}
add_task(function* test_service_parent() {
let db = PushServiceWebSocket.newPushDB();
do_register_cleanup(() => {return db.drop().then(_ => db.close());});
yield setUpServiceInParent(PushService, db);
// Start the service in the main process.
Cc['@mozilla.org/push/Service;1'].getService(Ci.nsIPushService);
yield run_test_in_child('./test_service_child.js');
yield tearDownServiceInParent(db);
});

View File

@ -29,8 +29,11 @@ add_task(function* test_unregister_empty_scope() {
});
yield rejects(
PushNotificationService.unregister('',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })),
PushService.unregister({
scope: '',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
}),
'Expected error for empty endpoint'
);
});

View File

@ -56,8 +56,10 @@ add_task(function* test_unregister_error() {
}
});
yield PushNotificationService.unregister(
'https://example.net/page/failure', '');
yield PushService.unregister({
scope: 'https://example.net/page/failure',
originAttributes: '',
});
let result = yield db.getByKeyID(channelID);
ok(!result, 'Deleted push record exists');

View File

@ -64,14 +64,19 @@ add_task(function* test_unregister_invalid_json() {
// "unregister" is fire-and-forget: it's sent via _send(), not
// _sendRequest().
yield PushNotificationService.unregister(
'https://example.edu/page/1', '');
yield PushService.unregister({
scope: 'https://example.edu/page/1',
originAttributes: '',
});
let record = yield db.getByKeyID(
'87902e90-c57e-4d18-8354-013f4a556559');
ok(!record, 'Failed to delete unregistered record');
yield PushNotificationService.unregister(
'https://example.net/page/1', '');
yield PushService.unregister({
scope: 'https://example.net/page/1',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
});
record = yield db.getByKeyID(
'057caa8f-9b99-47ff-891c-adad18ce603e');
ok(!record,

View File

@ -28,8 +28,10 @@ add_task(function* test_unregister_not_found() {
}
});
let result = yield PushNotificationService.unregister(
'https://example.net/nonexistent',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }));
let result = yield PushService.unregister({
scope: 'https://example.net/nonexistent',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
});
ok(result === false, "unregister should resolve with false for nonexistent scope");
});

View File

@ -53,8 +53,10 @@ add_task(function* test_unregister_success() {
}
});
yield PushNotificationService.unregister(
'https://example.com/page/unregister-success', '');
yield PushService.unregister({
scope: 'https://example.com/page/unregister-success',
originAttributes: '',
});
let record = yield db.getByKeyID(channelID);
ok(!record, 'Unregister did not remove record');

View File

@ -54,7 +54,8 @@ add_task(function* test_pushUnsubscriptionSuccess() {
pushEndpoint: serverURL + '/pushEndpointUnsubscriptionSuccess',
pushReceiptEndpoint: serverURL + '/receiptPushEndpointUnsubscriptionSuccess',
scope: 'https://example.com/page/unregister-success',
originAttributes: ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
quota: Infinity,
});
@ -63,9 +64,11 @@ add_task(function* test_pushUnsubscriptionSuccess() {
db
});
yield PushNotificationService.unregister(
'https://example.com/page/unregister-success',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }));
yield PushService.unregister({
scope: 'https://example.com/page/unregister-success',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
});
let record = yield db.getByKeyID(serverURL + '/subscriptionUnsubscriptionSuccess');
ok(!record, 'Unregister did not remove record');

View File

@ -73,10 +73,11 @@ add_task(function* test_with_data_enabled() {
},
});
let newRecord = yield PushNotificationService.register(
'https://example.com/page/3',
ChromeUtils.originAttributesToSuffix({ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false })
);
let newRecord = yield PushService.register({
scope: 'https://example.com/page/3',
originAttributes: ChromeUtils.originAttributesToSuffix(
{ appId: Ci.nsIScriptSecurityManager.NO_APP_ID, inBrowser: false }),
});
ok(newRecord.p256dhKey, 'Should generate public keys for new records');
let record = yield db.getByKeyID('eb18f12a-cc42-4f14-accb-3bfc1227f1aa');

View File

@ -43,6 +43,9 @@ run-sequentially = This will delete all existing push subscriptions.
[test_updateRecordNoEncryptionKeys_ws.js]
[test_reconnect_retry.js]
[test_retry_ws.js]
[test_service_parent.js]
[test_service_child.js]
#http2 test
[test_resubscribe_4xxCode_http2.js]
[test_resubscribe_5xxCode_http2.js]