Skip to content

Commit

Permalink
Merge pull request mozilla-b2g#24308 from nullaus/bug1062136
Browse files Browse the repository at this point in the history
bug 1062136 - getScreenshot should check for frontWindow. r=alive
  • Loading branch information
nullaus committed Sep 24, 2014
2 parents 2f7e36d + e74b637 commit ec32f3e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions apps/system/js/browser_mixin.js
Expand Up @@ -80,6 +80,13 @@
var invoked = false;
var timer;

// First, let's check if we have a frontWindow, if so this is the one
// we will want a screenshot of!
if (this.frontWindow && this.frontWindow.isActive()) {
this.frontWindow.getScreenshot(callback, width, height, timeout);
return;
}

if (timeout) {
timer = window.setTimeout(function() {
if (invoked) {
Expand Down
34 changes: 34 additions & 0 deletions apps/system/test/unit/app_window_test.js
Expand Up @@ -938,6 +938,40 @@ suite('system/AppWindow', function() {
assert.isTrue(callback1.called);
});

test('MozBrowser API: getScreenshot (with frontWindow active)', function() {
var app1 = new AppWindow(fakeAppConfig1);
var app2 = new AppWindow(fakeAppConfig2);

injectFakeMozBrowserAPI(app1.browser.element);
injectFakeMozBrowserAPI(app2.browser.element);
var stubScreenshot = this.sinon.stub(app1.browser.element,
'getScreenshot');
var stubScreenshot2 = this.sinon.stub(app2.browser.element,
'getScreenshot');
this.sinon.stub(app2, 'isActive', function() { return true; });

var fakeDOMRequest = {
onsuccess: function() {},
onerror: function() {}
};

stubScreenshot.returns(fakeDOMRequest);
stubScreenshot2.returns(fakeDOMRequest);

var callback1 = this.sinon.spy();
app1.frontWindow = app2;
app1.getScreenshot(callback1);

assert.isFalse(stubScreenshot.called);
assert.isTrue(stubScreenshot2.called);
fakeDOMRequest.onsuccess({ target: { result: 'fakeBlob' } });
assert.equal(app2._screenshotBlob, 'fakeBlob');
assert.isTrue(callback1.calledWith('fakeBlob'));

fakeDOMRequest.onerror();
assert.isTrue(callback1.called);
});

test('MozBrowser API: getGoForward', function() {
var app1 = new AppWindow(fakeAppConfig1);
injectFakeMozBrowserAPI(app1.browser.element);
Expand Down

0 comments on commit ec32f3e

Please sign in to comment.