From c5efbb12f90e3dbbfb5a99e6145e4c0cb210ab97 Mon Sep 17 00:00:00 2001 From: Ben Adida <ben@adida.net> Date: Tue, 20 Dec 2011 12:05:50 -0800 Subject: [PATCH] revived the navigator.id.channel, as well as the #NATIVE and #INTERNAL indications that internal APIs are about to be called --- resources/static/dialog/controllers/dialog.js | 12 +++++ .../qunit/controllers/dialog_unit_test.js | 49 +++++++++++++++++-- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/resources/static/dialog/controllers/dialog.js b/resources/static/dialog/controllers/dialog.js index e570e4e71..0cc46aab5 100644 --- a/resources/static/dialog/controllers/dialog.js +++ b/resources/static/dialog/controllers/dialog.js @@ -74,6 +74,18 @@ BrowserID.Modules.Dialog = (function() { function startChannel() { var self = this; + // first, we see if there is a local channel + if (win.navigator.id && win.navigator.id.channel) { + win.navigator.id.channel.registerController(self); + return; + } + + // next, we see if the caller intends to call native APIs + if (win.location.hash == "#NATIVE" || win.location.hash == "#INTERNAL") { + // don't do winchan, let it be. + return; + } + try { // WinChan.onOpen(function(origin, args, cb) { diff --git a/resources/static/test/qunit/controllers/dialog_unit_test.js b/resources/static/test/qunit/controllers/dialog_unit_test.js index d2d04bee3..dca71d36c 100644 --- a/resources/static/test/qunit/controllers/dialog_unit_test.js +++ b/resources/static/test/qunit/controllers/dialog_unit_test.js @@ -72,10 +72,10 @@ }, location: { - } - + }, - } + navigator: {}, + }; function createController(config) { var config = $.extend({ @@ -116,6 +116,49 @@ }); }); + asyncTest("initialization with add-on navigator.id.channel", function() { + var ok_p = false; + + // expect registerController to be called. + winMock.navigator.id = { + channel : { + registerController: function(controller) { + ok_p = controller.getVerifiedEmail && controller.get; + } + } + }; + + createController({ + ready: function() { + ok(ok_p, "registerController was not called with proper controller"); + start(); + } + }); + }); + + asyncTest("initialization with #NATIVE", function() { + winMock.location.hash = "#NATIVE"; + + createController({ + ready: function() { + ok($("#error .contents").text().length == 0, "no error should be reported"); + start(); + } + }); + }); + + + asyncTest("initialization with #INTERNAL", function() { + winMock.location.hash = "#INTERNAL"; + + createController({ + ready: function() { + ok($("#error .contents").text().length == 0, "no error should be reported"); + start(); + } + }); + }); + /* test("doXHRError while online, no network info given", function() { createController(); -- GitLab