Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Bug 1130547 - merge pull request #28276 from jrburke:bug1130547-email…
Browse files Browse the repository at this point in the history
…-test-notification to mozilla-b2g:master
  • Loading branch information
mozilla-autolander-deprecated committed Feb 18, 2015
2 parents 82f286f + 91b802a commit a966e77
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 80 deletions.
29 changes: 0 additions & 29 deletions apps/email/test/marionette/lib/email_evt.js

This file was deleted.

89 changes: 75 additions & 14 deletions apps/email/test/marionette/lib/notification.js
@@ -1,36 +1,97 @@
/*jshint node: true, browser: true */
'use strict';

var assert = require('assert'),
imgSelector = '#desktop-notifications-container [data-notification-id] img';
containerSelector = '#desktop-notifications-container .other-notifications';

function Notification(client) {
this.client = client;
}
module.exports = Notification;

Notification.prototype = {
getContainer: function() {
return this.client.findElement(containerSelector);
},

assertNoNotification: function() {
this.getContainer().findElement('div', function(error) {
assert.ok(!!error);
});
},

/*
tapFirstNotification: function() {
// This one does not throw an error, but it also does not end
// up triggering the action for the
// return this.client.findElement('#notification-toaster').tap();
},
*/
/**
* Uses Notification.get to get the first notification to show up. This
* approach is used instead of something like tapping on the notification,
* since the notification UI is normally hidden and it is non-trivial to open,
* and the data API really reflects the result of the notification work done
* by the email app.
*/
triggerFirstNotification: function() {
var client = this.client;
return client.executeAsyncScript(function() {
function getFirstNotification() {
window.Notification.get().then(function(notifications) {
if (!notifications) {
marionetteScriptFinished(false);
} else if (!notifications.length) {
// The check was done too fast. Wait for some time to pass
// and check again.
window.setTimeout(getFirstNotification, 300);
} else {
var notification = notifications[0],
evt = window.wrappedJSObject.require('evt');

getContainer: function() {
return this.client
.findElement('#desktop-notifications-container .other-notifications');
evt.emit('notification', {
clicked: true,
imageURL: notification.imageURL,
data: notification.data,
tag: notification.tag
});

marionetteScriptFinished(true);
}
}).catch(function(error) {
console.error('Notification.get failed with: ' + error);
marionetteScriptFinished(false);
});
}

getFirstNotification();
});
},

getFirstIconUrl: function() {
var img = this.getContainer().findElement('img');
return img.getAttribute('src');
/**
* Uses Notification.get to get the first notification's data.
*/
getFirstNotificationData: function() {
var client = this.client;
return client.executeAsyncScript(function() {
function getFirstNotification() {
window.Notification.get().then(function(notifications) {
if (!notifications) {
marionetteScriptFinished(false);
} else if (!notifications.length) {
// The check was done too fast. Wait for some time to pass
// and check again.
window.setTimeout(getFirstNotification, 300);
} else {
var notification = notifications[0];

marionetteScriptFinished({
imageURL: notification.imageURL,
data: notification.data,
tag: notification.tag
});
}
}).catch(function(error) {
console.error('Notification.get failed with: ' + error);
marionetteScriptFinished(false);
});
}

getFirstNotification();
});
}
};

Expand Down
28 changes: 8 additions & 20 deletions apps/email/test/marionette/notification_click_test.js
@@ -1,14 +1,14 @@
/*jshint node: true */
/*global marionette, setup, test */
'use strict';

var Email = require('./lib/email');
var EmailEvt = require('./lib/email_evt');
var EmailSync = require('./lib/email_sync');
var Notification = require('./lib/notification');
var NotificationLib = require('./lib/notification');
var serverHelper = require('./lib/server_helper');

marionette('email notifications, click', function() {
var app, sync, notification, evt,
var app, sync, notification,
client = marionette.client(),
server1 = serverHelper.use({
credentials: {
Expand Down Expand Up @@ -39,8 +39,9 @@ marionette('email notifications, click', function() {
// no cross sending of email across fakeserver instances.
app.manualSetupImapEmail(server1);

for (var i = 0; i < messageCount; i++)
for (var i = 0; i < messageCount; i++) {
sendEmail(server1);
}

// Now set up second account, to confirm system notifications
// are only triggered in certain situations.
Expand All @@ -52,8 +53,7 @@ marionette('email notifications, click', function() {

setup(function() {
app = new Email(client);
evt = new EmailEvt(client);
notification = new Notification(client);
notification = new NotificationLib(client);
sync = new EmailSync(client);
sync.setup();

Expand All @@ -65,13 +65,7 @@ marionette('email notifications, click', function() {

sync.triggerSync();

// Go back to system app
client.switchToFrame();
var url = notification.getFirstIconUrl();

// Then back to email, and fake a notification event
client.apps.switchToApp(Email.EMAIL_ORIGIN);
evt.emitNotificationWithUrl(url);
notification.triggerFirstNotification();

// Since a single message notification, should go to message_reader.
app.waitForMessageReader();
Expand All @@ -83,13 +77,7 @@ marionette('email notifications, click', function() {

sync.triggerSync();

// Go back to system app
client.switchToFrame();
var url = notification.getFirstIconUrl();

// Then back to email, and fake a notification event
client.apps.switchToApp(Email.EMAIL_ORIGIN);
evt.emitNotificationWithUrl(url);
notification.triggerFirstNotification();

// Since a single message notification, should go to message_reader.
app.waitForMessageList();
Expand Down
20 changes: 7 additions & 13 deletions apps/email/test/marionette/notification_foreground_test.js
@@ -1,10 +1,11 @@
/*jshint node: true */
/*global marionette, setup, test */
'use strict';

var Email = require('./lib/email');
var EmailSync = require('./lib/email_sync');
var assert = require('assert');
var Notification = require('./lib/notification');
var NotificationLib = require('./lib/notification');
var serverHelper = require('./lib/server_helper');

marionette('email notifications, foreground', function() {
Expand Down Expand Up @@ -39,8 +40,9 @@ marionette('email notifications, foreground', function() {
// no cross sending of email across fakeserver instances.
app.manualSetupImapEmail(server1);

for (var i = 0; i < messageCount; i++)
for (var i = 0; i < messageCount; i++) {
sendEmail(server1);
}

// Now set up second account, to confirm system notifications
// are only triggered in certain situations.
Expand All @@ -52,7 +54,7 @@ marionette('email notifications, foreground', function() {

setup(function() {
app = new Email(client);
notification = new Notification(client);
notification = new NotificationLib(client);
sync = new EmailSync(client);
sync.setup();

Expand All @@ -65,12 +67,8 @@ marionette('email notifications, foreground', function() {

sync.triggerSync();

// Go back to system app
client.switchToFrame();

// Make sure notification container is visible
assert(notification
.getFirstIconUrl().indexOf('type=message_reader') !== -1);
.getFirstNotificationData().data.type === 'message_reader');
});

test('should have bulk message notification in the different account',
Expand All @@ -79,12 +77,8 @@ marionette('email notifications, foreground', function() {

sync.triggerSync();

// Go back to system app
client.switchToFrame();

// Make sure notification container is visible
assert(notification
.getFirstIconUrl().indexOf('type=message_list') !== -1);
.getFirstNotificationData().data.type === 'message_list');
});

test('should not get a notification for same account', function() {
Expand Down
4 changes: 0 additions & 4 deletions build/jshint/xfail.list
Expand Up @@ -13,15 +13,11 @@ apps/email/test/config.js
apps/email/test/marionette/activity_create_email_account_complete_test.js
apps/email/test/marionette/lib/debug.js
apps/email/test/marionette/lib/email_data.js
apps/email/test/marionette/lib/email_evt.js
apps/email/test/marionette/lib/email_sync.js
apps/email/test/marionette/lib/notification.js
apps/email/test/marionette/lib/server_helper.js
apps/email/test/marionette/lib/servers/fakeimap.js
apps/email/test/marionette/local_drafts_test.js
apps/email/test/marionette/notification_click_test.js
apps/email/test/marionette/notification_disable_test.js
apps/email/test/marionette/notification_foreground_test.js
apps/email/test/marionette/notification_set_interval_test.js
apps/email/test/marionette/reply_imap_email_test.js
apps/email/test/marionette/send_imap_email_test.js
Expand Down

0 comments on commit a966e77

Please sign in to comment.