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 #22149 from etiennesegonzac/bug-1043857
Browse files Browse the repository at this point in the history
Bug 1043857 - Follow up to bug 1042083, launch time regression r=alive
  • Loading branch information
etiennesegonzac committed Jul 25, 2014
2 parents 730b9da + d3707e2 commit 8532cb6
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 44 deletions.
4 changes: 4 additions & 0 deletions apps/system/js/app_titlebar.js
Expand Up @@ -24,6 +24,10 @@
this._gotName = true;
this.title.textContent = appName;
}

if (this.app.themeColor) {
this.element.style.backgroundColor = this.app.themeColor;
}
};

AppTitleBar.prototype = Object.create(window.BaseUI.prototype);
Expand Down
10 changes: 9 additions & 1 deletion apps/system/js/app_window.js
Expand Up @@ -720,7 +720,15 @@
}

if (!this.config.chrome || !this.config.chrome.bar) {
this.appTitleBar = new self.AppTitleBar(this);
if (this.manifest) {
var that = this;
that.element.addEventListener('_opened', function onOpened() {
that.element.removeEventListener('_opened', onOpened);
that.appTitleBar = new self.AppTitleBar(that);
});
} else {
this.appTitleBar = new self.AppTitleBar(this);
}
}
};

Expand Down
91 changes: 50 additions & 41 deletions apps/system/test/unit/app_titlebar_test.js
Expand Up @@ -35,47 +35,6 @@ suite('system/AppTitleBar', function() {
stubById.returns(document.createElement('div'));
});

suite('mozbrowsermetachange', function() {
var subject = null;
setup(function() {
var app = new AppWindow(fakeApp);
subject = new AppTitleBar(app);
subject._registerEvents();
});

teardown(function() {
subject._unregisterEvents();
});

test('should set background when the meta is added', function() {
subject.element.style.backgroundColor = '';
var evt = new CustomEvent('mozbrowsermetachange', {
detail: {
type: 'added',
name: 'theme-color',
content: 'orange'
}
});
subject.app.element.dispatchEvent(evt);

assert.equal(subject.element.style.backgroundColor, 'orange');
});

test('should remove color when the meta is removed', function() {
subject.element.style.backgroundColor = 'orange';
var evt = new CustomEvent('mozbrowsermetachange', {
detail: {
type: 'removed',
name: 'theme-color',
content: 'orange'
}
});
subject.app.element.dispatchEvent(evt);

assert.equal(subject.element.style.backgroundColor, '');
});
});

suite('mozbrowsertitlechange', function() {
var subject = null;
setup(function() {
Expand Down Expand Up @@ -183,4 +142,54 @@ suite('system/AppTitleBar', function() {
assert.equal(subject.title.textContent, 'Téléphone');
});
});

suite('theme color', function() {
test('should take the current themeColor of the app at init', function() {
var app = new AppWindow(fakeApp);
app.themeColor = 'blue';
var subject = new AppTitleBar(app);
assert.equal(subject.element.style.backgroundColor, 'blue');
});

suite('mozbrowsermetachange', function() {
var subject = null;
setup(function() {
var app = new AppWindow(fakeApp);
subject = new AppTitleBar(app);
subject._registerEvents();
});

teardown(function() {
subject._unregisterEvents();
});

test('should set background when the meta is added', function() {
subject.element.style.backgroundColor = '';
var evt = new CustomEvent('mozbrowsermetachange', {
detail: {
type: 'added',
name: 'theme-color',
content: 'orange'
}
});
subject.app.element.dispatchEvent(evt);

assert.equal(subject.element.style.backgroundColor, 'orange');
});

test('should remove color when the meta is removed', function() {
subject.element.style.backgroundColor = 'orange';
var evt = new CustomEvent('mozbrowsermetachange', {
detail: {
type: 'removed',
name: 'theme-color',
content: 'orange'
}
});
subject.app.element.dispatchEvent(evt);

assert.equal(subject.element.style.backgroundColor, '');
});
});
});
});
12 changes: 10 additions & 2 deletions apps/system/test/unit/app_window_test.js
Expand Up @@ -254,9 +254,17 @@ suite('system/AppWindow', function() {
assert.isFalse(spy.calledWithNew());
});

test('No navigation setting in manifest - titlebar', function() {
test('No navigation setting in manifest - app - titlebar', function() {
var spy = this.sinon.spy(window, 'AppTitleBar');
new AppWindow(fakeChromeConfigWithoutNavigation); // jshint ignore:line
var aw = new AppWindow(fakeChromeConfigWithoutNavigation);
assert.isFalse(spy.calledWithNew());
aw.element.dispatchEvent(new CustomEvent('_opened'));
assert.isTrue(spy.calledWithNew());
});

test('No navigation setting in manifest - wrapper - titlebar', function() {
var spy = this.sinon.spy(window, 'AppTitleBar');
new AppWindow(fakeWrapperConfig); // jshint ignore:line
assert.isTrue(spy.calledWithNew());
});

Expand Down

0 comments on commit 8532cb6

Please sign in to comment.