~ubuntu-branches/ubuntu/oneiric/weave/oneiric

« back to all changes in this revision

Viewing changes to tests/unit/attic/test_bookmark_sharing.js

  • Committer: Bazaar Package Importer
  • Author(s): Micah Gersten
  • Date: 2010-08-11 00:35:15 UTC
  • mfrom: (3.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100811003515-o3jbh826bnd1syjv
Tags: 1.4.3-1ubuntu1
* Add -fshort-wchar to CXXFLAGS to fix FTBFS in Ubuntu
  - update debian/rules 

Show diffs side-by-side

added added

removed removed

Lines of Context:
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");
5
 
 
6
 
Function.prototype.async = Async.sugar;
7
 
 
8
 
load("bookmark_setup.js");
9
 
 
10
 
function FakeMicrosummaryService() {
11
 
  return {hasMicrosummary: function() { return false; }};
12
 
}
13
 
 
14
 
function FakeAnnotationService() {
15
 
  this._annotations = {};
16
 
}
17
 
FakeAnnotationService.prototype = {
18
 
  EXPIRE_NEVER: 0,
19
 
  getItemAnnotation: function (aItemId, aName) {
20
 
    if (this._annotations[aItemId] != undefined)
21
 
      if (this._annotations[aItemId][aName])
22
 
        return this._annotations[aItemId][aName];
23
 
    return null;
24
 
  },
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
31
 
  },
32
 
  getItemsWithAnnotation: function(aName, resultCount, results) {
33
 
    var list = [];
34
 
    for ( var x in this._annotations) {
35
 
      if (this._annotations[x][aName] != undefined) {
36
 
        return x;
37
 
      }
38
 
    }
39
 
    return list;
40
 
  }
41
 
}
42
 
 
43
 
 
44
 
function FakeSharingApi() {
45
 
}
46
 
FakeSharingApi.prototype = {
47
 
  shareWithUsers: function FakeSharingApi_shareWith(path, users, onComplete) {
48
 
    // TODO just set a flag on the fake DAV thing.
49
 
  }
50
 
}
51
 
Sharing.Api = FakeSharingApi;
52
 
 
53
 
 
54
 
var annoSvc = new FakeAnnotationService();
55
 
 
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
61
 
  return engine;
62
 
}
63
 
 
64
 
function run_test() {
65
 
  let bms = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
66
 
    getService(Ci.nsINavBookmarksService);
67
 
 
68
 
 
69
 
  var syncTesting = new SyncTestingInfrastructure( makeBookmarksEngine );
70
 
 
71
 
  let folderName = "Funny Pictures of Manatees and Walruses";
72
 
  let folderToShare = bms.createFolder( bms.bookmarksMenuFolder,
73
 
                                        folderName, -1 );
74
 
  let lolrusBm = bms.insertBookmark(folderToShare,
75
 
                                    uri("http://www.lolrus.com"),
76
 
                                    -1, "LOLrus" );
77
 
  let lolateeBm = bms.insertBookmark(folderToShare,
78
 
                                    uri("http://www.lolatee.com"),
79
 
                                    -1, "LOLatee" );
80
 
 
81
 
  // Note xmpp.enabled is set to false by the SyncTestingInfrastructure.
82
 
 
83
 
  let username = "rusty";
84
 
  let engine = makeBookmarksEngine();
85
 
  let shareManager = engine._sharing;
86
 
 
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
90
 
    // Places ID.
91
 
    shareManager._share.async( shareManager, cb, folderToShare, "jonas" );
92
 
  }
93
 
 
94
 
  /*
95
 
  syncTesting.runAsyncFunc("Share folder with Jonas", setupShare);
96
 
 
97
 
 
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");
103
 
 
104
 
  // get off rusty's computer, switch to Jonas's computer:
105
 
  syncTesting.saveClientState( "rusty computer 1" );
106
 
  syncTesting.resetClientState();
107
 
 
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();
112
 
 
113
 
  // now look for a bookmark folder with an incoming-share annotation
114
 
  let a = annoSvc.getItemsWithAnnotation("weave/shared-incoming",
115
 
                                         {});
116
 
  do_check_eq( a.length, 1); // should be just one
117
 
  // TODO next look at its children:
118
 
   */
119
 
}
120
 
 
121