mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 01:05:45 +00:00
Bug 1078718 - Force standalone app reload on hashchange event. r=Standard8
This commit is contained in:
parent
d1e334365e
commit
f20575cd52
@ -26,6 +26,37 @@ loop.shared.mixins = (function() {
|
|||||||
rootObject = obj;
|
rootObject = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* window.location mixin. Handles changes in the call url.
|
||||||
|
* Forces a reload of the page to ensure proper state of the webapp
|
||||||
|
*
|
||||||
|
* @type {Object}
|
||||||
|
*/
|
||||||
|
var UrlHashChangeMixin = {
|
||||||
|
propTypes: {
|
||||||
|
onUrlHashChange: React.PropTypes.func.isRequired
|
||||||
|
},
|
||||||
|
|
||||||
|
componentDidMount: function() {
|
||||||
|
rootObject.addEventListener("hashchange", this.onUrlHashChange, false);
|
||||||
|
},
|
||||||
|
|
||||||
|
componentWillUnmount: function() {
|
||||||
|
rootObject.removeEventListener("hashchange", this.onUrlHashChange, false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Document location mixin.
|
||||||
|
*
|
||||||
|
* @type {Object}
|
||||||
|
*/
|
||||||
|
var DocumentLocationMixin = {
|
||||||
|
locationReload: function() {
|
||||||
|
rootObject.location.reload();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dropdown menu mixin.
|
* Dropdown menu mixin.
|
||||||
* @type {Object}
|
* @type {Object}
|
||||||
@ -151,6 +182,8 @@ loop.shared.mixins = (function() {
|
|||||||
AudioMixin: AudioMixin,
|
AudioMixin: AudioMixin,
|
||||||
setRootObject: setRootObject,
|
setRootObject: setRootObject,
|
||||||
DropdownMenuMixin: DropdownMenuMixin,
|
DropdownMenuMixin: DropdownMenuMixin,
|
||||||
DocumentVisibilityMixin: DocumentVisibilityMixin
|
DocumentVisibilityMixin: DocumentVisibilityMixin,
|
||||||
|
DocumentLocationMixin: DocumentLocationMixin,
|
||||||
|
UrlHashChangeMixin: UrlHashChangeMixin
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
@ -859,6 +859,10 @@ loop.webapp = (function($, _, OT, mozL10n) {
|
|||||||
* of the webapp page.
|
* of the webapp page.
|
||||||
*/
|
*/
|
||||||
var WebappRootView = React.createClass({displayName: 'WebappRootView',
|
var WebappRootView = React.createClass({displayName: 'WebappRootView',
|
||||||
|
|
||||||
|
mixins: [sharedMixins.UrlHashChangeMixin,
|
||||||
|
sharedMixins.DocumentLocationMixin],
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
client: React.PropTypes.instanceOf(loop.StandaloneClient).isRequired,
|
client: React.PropTypes.instanceOf(loop.StandaloneClient).isRequired,
|
||||||
conversation: React.PropTypes.oneOfType([
|
conversation: React.PropTypes.oneOfType([
|
||||||
@ -879,6 +883,10 @@ loop.webapp = (function($, _, OT, mozL10n) {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onUrlHashChange: function() {
|
||||||
|
this.locationReload();
|
||||||
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
if (this.state.unsupportedDevice) {
|
if (this.state.unsupportedDevice) {
|
||||||
return UnsupportedDeviceView(null);
|
return UnsupportedDeviceView(null);
|
||||||
|
@ -859,6 +859,10 @@ loop.webapp = (function($, _, OT, mozL10n) {
|
|||||||
* of the webapp page.
|
* of the webapp page.
|
||||||
*/
|
*/
|
||||||
var WebappRootView = React.createClass({
|
var WebappRootView = React.createClass({
|
||||||
|
|
||||||
|
mixins: [sharedMixins.UrlHashChangeMixin,
|
||||||
|
sharedMixins.DocumentLocationMixin],
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
client: React.PropTypes.instanceOf(loop.StandaloneClient).isRequired,
|
client: React.PropTypes.instanceOf(loop.StandaloneClient).isRequired,
|
||||||
conversation: React.PropTypes.oneOfType([
|
conversation: React.PropTypes.oneOfType([
|
||||||
@ -879,6 +883,10 @@ loop.webapp = (function($, _, OT, mozL10n) {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onUrlHashChange: function() {
|
||||||
|
this.locationReload();
|
||||||
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
if (this.state.unsupportedDevice) {
|
if (this.state.unsupportedDevice) {
|
||||||
return <UnsupportedDeviceView />;
|
return <UnsupportedDeviceView />;
|
||||||
|
@ -21,6 +21,75 @@ describe("loop.shared.mixins", function() {
|
|||||||
sandbox.restore();
|
sandbox.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("loop.webapp.UrlHashChangeMixin", function() {
|
||||||
|
function createTestComponent(onUrlHashChange) {
|
||||||
|
var TestComp = React.createClass({
|
||||||
|
mixins: [loop.shared.mixins.UrlHashChangeMixin],
|
||||||
|
onUrlHashChange: onUrlHashChange || function(){},
|
||||||
|
render: function() {
|
||||||
|
return React.DOM.div();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return new TestComp();
|
||||||
|
}
|
||||||
|
|
||||||
|
it("should watch for hashchange event", function() {
|
||||||
|
var addEventListener = sandbox.spy();
|
||||||
|
sharedMixins.setRootObject({
|
||||||
|
addEventListener: addEventListener
|
||||||
|
});
|
||||||
|
|
||||||
|
TestUtils.renderIntoDocument(createTestComponent());
|
||||||
|
|
||||||
|
sinon.assert.calledOnce(addEventListener);
|
||||||
|
sinon.assert.calledWith(addEventListener, "hashchange");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call onUrlHashChange when the url is updated", function() {
|
||||||
|
sharedMixins.setRootObject({
|
||||||
|
addEventListener: function(name, cb) {
|
||||||
|
if (name === "hashchange") {
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var onUrlHashChange = sandbox.stub();
|
||||||
|
|
||||||
|
TestUtils.renderIntoDocument(createTestComponent(onUrlHashChange));
|
||||||
|
|
||||||
|
sinon.assert.calledOnce(onUrlHashChange);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("loop.webapp.DocumentLocationMixin", function() {
|
||||||
|
var reloadStub, TestComp;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
reloadStub = sandbox.stub();
|
||||||
|
|
||||||
|
sharedMixins.setRootObject({
|
||||||
|
location: {
|
||||||
|
reload: reloadStub
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
TestComp = React.createClass({
|
||||||
|
mixins: [loop.shared.mixins.DocumentLocationMixin],
|
||||||
|
render: function() {
|
||||||
|
return React.DOM.div();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call window.location.reload", function() {
|
||||||
|
var comp = TestUtils.renderIntoDocument(TestComp());
|
||||||
|
|
||||||
|
comp.locationReload();
|
||||||
|
|
||||||
|
sinon.assert.calledOnce(reloadStub);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("loop.panel.DocumentVisibilityMixin", function() {
|
describe("loop.panel.DocumentVisibilityMixin", function() {
|
||||||
var comp, TestComp, onDocumentVisibleStub, onDocumentHiddenStub;
|
var comp, TestComp, onDocumentVisibleStub, onDocumentHiddenStub;
|
||||||
|
|
||||||
|
@ -514,7 +514,8 @@ describe("loop.webapp", function() {
|
|||||||
notifications: notifications,
|
notifications: notifications,
|
||||||
sdk: sdk,
|
sdk: sdk,
|
||||||
conversation: conversationModel,
|
conversation: conversationModel,
|
||||||
feedbackApiClient: feedbackApiClient
|
feedbackApiClient: feedbackApiClient,
|
||||||
|
onUrlHashChange: sandbox.stub()
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user