Merge branch 'master' into absolute-URLs-compatibility

Conflicts:
	www/js/app.js
This commit is contained in:
mossroy 2016-01-16 13:56:46 +01:00
commit e9b4b12053
6 changed files with 2306 additions and 1905 deletions

View File

@ -143,7 +143,7 @@ function(util) {
}
// We need to remove the potential parameters in the URL
titleName = util.removeUrlParameters(titleName);
titleName = util.removeUrlParameters(decodeURIComponent(titleName));
titleNameWithNameSpace = nameSpace + '/' + titleName;

View File

@ -24,8 +24,8 @@
along with Evopedia (file LICENSE-GPLv3.txt). If not, see <http://www.gnu.org/licenses/>
-->
<link rel="stylesheet" href="tests/qunit-1.18.0.css" />
<script src="tests/qunit-1.18.0.js"></script>
<link rel="stylesheet" href="tests/qunit-1.20.0.css" />
<script src="tests/qunit-1.20.0.js"></script>
<!-- Using require.js, a module system for javascript, include the
js files. This loads "main.js", which in turn can load other

View File

@ -1,27 +1,27 @@
/*!
* QUnit 1.18.0
* QUnit 1.20.0
* http://qunitjs.com/
*
* Copyright jQuery Foundation and other contributors
* Released under the MIT license
* http://jquery.org/license
*
* Date: 2015-04-03T10:23Z
* Date: 2015-10-27T17:53Z
*/
/** Font Family and Sizes */
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult {
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
}
#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
#qunit-testrunner-toolbar, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
#qunit-tests { font-size: smaller; }
/** Resets */
#qunit-tests, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter {
#qunit-tests, #qunit-header, #qunit-banner, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter {
margin: 0;
padding: 0;
}
@ -68,6 +68,12 @@
overflow: hidden;
}
#qunit-filteredTest {
padding: 0.5em 1em 0.5em 1em;
background-color: #F4FF77;
color: #366097;
}
#qunit-userAgent {
padding: 0.5em 1em 0.5em 1em;
background-color: #2B81AF;
@ -118,8 +124,8 @@
#qunit-tests.hidepass li.pass {
visibility: hidden;
position: absolute;
width: 0px;
height: 0px;
width: 0;
height: 0;
padding: 0;
border: 0;
margin: 0;
@ -162,6 +168,10 @@
border-radius: 5px;
}
.qunit-source {
margin: 0.6em 0 0.3em;
}
.qunit-collapsed {
display: none;
}

File diff suppressed because it is too large Load Diff

View File

@ -94,6 +94,15 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom
});
});
});
/**
* Function to use in .fail() of an async test
* @param e Error
*/
function errorHandlerAsyncTest(e) {
ok(false, "Error in async call", e);
start();
}
var runTests = function() {
@ -172,7 +181,7 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom
equal(title._name, "Diego_Velázquez", "Name of the title is correct");
start();
};
localEvopediaArchive.getTitleByName("Diego_Velázquez").then(callbackFunction);
localEvopediaArchive.getTitleByName("Diego_Velázquez").then(callbackFunction).fail(errorHandlerAsyncTest);
});
asyncTest("check getTitleByName with quote : Hundred Years' War", function() {
expect(2);
@ -181,7 +190,7 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom
equal(title._name, "Hundred_Years'_War", "Name of the title is correct");
start();
};
localEvopediaArchive.getTitleByName("Hundred_Years'_War").then(callbackFunction);
localEvopediaArchive.getTitleByName("Hundred_Years'_War").then(callbackFunction).fail(errorHandlerAsyncTest);
});
test("check parseTitleFromId", function() {
@ -219,7 +228,7 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom
equal(title._name, "AIDS", "Name of the title is correct");
localEvopediaArchive.readArticle(title, callbackArticleRead);
};
localEvopediaArchive.getTitleByName("AIDS").then(callbackTitleFound);
localEvopediaArchive.getTitleByName("AIDS").then(callbackTitleFound).fail(errorHandlerAsyncTest);
});
asyncTest("check getTitleByName with a title name that does not exist in the archive", function() {
@ -228,7 +237,7 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom
ok(title === null, "No title found because it does not exist in the archive");
start();
};
localEvopediaArchive.getTitleByName("abcdef").then(callbackTitleFound);
localEvopediaArchive.getTitleByName("abcdef").then(callbackTitleFound).fail(errorHandlerAsyncTest);
});
asyncTest("check loading a math image", function() {
@ -507,43 +516,74 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom
expect(6);
localZimArchive.getTitleByName("A/(The_Night_Time_Is)_The_Right_Time.html").then(function(title) {
ok(title !== null, "Title found");
ok(title.isRedirect(), "Title is a redirect.");
equal(title.name(), "(The Night Time Is) The Right Time", "Correct redirect title name.");
localZimArchive.resolveRedirect(title, function(title) {
ok(title !== null, "Title found");
ok(!title.isRedirect(), "Title is not a redirect.");
equal(title.name(), "Night Time Is the Right Time", "Correct redirected title name.");
if (title !== null) {
ok(title.isRedirect(), "Title is a redirect.");
equal(title.name(), "(The Night Time Is) The Right Time", "Correct redirect title name.");
localZimArchive.resolveRedirect(title, function(title) {
ok(title !== null, "Title found");
ok(!title.isRedirect(), "Title is not a redirect.");
equal(title.name(), "Night Time Is the Right Time", "Correct redirected title name.");
start();
});
} else {
start();
});
});
}
}).fail(errorHandlerAsyncTest);
});
asyncTest("Image 'm/RayCharles_AManAndHisSoul.jpg' can be loaded", function() {
expect(4);
localZimArchive.getTitleByName("I/m/RayCharles_AManAndHisSoul.jpg").then(function(title) {
ok(title !== null, "Title found");
equal(title.url, "I/m/RayCharles_AManAndHisSoul.jpg", "URL is correct.");
localZimArchive.readBinaryFile(title, function(title, data) {
equal(data.length, 4951, "Data length is correct.");
var beginning = new Uint8Array([255, 216, 255, 224, 0, 16, 74, 70,
73, 70, 0, 1, 1, 0, 0, 1]);
equal(data.slice(0, beginning.length).toSource(), beginning.toSource(), "Data beginning is correct.");
if (title !== null) {
equal(title.url, "I/m/RayCharles_AManAndHisSoul.jpg", "URL is correct.");
localZimArchive.readBinaryFile(title, function(title, data) {
equal(data.length, 4951, "Data length is correct.");
var beginning = new Uint8Array([255, 216, 255, 224, 0, 16, 74, 70,
73, 70, 0, 1, 1, 0, 0, 1]);
equal(data.slice(0, beginning.length).toSource(), beginning.toSource(), "Data beginning is correct.");
start();
});
} else {
start();
});
});
}
}).fail(errorHandlerAsyncTest);
});
asyncTest("Stylesheet 's/style.css' can be loaded", function() {
asyncTest("Stylesheet '-/s/style.css' can be loaded", function() {
expect(4);
localZimArchive.getTitleByName("-/s/style.css").then(function(title) {
ok(title !== null, "Title found");
equal(title.url, "-/s/style.css", "URL is correct.");
localZimArchive.readBinaryFile(title, function(title, data) {
equal(data.length, 104495, "Data length is correct.");
data = utf8.parse(data);
var beginning = "\n/* start http://en.wikipedia.org/w/load.php?debug=false&lang=en&modules=site&only=styles&skin=vector";
equal(data.slice(0, beginning.length), beginning, "Content starts correctly.");
if (title !== null) {
equal(title.url, "-/s/style.css", "URL is correct.");
localZimArchive.readBinaryFile(title, function(title, data) {
equal(data.length, 104495, "Data length is correct.");
data = utf8.parse(data);
var beginning = "\n/* start http://en.wikipedia.org/w/load.php?debug=false&lang=en&modules=site&only=styles&skin=vector";
equal(data.slice(0, beginning.length), beginning, "Content starts correctly.");
start();
});
} else {
start();
});
});
}
}).fail(errorHandlerAsyncTest);
});
asyncTest("Javascript '-/j/local.js' can be loaded", function() {
expect(4);
localZimArchive.getTitleByName("-/j/local.js").then(function(title) {
ok(title !== null, "Title found");
if (title !== null) {
equal(title.url, "-/j/local.js", "URL is correct.");
localZimArchive.readBinaryFile(title, function(title, data) {
equal(data.length, 41, "Data length is correct.");
data = utf8.parse(data);
var beginning = "console.log( \"mw.loader";
equal(data.slice(0, beginning.length), beginning, "Content starts correctly.");
start();
});
}
else {
start();
}
}).fail(errorHandlerAsyncTest);
});
};
});

View File

@ -861,7 +861,7 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
console.log("content sent to ServiceWorker");
});
}
}
};
selectedArchive.getTitleByName(titleName).then(readFile).fail(function() {
messagePort.postMessage({'action': 'giveContent', 'titleName' : titleName, 'content': new UInt8Array()});
});
@ -988,13 +988,14 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
// We try to find its name (from an absolute or relative URL)
var imageMatch = image.attr("src").match(regexpImageUrl);
if (imageMatch) {
selectedArchive.getTitleByName(imageMatch[1]).then(function(title) {
var titleName = decodeURIComponent(imageMatch[1]);
selectedArchive.getTitleByName(titleName).then(function(title) {
selectedArchive.readBinaryFile(title, function (readableTitleName, content) {
// TODO : add the complete MIME-type of the image (as read from the ZIM file)
image.attr("src", 'data:image;base64,' + util.uint8ArrayToBase64(content));
});
}).fail(function (error) {
console.error("could not find title for image " + imageMatch[1] + " : " + error);
}).fail(function (e) {
console.error("could not find title for image:" + titleName, e);
});
}
}
@ -1007,14 +1008,34 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
var hrefMatch = link.attr("href").match(regexpMetadataUrl);
if (hrefMatch) {
// It's a CSS file contained in the ZIM file
var titleName = util.removeUrlParameters(hrefMatch[1]);
var titleName = util.removeUrlParameters(decodeURIComponent(hrefMatch[1]));
selectedArchive.getTitleByName(titleName).then(function(title) {
selectedArchive.readBinaryFile(title, function (readableTitleName, content) {
var cssContent = encodeURIComponent(util.uintToString(content));
link.attr("href", 'data:text/css;charset=UTF-8,' + cssContent);
var cssContent = util.uintToString(content);
// For some reason, Firefox OS does not accept the syntax <link rel="stylesheet" href="data:text/css,...">
// So we replace the tag with a <style type="text/css">...</style>
// while copying some attributes of the original tag
// Cf http://jonraasch.com/blog/javascript-style-node
var cssElement = document.createElement('style');
cssElement.type = 'text/css';
if (cssElement.styleSheet) {
cssElement.styleSheet.cssText = cssContent;
} else {
cssElement.appendChild(document.createTextNode(cssContent));
}
var mediaAttributeValue = link.attr('media');
if (mediaAttributeValue) {
cssElement.media = mediaAttributeValue;
}
var disabledAttributeValue = link.attr('media');
if (disabledAttributeValue) {
cssElement.disabled = disabledAttributeValue;
}
link.replaceWith(cssElement);
});
}).fail(function (error) {
console.error("could not find title for CSS " + titleName + " : " + error);
}).fail(function (e) {
console.error("could not find title for CSS : " + titleName, e);
});
}
});
@ -1027,15 +1048,15 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
// TODO check that the type of the script is text/javascript or application/javascript
if (srcMatch) {
// It's a Javascript file contained in the ZIM file
var titleName = util.removeUrlParameters(srcMatch[1]);
var titleName = util.removeUrlParameters(decodeURIComponent(srcMatch[1]));
selectedArchive.getTitleByName(titleName).then(function(title) {
selectedArchive.readBinaryFile(title, function (readableTitleName, content) {
// TODO : I have to disable javascript for now
// var jsContent = encodeURIComponent(util.uintToString(content));
//script.attr("src", 'data:text/javascript;charset=UTF-8,' + jsContent);
});
}).fail(function (error) {
console.error("could not find title for javascript " + titleName + " : " + error);
}).fail(function (e) {
console.error("could not find title for javascript : " + titleName, e);
});
}
});