diff --git a/resources/static/shared/network.js b/resources/static/shared/network.js index be58ccc312ca02b373365023ce7121e82b64da58..a91dc475e0885c4b463f635d858bfb7f5f32e6c5 100644 --- a/resources/static/shared/network.js +++ b/resources/static/shared/network.js @@ -577,10 +577,11 @@ BrowserID.Network = (function() { // http://stackoverflow.com/questions/8509387/android-browser-not-respecting-cookies-disabled/9264996#9264996 document.cookie = "test=true; max-age=1"; var enabled = document.cookie.indexOf("test") > -1; - complete(onComplete, enabled); } catch(e) { - complete(onComplete, false); + enabled = false; } + + complete(onComplete, enabled); }, onFailure); } }; diff --git a/resources/static/test/cases/shared/network.js b/resources/static/test/cases/shared/network.js index 64e6b809ff5e587981d73fc1ceb7ed77c21d8057..c30bcf46dc557e44b4dd934e7c4bc77f0995d058 100644 --- a/resources/static/test/cases/shared/network.js +++ b/resources/static/test/cases/shared/network.js @@ -548,4 +548,21 @@ }, testHelpers.unexpectedXHRFailure); }); + asyncTest("cookiesEnabled with onComplete exception thrown - should not call onComplete a second time", function() { + // Since we are manually throwing an exception, it must be caught + // below. + try { + network.cookiesEnabled(function(status) { + // if there is a problem, this callback will be called a second time + // with a false status. + equal(status, true, "cookies are enabled, correct status"); + start(); + + throw "callback exception"; + }, testHelpers.unexpectedXHRFailure); + } catch(e) { + equal(e.toString(), "callback exception", "correct exception caught"); + } + }); + }());