1
Cu.import("resource://weave/engines/bookmarks.js");
2
Cu.import("resource://weave/util.js");
3
Cu.import("resource://weave/async.js");
4
Cu.import("resource://weave/sharing.js");
6
Function.prototype.async = Async.sugar;
8
load("bookmark_setup.js");
10
function FakeMicrosummaryService() {
11
return {hasMicrosummary: function() { return false; }};
14
function FakeAnnotationService() {
15
this._annotations = {};
17
FakeAnnotationService.prototype = {
19
getItemAnnotation: function (aItemId, aName) {
20
if (this._annotations[aItemId] != undefined)
21
if (this._annotations[aItemId][aName])
22
return this._annotations[aItemId][aName];
25
setItemAnnotation: function (aItemId, aName, aValue, aFlags, aExpiration) {
26
if (this._annotations[aItemId] == undefined)
27
this._annotations[aItemId] = {};
28
this._annotations[aItemId][aName] = aValue;
29
dump( "Annotated item " + aItemId + " with " + aName + " = " + aValue + "\n");
30
//ignore flags and expiration
32
getItemsWithAnnotation: function(aName, resultCount, results) {
34
for ( var x in this._annotations) {
35
if (this._annotations[x][aName] != undefined) {
44
function FakeSharingApi() {
46
FakeSharingApi.prototype = {
47
shareWithUsers: function FakeSharingApi_shareWith(path, users, onComplete) {
48
// TODO just set a flag on the fake DAV thing.
51
Sharing.Api = FakeSharingApi;
54
var annoSvc = new FakeAnnotationService();
56
function makeBookmarksEngine() {
57
let engine = new BookmarksEngine();
58
engine._store.__ms = new FakeMicrosummaryService();
59
let shareManager = engine._sharing;
60
shareManager.__annoSvc = annoSvc; // use fake annotation service
65
let bms = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
66
getService(Ci.nsINavBookmarksService);
69
var syncTesting = new SyncTestingInfrastructure( makeBookmarksEngine );
71
let folderName = "Funny Pictures of Manatees and Walruses";
72
let folderToShare = bms.createFolder( bms.bookmarksMenuFolder,
74
let lolrusBm = bms.insertBookmark(folderToShare,
75
uri("http://www.lolrus.com"),
77
let lolateeBm = bms.insertBookmark(folderToShare,
78
uri("http://www.lolatee.com"),
81
// Note xmpp.enabled is set to false by the SyncTestingInfrastructure.
83
let username = "rusty";
84
let engine = makeBookmarksEngine();
85
let shareManager = engine._sharing;
87
function setupShare(cb) {
88
// TODO: Passing in folderToShare won't work at the time of writing
89
// this because folderToShare is expected to be a DOM node, not a
91
shareManager._share.async( shareManager, cb, folderToShare, "jonas" );
95
syncTesting.runAsyncFunc("Share folder with Jonas", setupShare);
98
dump( "folderToShare = " + folderToShare + "\n");
99
// Get the server path from folder annotation...
100
let serverPath = annoSvc.getItemAnnotation( folderToShare,
101
"weave/shared-server-path" );
102
dump( "Shared it to server path " + serverPath + "\n");
104
// get off rusty's computer, switch to Jonas's computer:
105
syncTesting.saveClientState( "rusty computer 1" );
106
syncTesting.resetClientState();
108
// These next two lines simulate what would happen when jonas received
109
// the xmpp message and clicked "accept".
110
shareManager._createIncomingShare(username, serverPath, folderName);
111
shareManager._updateAllIncomingShares();
113
// now look for a bookmark folder with an incoming-share annotation
114
let a = annoSvc.getItemsWithAnnotation("weave/shared-incoming",
116
do_check_eq( a.length, 1); // should be just one
117
// TODO next look at its children: