Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Roque
jio
Commits
d110ccea
Commit
d110ccea
authored
Sep 20, 2019
by
Roque
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: resuming officejs scenario
parent
5d72e7e1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16333 additions
and
0 deletions
+16333
-0
dist/jio-latest.js
dist/jio-latest.js
+219
-0
dist/jio-v3.40.0-node.js
dist/jio-v3.40.0-node.js
+15378
-0
examples/scenario_officejs.html
examples/scenario_officejs.html
+44
-0
examples/scenario_officejs.js
examples/scenario_officejs.js
+692
-0
No files found.
dist/jio-latest.js
View file @
d110ccea
...
@@ -16006,3 +16006,222 @@ return new Parser;
...
@@ -16006,3 +16006,222 @@ return new Parser;
jIO
.
addStorage
(
'
cloudooo
'
,
CloudoooStorage
);
jIO
.
addStorage
(
'
cloudooo
'
,
CloudoooStorage
);
}(
jIO
,
RSVP
,
DOMParser
,
XMLSerializer
));
}(
jIO
,
RSVP
,
DOMParser
,
XMLSerializer
));
/*jslint nomen: true*/
(
function
(
jIO
)
{
"
use strict
"
;
/**
* The jIO SafeRepairStorage extension
*
* @class SafeRepairStorage
* @constructor
*/
function
SafeRepairStorage
(
spec
)
{
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
this
.
_id_dict
=
{};
}
SafeRepairStorage
.
prototype
.
get
=
function
()
{
return
this
.
_sub_storage
.
get
.
apply
(
this
.
_sub_storage
,
arguments
);
};
SafeRepairStorage
.
prototype
.
allAttachments
=
function
()
{
return
this
.
_sub_storage
.
allAttachments
.
apply
(
this
.
_sub_storage
,
arguments
);
};
SafeRepairStorage
.
prototype
.
post
=
function
()
{
return
this
.
_sub_storage
.
post
.
apply
(
this
.
_sub_storage
,
arguments
);
};
SafeRepairStorage
.
prototype
.
put
=
function
(
id
,
doc
)
{
var
storage
=
this
;
return
this
.
_sub_storage
.
put
.
apply
(
this
.
_sub_storage
,
arguments
)
.
push
(
undefined
,
function
(
error
)
{
if
(
error
instanceof
jIO
.
util
.
jIOError
&&
error
.
status_code
===
403
)
{
if
(
storage
.
_id_dict
[
id
])
{
return
storage
.
_sub_storage
.
put
(
storage
.
_id_dict
[
id
],
doc
);
}
return
storage
.
_sub_storage
.
post
(
doc
)
.
push
(
function
(
sub_id
)
{
storage
.
_id_dict
[
id
]
=
sub_id
;
return
sub_id
;
});
}
});
};
SafeRepairStorage
.
prototype
.
remove
=
function
()
{
return
;
};
SafeRepairStorage
.
prototype
.
getAttachment
=
function
()
{
return
this
.
_sub_storage
.
getAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
};
SafeRepairStorage
.
prototype
.
putAttachment
=
function
(
id
,
attachment_id
,
attachment
)
{
var
storage
=
this
;
return
this
.
_sub_storage
.
putAttachment
.
apply
(
this
.
_sub_storage
,
arguments
)
.
push
(
undefined
,
function
(
error
)
{
if
(
error
instanceof
jIO
.
util
.
jIOError
&&
error
.
status_code
===
403
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
if
(
storage
.
_id_dict
[
id
])
{
return
storage
.
_id_dict
[
id
];
}
return
storage
.
_sub_storage
.
get
(
id
)
.
push
(
function
(
doc
)
{
return
storage
.
_sub_storage
.
post
(
doc
);
});
})
.
push
(
function
(
sub_id
)
{
storage
.
_id_dict
[
id
]
=
sub_id
;
return
storage
.
_sub_storage
.
putAttachment
(
sub_id
,
attachment_id
,
attachment
);
});
}
});
};
SafeRepairStorage
.
prototype
.
removeAttachment
=
function
()
{
return
;
};
SafeRepairStorage
.
prototype
.
repair
=
function
()
{
return
this
.
_sub_storage
.
repair
.
apply
(
this
.
_sub_storage
,
arguments
);
};
SafeRepairStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
return
this
.
_sub_storage
.
hasCapacity
(
name
);
};
SafeRepairStorage
.
prototype
.
buildQuery
=
function
()
{
return
this
.
_sub_storage
.
buildQuery
.
apply
(
this
.
_sub_storage
,
arguments
);
};
jIO
.
addStorage
(
'
saferepair
'
,
SafeRepairStorage
);
}(
jIO
));
/*jslint indent:2, maxlen: 80, nomen: true */
/*global jIO, RSVP, window, Rusha, Blob, URL */
(
function
(
window
,
jIO
,
RSVP
,
Rusha
,
Blob
,
URL
)
{
"
use strict
"
;
var
rusha
=
new
Rusha
();
function
AppCacheStorage
(
spec
)
{
this
.
_manifest
=
spec
.
manifest
;
this
.
_take_installer
=
spec
.
take_installer
||
false
;
this
.
_origin_url
=
spec
.
origin_url
!==
undefined
?
spec
.
origin_url
:
window
.
location
.
href
;
this
.
_version
=
spec
.
version
||
""
;
this
.
_prefix
=
spec
.
prefix
||
"
./
"
;
this
.
_documents
=
{};
// Harcoded here, find a better way.
if
(
this
.
_take_installer
)
{
this
.
_relative_url_list
=
[
this
.
_prefix
,
this
.
_prefix
+
"
gadget_officejs_bootloader.js
"
,
this
.
_prefix
+
"
gadget_officejs_bootloader_presentation.html
"
,
this
.
_prefix
+
"
gadget_officejs_bootloader_presentation.js
"
,
this
.
_prefix
+
"
gadget_officejs_bootloader_presentation.css
"
,
this
.
_prefix
+
"
gadget_officejs_bootloader_serviceworker.js
"
,
this
.
_prefix
+
"
gadget_erp5_nojqm.css
"
,
this
.
_prefix
+
"
officejs_logo.png
"
,
this
.
_prefix
+
"
jio_appcachestorage.js
"
];
}
else
{
this
.
_relative_url_list
=
[
this
.
_prefix
+
"
/
"
];
}
if
(
this
.
_take_installer
)
{
this
.
_version
=
'
app/
'
;
}
this
.
_version
=
this
.
_prefix
+
this
.
_version
;
}
AppCacheStorage
.
prototype
.
get
=
function
(
id
)
{
if
(
this
.
_documents
.
hasOwnProperty
(
id
))
{
return
this
.
_documents
[
id
];
}
throw
new
jIO
.
util
.
jIOError
(
'
can not find document :
'
+
id
,
404
);
};
AppCacheStorage
.
prototype
.
hasCapacity
=
function
()
{
return
true
;
};
AppCacheStorage
.
prototype
.
getAttachment
=
function
(
origin_url
,
relative_url
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
ajax
({
type
:
"
GET
"
,
url
:
new
URL
(
relative_url
,
origin_url
),
dataType
:
"
blob
"
});
})
.
push
(
function
(
result
)
{
return
result
.
target
.
response
;
});
};
AppCacheStorage
.
prototype
.
allAttachments
=
function
(
id
)
{
if
(
id
===
this
.
_origin_url
)
{
var
result
=
{},
i
,
len
=
this
.
_relative_url_list
.
length
;
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
result
[
this
.
_relative_url_list
[
i
]]
=
{};
}
return
result
;
}
return
[];
};
AppCacheStorage
.
prototype
.
buildQuery
=
function
()
{
var
result
=
[],
id
;
for
(
id
in
this
.
_documents
)
{
if
(
this
.
_documents
.
hasOwnProperty
(
id
))
{
result
.
push
({
'
id
'
:
id
,
'
value
'
:
this
.
_documents
[
id
],
'
doc
'
:
this
.
_documents
[
id
]
});
}
}
return
result
;
};
AppCacheStorage
.
prototype
.
repair
=
function
()
{
var
storage
=
this
,
url
=
""
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
url
=
new
URL
(
storage
.
_manifest
,
new
URL
(
storage
.
_version
,
storage
.
_origin_url
));
return
jIO
.
util
.
ajax
({
type
:
"
GET
"
,
url
:
url
});
})
.
push
(
function
(
response
)
{
var
text
=
response
.
target
.
responseText
,
relative_url_list
=
text
.
split
(
'
\n
'
),
i
,
take
=
false
,
hash
=
rusha
.
digestFromString
(
text
);
storage
.
_documents
[
storage
.
_origin_url
]
=
{
'
hash
'
:
hash
};
storage
.
_relative_url_list
.
push
(
storage
.
_version
);
storage
.
_relative_url_list
.
push
(
storage
.
_version
+
storage
.
_manifest
);
for
(
i
=
0
;
i
<
relative_url_list
.
length
;
i
+=
1
)
{
if
(
relative_url_list
[
i
].
indexOf
(
"
NETWORK:
"
)
>=
0
)
{
take
=
false
;
}
else
if
(
relative_url_list
[
i
]
!==
""
&&
relative_url_list
[
i
].
charAt
(
0
)
!==
'
#
'
&&
relative_url_list
[
i
].
charAt
(
0
)
!==
'
'
&&
take
)
{
storage
.
_relative_url_list
.
push
(
storage
.
_version
+
relative_url_list
[
i
]
);
}
if
(
relative_url_list
[
i
].
indexOf
(
"
CACHE:
"
)
>=
0
)
{
take
=
true
;
}
}
})
.
push
(
undefined
,
function
(
error
)
{
if
(
!
error
.
message
)
{
error
.
message
=
"
Can't get manifest. URL:
"
+
url
;
}
throw
error
;
});
};
jIO
.
addStorage
(
'
appcache
'
,
AppCacheStorage
);
}(
window
,
jIO
,
RSVP
,
Rusha
,
Blob
,
URL
));
dist/jio-v3.40.0-node.js
0 → 100644
View file @
d110ccea
This source diff could not be displayed because it is too large. You can
view the blob
instead.
examples/scenario_officejs.html
0 → 100644
View file @
d110ccea
<!DOCTYPE html>
<!--
Copyright 2014, Nexedi SA
This program is free software: you can Use, Study, Modify and Redistribute
it under the terms of the GNU General Public License version 3, or (at your
option) any later version, as published by the Free Software Foundation.
You can also Link and Combine this program with other software covered by
the terms of any of the Free Software licenses or any of the Open Source
Initiative approved licenses and Convey the resulting work. Corresponding
source of such a combination shall include the source code for all other
software used.
This program is distributed WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See COPYING file for full licensing terms.
See https://www.nexedi.com/licensing for rationale and options.
-->
<html
lang=
"en"
>
<head>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
>
<title>
OfficeJS Coverage Scenario
</title>
<script
src=
"../external/rsvp-2.0.4.js"
></script>
<script
src=
"../external/renderjs-latest.js"
></script>
<script
src=
"../dist/jio-latest.js"
></script>
<link
rel=
"stylesheet"
href=
"../external/qunit.css"
type=
"text/css"
media=
"screen"
/>
<script
src=
"../external/qunit.js"
type=
"text/javascript"
></script>
<script
src=
"scenario_officejs.js"
></script>
</head>
<body>
<h1
id=
"qunit-header"
>
OfficeJS Coverage Scenario
</h1>
<h2
id=
"qunit-banner"
></h2>
<div
id=
"qunit-testrunner-toolbar"
></div>
<h2
id=
"qunit-userAgent"
></h2>
<ol
id=
"qunit-tests"
></ol>
<div
id=
"qunit-fixture"
>
test markup, will be hidden
</div>
</body>
</html>
\ No newline at end of file
examples/scenario_officejs.js
0 → 100644
View file @
d110ccea
/*
* Copyright 2014, Nexedi SA
*
* This program is free software: you can Use, Study, Modify and Redistribute
* it under the terms of the GNU General Public License version 3, or (at your
* option) any later version, as published by the Free Software Foundation.
*
* You can also Link and Combine this program with other software covered by
* the terms of any of the Free Software licenses or any of the Open Source
* Initiative approved licenses and Convey the resulting work. Corresponding
* source of such a combination shall include the source code for all other
* software used.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
/*global console, btoa, Blob*/
/*jslint nomen: true, maxlen: 200*/
(
function
(
QUnit
,
jIO
,
Blob
)
{
"
use strict
"
;
var
test
=
QUnit
.
test
,
// equal = QUnit.equal,
expect
=
QUnit
.
expect
,
ok
=
QUnit
.
ok
,
stop
=
QUnit
.
stop
,
start
=
QUnit
.
start
,
deepEqual
=
QUnit
.
deepEqual
,
module
=
QUnit
.
module
,
ATTACHMENT
=
'
data
'
,
i
,
name_list
=
[
'
get
'
,
'
post
'
,
'
put
'
,
'
buildQuery
'
,
'
putAttachment
'
,
'
getAttachment
'
,
'
allAttachments
'
];
///////////////////////////////////////////////////////
// Fake Storage
///////////////////////////////////////////////////////
function
resetCount
(
count
)
{
for
(
i
=
0
;
i
<
name_list
.
length
;
i
+=
1
)
{
count
[
name_list
[
i
]]
=
0
;
}
}
function
MockStorage
(
spec
)
{
this
.
_erp5_storage
=
jIO
.
createJIO
({
type
:
"
erp5
"
,
url
:
"
http://example.org
"
});
this
.
_sub_storage
=
jIO
.
createJIO
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
}
}
});
this
.
_options
=
spec
.
options
;
resetCount
(
spec
.
options
.
count
);
}
function
mockFunction
(
name
)
{
MockStorage
.
prototype
[
name
]
=
function
()
{
this
.
_options
.
count
[
name
]
+=
1
;
if
(
this
.
_options
.
mock
.
hasOwnProperty
(
name
))
{
return
this
.
_options
.
mock
[
name
].
apply
(
this
,
arguments
);
}
return
this
.
_sub_storage
[
name
].
apply
(
this
.
_sub_storage
,
arguments
);
};
}
for
(
i
=
0
;
i
<
name_list
.
length
;
i
+=
1
)
{
mockFunction
(
name_list
[
i
]);
}
MockStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
return
this
.
_erp5_storage
.
hasCapacity
(
name
);
};
jIO
.
addStorage
(
'
mock
'
,
MockStorage
);
///////////////////////////////////////////////////////
// Helpers
///////////////////////////////////////////////////////
function
putFullDoc
(
storage
,
id
,
doc
,
attachment
)
{
return
storage
.
put
(
id
,
doc
)
.
push
(
function
()
{
return
storage
.
putAttachment
(
id
,
ATTACHMENT
,
attachment
);
});
}
function
equalStorage
(
storage
,
doc_tuple_list
)
{
return
storage
.
allDocs
()
.
push
(
function
(
result
)
{
var
i
,
promise_list
=
[];
for
(
i
=
0
;
i
<
result
.
data
.
rows
.
length
;
i
+=
1
)
{
promise_list
.
push
(
RSVP
.
all
([
result
.
data
.
rows
[
i
].
id
,
storage
.
get
(
result
.
data
.
rows
[
i
].
id
),
storage
.
getAttachment
(
result
.
data
.
rows
[
i
].
id
,
ATTACHMENT
)
]));
}
return
RSVP
.
all
(
promise_list
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
doc_tuple_list
,
'
Storage content
'
);
});
}
function
isEmptyStorage
(
storage
)
{
return
equalStorage
(
storage
,
[]);
}
function
equalRemoteStorageCallCount
(
mock_count
,
expected_count
)
{
for
(
i
=
0
;
i
<
name_list
.
length
;
i
+=
1
)
{
if
(
!
expected_count
.
hasOwnProperty
(
name_list
[
i
]))
{
expected_count
[
name_list
[
i
]]
=
0
;
}
}
deepEqual
(
mock_count
,
expected_count
,
'
Expected method call count
'
);
}
///////////////////////////////////////////////////////
// Module
///////////////////////////////////////////////////////
module
(
"
scenario_officejs
"
,
{
setup
:
function
()
{
this
.
remote_mock_options
=
{
mock
:
{
remove
:
function
()
{
throw
new
Error
(
'
remove not supported
'
);
},
removeAttachment
:
function
()
{
throw
new
Error
(
'
removeAttachment not supported
'
);
},
allAttachments
:
function
()
{
return
{
data
:
null
};
},
post
:
function
(
doc
)
{
var
context
=
this
;
return
this
.
_sub_storage
.
post
(
doc
)
.
push
(
function
(
post_id
)
{
context
.
_options
.
last_post_id
=
post_id
;
return
post_id
;
});
}
},
count
:
{}
};
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
query
:
{
query
:
'
portal_type:"Foo"
'
,
sort_on
:
[[
"
modification_date
"
,
"
descending
"
]]
},
use_remote_post
:
true
,
conflict_handling
:
1
,
signature_hash_key
:
'
modification_date
'
,
check_local_attachment_modification
:
true
,
check_local_attachment_creation
:
true
,
check_remote_attachment_modification
:
true
,
check_remote_attachment_creation
:
true
,
check_remote_attachment_deletion
:
true
,
check_local_deletion
:
false
,
parallel_operation_amount
:
10
,
parallel_operation_attachment_amount
:
10
,
local_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
}
}
},
signature_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
memory
"
}
},
remote_sub_storage
:
{
type
:
"
saferepair
"
,
sub_storage
:
{
type
:
"
mock
"
,
options
:
this
.
remote_mock_options
}
}
});
}
});
///////////////////////////////////////////////////////
// Do nothing cases
///////////////////////////////////////////////////////
test
(
"
empty: nothing to do
"
,
function
()
{
expect
(
2
);
stop
();
var
test
=
this
;
this
.
jio
.
repair
()
.
then
(
function
()
{
return
RSVP
.
all
([
isEmptyStorage
(
test
.
jio
),
equalRemoteStorageCallCount
(
test
.
remote_mock_options
.
count
,
{
buildQuery
:
1
}
)
]);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
allready synced: nothing to do
"
,
function
()
{
expect
(
2
);
stop
();
var
test
=
this
,
doc_id
=
'
foo_module/1
'
,
doc
=
{
title
:
doc_id
,
portal_type
:
"
Foo
"
,
modification_date
:
'
a
'
},
blob
=
new
Blob
([
'
a
'
]);
putFullDoc
(
this
.
jio
.
__storage
.
_remote_sub_storage
,
doc_id
,
doc
,
blob
)
.
then
(
function
()
{
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
resetCount
(
test
.
remote_mock_options
.
count
);
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
equalRemoteStorageCallCount
(
test
.
remote_mock_options
.
count
,
{
buildQuery
:
1
}
);
return
equalStorage
(
test
.
jio
,
[[
doc_id
,
doc
,
blob
]]);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
///////////////////////////////////////////////////////
// Remote creation
///////////////////////////////////////////////////////
test
(
"
remote document creation: copy
"
,
function
()
{
expect
(
2
);
stop
();
var
test
=
this
,
doc_id
=
'
foo_module/1
'
,
doc
=
{
title
:
doc_id
,
portal_type
:
"
Foo
"
,
modification_date
:
'
a
'
},
blob
=
new
Blob
([
'
a
'
]);
putFullDoc
(
this
.
jio
.
__storage
.
_remote_sub_storage
,
doc_id
,
doc
,
blob
)
.
then
(
function
()
{
resetCount
(
test
.
remote_mock_options
.
count
);
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
equalRemoteStorageCallCount
(
test
.
remote_mock_options
.
count
,
{
buildQuery
:
1
,
get
:
1
,
getAttachment
:
1
,
allAttachments
:
1
}
);
return
equalStorage
(
test
.
jio
,
[[
doc_id
,
doc
,
blob
]]);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
///////////////////////////////////////////////////////
// Remote modification
///////////////////////////////////////////////////////
test
(
"
remote document modification: copy
"
,
function
()
{
expect
(
2
);
stop
();
var
test
=
this
,
doc_id
=
'
foo_module/1
'
,
doc
=
{
title
:
doc_id
,
portal_type
:
"
Foo
"
,
modification_date
:
'
a
'
},
doc2
=
{
title
:
doc_id
+
'
a
'
,
portal_type
:
"
Foo
"
,
modification_date
:
'
b
'
},
blob
=
new
Blob
([
'
a
'
]),
blob2
=
new
Blob
([
'
b
'
]);
putFullDoc
(
this
.
jio
.
__storage
.
_remote_sub_storage
,
doc_id
,
doc
,
blob
)
.
then
(
function
()
{
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
return
putFullDoc
(
test
.
jio
.
__storage
.
_remote_sub_storage
,
doc_id
,
doc2
,
blob2
);
})
.
then
(
function
()
{
resetCount
(
test
.
remote_mock_options
.
count
);
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
equalRemoteStorageCallCount
(
test
.
remote_mock_options
.
count
,
{
buildQuery
:
1
,
get
:
1
,
getAttachment
:
1
,
allAttachments
:
1
}
);
return
equalStorage
(
test
.
jio
,
[[
doc_id
,
doc2
,
blob2
]]);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
///////////////////////////////////////////////////////
// Remote hide
///////////////////////////////////////////////////////
test
(
"
remote document deletion: delete
"
,
function
()
{
expect
(
2
);
stop
();
var
test
=
this
,
doc_id
=
'
foo_module/1
'
,
doc
=
{
title
:
doc_id
,
portal_type
:
"
Foo
"
,
modification_date
:
'
a
'
},
blob
=
new
Blob
([
'
a
'
]);
putFullDoc
(
this
.
jio
.
__storage
.
_remote_sub_storage
,
doc_id
,
doc
,
blob
)
.
then
(
function
()
{
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
test
.
remote_mock_options
.
mock
.
buildQuery
=
function
()
{
return
[];
};
resetCount
(
test
.
remote_mock_options
.
count
);
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
return
RSVP
.
all
([
isEmptyStorage
(
test
.
jio
),
equalRemoteStorageCallCount
(
test
.
remote_mock_options
.
count
,
{
buildQuery
:
1
}
)
]);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
///////////////////////////////////////////////////////
// Local creation
///////////////////////////////////////////////////////
test
(
"
local document creation: copy
"
,
function
()
{
expect
(
3
);
stop
();
var
test
=
this
,
doc_id
=
'
abc
'
,
doc
=
{
title
:
doc_id
,
portal_type
:
"
Foo
"
,
modification_date
:
'
a
'
},
blob
=
new
Blob
([
'
a
'
]);
putFullDoc
(
this
.
jio
,
doc_id
,
doc
,
blob
)
.
then
(
function
()
{
resetCount
(
test
.
remote_mock_options
.
count
);
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
equalRemoteStorageCallCount
(
test
.
remote_mock_options
.
count
,
{
buildQuery
:
1
,
post
:
1
,
putAttachment
:
1
,
allAttachments
:
1
}
);
return
equalStorage
(
test
.
jio
,
[[
test
.
remote_mock_options
.
last_post_id
,
doc
,
blob
]]
);
})
.
then
(
function
()
{
return
equalStorage
(
test
.
jio
.
__storage
.
_remote_sub_storage
,
[[
test
.
remote_mock_options
.
last_post_id
,
doc
,
blob
]]
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
///////////////////////////////////////////////////////
// Local modification
///////////////////////////////////////////////////////
test
(
"
local document modification: copy
"
,
function
()
{
expect
(
2
);
stop
();
var
test
=
this
,
doc_id
=
'
foo_module/1
'
,
doc
=
{
title
:
doc_id
,
portal_type
:
"
Foo
"
,
modification_date
:
'
a
'
},
doc2
=
{
title
:
doc_id
+
'
a
'
,
portal_type
:
"
Foo
"
,
modification_date
:
'
b
'
},
blob
=
new
Blob
([
'
a
'
]),
blob2
=
new
Blob
([
'
b
'
]),
last_id
;
putFullDoc
(
this
.
jio
,
doc_id
,
doc
,
blob
)
.
then
(
function
()
{
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
last_id
=
test
.
remote_mock_options
.
last_post_id
;
return
putFullDoc
(
test
.
jio
,
last_id
,
doc2
,
blob2
);
})
.
then
(
function
()
{
resetCount
(
test
.
remote_mock_options
.
count
);
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
equalRemoteStorageCallCount
(
test
.
remote_mock_options
.
count
,
{
buildQuery
:
1
,
put
:
1
,
allAttachments
:
1
,
putAttachment
:
1
}
);
return
equalStorage
(
test
.
jio
.
__storage
.
_remote_sub_storage
,
[[
last_id
,
doc2
,
blob2
]]
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
///////////////////////////////////////////////////////
// Conflict
///////////////////////////////////////////////////////
test
(
"
both modification: keep local
"
,
function
()
{
expect
(
2
);
stop
();
var
test
=
this
,
doc_id
=
'
foo_module/1
'
,
doc
=
{
title
:
doc_id
,
portal_type
:
"
Foo
"
,
modification_date
:
'
a
'
},
doc2
=
{
title
:
doc_id
+
'
a
'
,
portal_type
:
"
Foo
"
,
modification_date
:
'
b
'
},
doc3
=
{
title
:
doc_id
+
'
c
'
,
portal_type
:
"
Foo
"
,
modification_date
:
'
c
'
},
blob
=
new
Blob
([
'
a
'
]),
blob2
=
new
Blob
([
'
b
'
]),
blob3
=
new
Blob
([
'
c
'
]);
putFullDoc
(
this
.
jio
.
__storage
.
_remote_sub_storage
,
doc_id
,
doc
,
blob
)
.
then
(
function
()
{
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
return
RSVP
.
all
([
putFullDoc
(
test
.
jio
.
__storage
.
_remote_sub_storage
,
doc_id
,
doc2
,
blob2
),
putFullDoc
(
test
.
jio
,
doc_id
,
doc3
,
blob3
)
]);
})
.
then
(
function
()
{
resetCount
(
test
.
remote_mock_options
.
count
);
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
equalRemoteStorageCallCount
(
test
.
remote_mock_options
.
count
,
{
buildQuery
:
1
,
put
:
1
,
allAttachments
:
1
,
putAttachment
:
1
}
);
return
equalStorage
(
test
.
jio
.
__storage
.
_remote_sub_storage
,
[[
doc_id
,
doc3
,
blob3
]]
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
local modification / frozen remote
"
,
function
()
{
expect
(
1
);
stop
();
var
test
=
this
,
doc_id
=
'
foo_module/1
'
,
doc
=
{
title
:
doc_id
,
portal_type
:
"
Foo
"
,
modification_date
:
'
a
'
},
doc2
=
{
title
:
doc_id
+
'
a
'
,
portal_type
:
"
Foo
"
,
modification_date
:
'
b
'
},
blob
=
new
Blob
([
'
a
'
]),
blob2
=
new
Blob
([
'
b
'
]);
putFullDoc
(
this
.
jio
.
__storage
.
_remote_sub_storage
,
doc_id
,
doc
,
blob
)
.
then
(
function
()
{
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
return
putFullDoc
(
test
.
jio
,
doc_id
,
doc2
,
blob2
);
})
.
then
(
function
()
{
test
.
remote_mock_options
.
mock
.
put
=
function
(
id
)
{
if
(
id
===
doc_id
)
{
throw
new
jIO
.
util
.
jIOError
(
'
put not allowed
'
,
403
);
}
return
id
;
};
test
.
remote_mock_options
.
mock
.
putAttachment
=
function
(
id
)
{
if
(
id
===
doc_id
)
{
throw
new
jIO
.
util
.
jIOError
(
'
putattachment not allowed
'
,
403
);
}
return
id
;
};
resetCount
(
test
.
remote_mock_options
.
count
);
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
// Create New Document When State is Frozen
equalRemoteStorageCallCount
(
test
.
remote_mock_options
.
count
,
{
buildQuery
:
1
,
allAttachments
:
1
,
put
:
1
,
post
:
1
,
putAttachment
:
2
}
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
///////////////////////////////////////////////////////
// Local deletion (aka, people playing manually with the browser storage)
///////////////////////////////////////////////////////
test
(
"
local document deletion: do nothing
"
,
function
()
{
expect
(
3
);
stop
();
var
test
=
this
,
doc_id
=
'
foo_module/1
'
,
doc
=
{
title
:
doc_id
,
portal_type
:
"
Foo
"
,
modification_date
:
'
a
'
},
blob
=
new
Blob
([
'
a
'
]);
putFullDoc
(
this
.
jio
.
__storage
.
_remote_sub_storage
,
doc_id
,
doc
,
blob
)
.
then
(
function
()
{
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
return
test
.
jio
.
remove
(
doc_id
);
})
.
then
(
function
()
{
resetCount
(
test
.
remote_mock_options
.
count
);
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
equalRemoteStorageCallCount
(
test
.
remote_mock_options
.
count
,
{
buildQuery
:
1
}
);
return
RSVP
.
all
([
isEmptyStorage
(
test
.
jio
),
equalStorage
(
test
.
jio
.
__storage
.
_remote_sub_storage
,
[[
doc_id
,
doc
,
blob
]]
)
]);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
local attachment deletion: do nothing
"
,
function
()
{
expect
(
2
);
stop
();
var
test
=
this
,
doc_id
=
'
foo_module/1
'
,
doc
=
{
title
:
doc_id
,
portal_type
:
"
Foo
"
,
modification_date
:
'
a
'
},
blob
=
new
Blob
([
'
a
'
]);
putFullDoc
(
this
.
jio
.
__storage
.
_remote_sub_storage
,
doc_id
,
doc
,
blob
)
.
then
(
function
()
{
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
return
test
.
jio
.
removeAttachment
(
doc_id
,
ATTACHMENT
);
})
.
then
(
function
()
{
resetCount
(
test
.
remote_mock_options
.
count
);
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
equalRemoteStorageCallCount
(
test
.
remote_mock_options
.
count
,
{
buildQuery
:
1
}
);
return
equalStorage
(
test
.
jio
.
__storage
.
_remote_sub_storage
,
[[
doc_id
,
doc
,
blob
]]
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
local deletion / remote modification
"
,
function
()
{
expect
(
2
);
stop
();
var
test
=
this
,
doc_id
=
'
foo_module/1
'
,
doc
=
{
title
:
doc_id
,
portal_type
:
"
Foo
"
,
modification_date
:
'
a
'
},
doc2
=
{
title
:
doc_id
+
'
a
'
,
portal_type
:
"
Foo
"
,
modification_date
:
'
b
'
},
blob
=
new
Blob
([
'
a
'
]),
blob2
=
new
Blob
([
'
b
'
]);
putFullDoc
(
this
.
jio
.
__storage
.
_remote_sub_storage
,
doc_id
,
doc
,
blob
)
.
then
(
function
()
{
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
return
RSVP
.
all
([
putFullDoc
(
test
.
jio
.
__storage
.
_remote_sub_storage
,
doc_id
,
doc2
,
blob2
),
test
.
jio
.
remove
(
doc_id
)
]);
})
.
then
(
function
()
{
resetCount
(
test
.
remote_mock_options
.
count
);
return
test
.
jio
.
repair
();
})
.
then
(
function
()
{
equalRemoteStorageCallCount
(
test
.
remote_mock_options
.
count
,
{
buildQuery
:
1
,
get
:
1
,
allAttachments
:
1
,
getAttachment
:
1
}
);
return
RSVP
.
all
([
equalStorage
(
test
.
jio
,
[[
doc_id
,
doc2
,
blob2
]]
),
equalStorage
(
test
.
jio
.
__storage
.
_remote_sub_storage
,
[[
doc_id
,
doc2
,
blob2
]]
)
]);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
}(
QUnit
,
jIO
,
Blob
));
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment