Bug 1239584, Part 3 - Update tests. r=dragana

--HG--
extra : commitid : KIDc3UHjz1N
extra : rebase_source : 9eccff6802a9453cfe5b3b318d38d13f1aab8a09
This commit is contained in:
Kit Cambridge 2016-01-13 22:26:57 -07:00
Родитель 942b8f74cd
Коммит a2a02af8bf
33 изменённых файлов: 43 добавлений и 176 удалений

Просмотреть файл

@ -168,23 +168,6 @@ function makeStub(target, stubs) {
});
}
/**
* Disables `push` and `pushsubscriptionchange` service worker events for the
* given scopes. These events cause crashes in xpcshell, so we disable them
* for testing nsIPushNotificationService.
*
* @param {String[]} scopes A list of scope URLs.
*/
function disableServiceWorkerEvents(...scopes) {
for (let scope of scopes) {
Services.perms.add(
Services.io.newURI(scope, null, null),
'desktop-notification',
Ci.nsIPermissionManager.DENY_ACTION
);
}
}
/**
* Sets default PushService preferences. All pref names are prefixed with
* `dom.push.`; any additional preferences will override the defaults.
@ -221,6 +204,8 @@ function setPrefs(prefs = {}) {
'http2.reset_retry_count_after_ms': 60000,
maxQuotaPerSubscription: 16,
quotaUpdateDelay: 3000,
'testing.notifyWorkers': false,
'testing.notifyAllObservers': true,
}, prefs);
for (let pref in defaultPrefs) {
servicePrefs.set(pref, defaultPrefs[pref]);

Просмотреть файл

@ -41,9 +41,6 @@ function run_test() {
requestTimeout: 1000,
retryBaseInterval: 150
});
disableServiceWorkerEvents(
'https://example.org/1'
);
run_next_test();
}

Просмотреть файл

@ -10,11 +10,6 @@ var userAgentID = '5ab1d1df-7a3d-4024-a469-b9e1bb399fad';
function run_test() {
do_get_profile();
setPrefs({userAgentID});
disableServiceWorkerEvents(
'https://example.org/1',
'https://example.org/2',
'https://example.org/3'
);
run_next_test();
}
@ -50,11 +45,9 @@ add_task(function* test_notification_ack() {
yield db.put(record);
}
let notifyPromise = Promise.all([
promiseObserverNotification('push-notification'),
promiseObserverNotification('push-notification'),
promiseObserverNotification('push-notification')
]);
let notifyCount = 0;
let notifyPromise = promiseObserverNotification('push-message', () =>
++notifyCount == 3);
let acks = 0;
let ackDone;

Просмотреть файл

@ -218,9 +218,9 @@ add_task(function* test_notification_ack_data() {
];
let sendAndReceive = testData => {
let messageReceived = promiseObserverNotification('push-notification', (subject, data) => {
let notification = subject.QueryInterface(Ci.nsIPushObserverNotification);
equal(notification.data, testData.receive.data,
let messageReceived = promiseObserverNotification('push-message', (subject, data) => {
let notification = subject.QueryInterface(Ci.nsIPushMessage);
equal(notification.text(), testData.receive.data,
'Check data for notification ' + testData.version);
equal(data, testData.receive.scope,
'Check scope for notification ' + testData.version);

Просмотреть файл

@ -12,10 +12,6 @@ function run_test() {
setPrefs({
userAgentID: userAgentID,
});
disableServiceWorkerEvents(
'https://example.com/1',
'https://example.com/2'
);
run_next_test();
}
@ -44,7 +40,7 @@ add_task(function* test_notification_duplicate() {
yield db.put(record);
}
let notifyPromise = promiseObserverNotification('push-notification');
let notifyPromise = promiseObserverNotification('push-message');
let acks = 0;
let ackDone;

Просмотреть файл

@ -12,11 +12,6 @@ function run_test() {
setPrefs({
userAgentID: userAgentID,
});
disableServiceWorkerEvents(
'https://example.com/a',
'https://example.com/b',
'https://example.com/c'
);
run_next_test();
}
@ -54,16 +49,9 @@ add_task(function* test_notification_error() {
yield db.put(record);
}
let notifyPromise = Promise.all([
promiseObserverNotification(
'push-notification',
(subject, data) => data == 'https://example.com/a'
),
promiseObserverNotification(
'push-notification',
(subject, data) => data == 'https://example.com/c'
)
]);
let scopes = [];
let notifyPromise = promiseObserverNotification('push-message', (subject, data) =>
scopes.push(data) == 2);
let ackDone;
let ackPromise = new Promise(resolve => ackDone = after(records.length, resolve));
@ -99,20 +87,15 @@ add_task(function* test_notification_error() {
}
});
let [a, c] = yield waitForPromise(
yield waitForPromise(
notifyPromise,
DEFAULT_TIMEOUT,
'Timed out waiting for notifications'
);
let aPush = a.subject.QueryInterface(Ci.nsIPushObserverNotification);
equal(aPush.pushEndpoint, 'https://example.org/update/success-1',
'Wrong endpoint for notification A');
equal(aPush.version, 2, 'Wrong version for notification A');
let cPush = c.subject.QueryInterface(Ci.nsIPushObserverNotification);
equal(cPush.pushEndpoint, 'https://example.org/update/success-2',
'Wrong endpoint for notification C');
equal(cPush.version, 4, 'Wrong version for notification C');
ok(scopes.includes('https://example.com/a'),
'Missing scope for notification A');
ok(scopes.includes('https://example.com/c'),
'Missing scope for notification C');
yield waitForPromise(ackPromise, DEFAULT_TIMEOUT,
'Timed out waiting for acknowledgements');

Просмотреть файл

@ -35,11 +35,8 @@ function run_test() {
prefs.setIntPref("network.http.speculative-parallel-limit", oldPref);
disableServiceWorkerEvents(
'https://example.com/page/1',
'https://example.com/page/2',
'https://example.com/page/3'
);
servicePrefs.set('testing.notifyWorkers', false);
servicePrefs.set('testing.notifyAllObservers', true);
run_next_test();
}
@ -124,24 +121,24 @@ add_task(function* test_pushNotifications() {
}
let notifyPromise = Promise.all([
promiseObserverNotification('push-notification', function(subject, data) {
var notification = subject.QueryInterface(Ci.nsIPushObserverNotification);
if (notification && (data == "https://example.com/page/1")){
equal(subject.data, "Some message", "decoded message is incorrect");
promiseObserverNotification('push-message', function(subject, data) {
var message = subject.QueryInterface(Ci.nsIPushMessage);
if (message && (data == "https://example.com/page/1")){
equal(message.text(), "Some message", "decoded message is incorrect");
return true;
}
}),
promiseObserverNotification('push-notification', function(subject, data) {
var notification = subject.QueryInterface(Ci.nsIPushObserverNotification);
if (notification && (data == "https://example.com/page/2")){
equal(subject.data, "Some message", "decoded message is incorrect");
promiseObserverNotification('push-message', function(subject, data) {
var message = subject.QueryInterface(Ci.nsIPushMessage);
if (message && (data == "https://example.com/page/2")){
equal(message.text(), "Some message", "decoded message is incorrect");
return true;
}
}),
promiseObserverNotification('push-notification', function(subject, data) {
var notification = subject.QueryInterface(Ci.nsIPushObserverNotification);
if (notification && (data == "https://example.com/page/3")){
equal(subject.data, "Some message", "decoded message is incorrect");
promiseObserverNotification('push-message', function(subject, data) {
var message = subject.QueryInterface(Ci.nsIPushMessage);
if (message && (data == "https://example.com/page/3")){
equal(message.text(), "Some message", "decoded message is incorrect");
return true;
}
})

Просмотреть файл

@ -12,12 +12,6 @@ function run_test() {
setPrefs({
userAgentID: userAgentID,
});
disableServiceWorkerEvents(
'https://example.com/page/1',
'https://example.com/page/2',
'https://example.com/page/3',
'https://example.com/page/4'
);
run_next_test();
}
@ -57,9 +51,12 @@ add_task(function* test_notification_incomplete() {
yield db.put(record);
}
Services.obs.addObserver(function observe(subject, topic, data) {
function observeMessage(subject, topic, data) {
ok(false, 'Should not deliver malformed updates');
}, 'push-notification', false);
}
do_register_cleanup(() =>
Services.obs.removeObserver(observeMessage, 'push-message'));
Services.obs.addObserver(observeMessage, 'push-message', false);
let notificationDone;
let notificationPromise = new Promise(resolve => notificationDone = after(2, resolve));

Просмотреть файл

@ -12,9 +12,6 @@ function run_test() {
setPrefs({
userAgentID: userAgentID,
});
disableServiceWorkerEvents(
'https://example.net/case'
);
run_next_test();
}
@ -31,7 +28,7 @@ add_task(function* test_notification_version_string() {
systemRecord: true,
});
let notifyPromise = promiseObserverNotification('push-notification');
let notifyPromise = promiseObserverNotification('push-message');
let ackDone;
let ackPromise = new Promise(resolve => ackDone = resolve);
@ -65,11 +62,7 @@ add_task(function* test_notification_version_string() {
DEFAULT_TIMEOUT,
'Timed out waiting for string notification'
);
let message = notification.QueryInterface(Ci.nsIPushObserverNotification);
equal(scope, 'https://example.com/page/1', 'Wrong scope');
equal(message.pushEndpoint, 'https://example.org/updates/1',
'Wrong push endpoint');
strictEqual(message.version, 4, 'Wrong version');
equal(notification, null, 'Unexpected data for Simple Push message');
yield waitForPromise(ackPromise, DEFAULT_TIMEOUT,
'Timed out waiting for string acknowledgement');

Просмотреть файл

@ -82,7 +82,7 @@ add_task(function* test_expiration_origin_threshold() {
// different scopes, so each can send 5 notifications before we remove
// their subscription.
let updates = 0;
let notifyPromise = promiseObserverNotification('push-notification', (subject, data) => {
let notifyPromise = promiseObserverNotification('push-message', (subject, data) => {
updates++;
return updates == 6;
});

Просмотреть файл

@ -55,7 +55,7 @@ add_task(function* test_expiration_origin_threshold() {
let numMessages = 10;
let updates = 0;
let notifyPromise = promiseObserverNotification('push-notification', (subject, data) => {
let notifyPromise = promiseObserverNotification('push-message', (subject, data) => {
updates++;
return updates == numMessages;
});

Просмотреть файл

@ -56,9 +56,6 @@ function run_test() {
'http2.retryInterval': 1000,
'http2.maxRetries': 2
});
disableServiceWorkerEvents(
'https://example.com/retry5xxCode'
);
run_next_test();
}

Просмотреть файл

@ -10,9 +10,6 @@ const userAgentID = '1760b1f5-c3ba-40e3-9344-adef7c18ab12';
function run_test() {
do_get_profile();
setPrefs();
disableServiceWorkerEvents(
'https://example.net/case'
);
run_next_test();
}

Просмотреть файл

@ -23,10 +23,6 @@ function run_test() {
tlsProfile = prefs.getBoolPref("network.http.spdy.enforce-tls-profile");
disableServiceWorkerEvents(
'https://example.net/page/invalid-response'
);
serverURL = "https://localhost:" + serverPort;
run_next_test();

Просмотреть файл

@ -15,10 +15,6 @@ function run_test() {
requestTimeout: 1000,
retryBaseInterval: 150
});
disableServiceWorkerEvents(
'https://example.com/page/1',
'https://example.com/page/2'
);
run_next_test();
}
@ -36,7 +32,7 @@ add_task(function* test_register_flush() {
};
yield db.put(record);
let notifyPromise = promiseObserverNotification('push-notification');
let notifyPromise = promiseObserverNotification('push-message');
let ackDone;
let ackPromise = new Promise(resolve => ackDone = after(2, resolve));

Просмотреть файл

@ -11,9 +11,6 @@ const channelID = 'cafed00d';
function run_test() {
do_get_profile();
setPrefs();
disableServiceWorkerEvents(
'https://example.com/invalid-channel'
);
run_next_test();
}

Просмотреть файл

@ -11,9 +11,6 @@ const channelID = 'c0660af8-b532-4931-81f0-9fd27a12d6ab';
function run_test() {
do_get_profile();
setPrefs();
disableServiceWorkerEvents(
'https://example.net/page/invalid-endpoint'
);
run_next_test();
}

Просмотреть файл

@ -14,9 +14,6 @@ function run_test() {
requestTimeout: 1000,
retryBaseInterval: 150
});
disableServiceWorkerEvents(
'https://example.net/page/invalid-json'
);
run_next_test();
}

Просмотреть файл

@ -15,9 +15,6 @@ function run_test() {
requestTimeout: 1000,
retryBaseInterval: 150
});
disableServiceWorkerEvents(
'https://example.com/incomplete'
);
run_next_test();
}

Просмотреть файл

@ -11,9 +11,6 @@ function run_test() {
requestTimeout: 1000,
retryBaseInterval: 150
});
disableServiceWorkerEvents(
'https://example.com/page/1'
);
run_next_test();
}

Просмотреть файл

@ -15,9 +15,6 @@ function run_test() {
requestTimeout: 1000,
retryBaseInterval: 150
});
disableServiceWorkerEvents(
'https://example.com/storage-error'
);
run_next_test();
}

Просмотреть файл

@ -15,9 +15,6 @@ function run_test() {
requestTimeout: 1000,
retryBaseInterval: 150
});
disableServiceWorkerEvents(
'https://example.org/1'
);
run_next_test();
}

Просмотреть файл

@ -37,11 +37,6 @@ function run_test() {
serverURL = "https://localhost:" + serverPort;
disableServiceWorkerEvents(
'https://example.org/1',
'https://example.org/no_receiptEndpoint'
);
run_next_test();
}

Просмотреть файл

@ -14,9 +14,6 @@ function run_test() {
requestTimeout: 1000,
retryBaseInterval: 150
});
disableServiceWorkerEvents(
'https://example.net/page/timeout'
);
run_next_test();
}

Просмотреть файл

@ -16,9 +16,6 @@ function run_test() {
requestTimeout: 1000,
retryBaseInterval: 150
});
disableServiceWorkerEvents(
'https://example.com/mismatched'
);
run_next_test();
}

Просмотреть файл

@ -13,9 +13,6 @@ function run_test() {
requestTimeout: 1000,
retryBaseInterval: 150
});
disableServiceWorkerEvents(
'https://example.com/mistyped'
);
run_next_test();
}

Просмотреть файл

@ -19,12 +19,6 @@ function run_test() {
do_get_profile();
prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
disableServiceWorkerEvents(
'https://example.net/a',
'https://example.net/b',
'https://example.net/c'
);
run_next_test();
}

Просмотреть файл

@ -48,9 +48,8 @@ function run_test() {
do_get_profile();
disableServiceWorkerEvents(
'https://example.com/page'
);
servicePrefs.set('testing.notifyWorkers', false);
servicePrefs.set('testing.notifyAllObservers', true);
run_next_test();
}

Просмотреть файл

@ -56,9 +56,6 @@ function run_test() {
'http2.retryInterval': 1000,
'http2.maxRetries': 2
});
disableServiceWorkerEvents(
'https://example.com/page'
);
run_next_test();
}

Просмотреть файл

@ -44,9 +44,6 @@ function run_test() {
'http2.retryInterval': 1000,
'http2.maxRetries': 2
});
disableServiceWorkerEvents(
'https://example.com/page'
);
run_next_test();
}

Просмотреть файл

@ -34,10 +34,6 @@ function run_test() {
prefs.setIntPref("network.http.speculative-parallel-limit", oldPref);
disableServiceWorkerEvents(
'https://example.com/page/unregister-success'
);
run_next_test();
}

Просмотреть файл

@ -32,9 +32,6 @@ function run_test() {
'http2.retryInterval': 1000,
'http2.maxRetries': 2
});
disableServiceWorkerEvents(
'https://example.com/page'
);
run_next_test();
}

Просмотреть файл

@ -12,11 +12,6 @@ function run_test() {
setPrefs({
userAgentID,
});
disableServiceWorkerEvents(
'https://example.com/page/1',
'https://example.com/page/2',
'https://example.com/page/3'
);
run_next_test();
}