diff --git a/resources/static/shared/network.js b/resources/static/shared/network.js index ce84f5616a89d131fbfccd70e9a04056af01f12e..be58ccc312ca02b373365023ce7121e82b64da58 100644 --- a/resources/static/shared/network.js +++ b/resources/static/shared/network.js @@ -13,7 +13,6 @@ BrowserID.Network = (function() { domain_key_creation_time, auth_status, code_version, - cookies_enabled, time_until_delay, mediator = bid.Mediator, xhr = bid.XHR, @@ -29,7 +28,6 @@ BrowserID.Network = (function() { domain_key_creation_time = result.domain_key_creation_time; auth_status = result.auth_level; code_version = result.code_version; - cookies_enabled = result.cookies_enabled || true; // seed the PRNG // FIXME: properly abstract this out, probably by exposing a jwcrypto @@ -570,8 +568,19 @@ BrowserID.Network = (function() { * @method cookiesEnabled */ cookiesEnabled: function(onComplete, onFailure) { + // Make sure we get context first or else we will needlessly send + // a cookie to the server. withContext(function() { - complete(onComplete, cookies_enabled); + try { + // set a test cookie with a duration of 1 second. + // NOTE - The Android 3.3 default browser will still pass this. + // 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); + } }, onFailure); } }; diff --git a/resources/static/test/cases/shared/network.js b/resources/static/test/cases/shared/network.js index ba08d8f894ccc074c6421e2a42416aa9b79560c7..64e6b809ff5e587981d73fc1ceb7ed77c21d8057 100644 --- a/resources/static/test/cases/shared/network.js +++ b/resources/static/test/cases/shared/network.js @@ -541,18 +541,11 @@ failureCheck(network.changePassword, "oldpassword", "newpassword"); }); - asyncTest("cookiesEnabled with cookies enabled", function() { - transport.setContextInfo("cookies_enabled", true); - + asyncTest("cookiesEnabled with cookies enabled - return true status", function() { network.cookiesEnabled(function(status) { equal(status, true, "cookies are enabled, correct status"); start(); }, testHelpers.unexpectedXHRFailure); }); - asyncTest("cookiesEnabled with XHR failure", function() { - transport.useResult("contextAjaxError"); - failureCheck(network.cookiesEnabled); - }); - }());