Skip to content

Commit aa65bb2

Browse files
committed
Look up notifier in the registry
Extension modules should look up implementations of particular interfaces in the application registry, not by magic keyword on the application itself.
1 parent f6c1106 commit aa65bb2

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/ext/unsupported.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,24 @@ function unsupported() {
4545
// Reference as exports.checkSupport so that we can stub it for testing.
4646
var result = exports.checkSupport();
4747

48+
function fallback(message, severity) {
49+
if (severity === annotator.notification.ERROR) {
50+
console.error(message);
51+
return;
52+
}
53+
console.log(message);
54+
}
55+
4856
function notifyUser(app) {
4957
if (result.supported) {
5058
return;
5159
}
60+
var notify = app.registry.queryUtility('notifier') || fallback;
5261
var msg;
5362
msg = _t("Sorry, Annotator does not currently support your browser! ");
5463
msg += _t("Errors: ");
5564
msg += result.errors.join(", ");
56-
app.notify(msg);
65+
notify(msg);
5766
}
5867

5968
return {

test/spec/ext/unsupported_spec.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,16 @@ describe("unsupported.checkSupport()", function () {
5959

6060

6161
describe('annotator.ext.unsupported module', function () {
62+
var mockNotify;
6263
var mockApp;
6364
var sandbox = sinon.sandbox.create();
6465

6566
beforeEach(function () {
67+
mockNotify = sandbox.stub();
6668
mockApp = {
67-
notify: sandbox.stub()
69+
registry: {
70+
queryUtility: sandbox.stub().withArgs('notifier').returns(mockNotify)
71+
}
6872
};
6973

7074
sandbox.stub(unsupported, 'checkSupport').returns({
@@ -82,7 +86,7 @@ describe('annotator.ext.unsupported module', function () {
8286
plugin.start(mockApp);
8387

8488
sinon.assert.calledWith(
85-
mockApp.notify,
89+
mockNotify,
8690
sinon.match('widgets are discombobulated')
8791
);
8892
});

0 commit comments

Comments
 (0)