Skip to content

Commit

Permalink
Merge pull request YahooArchive#46 from SOASTA/04-custom-dimensions-c…
Browse files Browse the repository at this point in the history
…ookies-fix

Test if a cookie can be set to determine which branch to test, as PhantomJS can set cookies on localhost.

Reviewed by: @cvazac
  • Loading branch information
nicjansma committed Apr 24, 2015
2 parents 5434b15 + 53a7639 commit f97eb55
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
12 changes: 11 additions & 1 deletion tests/boomerang-test-framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
}
Expand Down

0 comments on commit f97eb55

Please sign in to comment.