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 #30536 from alivedise/bugzilla/1102675/send-activi…
Browse files Browse the repository at this point in the history
…ty-window-opener-to-background

Bug 1144132 - Activity opener visibility state r=etienne,schung
  • Loading branch information
gabrielesvelto committed Jun 24, 2015
2 parents 4d7da51 + bb54ada commit eb0d4ae
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 8 deletions.
2 changes: 1 addition & 1 deletion apps/sms/test/marionette/drafts_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ marionette('Messages Drafts', function() {
messagesApp.switchTo();
messagesApp.performHeaderAction();

messagesApp.selectAppMenuOption('Save as Draft');
messagesApp.selectAppMenuOption('Replace existing Draft');
}

function assertDraft(draft) {
Expand Down
5 changes: 3 additions & 2 deletions apps/system/js/app_window.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,11 @@
* _hideScreenshotOverlay.
*/
AppWindow.prototype.setVisible =
function aw_setVisible(visible) {
function aw_setVisible(visible, doNotPropagate) {
this.setVisibleForScreenReader(visible);
if (this.frontWindow) {
if (!doNotPropagate && this.frontWindow && this.frontWindow.isActive()) {
this.frontWindow.setVisible(visible);
return;
}

if (this._visible === visible) {
Expand Down
3 changes: 2 additions & 1 deletion apps/system/js/app_window_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,8 @@

_handle_launchactivity: function(evt) {
if (evt.detail.isActivity && evt.detail.inline && this._activeApp) {
this._activeApp.broadcast('launchactivity', evt.detail);
this._activeApp.getTopMostWindow().broadcast('launchactivity',
evt.detail);
return false;
}
return true;
Expand Down
15 changes: 14 additions & 1 deletion apps/system/js/child_window_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,26 @@
return true;
};

ChildWindowFactory.prototype._handle_child__opened = function(evt) {
// Do nothing if we are not active or we are being killing.
if (!this.app.isVisible() || this.app._killed) {
return;
}

this.app.setVisible(false, true);
};

ChildWindowFactory.prototype._handle_child__closing = function(evt) {
// Do nothing if we are not active or we are being killing.
if (!this.app.isVisible() || this.app._killed) {
return;
}

this.app.setOrientation();
this.app.requestForeground();
if (Service.query('getTopMostWindow').getBottomMostWindow() ===
this.app.getBottomMostWindow()) {
this.app.setVisible(true, true);
}

// An activity handled by ActivityWindow is always an inline activity.
// All window activities are handled by AppWindow. All inline
Expand All @@ -261,6 +273,7 @@
top.setNFCFocus(false);
var activity = new ActivityWindow(configuration, top);
activity.element.addEventListener('_closing', this);
activity.element.addEventListener('_opened', this);
activity.open();
// Make topmost window browser element invisibile to screen reader.
top._setVisibleForScreenReader(false);
Expand Down
21 changes: 21 additions & 0 deletions apps/system/test/unit/app_window_manager_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ suite('system/AppWindowManager', function() {
parentApp: ''
};

var fakeActivityConfigInline = {
url: 'app://www.fake8/index.html',
manifest: {},
manifestURL: 'app://wwww.fake8/ManifestURL',
origin: 'app://www.fake8',
isActivity: true,
parentApp: '',
inline: true
};

var fakeBrowserConfig = {
url: 'http://mozilla.org/index.html',
manifest: {},
Expand Down Expand Up @@ -545,6 +555,17 @@ suite('system/AppWindowManager', function() {

});

test('Launch activity dispatched on top most window', function() {
subject._activeApp = app1;
this.sinon.stub(app1, 'getTopMostWindow').returns(app2);
this.sinon.stub(app2, 'broadcast');

subject.handleEvent(
{ type: 'launchactivity', detail: fakeActivityConfigInline });
assert.isTrue(app2.broadcast.calledWith('launchactivity',
fakeActivityConfigInline));
});

test('Launch app', function() {
var stubLaunch =
this.sinon.stub(subject, 'launch');
Expand Down
14 changes: 14 additions & 0 deletions apps/system/test/unit/app_window_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,7 @@ suite('system/AppWindow', function() {

var stubApp2SetVisible = this.sinon.stub(app2, 'setVisible');
app1.frontWindow = app2;
this.sinon.stub(app2, 'isActive').returns(true);
app2.rearWindow = app1;

app1.setVisible(true);
Expand All @@ -1508,6 +1509,19 @@ suite('system/AppWindow', function() {
assert.isTrue(stubApp2SetVisible.calledWith(false));
});

test('doNotPropagate', function() {
var app1 = new AppWindow(fakeAppConfig1);
var app2 = new AppWindow(fakeAppConfig2);
app1.setVisible(false);

this.sinon.stub(app2, 'setVisible');
app1.frontWindow = app2;
this.sinon.stub(app2, 'isActive').returns(true);
app2.rearWindow = app1;
app1.setVisible(true, true);
assert.isFalse(app2.setVisible.called);
});

test('setVisible: homescreen', function() {
var app1 = new AppWindow(fakeAppConfig1);
injectFakeMozBrowserAPI(app1.browser.element);
Expand Down
23 changes: 21 additions & 2 deletions apps/system/test/unit/child_window_factory_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,24 @@ suite('system/ChildWindowFactory', function() {
assert.isFalse(spy.calledWithNew());
});

test('opened of activity should hide the back', function() {
var app1 = new MockAppWindow(fakeAppConfig1);
var spy = this.sinon.spy(window, 'ActivityWindow');
app1.cwf = new ChildWindowFactory(app1);
this.sinon.stub(app1, 'isActive').returns(true);
this.sinon.stub(app1, 'isVisible').returns(true);
app1.element.dispatchEvent(new CustomEvent('_launchactivity',
{
detail: fakeActivityDetail
}));
this.sinon.stub(app1, 'setVisible');
var activity = spy.getCall(0).returnValue;
activity.element.dispatchEvent(new CustomEvent('_opened', {
detail: spy.getCall(0).returnValue
}));
assert.isTrue(app1.setVisible.calledWith(false, true));
});

test('closing of popup should resume visibility and orientation', function() {
MockSettingsListener.mCallbacks['in-app-sheet.enabled'](false);
var app1 = new MockAppWindow(fakeAppConfig1);
Expand All @@ -370,18 +388,19 @@ suite('system/ChildWindowFactory', function() {
this.sinon.stub(app1, 'isActive').returns(true);
this.sinon.stub(app1, 'isVisible').returns(true);
this.sinon.spy(app1, '_setVisibleForScreenReader');
MockService.mockQueryWith('getTopMostWindow', app1);
cwf.handleEvent(new CustomEvent('mozbrowseropenwindow',
{
detail: fakeWindowOpenPopup
}));
var stubSetOrientation = this.sinon.stub(app1, 'setOrientation');
var stubRequestForeground = this.sinon.stub(app1, 'requestForeground');
this.sinon.stub(app1, 'setVisible');
spy.getCall(0).returnValue.element
.dispatchEvent(new CustomEvent('_closing', {
detail: spy.getCall(0).returnValue
}));
assert.isTrue(stubSetOrientation.called);
assert.isTrue(stubRequestForeground.called);
assert.isTrue(app1.setVisible.calledWith(true, true));
sinon.assert.calledWith(app1._setVisibleForScreenReader, true);
});

Expand Down
4 changes: 3 additions & 1 deletion apps/system/test/unit/mock_app_window.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@
setActive: function() {},
getSSLState: function() { return ''; },
getCachedScreenshotBlob: function() {},
requestScreenshotURL: function() {}
requestScreenshotURL: function() {},
_showFrame: function() {},
_hideFrame: function() {}
};

MockAppWindow.addMixin = function() {};
Expand Down

0 comments on commit eb0d4ae

Please sign in to comment.