diff --git a/resources/static/dialog/resources/channel.js b/resources/static/dialog/resources/channel.js index 99dd6d836630eb04dde0d573a6b696f4ba87672e..b8ba0f92c790ede7a170862535b570ce06f7c468 100644 --- a/resources/static/dialog/resources/channel.js +++ b/resources/static/dialog/resources/channel.js @@ -83,7 +83,13 @@ // (has window.opener) as well as whether the relay function exists. // If these conditions are not met, then print an appropriate message. _relayName = getRelayName(); - if(_relayName !== "NATIVE") { + + // If the relay name is NATIVE, that means do nothing because the + // channel will be set up by the dialog implementer. + if(_relayName === "NATIVE") { + // In a native channel, do nothing. + } + else { var REGISTERED_METHODS = { 'get': function(origin, params, onsuccess, onerror) { // check for old controller methods @@ -104,10 +110,6 @@ frameWindow.BrowserID.Relay.registerClient(REGISTERED_METHODS); } else { - // Only run if we are searching for the IFRAME. If the relay name is - // NATIVE, that means that either the channel has already been set up - // before this or it will be set up after this. Since the relay name is - // native, do not throw an exception. throw "relay frame not found"; } } diff --git a/resources/static/dialog/resources/internal_api.js b/resources/static/dialog/resources/internal_api.js index 29bdd85d297ac251f83a7dd289b8b0ec85057f79..b0faf8f9708f8a49afb3f509d1dc541a0a0abcb2 100644 --- a/resources/static/dialog/resources/internal_api.js +++ b/resources/static/dialog/resources/internal_api.js @@ -69,15 +69,15 @@ /** * Get an assertion. Mimics the behavior of navigator.id.get. - * options.silent defaults to true. To use the dialog to get an assertion, - * set options.silent to false. To specify a required email, set + * options.silent defaults to false. To get an assertion without using the + * dialog, set options.silent to true. To specify a required email, set * options.requiredEmail. By specifying both silent:true and requiredEmail: * <email>, an assertion will be attempted to be retreived for the given - * email. + * email without showing the dialog. * @method get * @param {string} origin * @param {object} options. See options block for navigator.id.get. - * options.silent defaults to true. + * options.silent defaults to false. * @param {function} callback - called when complete. Called with assertion * if success, null if the user cancels. Other conditions causing null * return value: silent is true and user is not authenticated. silent is @@ -89,7 +89,9 @@ callback && callback(assertion || null); } - var silent = options.silent !== false; + options = options || {}; + + var silent = !!options.silent; if(silent) { // first, check the required email field, if that is not specified, go // check if an email is associated with this site. If that is not diff --git a/resources/static/test/qunit/resources/internal_api_unit_test.js b/resources/static/test/qunit/resources/internal_api_unit_test.js index e4d01bedc41e9c9259b0f83c0b123fbb890aaf6c..197420f3013765718c2c21c6132fa6542968b21e 100644 --- a/resources/static/test/qunit/resources/internal_api_unit_test.js +++ b/resources/static/test/qunit/resources/internal_api_unit_test.js @@ -86,7 +86,8 @@ asyncTest("BrowserID.internal.get with silent: true, non-authenticated user - returns null assertion", function() { internal.get(origin, { - requiredEmail: "testuser@testuser.com" + requiredEmail: "testuser@testuser.com", + silent: true }, function(assertion) { strictEqual(assertion, null, "user not logged in, assertion impossible to get"); start(); @@ -95,7 +96,9 @@ asyncTest("BrowserID.internal.get with silent: true, authenticated user, no requiredEmail, and no email address associated with site - not enough info to generate an assertion", function() { user.authenticate("testuser@testuser.com", "password", function() { - internal.get(origin, {}, function(assertion) { + internal.get(origin, { + silent: true + }, function(assertion) { strictEqual(assertion, null, "not enough info to generate an assertion, assertion should not be generated"); start(); }); @@ -109,7 +112,9 @@ xhr.useResult("invalid"); - internal.get(origin, {}, function(assertion) { + internal.get(origin, { + silent: true + }, function(assertion) { strictEqual(assertion, null, "XHR failure while getting assertion"); start(); }); @@ -122,7 +127,9 @@ user.syncEmails(function() { storage.site.set(origin, "email", "testuser@testuser.com"); - internal.get(origin, {}, function(assertion) { + internal.get(origin, { + silent: true + }, function(assertion) { ok(assertion, "assertion generated using stored email address for site."); start(); }); @@ -135,6 +142,7 @@ // email addresses will not be synced just because we authenticated. // Depending on get to do the sync. internal.get(origin, { + silent: true, requiredEmail: "invalid@testuser.com" }, function(assertion) { strictEqual(assertion, null, "uncontrolled email address returns null assertion"); @@ -147,6 +155,7 @@ user.authenticate("testuser@testuser.com", "password", function() { xhr.useResult("invalid"); internal.get(origin, { + silent: true, requiredEmail: "invalid@testuser.com" }, function(assertion) { strictEqual(assertion, null, "unregistered email address returns null assertion"); @@ -158,6 +167,7 @@ asyncTest("BrowserID.internal.get with silent: true, authenticated user, requiredEmail, and registered email address - return an assertion", function() { user.authenticate("testuser@testuser.com", "password", function() { internal.get(origin, { + silent: true, requiredEmail: "testuser@testuser.com" }, function(assertion) { ok(assertion, "assertion has been returned"); @@ -166,25 +176,27 @@ }); }); - asyncTest("BrowserID.internal.get with dialog - return an assertion", function() { + asyncTest("BrowserID.internal.get with dialog - simulate the user return of an assertion", function() { moduleManager.reset(); + var controllerOrigin; + moduleManager.register("dialog", { get: function(getOrigin, options, onsuccess, onerror) { - equal(getOrigin, origin, "correct origin passed"); - onsuccess("assertion"); + controllerOrigin = getOrigin; + // simulate the full dialog flow. + onsuccess("simulated_assertion"); } }); - internal.get(origin, { - silent: false - }, function onComplete(assertion) { - equal(assertion, "assertion", "Kosher assertion"); + internal.get(origin, {}, function onComplete(assertion) { + equal(controllerOrigin, origin, "correct origin passed"); + equal(assertion, "simulated_assertion", "Kosher assertion"); start(); }); }); - asyncTest("BrowserID.internal.get with dialog with failure - return null assertion", function() { + asyncTest("BrowserID.internal.get with dialog with failure - simulate the return of a null assertion", function() { moduleManager.reset(); moduleManager.register("dialog", { @@ -193,9 +205,7 @@ } }); - internal.get(origin, { - silent: false - }, function onComplete(assertion) { + internal.get(origin, {}, function onComplete(assertion) { equal(assertion, null, "on failure, assertion is null"); start(); }); @@ -210,9 +220,7 @@ } }); - internal.get(origin, { - silent: false - }, function onComplete(assertion) { + internal.get(origin, {}, function onComplete(assertion) { equal(assertion, null, "on cancel, assertion is null"); start(); });