diff --git a/tests/boomerang-test-framework.js b/tests/boomerang-test-framework.js index 8458d2187..21bf77af1 100644 --- a/tests/boomerang-test-framework.js +++ b/tests/boomerang-test-framework.js @@ -262,7 +262,17 @@ assert.isString(tf.lastBeacon().v); done(); - } + }; + + t.canSetCookies = function() { + var testCookieName = "test_cookie"; + + // set a cookie + document.cookie = [testCookieName + "=true", "path=/", "domain=" + location.hostname].join("; "); + + // determine if it was set OK + return (" " + document.cookie + ";").indexOf(" " + testCookieName + "=") !== -1; + }; window.BOOMR_test = t; diff --git a/tests/page-templates/04-page-params/04-custom-dimensions-cookies.js b/tests/page-templates/04-page-params/04-custom-dimensions-cookies.js index 6575fda0f..996594437 100644 --- a/tests/page-templates/04-page-params/04-custom-dimensions-cookies.js +++ b/tests/page-templates/04-page-params/04-custom-dimensions-cookies.js @@ -5,9 +5,6 @@ describe("e2e/04-page-params/04-custom-dimensions-cookies", function() { var tf = BOOMR.plugins.TestFramework; var t = BOOMR_test; - var dom = location.hostname; - var onDomain = !(!dom || dom === "localhost" || dom.match(/\.\d+$/) || dom.match(/^mhtml/) || dom.match(/^file:\//)); - it("Should pass basic beacon validation", function(done) { t.validateBeaconWasSent(done); }); @@ -17,15 +14,15 @@ describe("e2e/04-page-params/04-custom-dimensions-cookies", function() { assert.equal(b["cdim.CD1"], undefined); }); - it("Should be have custom dimension 2 - Cookie - If running on a domain", function() { - if (onDomain) { + it("Should be have custom dimension 2 - Cookie - If cookies can be set (on a domain or in PhantomJS)", function() { + if (t.canSetCookies()) { var b = tf.lastBeacon(); assert.equal(b["cdim.CD2"], "true"); } }); - it("Should be missing custom dimension 2 - Cookie - If running on localhost or an IP", function() { - if (!onDomain) { + it("Should be missing custom dimension 2 - Cookie - If cookies can't be set (on localhost or an IP)", function() { + if (!t.canSetCookies()) { var b = tf.lastBeacon(); assert.equal(b["cdim.CD2"], undefined); }