Bug 1074640 - More tests for bookmarks r=rnewman
authorAlan K <akligman@mozilla.com>
Mon, 29 Sep 2014 23:31:52 -0400
changeset 208641 7c28c8e03229ca44bead5c86cb10e2b601c0ec75
parent 208640 248b7b6c41d54181ef110a0c459ffa5477ccadb5
child 208642 5da210c60d3815e729f5914b0cb341247fa41357
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersrnewman
bugs1074640
milestone35.0a1
Bug 1074640 - More tests for bookmarks r=rnewman From 3f7cc234b5c7a292b06f758bde037192f4afd591 Mon Sep 17 00:00:00 2001 --- .../cloudsync/tests/xpcshell/test_bookmarks.js | 64 +++++++++++++++++++++- 1 file changed, 61 insertions(+), 3 deletions(-)
services/cloudsync/tests/xpcshell/test_bookmarks.js
--- a/services/cloudsync/tests/xpcshell/test_bookmarks.js
+++ b/services/cloudsync/tests/xpcshell/test_bookmarks.js
@@ -4,12 +4,70 @@
 "use strict";
 
 Cu.import("resource://gre/modules/CloudSync.jsm");
 
 function run_test () {
   run_next_test();
 }
 
-add_task(function test_get_remote_tabs () {
-  let rootFolder = yield CloudSync().bookmarks.getRootFolder("TEST");
-  ok(rootFolder.id);
+function cleanup () {
+
+}
+
+add_task(function* test_merge_bookmarks_flat () {
+  try {
+	  let rootFolder = yield CloudSync().bookmarks.getRootFolder("TEST");
+	  ok(rootFolder.id, "root folder id is ok");
+
+	  let items = [
+		{"id":"G_UL4ZhOyX8m","type":rootFolder.BOOKMARK,"title":"reddit: the front page of the internet 1","uri":"http://www.reddit.com",index:2},
+		{"id":"G_UL4ZhOyX8n","type":rootFolder.BOOKMARK,"title":"reddit: the front page of the internet 2","uri":"http://www.reddit.com?1",index:1},
+	  ];
+	  yield rootFolder.mergeRemoteItems(items);
+
+	  let localItems = yield rootFolder.getLocalItems();
+	  equal(Object.keys(localItems).length, items.length, "found merged items");
+  } finally {
+  	yield CloudSync().bookmarks.deleteRootFolder("TEST");
+  }
 });
+
+add_task(function* test_merge_bookmarks_in_folders () {
+  try {
+	  let rootFolder = yield CloudSync().bookmarks.getRootFolder("TEST");
+	  ok(rootFolder.id, "root folder id is ok");
+
+	  let items = [
+	  	{"id":"G_UL4ZhOyX8m","type":rootFolder.BOOKMARK,"title":"reddit: the front page of the internet 1","uri":"http://www.reddit.com",index:2},
+	    {"id":"G_UL4ZhOyX8n","type":rootFolder.BOOKMARK,parent:"G_UL4ZhOyX8x","title":"reddit: the front page of the internet 2","uri":"http://www.reddit.com/?a=å%20ä%20ö",index:1},
+	    {"id":"G_UL4ZhOyX8x","type":rootFolder.FOLDER},
+	  ];
+	  yield rootFolder.mergeRemoteItems(items);
+
+	  let localItems = yield rootFolder.getLocalItems();
+	  equal(localItems.length, items.length, "found merged items");
+
+	  localItems.forEach(function(item) {
+	    ok(item.id == "G_UL4ZhOyX8m" ||
+	       item.id == "G_UL4ZhOyX8n" ||
+	       item.id == "G_UL4ZhOyX8x");
+	    if (item.id == "G_UL4ZhOyX8n") {
+	    	equal(item.parent, "G_UL4ZhOyX8x")
+	    } else {
+	    	equal(item.parent, rootFolder.id);
+	    }
+	  });
+
+	  let folder = (yield rootFolder.getLocalItemsById(["G_UL4ZhOyX8x"]))[0];
+	  equal(folder.id, "G_UL4ZhOyX8x");
+	  equal(folder.type, rootFolder.FOLDER);
+
+	  let bookmark = (yield rootFolder.getLocalItemsById(["G_UL4ZhOyX8n"]))[0];
+	  equal(bookmark.id, "G_UL4ZhOyX8n");
+	  equal(bookmark.parent, "G_UL4ZhOyX8x");
+	  equal(bookmark.title, "reddit: the front page of the internet 2");
+	  equal(bookmark.index, 0);
+	  equal(bookmark.uri, "http://www.reddit.com/?a=%C3%A5%20%C3%A4%20%C3%B6");
+  } finally {
+	yield CloudSync().bookmarks.deleteRootFolder("TEST");
+  }
+});
\ No newline at end of file