Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKate Butler <kate@innocraft.com>2019-12-31 05:55:03 +0300
committerThomas Steur <tsteur@users.noreply.github.com>2019-12-31 05:55:03 +0300
commit8aeaee6c84dfb504decaae79f2012ec01a6a0e83 (patch)
tree5b91998a3833968bf36a97d86e40d9b5530b2280 /tests/javascript
parentcdf8d6b2a02a4dd24e1f6b719d83cb38bddd79ef (diff)
Set a first-party cookie when user opts out of tracking (#15184)
Diffstat (limited to 'tests/javascript')
-rw-r--r--tests/javascript/index.php61
-rw-r--r--tests/javascript/matomotest.js2
2 files changed, 61 insertions, 2 deletions
diff --git a/tests/javascript/index.php b/tests/javascript/index.php
index 70826b0c26..900aa2dcbe 100644
--- a/tests/javascript/index.php
+++ b/tests/javascript/index.php
@@ -2149,7 +2149,7 @@ function PiwikTest() {
});
test("API methods", function() {
- expect(109);
+ expect(110);
equal( typeof Piwik.addPlugin, 'function', 'addPlugin' );
equal( typeof Piwik.addPlugin, 'function', 'addTracker' );
@@ -2263,6 +2263,7 @@ function PiwikTest() {
// consent
equal( typeof tracker.getRememberedConsent, 'function', 'getRememberedConsent' );
equal( typeof tracker.hasRememberedConsent, 'function', 'hasRememberedConsent' );
+ equal( typeof tracker.isConsentRequired, 'function', 'isConsentRequired' );
equal( typeof tracker.requireConsent, 'function', 'requireConsent' );
equal( typeof tracker.setConsentGiven, 'function', 'setConsentGiven' );
equal( typeof tracker.rememberConsentGiven, 'function', 'rememberConsentGiven' );
@@ -4930,7 +4931,7 @@ if ($mysql) {
});
test("Test API - consent", function() {
- expect(27);
+ expect(29);
var queue;
var tracker = Piwik.getTracker();
@@ -4940,7 +4941,10 @@ if ($mysql) {
strictEqual(tracker.getRememberedConsent(), null, "getConsentRequestsQueue, does not return consent cookie content as no consent given" );
strictEqual(tracker.hasConsent(), true, "hasConsent, assumes consent by default" );
+ ok(!tracker.isConsentRequired(), 'by default consent is not required')
tracker.requireConsent();
+
+ ok(tracker.isConsentRequired(), 'consent is required after requiring it')
deepEqual(tracker.getConsentRequestsQueue(), [], "getConsentRequestsQueue, still empty after requiring consent" );
tracker.trackRequest('myFoo=bar&baz=1');
@@ -5045,6 +5049,59 @@ if ($mysql) {
});
});
+ test("Test optOut (via iframe)", function () {
+ expect(6);
+
+ var tracker = Piwik.addTracker();
+
+ strictEqual(tracker.hasConsent(), true, "hasConsent(), should be true by default" );
+
+ stop();
+ Q.delay(1).then(function () {
+ // Fire a message to set the opt in status to false
+ var optOutMessage = JSON.stringify({maq_opted_in: false});
+ tracker.hook.test._windowAlias.postMessage(optOutMessage, '*');
+ return Q.delay(500);
+ }).then(function () {
+ strictEqual(tracker.hasConsent(), false, "optout message listener should have set the cookie to false (async tracker)" );
+ // Fire another message to set it back to true
+ var optInMessage = JSON.stringify({maq_opted_in: true});
+ tracker.hook.test._windowAlias.postMessage(optInMessage, '*');
+ return Q.delay(500);
+ }).then(function () {
+ strictEqual(tracker.hasConsent(), true, "optout message listener should have set the cookie to true" );
+ start();
+ }).catch(function (e) {
+ console.log('caught', e.stack || e.message || e);
+ });
+ });
+
+ test("Test refreshConsentStatus()", function() {
+ expect(7);
+
+ var tracker = Piwik.addTracker();
+ var document = tracker.hook.test._windowAlias.document;
+
+ // Test 1: no cookies
+ tracker.hook.test._refreshConsentStatus();
+ strictEqual(tracker.hasConsent(), true, "hasConsent() true when no cookies present");
+
+ // Test 2: optout cookie
+ document.cookie = 'mtm_consent_removed=12345';
+ tracker.hook.test._refreshConsentStatus();
+ strictEqual(tracker.hasConsent(), false, "hasConsent() false when optout cookie present");
+
+ // Test 3: optin cookie
+ document.cookie = 'mtm_consent_removed=;expires=Sun, 01 Dec 2019 00:00:01 GMT';
+ document.cookie = 'mtm_consent=12345';
+ tracker.hook.test._refreshConsentStatus();
+ strictEqual(tracker.hasConsent(), true, "hasConsent() true when optin cookie present");
+
+ // Test 4: both cookies
+ document.cookie = 'mtm_consent_removed=12345';
+ tracker.hook.test._refreshConsentStatus();
+ strictEqual(tracker.hasConsent(), false, "hasConsent() false when optout cookie present");
+ });
test("Internal timers and setLinkTrackingTimer()", function() {
expect(8);
diff --git a/tests/javascript/matomotest.js b/tests/javascript/matomotest.js
index 5487f39048..a4609a4b01 100644
--- a/tests/javascript/matomotest.js
+++ b/tests/javascript/matomotest.js
@@ -54,6 +54,8 @@ Piwik.addPlugin('testPlugin', {
'_addEventListener : addEventListener,' +
'_prefixPropertyName : prefixPropertyName,' +
'_getPiwikUrlForOverlay : getPiwikUrlForOverlay, ' +
+ '_windowAlias : windowAlias, ' +
+ '_refreshConsentStatus : refreshConsentStatus, ' +
'_isInsideAnIframe : isInsideAnIframe' +
'}'
);