Missing unit tests for:
Cannot test in WebTest or QUnit:
Will require Selenium:
These tests are incomplete:
Attachment: IE8 BUG: outputs JSON.parse error on second refresh
index2.php
(In [3863]) refs #2072 - add some missing unit tests
It would be nice to re-enable getVisitorId() but this is not critical for 1.2
In IE, there seem to be an error in JSON.parse when trying to decode the cookie.
The attached file should replicate the issue (ie 8). The error only shows on the second refresh.
Opera also fails (tested on Windows), with this test use case.
(In [3903]) Refs #2072
Opera has a built-in/native JSON implementation since Opera 10.50. I've already found a bug in its stringify() implementation (reproduceable with 10.62 and 11.01), so I'll be tweaking piwik.js to always use Crockford's JSON module (even if the browser has native support). This should give us more consistent results across platforms.
(The native JSON implementation was introduced in IE8. Hence the JSON.parse differences.)
I was echoing in the implementation in json.js and it was executed I think. I just put a document.write(err.message); in the piwik catch block and it was showing the exception thrown in JSON.parse
Maybe they interact somehow?
I'm not sure why (this is not a regression apparently), but sometimes downloads eg. http://piwik.org/latest.zip is counted as an outlink in Piwik. For example, yesterday Piwik missed 39 out of 310 downloads or 13% - there might be a bug somewhere in the JS ?
That's the behaviour for subdomains (e.g., de.piwik.org) if you don't use tracker.setDomains('*.piwik.org').
Replying to matt:
I was echoing in the implementation in json.js and it was executed I think. I just put a document.write(err.message); in the piwik catch block and it was showing the exception thrown in JSON.parse
Maybe they interact somehow?
shrug I'm not getting the exception with my dev version of piwik.js on IE8 or Opera.
on trunk, I apply this patch:
### Eclipse Workspace Patch 1.0
#P trunk
Index: js/piwik.js
===================================================================
--- js/piwik.js (revision 3936)
+++ js/piwik.js (working copy)
@@ -1105,7 +1105,9 @@
if (cookie.length) {
//JSON.parse doesn't work in IE and Opera for an unknown reason - see comment in <a href='/2072'>#2072</a>
- cookie = eval('('+cookie+')');
+// cookie = eval('('+cookie+')');
+
+ cookie = JSON.parse(cookie);
if (isObject(cookie)) {
return cookie;
}
then create a index.php for your root directory containing hte following code:
<html><body>
<!-- Piwik -->
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://localhost/trunk/" : "http://localhost/trunk/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "js/piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
piwikTracker.setSessionCookieTimeout(10000);
piwikTracker.setCookieNamePrefix('PREFIX');
piwikTracker.setCustomVariable(1, 'visitor type', 'engaged');
piwikTracker.setCustomVariable(2, 'INDEX2.php', navigator.userAgent.substr(30));
piwikTracker.setCustomVariable(6, 'loggedIN', 'yes');
piwikTracker.trackPageView();
piwikTracker.setCustomVariable(3, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {
document.write(err.message + "<br/>");
}
</script><noscript><p><img src="http://localhost/trunk/piwik.php?idsite=1" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tracking Code -->
<a href='http://localhost/index.php'>CODE JS INDEX</a>
with your piwik trunk installed in localhost/trunk
I see the JSON.parse message displayed in IE 8.0.6001.
After upgrading Opera, opera doesn't show an error anymore, nice!
But still IE :(
Ran into another bug in Opera 10.62 and 11.01 where the browser may spontaneously duplicate an HTTP request (i.e., the server will receive two requests for the same URL, including query parameters). This one has no workaround. It's spurious, so I use a loop to increase the chances of reproducing the bug.
Filed as DSK-328881:
<script type="text/javascript">
var myClass = function () {
this.getImage = function (i) {
var image = new Image(1, 1);
image.onLoad = function () { };
image.src = 'something.php?data=123&q=' + i;
}
};
for (var i = 0; i < 20; i++) {
var myObj = new myClass();
myObj.getImage(i);
}
</script>
excellent work Anthon, I wouldnt have thought of the native JSON conflict. but why was the JSON function triggered?
Is there any manual testing to be done, for example the following functions and check the cookies:
* setConversionAttributionFirstReferrer
* setSessionCookieTimeout
* setCookieDomain
* setCookiePath
* setVisitorCookieTimeout
* setReferralCookieTimeout
Regarding getVisitorId() it looks like it now works when called before track*, excellent. Maybe we should advertise this feature as it could lead to interesting features and integrate (with the Live! API) cool features.
Let me know. Otherwise, please close the ticket as I don't have the error anymore and code & tests looks good
(In [3944]) refs #2072 - handle misconfigured "*." wildcard in setCookieDomain()
(In [3945]) refs #2072 - refactor to simplify isSiteHostName()
re: comment:17 yes these are tested manually. (For example, using Firefox's "View Cookie Information" to examine the cookie domain and path.)
FYI piwik.js unit tests ran successfully on:
On Win98SE with IE6, the unit tests passed but ran twice (reported 544 tests). On other version of Windows with IE6, the unit tests ran correctly (reporting 272 tests).
Other browsers included:
The unit tests failed on:
Untested on:
For the unit tests that failed, basic tracking code worked for:
These errored out:
wow very impressive test suite! I think as long as the basic tracking at least works, it is good. Of course it would be nice if at least there was no error thrown, but I think the browsers that fail the tests are definitely very old and not expected.