Commit 9af14f8a authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

Trailing spaces deleted.

console.log no longer in scripts.
JIO classes are more secure now.
parent b149e374
...@@ -7,38 +7,46 @@ ...@@ -7,38 +7,46 @@
</head> </head>
<body> <body>
<script type="text/javascript" src="js/jquery/jquery.js"></script> <script type="text/javascript" src="js/jquery/jquery.js"></script>
<script type="text/javascript" src="unhosted/localorcookiestorage.js"></script> <script type="text/javascript" src="unhosted/localorcookiestorage.js">
</script>
<script type="text/javascript" src="unhosted/jio.js"></script> <script type="text/javascript" src="unhosted/jio.js"></script>
<script type="text/javascript" src="unhosted/base64.js"></script> <script type="text/javascript" src="unhosted/base64.js"></script>
<script type="text/javascript" src="unhosted/jio.storage.js"></script> <script type="text/javascript" src="unhosted/jio.storage.js"></script>
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
var mammal = function (description) { var maClassPasProtegee = function () {
this.caracteristics = description; this.monAttributPasProtegee = 0;
};
mammal.prototype = {
createMammal: function () {
// c'est un chat alors
var mycat = new cat(this.caracteristics);
var t = this;
mycat.say = function () { return t.caracteristics.say; };
mycat.name = function () { return t.caracteristics.name; };
return mycat;
}
}; };
var cat = function (detaileddescription) { maClassPasProtegee.prototype = {
// (...) getMonAttribut: function () {
}; return this.monAttributPasProtegee;
cat.prototype = { },
talk: function () { logMonAttribut: function () {
alert('My name is ' + this.name() + ', ' + this.say()); console.log (this.monAttributPasProtegee);
} }
}; };
var maclass1 = new maClassPasProtegee();
maclass1.logMonAttribut();
maclass1.monAttributPasProtegee ++;
maclass1.logMonAttribut();
var mam = new mammal({'say':'meow','name':'nyancat'}); var maClassProtegee = function () {
var mycat = mam.createMammal(); var publ = {}, priv = {};
mycat.talk(); priv.monAttributProtegee = 0;
//--> publ.getMonAttribut = function () {
return priv.monAttributProtegee;
};
publ.logMonAttribut = function () {
console.log (priv.monAttributProtegee);
};
return publ;
};
var maclass2 = new maClassProtegee();
maclass2.logMonAttribut();
maclass2.monAttributProtegee ++;
maclass2.logMonAttribut();
//-->
</script> </script>
</body> </body>
</html> </html>
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
// - dummyallnotfound // - dummyallnotfound
// - dummyall3tries // - dummyall3tries
;(function ( Jio ) { ;(function ( Jio ) {
// check dependencies // check dependencies
var errorDependencies=function(){$.error('Cannot find Jio');}; var errorDependencies=function(){$.error('Cannot find Jio');};
try{if (!Jio){ try{if (!Jio){
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
var jioGlobalObj = Jio.getGlobalObject(), var jioGlobalObj = Jio.getGlobalObject(),
// end globals // end globals
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Dummy Storage 1 : all ok // Dummy Storage 1 : all ok
DummyStorageAllOk = function ( args ) { DummyStorageAllOk = function ( args ) {
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
that.loadDocument = function () { that.loadDocument = function () {
// Returns a document object containing all information of the // Returns a document object containing all information of the
// document and its content. // document and its content.
// document object is {'fileName':string,'fileContent':string, // document object is {'fileName':string,'fileContent':string,
// 'creationDate':date,'lastModified':date} // 'creationDate':date,'lastModified':date}
...@@ -96,7 +96,7 @@ ...@@ -96,7 +96,7 @@
// Dummy Storage 2 : all fail // Dummy Storage 2 : all fail
DummyStorageAllFail = function ( args ) { DummyStorageAllFail = function ( args ) {
var that = Jio.newBaseStorage( args ); var that = Jio.newBaseStorage( args );
that.checkNameAvailability = function () { that.checkNameAvailability = function () {
// Fails to check [job.userName]. // Fails to check [job.userName].
...@@ -117,7 +117,7 @@ ...@@ -117,7 +117,7 @@
that.loadDocument = function () { that.loadDocument = function () {
// Returns a document object containing nothing. // Returns a document object containing nothing.
// document object is {'fileName':string,'fileContent':string, // document object is {'fileName':string,'fileContent':string,
// 'creationDate':date,'lastModified':date} // 'creationDate':date,'lastModified':date}
...@@ -157,7 +157,7 @@ ...@@ -157,7 +157,7 @@
// Dummy Storage 3 : all not found // Dummy Storage 3 : all not found
DummyStorageAllNotFound = function ( args ) { DummyStorageAllNotFound = function ( args ) {
var that = Jio.newBaseStorage( args ); var that = Jio.newBaseStorage( args );
that.checkNameAvailability = function () { that.checkNameAvailability = function () {
// [job.userName] not found, so the name is available. // [job.userName] not found, so the name is available.
...@@ -178,7 +178,7 @@ ...@@ -178,7 +178,7 @@
that.loadDocument = function () { that.loadDocument = function () {
// Returns a document object containing nothing. // Returns a document object containing nothing.
// document object is {'fileName':string,'fileContent':string, // document object is {'fileName':string,'fileContent':string,
// 'creationDate':date,'lastModified':date} // 'creationDate':date,'lastModified':date}
...@@ -218,7 +218,7 @@ ...@@ -218,7 +218,7 @@
// Dummy Storage 4 : all 3 tries // Dummy Storage 4 : all 3 tries
DummyStorageAll3Tries = function ( args ) { DummyStorageAll3Tries = function ( args ) {
var that = Jio.newBaseStorage( args ), priv = {}; var that = Jio.newBaseStorage( args ), priv = {};
priv.doJob = function (ifokreturn) { priv.doJob = function (ifokreturn) {
// wait a little in order to simulate asynchronous operation // wait a little in order to simulate asynchronous operation
setTimeout(function () { setTimeout(function () {
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
return that.fail('Too much tries.'); return that.fail('Too much tries.');
} }
}; };
that.checkNameAvailability = function () { that.checkNameAvailability = function () {
priv.doJob (true); priv.doJob (true);
}; // end userNameAvailable }; // end userNameAvailable
......
...@@ -40,7 +40,7 @@ test ( "Jio simple methods", function () { ...@@ -40,7 +40,7 @@ test ( "Jio simple methods", function () {
deepEqual ( o.jio.isReady(), true, '1 must be not ready'); deepEqual ( o.jio.isReady(), true, '1 must be not ready');
ok ( o.jio2.id !== o.jio.id, '1 and 2 must be different'); ok ( o.jio2.getID() !== o.jio.getID(), '1 and 2 must be different');
deepEqual ( o.jio.stop(), true, '1 must be stopped'); deepEqual ( o.jio.stop(), true, '1 must be stopped');
...@@ -67,11 +67,11 @@ test ( 'Jio Publish/Sububscribe/Unsubscribe methods', function () { ...@@ -67,11 +67,11 @@ test ( 'Jio Publish/Sububscribe/Unsubscribe methods', function () {
// And publish the event. // And publish the event.
o.jio.publish('pubsub_test'); o.jio.publish('pubsub_test');
ok (spy1.calledOnce, 'subscribing & publishing, event called once'); ok (spy1.calledOnce, 'subscribing & publishing, event called once');
o.jio.unsubscribe('pubsub_test',spy1); o.jio.unsubscribe('pubsub_test',spy1);
o.jio.publish('pubsub_test'); o.jio.publish('pubsub_test');
ok (spy1.calledOnce, 'unsubscribing, same event not called twice'); ok (spy1.calledOnce, 'unsubscribing, same event not called twice');
o.jio.stop(); o.jio.stop();
}); });
...@@ -108,7 +108,7 @@ test ('All tests', function () { ...@@ -108,7 +108,7 @@ test ('All tests', function () {
{'fileName':'memo','creationDate':20000,'lastModified':25000}]); {'fileName':'memo','creationDate':20000,'lastModified':25000}]);
mytest('remove document OK','removeDocument','isRemoved',true); mytest('remove document OK','removeDocument','isRemoved',true);
o.jio.stop(); o.jio.stop();
// All Fail Dummy Storage // All Fail Dummy Storage
o.jio = JIO.createNew({'type':'dummyallfail','userName':'Dummy'}, o.jio = JIO.createNew({'type':'dummyallfail','userName':'Dummy'},
{'ID':'jiotests'}); {'ID':'jiotests'});
...@@ -140,25 +140,21 @@ test ('Simple Job Elimination', function () { ...@@ -140,25 +140,21 @@ test ('Simple Job Elimination', function () {
o.jio = JIO.createNew({'type':'dummyallok','userName':'dummy'}, o.jio = JIO.createNew({'type':'dummyallok','userName':'dummy'},
{'ID':'jiotests'}); {'ID':'jiotests'});
id = o.jio.id; id = o.jio.getID();
o.jio.saveDocument({'fileName':'file','fileContent':'content', o.jio.saveDocument({'fileName':'file','fileContent':'content',
'callback':o.f1,'maxtries':1}); 'callback':o.f1,'maxtries':1});
console.log (localStorage.getItem('jio/jobObject/'+id));
ok(LocalOrCookieStorage.getItem('jio/jobObject/'+id)['1'], ok(LocalOrCookieStorage.getItem('jio/jobObject/'+id)['1'],
'job creation'); 'job creation');
console.log (localStorage.getItem('jio/jobObject/'+id));
clock.tick(10); clock.tick(10);
console.log (localStorage.getItem('jio/jobObject/'+id));
o.jio.removeDocument({'fileName':'file','fileContent':'content', o.jio.removeDocument({'fileName':'file','fileContent':'content',
'callback':o.f2,'maxtries':1}); 'callback':o.f2,'maxtries':1});
o.tmp = LocalOrCookieStorage.getItem('jio/jobObject/'+id)['1']; o.tmp = LocalOrCookieStorage.getItem('jio/jobObject/'+id)['1'];
console.log (localStorage.getItem('jio/jobObject/'+id));
ok(!o.tmp || o.tmp.status === 'fail','job elimination'); ok(!o.tmp || o.tmp.status === 'fail','job elimination');
}); });
test ('Simple Job Replacement', function () { test ('Simple Job Replacement', function () {
// Test if the second job write over the first one // Test if the second job write over the first one
var o = {}, clock = this.sandbox.useFakeTimers(), id = 0; var o = {}, clock = this.sandbox.useFakeTimers(), id = 0;
o.f1 = function (result) { o.f1 = function (result) {
o.status = result.status; o.status = result.status;
...@@ -168,7 +164,7 @@ test ('Simple Job Replacement', function () { ...@@ -168,7 +164,7 @@ test ('Simple Job Replacement', function () {
o.jio = JIO.createNew({'type':'dummyallok','userName':'dummy'}, o.jio = JIO.createNew({'type':'dummyallok','userName':'dummy'},
{'ID':'jiotests'}); {'ID':'jiotests'});
id = o.jio.id; id = o.jio.getID();
o.jio.saveDocument({'fileName':'file','fileContent':'content', o.jio.saveDocument({'fileName':'file','fileContent':'content',
'callback':o.f1,'maxtries':1}); 'callback':o.f1,'maxtries':1});
clock.tick(10); clock.tick(10);
...@@ -184,8 +180,8 @@ test ('Simple Job Replacement', function () { ...@@ -184,8 +180,8 @@ test ('Simple Job Replacement', function () {
o.jio.stop(); o.jio.stop();
}); });
test ('Simple Job Waiting', function () { test ('Simple Job Waiting', function () {
// Test if the second job doesn't erase the first ongoing one // Test if the second job doesn't erase the first ongoing one
var o = {}, clock = this.sandbox.useFakeTimers(), id = 0; var o = {}, clock = this.sandbox.useFakeTimers(), id = 0;
...@@ -193,7 +189,7 @@ test ('Simple Job Waiting', function () { ...@@ -193,7 +189,7 @@ test ('Simple Job Waiting', function () {
o.jio = JIO.createNew({'type':'dummyallok','userName':'dummy'}, o.jio = JIO.createNew({'type':'dummyallok','userName':'dummy'},
{'ID':'jiotests'}); {'ID':'jiotests'});
id = o.jio.id; id = o.jio.getID();
o.jio.saveDocument({'fileName':'file','fileContent':'content', o.jio.saveDocument({'fileName':'file','fileContent':'content',
'callback':o.f3,'maxtries':1}); 'callback':o.f3,'maxtries':1});
clock.tick(200); clock.tick(200);
...@@ -220,7 +216,7 @@ test ('Simple Job Waiting', function () { ...@@ -220,7 +216,7 @@ test ('Simple Job Waiting', function () {
test ('Simple Time Waiting' , function () { test ('Simple Time Waiting' , function () {
// Test if the job that have fail wait until a certain moment to restart. // Test if the job that have fail wait until a certain moment to restart.
// It will use the dummyall3tries, which will work after the 3rd try. // It will use the dummyall3tries, which will work after the 3rd try.
var o = {}, clock = this.sandbox.useFakeTimers(), id = 0; var o = {}, clock = this.sandbox.useFakeTimers(), id = 0;
o.f = function (result) { o.f = function (result) {
o.res = (result.status === 'done'); o.res = (result.status === 'done');
...@@ -273,7 +269,7 @@ test ('Check name availability', function () { ...@@ -273,7 +269,7 @@ test ('Check name availability', function () {
test ('Document save', function () { test ('Document save', function () {
// Test if LocalStorage can save documents. // Test if LocalStorage can save documents.
// We launch a saving to localstorage and we check if the file is // We launch a saving to localstorage and we check if the file is
// realy saved. Then save again and check if // realy saved. Then save again and check if
var o = {}, clock = this.sandbox.useFakeTimers(), t = this, tmp, var o = {}, clock = this.sandbox.useFakeTimers(), t = this, tmp,
mytest = function (message,value,lmcd){ mytest = function (message,value,lmcd){
...@@ -306,7 +302,7 @@ test ('Document save', function () { ...@@ -306,7 +302,7 @@ test ('Document save', function () {
mytest('saving document',true,function(cd,lm){ mytest('saving document',true,function(cd,lm){
return (cd === lm); return (cd === lm);
}); });
// re-save and check modification date // re-save and check modification date
mytest('saving again',true,function(cd,lm){ mytest('saving again',true,function(cd,lm){
return (cd < lm); return (cd < lm);
...@@ -337,7 +333,7 @@ test ('Document load', function () { ...@@ -337,7 +333,7 @@ test ('Document load', function () {
// load a non existing file // load a non existing file
LocalOrCookieStorage.deleteItem ('jio/local/MrLoadName/jiotests/file'); LocalOrCookieStorage.deleteItem ('jio/local/MrLoadName/jiotests/file');
mytest ('status','fail'); mytest ('status','fail');
// re-load file after saving it manually // re-load file after saving it manually
doc = {'fileName':'file','fileContent':'content', doc = {'fileName':'file','fileContent':'content',
'lastModified':1234,'creationDate':1000}; 'lastModified':1234,'creationDate':1000};
...@@ -418,7 +414,7 @@ module ('Jio DAVStorage'); ...@@ -418,7 +414,7 @@ module ('Jio DAVStorage');
test ('Check name availability', function () { test ('Check name availability', function () {
// Test if DavStorage can check the availabality of a name. // Test if DavStorage can check the availabality of a name.
var o = {}, clock = this.sandbox.useFakeTimers(), t = this, var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (value,errno) { mytest = function (value,errno) {
var server = t.sandbox.useFakeServer(); var server = t.sandbox.useFakeServer();
...@@ -436,7 +432,7 @@ test ('Check name availability', function () { ...@@ -436,7 +432,7 @@ test ('Check name availability', function () {
if (!o.f.calledOnce) if (!o.f.calledOnce)
ok(false, 'no response / too much results'); ok(false, 'no response / too much results');
}; };
o.jio = JIO.createNew({'type':'dav','userName':'davcheck', o.jio = JIO.createNew({'type':'dav','userName':'davcheck',
'password':'checkpwd', 'password':'checkpwd',
'location':'https://ca-davstorage:8080'}, 'location':'https://ca-davstorage:8080'},
...@@ -479,8 +475,8 @@ test ('Document load', function () { ...@@ -479,8 +475,8 @@ test ('Document load', function () {
'location':'https://ca-davstorage:8080'}, 'location':'https://ca-davstorage:8080'},
{'ID':'jiotests'}); {'ID':'jiotests'});
// note: http errno: // note: http errno:
// 200 OK // 200 OK
// 201 Created // 201 Created
// 204 No Content // 204 No Content
// 207 Multi Status // 207 Multi Status
// 403 Forbidden // 403 Forbidden
...@@ -614,7 +610,7 @@ test ('Remove document', function () { ...@@ -614,7 +610,7 @@ test ('Remove document', function () {
'password':'checkpwd', 'password':'checkpwd',
'location':'https://ca-davstorage:8080'}, 'location':'https://ca-davstorage:8080'},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('remove document',true,204) mytest('remove document',true,204)
mytest('remove an already removed document',true,404) mytest('remove an already removed document',true,404)
o.jio.stop(); o.jio.stop();
...@@ -720,7 +716,7 @@ test ('Document load', function () { ...@@ -720,7 +716,7 @@ test ('Document load', function () {
'fileName':'file','fileContent':'content2', 'fileName':'file','fileContent':'content2',
'lastModified':17000, 'lastModified':17000,
'creationDate':10000}); 'creationDate':10000});
o.jio.stop(); o.jio.stop();
}); });
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment