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

Commit

Permalink
Merge pull request #21041 from vingtetun/ttl-view.events
Browse files Browse the repository at this point in the history
Bug 1028892 - Update TTL View to support new transition events, and make...
  • Loading branch information
vingtetun committed Jun 26, 2014
2 parents 6d33e72 + dbb2455 commit 8486489
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 18 deletions.
2 changes: 2 additions & 0 deletions apps/system/js/homescreen_window.js
Expand Up @@ -16,6 +16,7 @@
this.setBrowserConfig(manifestURL);
this.render();
this.publish('created');
this.createdTime = this.launchTime = Date.now();
return this;
};

Expand Down Expand Up @@ -120,6 +121,7 @@
HomescreenWindow.prototype._handle_mozbrowsererror =
function hw__handle_mozbrowsererror(evt) {
if (evt.detail.type == 'fatal') {
this.loaded = false;
this.publish('crashed');
this.restart();
}
Expand Down
30 changes: 18 additions & 12 deletions apps/system/js/ttlview.js
Expand Up @@ -3,6 +3,12 @@

(function(exports) {

var targets = [
'homescreen',
'app',
'activity'
];

/**
* TTLView measures and displays startup time as measured by "first paint".
* The load time is displayed in ms next to the type of load event.
Expand Down Expand Up @@ -44,10 +50,10 @@
this.element.style.visibility = 'hidden';
}

window.removeEventListener('appwillopen', this);
window.removeEventListener('apploadtime', this);
window.removeEventListener('activitywillopen', this);
window.removeEventListener('activityloadtime', this);
targets.forEach(function listen(target) {
window.removeEventListener(target + 'opening', this);
window.removeEventListener(target + 'loadtime', this);
}, this);
},

/**
Expand All @@ -61,12 +67,10 @@
this.element.style.visibility = 'visible';

// this is fired when the app launching is initialized
window.addEventListener('appwillopen', this);
window.addEventListener('apploadtime', this);

// this is to calculate the load time of inline activity
window.addEventListener('activitywillopen', this);
window.addEventListener('activityloadtime', this);
targets.forEach(function listen(target) {
window.addEventListener(target + 'opening', this);
window.addEventListener(target + 'loadtime', this);
}, this);
},

/**
Expand All @@ -91,13 +95,15 @@
*/
handleEvent: function(evt) {
switch (evt.type) {
case 'homescreenloadtime':
case 'apploadtime':
case 'activityloadtime':
this.updateLoadtime(evt.detail.time, evt.detail.type);
break;

case 'appwillopen':
case 'activitywillopen':
case 'homescreenopening':
case 'appopening':
case 'activityopening':
this.resetLoadtime();
break;
}
Expand Down
52 changes: 46 additions & 6 deletions apps/system/test/unit/ttlview_test.js
Expand Up @@ -44,8 +44,18 @@ suite('system/TTLView', function() {

suite('hide', function() {
test('removes listeners', function() {
var events = ['appwillopen', 'apploadtime',
'activitywillopen', 'activityloadtime'];
var targets = [
'homescreen',
'app',
'activity'
];

var events = [];
targets.forEach(function listen(target) {
events.push(target + 'opening');
events.push(target + 'loadtime');
});

var removeStub = this.sinon.stub(window, 'removeEventListener');
subject.hide();
events.forEach(function(evt) {
Expand All @@ -56,8 +66,18 @@ suite('system/TTLView', function() {

suite('show', function() {
test('adds listeners', function() {
var events = ['appwillopen', 'apploadtime',
'activitywillopen', 'activityloadtime'];
var targets = [
'homescreen',
'app',
'activity'
];

var events = [];
targets.forEach(function listen(target) {
events.push(target + 'opening');
events.push(target + 'loadtime');
});

var addEventStub = this.sinon.stub(window, 'addEventListener');
subject.show();
events.forEach(function(evt) {
Expand All @@ -68,7 +88,17 @@ suite('system/TTLView', function() {

suite('handleEvent', function() {
test('updateLoadtime events', function() {
var events = ['apploadtime', 'activityloadtime'];
var targets = [
'homescreen',
'app',
'activity'
];

var events = [];
targets.forEach(function listen(target) {
events.push(target + 'loadtime');
});

var updateStub = this.sinon.stub(subject, 'updateLoadtime');
events.forEach(function(evt, i) {
subject.handleEvent({
Expand All @@ -83,7 +113,17 @@ suite('system/TTLView', function() {
});

test('resetLoadtime events', function() {
var events = ['appwillopen', 'activitywillopen'];
var targets = [
'homescreen',
'app',
'activity'
];

var events = [];
targets.forEach(function listen(target) {
events.push(target + 'opening');
});

events.forEach(function(evt) {
var resetStub = this.sinon.stub(subject, 'resetLoadtime');
subject.handleEvent({
Expand Down

0 comments on commit 8486489

Please sign in to comment.