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 <thomas.steur@googlemail.com>2014-09-05 13:42:51 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-09-05 13:42:51 +0400
commit96ed663d643b55b2f6fa86777d58e25e53eb3fce (patch)
tree7e3bea0542b9c66a1732b8c63e79363c2720dd39 /tests/javascript
parente89de039de65e9bc8c92b738fd73ed3cf3fac371 (diff)
refs #4996 a lot of new tests and bugfixes, also some code improvements
Diffstat (limited to 'tests/javascript')
-rw-r--r--tests/javascript/content-fixtures/contentUtilities.html58
-rw-r--r--tests/javascript/index.php87
2 files changed, 139 insertions, 6 deletions
diff --git a/tests/javascript/content-fixtures/contentUtilities.html b/tests/javascript/content-fixtures/contentUtilities.html
index 92d6a690ae..e9a3e83b99 100644
--- a/tests/javascript/content-fixtures/contentUtilities.html
+++ b/tests/javascript/content-fixtures/contentUtilities.html
@@ -4,6 +4,64 @@
<div id="ignoreInteraction2" data-track-content>
<a href="http://www.example.com" class="piwikContentTarget" data-content-ignoreinteraction>Link</a>
</div>
+<!-- targetNode in this example is the content block node -->
+<div id="ignoreInteraction3" data-track-content data-content-ignoreinteraction>
+ <a href="http://www.example.com">Link</a>
+</div>
+<!-- targetNode in this example is the content block node -->
+<div id="ignoreInteraction4" data-track-content class="piwikContentIgnoreInteraction">
+ <a href="http://www.example.com">Link</a>
+</div>
+
<div id="notIgnoreInteraction1" data-track-content>
<a href="http://www.example.com" class="piwikContentTarget">Link</a>
+</div>
+<!-- Will not be ignored since set on wrong element, has to be set on content target node -->
+<div id="notIgnoreInteraction2" data-track-content data-content-ignoreinteraction class="piwikContentIgnoreInteraction">
+ <a href="http://www.example.com" class="piwikContentTarget">Link</a>
+</div>
+
+<a href="http://www.example.com" id="aLinkToBeChanged">Link</a>
+
+<div class="media">
+ <div id="mediaDiv" src="test/img.jpg"/>
+ <img id="mediaImg" src="test/img.jpg"/>
+
+ <video id="mediaVideo" width="320" height="240" controls>
+ <source src="movie.mp4" type="video/mp4">
+ <source src="movie.ogg" type="video/ogg">
+ Your browser does not support the video tag.
+ </video>
+
+ <audio id="mediaAudio" controls>
+ <source src="audio.ogg" type="audio/ogg">
+ <source src="audio.mp3" type="audio/mpeg">
+ Your browser does not support the audio element.
+ </audio>
+
+ <embed id="mediaEmbed" src="embed.swf">
+
+ <object id="mediaObjectSimple" width="400" height="400" data="objectSimple.swf"></object>
+
+ <object id="mediaObjectParam" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550"
+ height="400" id="movie_name" align="middle">
+ <param name="anything" value="anyvalue"/>
+ <param name="movie" value="movie_param1.swf"/>
+ <!--[if !IE]>-->
+ <object type="application/x-shockwave-flash" data="movie_inner.swf" width="550" height="400">
+ <param name="movie" value="movie_param2.swf"/>
+ <!<![endif]--> <a href="http://www.adobe.com/go/getflash"> <img
+ src="http://www.adobe.com/de/images/shared/download_buttons/get_flash_player.gif"
+ alt="Get Adobe Flash player"/> </a> <!--[if !IE]>--> </object>
+ <!<![endif]-->
+ </object>
+
+ <object id="mediaObjectPdf" data="document.pdf" type="application/pdf">
+ <embed src="document2.pdf" type="application/pdf" />
+ </object>
+
+ <!-- should fall back to embed as no data specified -->
+ <object id="mediaObjectEmbed" data="" type="application/pdf">
+ <embed src="document2.pdf" type="application/pdf" />
+ </object>
</div> \ No newline at end of file
diff --git a/tests/javascript/index.php b/tests/javascript/index.php
index 9e876445f6..dca94b2db4 100644
--- a/tests/javascript/index.php
+++ b/tests/javascript/index.php
@@ -200,6 +200,10 @@ function setupContentTrackingFixture(name) {
</ul>
<div id="clickDiv"></div>
</div>
+ <map name="map">
+ <area id="area1" shape="rect" coords="0,0,10,10" href="img.jpg" alt="Piwik">
+ <area shape="circle" coords="10,10,10,20" href="img2.jpg" alt="Piwik2">
+ </map>
<ol id="qunit-tests"></ol>
@@ -562,6 +566,25 @@ function PiwikTest() {
ok(-1 !== actual.indexOf(_e('click1')), 'htmlCollectionToArray, random check to make sure it contains a link');
+ actual = query.isLinkElement();
+ strictEqual(actual, false, "isLinkElement, no element set");
+
+ actual = query.isLinkElement(_e('div1'));
+ strictEqual(actual, false, "isLinkElement, a div is not a link element");
+
+ actual = query.isLinkElement(document.createTextNode('ff'));
+ strictEqual(actual, false, "isLinkElement, a text node is not a link element");
+
+ actual = query.isLinkElement(document.createComment('tt'));
+ strictEqual(actual, false, "isLinkElement, a comment is not a link element");
+
+ actual = query.isLinkElement(_e('area1'));
+ strictEqual(actual, true, "isLinkElement, an area element is a link element");
+
+ actual = query.isLinkElement(_e('click1'));
+ strictEqual(actual, true, "isLinkElement, an a element is a link element");
+
+
actual = query.find();
propEqual(actual, [], "find, no selector passed should return an empty array");
@@ -598,6 +621,26 @@ function PiwikTest() {
actual = query.findMultiple(['.piwik_link', '[data-content-piece]', '#image2', '#div1']);
propEqual(actual, [_e('image2'), _e('div1'), _e('click5')], "findMultiple, should make nodes unique in case we select the same multiple times");
+
+
+ actual = query.findNodesByTagName();
+ propEqual(actual, [], "findNodesByTagName, no element and no tag name set");
+
+ actual = query.findNodesByTagName(document.body);
+ propEqual(actual, [], "findNodesByTagName, no tag name set");
+
+ actual = query.findNodesByTagName(document.body, 'notExistingOne');
+ propEqual(actual, [], "findNodesByTagName, should not find any such element");
+
+ actual = query.findNodesByTagName(document.body, 'a');
+ ok($.isArray(actual), "findNodesByTagName, should always return an array");
+
+ actual = query.findNodesByTagName(document.body, 'h1');
+ propEqual(actual, [_e('qunit-header')], "findNodesByTagName, find exactly one");
+
+ actual = query.findNodesByTagName(document.body, 'a');
+ ok(actual.length > 10, "findNodesByTagName, find many, even nested ones");
+ ok(actual.indexOf(_e('click1')), "findNodesByTagName, just a random test to make sure it actually contains a link");
});
test("contentFindContentBlock", function() {
@@ -764,6 +807,7 @@ function PiwikTest() {
var tracker = Piwik.getTracker();
var content = tracker.getContent();
+ var query = tracker.getQuery();
content.setLocation(); // clear possible previous location
var actual, expected;
@@ -806,6 +850,11 @@ function PiwikTest() {
strictEqual(content.shouldIgnoreInteraction(node), false, message);
}
+ function assertFoundMediaUrl(id, expected, message) {
+ var node = content.findPieceNode(_e(id));
+ strictEqual(content.findMediaUrlInNode(node), expected, message);
+ }
+
var locationAlias = $.extend({}, window.location);
var origin = locationAlias.origin;
@@ -852,10 +901,11 @@ function PiwikTest() {
assertBuildsAbsoluteUrl('path/x?p=5', origin + '/tests/javascript/path/x?p=5', 'relative path');
assertBuildsAbsoluteUrl('#test', origin + '/tests/javascript/#test', 'anchor url');
assertBuildsAbsoluteUrl('//' + locationAlias.host + '/test/img.jpg', origin + '/test/img.jpg', 'inherit protocol url');
- assertBuildsAbsoluteUrl('mailto:test@example.com', 'mailto:test@example.com', 'mailto special url');
- assertBuildsAbsoluteUrl('tel:0123456789', 'tel:0123456789', 'tel special url');
- assertBuildsAbsoluteUrl('anythingg:test', origin + '/tests/javascript/anythingg:test', 'we do not treat this one as special url as we recognize max 8 characters currently');
- assertBuildsAbsoluteUrl('k1dm:test', origin + '/tests/javascript/k1dm:test', 'we do not treat this one as special url as it contains a number');
+ assertBuildsAbsoluteUrl('mailto:test@example.com', 'mailto:test@example.com', 'mailto pseudo-protocol url');
+ assertBuildsAbsoluteUrl('javascript:void 0', 'javascript:void 0', 'javascript pseudo-protocol url');
+ assertBuildsAbsoluteUrl('tel:0123456789', 'tel:0123456789', 'tel pseudo-protocol url');
+ assertBuildsAbsoluteUrl('anythinggggggggg:test', origin + '/tests/javascript/anythinggggggggg:test', 'we do not treat this one as pseudo-protocol url as there are too many characters before colon');
+ assertBuildsAbsoluteUrl('k1dm:test', origin + '/tests/javascript/k1dm:test', 'we do not treat this one as pseudo-protocol url as it contains a number');
locationAlias.pathname = '/test/';
content.setLocation(locationAlias);
@@ -886,12 +936,37 @@ function PiwikTest() {
ok("test shouldIgnoreInteraction(targetNode)");
assertShouldIgnoreInteraction('ignoreInteraction1', 'should be ignored because of CSS class');
assertShouldIgnoreInteraction('ignoreInteraction2', 'should be ignored because of Attribute');
+ assertShouldIgnoreInteraction('ignoreInteraction3', 'should be ignored because of CSS class');
+ assertShouldIgnoreInteraction('ignoreInteraction4', 'should be ignored because of Attribute');
assertShouldNotIgnoreInteraction('notIgnoreInteraction1', 'should not be ignored');
+ assertShouldNotIgnoreInteraction('notIgnoreInteraction2', 'should not be ignored as set in wrong element');
+
+
+ ok("test setHrefAttribute(node, url)");
+ var aElement = _e('aLinkToBeChanged');
+ content.setHrefAttribute(); // should not fail if no arguments
+ strictEqual(query.getAttributeValueFromNode(aElement, 'href'), 'http://www.example.com', 'setHrefAttribute, check initial link value');
+ content.setHrefAttribute(aElement);
+ content.setHrefAttribute(aElement, '');
+ strictEqual(query.getAttributeValueFromNode(aElement, 'href'), 'http://www.example.com', 'setHrefAttribute, an empty URL should not be set');
+ content.setHrefAttribute(aElement, '/test');
+ strictEqual(query.getAttributeValueFromNode(aElement, 'href'), '/test', 'setHrefAttribute, link should be changed now');
+
+ strictEqual(content.findMediaUrlInNode(), undefined, 'should not fail if no node passed');
+ ok(_e('click1') && _e('mediaDiv'), 'make sure both nodes exist otherwise following two assertions to not test what we want');
+ assertFoundMediaUrl('click1', undefined, 'should not find anything in a link as it is not a media');
+ assertFoundMediaUrl('mediaDiv', undefined, 'should not find anything in a non media element even if it defines a src attribute');
+ assertFoundMediaUrl('mediaImg', 'test/img.jpg', 'should find url of image');
+ assertFoundMediaUrl('mediaVideo', 'movie.mp4', 'should find url of video, first one should be used');
+ assertFoundMediaUrl('mediaAudio', 'audio.ogg', 'should find url of audio, first one should be used');
+ assertFoundMediaUrl('mediaEmbed', 'embed.swf', 'should find url of embed element');
+ assertFoundMediaUrl('mediaObjectSimple', 'objectSimple.swf', 'should find url of a simple object element');
+ assertFoundMediaUrl('mediaObjectParam', 'movie_param1.swf', 'should find url of a simple object element');
+ assertFoundMediaUrl('mediaObjectPdf', 'document.pdf', 'should find url of an object that contains non flash resources such as pdf');
+ assertFoundMediaUrl('mediaObjectEmbed', 'document2.pdf', 'should fallback to an embed in an object');
// isOrWasNodeInViewport
// isNodeVisible
- // findInternalTargetLinkFromHref
- // replaceTargetLink
});