Bug 1275434 - Add remote push observer tests. r=dragana
authorKit Cambridge <kcambridge@mozilla.com>
Thu, 19 May 2016 21:41:15 -0700
changeset 339036 332caaad198f1c9789a98408af76c6df9957bde3
parent 339035 80fbbee5de1fb2616014704c01b0752c2bd2f963
child 339037 32a8d48c26eeff52172de939d4d704104f8e5167
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana
bugs1275434
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1275434 - Add remote push observer tests. r=dragana MozReview-Commit-ID: 4BVWwEbI2FX
dom/push/test/xpcshell/test_handler_service_parent.js
dom/push/test/xpcshell/test_observer_remoting.js
dom/push/test/xpcshell/xpcshell.ini
deleted file mode 100644
--- a/dom/push/test/xpcshell/test_handler_service_parent.js
+++ /dev/null
@@ -1,50 +0,0 @@
-'use strict';
-
-function run_test() {
-  do_get_profile();
-  run_next_test();
-}
-
-add_task(function* test_observer_notifications() {
-  // Push observer notifications dispatched in the child should be forwarded to
-  // the parent.
-  let notifyPromise = promiseObserverNotification(
-    PushServiceComponent.pushTopic);
-  let subChangePromise = promiseObserverNotification(
-    PushServiceComponent.subscriptionChangeTopic);
-  let subModifiedPromise = promiseObserverNotification(
-    PushServiceComponent.subscriptionModifiedTopic);
-
-  yield run_test_in_child('./test_handler_service.js');
-
-  let principal = Services.scriptSecurityManager.getSystemPrincipal();
-
-  let {
-    data: notifyScope,
-    subject: notifySubject,
-  } = yield notifyPromise;
-  equal(notifyScope, 'chrome://test-scope',
-    'Should forward push notifications with the correct scope');
-  let message = notifySubject.QueryInterface(Ci.nsIPushMessage);
-  equal(message.principal, principal,
-    'Should include the principal in the push message');
-  strictEqual(message.data, null, 'Should not include data');
-
-  let {
-    data: subChangeScope,
-    subject: subChangePrincipal,
-  } = yield subChangePromise;
-  equal(subChangeScope, 'chrome://test-scope',
-    'Should forward subscription change notifications with the correct scope');
-  equal(subChangePrincipal, principal,
-    'Should pass the principal as the subject of a change notification');
-
-  let {
-    data: subModifiedScope,
-    subject: subModifiedPrincipal,
-  } = yield subModifiedPromise;
-  equal(subModifiedScope, 'chrome://test-scope',
-    'Should forward subscription modified notifications with the correct scope');
-  equal(subModifiedPrincipal, principal,
-    'Should pass the principal as the subject of a modified notification');
-});
new file mode 100644
--- /dev/null
+++ b/dom/push/test/xpcshell/test_observer_remoting.js
@@ -0,0 +1,90 @@
+'use strict';
+
+const pushNotifier = Cc['@mozilla.org/push/Notifier;1']
+                       .getService(Ci.nsIPushNotifier);
+
+add_task(function* test_observer_remoting() {
+  if (isParent) {
+    yield testInParent();
+  } else {
+    yield testInChild();
+  }
+});
+
+function* testInParent() {
+  // Register observers for notifications from the child, then run the test in
+  // the child and wait for the notifications.
+  let promiseNotifications = waitForNotifierObservers('Hello from child!');
+  let promiseFinished = run_test_in_child('./test_observer_remoting.js');
+  yield promiseNotifications;
+
+  // Wait until the child is listening for notifications from the parent.
+  yield do_await_remote_message('push_test_observer_remoting_child_ready');
+
+  // Fire an observer notification in the parent that should be forwarded to
+  // the child.
+  yield waitForNotifierObservers('Hello from parent!', true);
+
+  // Wait for the child to exit.
+  yield promiseFinished;
+}
+
+function* testInChild() {
+  // Fire an observer notification in the child that should be forwarded to
+  // the parent.
+  yield waitForNotifierObservers('Hello from child!', true);
+
+  // Register observers for notifications from the parent, let the parent know
+  // we're ready, and wait for the notifications.
+  let promiseNotifierObservers = waitForNotifierObservers('Hello from parent!');
+  do_send_remote_message('push_test_observer_remoting_child_ready');
+  yield promiseNotifierObservers;
+}
+
+function* waitForNotifierObservers(expectedText, shouldNotify = false) {
+  let notifyPromise = promiseObserverNotification(
+    PushServiceComponent.pushTopic);
+  let subChangePromise = promiseObserverNotification(
+    PushServiceComponent.subscriptionChangeTopic);
+  let subModifiedPromise = promiseObserverNotification(
+    PushServiceComponent.subscriptionModifiedTopic);
+
+  let scope = 'chrome://test-scope';
+  let principal = Services.scriptSecurityManager.getSystemPrincipal();
+  let data = new TextEncoder('utf-8').encode(expectedText);
+
+  if (shouldNotify) {
+    pushNotifier.notifyPushWithData(scope, principal, '', data.length, data);
+    pushNotifier.notifySubscriptionChange(scope, principal);
+    pushNotifier.notifySubscriptionModified(scope, principal);
+  }
+
+  let {
+    data: notifyScope,
+    subject: notifySubject,
+  } = yield notifyPromise;
+  equal(notifyScope, scope,
+    'Should fire push notifications with the correct scope');
+  let message = notifySubject.QueryInterface(Ci.nsIPushMessage);
+  equal(message.principal, principal,
+    'Should include the principal in the push message');
+  strictEqual(message.data.text(), expectedText, 'Should include data');
+
+  let {
+    data: subChangeScope,
+    subject: subChangePrincipal,
+  } = yield subChangePromise;
+  equal(subChangeScope, scope,
+    'Should fire subscription change notifications with the correct scope');
+  equal(subChangePrincipal, principal,
+    'Should pass the principal as the subject of a change notification');
+
+  let {
+    data: subModifiedScope,
+    subject: subModifiedPrincipal,
+  } = yield subModifiedPromise;
+  equal(subModifiedScope, scope,
+    'Should fire subscription modified notifications with the correct scope');
+  equal(subModifiedPrincipal, principal,
+    'Should pass the principal as the subject of a modified notification');
+}
--- a/dom/push/test/xpcshell/xpcshell.ini
+++ b/dom/push/test/xpcshell/xpcshell.ini
@@ -2,26 +2,26 @@
 head = head.js head-http2.js
 tail =
 # Push notifications and alarms are currently disabled on Android.
 skip-if = toolkit == 'android'
 
 [test_clear_origin_data.js]
 [test_crypto.js]
 [test_drop_expired.js]
-[test_handler_service_parent.js]
 [test_handler_service.js]
 support-files = PushServiceHandler.js PushServiceHandler.manifest
 [test_notification_ack.js]
 [test_notification_data.js]
 [test_notification_duplicate.js]
 [test_notification_error.js]
 [test_notification_incomplete.js]
 [test_notification_version_string.js]
 [test_observer_data.js]
+[test_observer_remoting.js]
 
 [test_permissions.js]
 run-sequentially = This will delete all existing push subscriptions.
 
 [test_quota_exceeded.js]
 [test_quota_observer.js]
 [test_quota_with_notification.js]
 [test_record.js]