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:
authorThomas Steur <tsteur@users.noreply.github.com>2018-12-06 05:41:14 +0300
committerdiosmosis <diosmosis@users.noreply.github.com>2018-12-06 05:41:14 +0300
commit1fe8a6ee582c2f61dc209b7df856695378007c23 (patch)
tree05fa03acb78ae04716df3b78a5c910dd957a63de /tests/javascript
parentac39d23b17d7bb9049f1e9cf68e266401a2b8847 (diff)
Add option to opt in to use send beacon (#13451)
* Add option to opt in to use send beacon * Fix JS tracker test.
Diffstat (limited to 'tests/javascript')
-rw-r--r--tests/javascript/index.php53
1 files changed, 46 insertions, 7 deletions
diff --git a/tests/javascript/index.php b/tests/javascript/index.php
index 0846639263..3dc16c8c2d 100644
--- a/tests/javascript/index.php
+++ b/tests/javascript/index.php
@@ -53,6 +53,9 @@ function getConsentToken() {
function getOptInToken() {
return "<?php $token = md5(uniqid(mt_rand(), true)); echo $token; ?>";
}
+function getAlwaysUseSendBeaconToken() {
+ return "<?php $token = md5(uniqid(mt_rand(), true)); echo $token; ?>";
+}
<?php
if ($mysql) {
@@ -135,6 +138,14 @@ function _s(selector) { // select node within content test scope
}
}
+function makeXhr()
+{
+ var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() :
+ window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") :
+ null;
+ return xhr;
+}
+
// Polyfill for IndexOf for IE6-IE8
function indexOfArray(theArray, searchElement)
{
@@ -270,9 +281,7 @@ function triggerEvent(element, type, buttonNumber) {
function fetchTrackedRequests(token, parse)
{
- var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() :
- window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") :
- null;
+ var xhr = makeXhr();
xhr.open("GET", "matomo.php?requests=" + token, false);
xhr.send(null);
@@ -2132,7 +2141,7 @@ function PiwikTest() {
});
test("API methods", function() {
- expect(104);
+ expect(105);
equal( typeof Piwik.addPlugin, 'function', 'addPlugin' );
equal( typeof Piwik.addPlugin, 'function', 'addTracker' );
@@ -2175,6 +2184,7 @@ function PiwikTest() {
equal( typeof tracker.deleteCustomVariables, 'function', 'deleteCustomVariables' );
equal( typeof tracker.setLinkTrackingTimer, 'function', 'setLinkTrackingTimer' );
equal( typeof tracker.getLinkTrackingTimer, 'function', 'getLinkTrackingTimer' );
+ equal( typeof tracker.alwaysUseSendBeacon, 'function', 'alwaysUseSendBeacon' );
equal( typeof tracker.setDownloadExtensions, 'function', 'setDownloadExtensions' );
equal( typeof tracker.addDownloadExtensions, 'function', 'addDownloadExtensions' );
equal( typeof tracker.removeDownloadExtensions, 'function', 'removeDownloadExtensions' );
@@ -3581,6 +3591,37 @@ if ($mysql) {
}
});
+ test("tracking with sendBeacon", function() {
+ expect(6);
+
+ var tracker = Piwik.getTracker();
+ tracker.setTrackerUrl("matomo.php");
+ tracker.setSiteId(1);
+ tracker.setCustomData({ "token" : getAlwaysUseSendBeaconToken() });
+ tracker.alwaysUseSendBeacon();
+
+ var shortTitle = 'CustomShortTitleTest';
+ var longTitle = "CustomLongTitleTest" + (Array(2500).join('f'));
+ tracker.trackPageView(shortTitle);
+ tracker.trackPageView(longTitle);
+
+ stop();
+ setTimeout(function() {
+ var xhr = makeXhr();
+ xhr.open("GET", "matomo.php?requests=" + getAlwaysUseSendBeaconToken(), false);
+ xhr.send(null);
+ var results = xhr.responseText;
+ var m = /<span\>([0-9]+)\<\/span\>/.exec(results);
+ equal( m ? m[1] : 0, "2", "count tracking events" );
+
+ ok(results.indexOf('matomo.php?action_name=' + shortTitle + '&') >= 0, "trackPageView() sends small request");
+ ok(results.indexOf('matomo.php?action_name=' + longTitle + '&') >= 0, "trackPageView() sends long request");
+
+ start();
+ }, 2000);
+ });
+
+
test("tracking", function() {
expect(155);
@@ -3778,9 +3819,7 @@ if ($mysql) {
triggerEvent(_e('click7'), 'mousedown', 1);
triggerEvent(_e('click7'), 'mouseup', 1); // middleclick
- var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() :
- window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") :
- null;
+ var xhr = makeXhr();
var clickDiv = _e("clickDiv"),
anchor = document.createElement("a");