browser/fuel/test/browser_Bookmarks.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 var gLastFolderAction = "";
     2 var gLastBookmarkAction = "";
     3 var gLastRootAction = "";
     5 function url(spec) {
     6   return Services.io.newURI(spec, null, null);
     7 }
     9 function test() {
    10   // Some very basic tests on the tags root
    11   var tags = Application.bookmarks.tags;
    12   ok(tags, "Check access to bookmark tags root");
    13   ok(!tags.parent, "Check tags parent (should be null)");
    15   //----------------------------------------------
    17   // Some very basic tests on the unfiled root
    18   var unfiled = Application.bookmarks.unfiled;
    19   ok(unfiled, "Check access to bookmark unfiled root");
    20   ok(!unfiled.parent, "Check unfiled parent (should be null)");
    22   //----------------------------------------------
    24   // Some basic tests on the toolbar root
    25   var toolbar = Application.bookmarks.toolbar;
    26   ok(toolbar, "Check access to bookmark toolbar root");
    27   ok(!toolbar.parent, "Check toolbar parent (should be null)");
    29   var toolbarKidCount = toolbar.children.length;
    31   // test adding folders
    32   var testFolderToolbar = toolbar.addFolder("FUEL in Toolbar");
    33   ok(testFolderToolbar, "Check folder creation");
    34   is(testFolderToolbar.type, "folder", "Check 'folder.type' after creation");
    35   ok(testFolderToolbar.parent, "Check parent after folder creation");
    37   toolbarKidCount++;
    38   is(toolbar.children.length, toolbarKidCount, "Check toolbar folder child count after adding a child folder");
    40   //----------------------------------------------
    42   // Main testing is done on the bookmarks menu root
    43   var root = Application.bookmarks.menu;
    44   ok(root, "Check access to bookmark root");
    45   ok(!root.parent, "Check root parent (should be null)");
    47   var rootKidCount = root.children.length;
    49   // test adding folders
    50   var testFolder = root.addFolder("FUEL");
    51   ok(testFolder, "Check folder creation");
    52   is(testFolder.type, "folder", "Check 'folder.type' after creation");
    53   ok(testFolder.parent, "Check parent after folder creation");
    55   rootKidCount++;
    56   is(root.children.length, rootKidCount, "Check root folder child count after adding a child folder");
    58   // test modifying a folder
    59   testFolder.events.addListener("change", onFolderChange);
    60   testFolder.description = "FUEL folder";
    61   is(testFolder.description, "FUEL folder", "Check setting 'folder.description'");
    62   is(gLastFolderAction, "bookmarkProperties/description", "Check event handler for setting 'folder.description'");
    64   testFolder.title = "fuel-is-cool";
    65   is(testFolder.title, "fuel-is-cool", "Check setting 'folder.title'");
    66   is(gLastFolderAction, "title", "Check event handler for setting 'folder.title'");
    68   testFolder.annotations.set("testing/folder", "annotate-this", 0);
    69   ok(testFolder.annotations.has("testing/folder"), "Checking existence of added annotation");
    70   is(gLastFolderAction, "testing/folder", "Check event handler for setting annotation");
    71   gLastFolderAction = "";
    72   is(testFolder.annotations.get("testing/folder"), "annotate-this", "Checking existence of added annotation");
    73   testFolder.annotations.remove("testing/folder");
    74   ok(!testFolder.annotations.has("testing/folder"), "Checking existence of removed annotation");
    75   is(gLastFolderAction, "testing/folder", "Check event handler for removing annotation");
    77   testFolder.events.addListener("addchild", onFolderAddChild);
    78   testFolder.events.addListener("removechild", onFolderRemoveChild);
    80   // test adding a bookmark
    81   var testBookmark = testFolder.addBookmark("Mozilla", url("https://www.mozilla.org/"));
    82   ok(testBookmark, "Check bookmark creation");
    83   ok(testBookmark.parent, "Check parent after bookmark creation");
    84   is(gLastFolderAction, "addchild", "Check event handler for adding a child to a folder");
    85   is(testBookmark.type, "bookmark", "Check 'bookmark.type' after creation");
    86   is(testBookmark.title, "Mozilla", "Check 'bookmark.title' after creation");
    87   is(testBookmark.uri.spec, "https://www.mozilla.org/", "Check 'bookmark.uri' after creation");
    89   is(testFolder.children.length, 1, "Check test folder child count after adding a child bookmark");
    91   // test modifying a bookmark
    92   testBookmark.events.addListener("change", onBookmarkChange);
    93   testBookmark.description = "mozcorp";
    94   is(testBookmark.description, "mozcorp", "Check setting 'bookmark.description'");
    95   is(gLastBookmarkAction, "bookmarkProperties/description", "Check event handler for setting 'bookmark.description'");
    97   testBookmark.keyword = "moz"
    98   is(testBookmark.keyword, "moz", "Check setting 'bookmark.keyword'");
    99   is(gLastBookmarkAction, "keyword", "Check event handler for setting 'bookmark.keyword'");
   101   testBookmark.title = "MozCorp"
   102   is(testBookmark.title, "MozCorp", "Check setting 'bookmark.title'");
   103   is(gLastBookmarkAction, "title", "Check event handler for setting 'bookmark.title'");
   105   testBookmark.uri = url("http://www.mozilla.org/");
   106   is(testBookmark.uri.spec, "http://www.mozilla.org/", "Check setting 'bookmark.uri'");
   107   is(gLastBookmarkAction, "uri", "Check event handler for setting 'bookmark.uri'");
   109   // test adding and removing a bookmark annotation
   110   testBookmark.annotations.set("testing/bookmark", "annotate-this", 0);
   111   ok(testBookmark.annotations.has("testing/bookmark"), "Checking existence of added annotation");
   112   is(gLastBookmarkAction, "testing/bookmark", "Check event handler for setting annotation");
   113   gLastBookmarkAction = "";
   114   is(testBookmark.annotations.get("testing/bookmark"), "annotate-this", "Checking existence of added annotation");
   115   testBookmark.annotations.remove("testing/bookmark");
   116   ok(!testBookmark.annotations.has("testing/bookmark"), "Checking existence of removed annotation");
   117   is(gLastBookmarkAction, "testing/bookmark", "Check event handler for removing annotation");
   118   is(testBookmark.annotations.get("testing/bookmark"), null, "Check existence of a missing annotation");
   120   // quick annotation type tests
   121   testBookmark.annotations.set("testing/bookmark/string", "annotate-this", 0);
   122   ok(testBookmark.annotations.has("testing/bookmark/string"), "Checking existence of added string annotation");
   123   is(testBookmark.annotations.get("testing/bookmark/string"), "annotate-this", "Checking value of added string annotation");
   124   is(gLastBookmarkAction, "testing/bookmark/string", "Check event handler for setting annotation");
   125   gLastBookmarkAction = "";
   126   testBookmark.annotations.set("testing/bookmark/int", 100, 0);
   127   ok(testBookmark.annotations.has("testing/bookmark/int"), "Checking existence of added integer annotation");
   128   is(testBookmark.annotations.get("testing/bookmark/int"), 100, "Checking value of added integer annotation");
   129   is(gLastBookmarkAction, "testing/bookmark/int", "Check event handler for setting annotation");
   130   gLastBookmarkAction = "";
   131   testBookmark.annotations.set("testing/bookmark/double", 3.333, 0);
   132   ok(testBookmark.annotations.has("testing/bookmark/double"), "Checking existence of added double annotation");
   133   is(testBookmark.annotations.get("testing/bookmark/double"), 3.333, "Checking value of added double annotation");
   134   is(gLastBookmarkAction, "testing/bookmark/double", "Check event handler for setting annotation");
   135   gLastBookmarkAction = "";
   137   // test names array - NOTE: "bookmarkProperties/description" is an annotation too
   138   var names = testBookmark.annotations.names;
   139   ok(names.some(function (f) f == "bookmarkProperties/description"), "Checking for description annotation");
   140   ok(names.some(function (f) f == "testing/bookmark/string"), "Checking for string test annotation");
   141   ok(names.some(function (f) f == "testing/bookmark/int"), "Checking for int test annotation");
   142   ok(names.some(function (f) f == "testing/bookmark/double"), "Checking for double test annotation");
   144   // test adding a separator
   145   var testSeparator = testFolder.addSeparator();
   146   ok(testSeparator, "Check bookmark creation");
   147   ok(testSeparator.parent, "Check parent after separator creation");
   148   is(gLastFolderAction, "addchild", "Check event handler for adding a child separator to a folder");
   149   is(testSeparator.type, "separator", "Check 'bookmark.type' after separator creation");
   151   is(testFolder.children.length, 2, "Check test folder child count after adding a child separator");
   153   // test removing separator
   154   testSeparator.events.addListener("remove", onBookmarkRemove);
   155   testSeparator.remove();
   156   is(gLastBookmarkAction, "remove", "Check event handler for removing separator");
   157   is(gLastFolderAction, "removechild", "Check event handler for removing a child separator from a folder");
   158   is(testFolder.children.length, 1, "Check test folder child count after removing a child separator");
   160   // test removing bookmark
   161   testBookmark.events.addListener("remove", onBookmarkRemove);
   162   testBookmark.remove();
   163   is(gLastBookmarkAction, "remove", "Check event handler for removing bookmark");
   164   is(gLastFolderAction, "removechild", "Check event handler for removing a child from a folder");
   165   is(testFolder.children.length, 0, "Check test folder child count after removing a child bookmark");
   167   // test removing a folder
   168   testFolder.events.addListener("remove", onFolderRemove);
   169   testFolder.remove();
   170   is(gLastFolderAction, "remove", "Check event handler for removing child folder");
   171   rootKidCount--;
   172   is(root.children.length, rootKidCount, "Check root folder child count after removing a child folder");
   174   // test moving between folders
   175   var testFolderA = root.addFolder("folder-a");
   176   var testFolderB = root.addFolder("folder-b");
   178   var testMove = testFolderA.addBookmark("Mozilla", url("https://www.mozilla.org/"));
   179   testMove.events.addListener("move", onBookmarkMove);
   180   is(testMove.parent.title, "folder-a", "Checking for new parent before moving bookmark");
   182   testMove.parent = testFolderB;
   183   is(testMove.parent.title, "folder-b", "Checking for new parent after moving bookmark");
   184   is(gLastBookmarkAction, "move", "Checking for event handler after moving bookmark");
   186   // test moving a folder
   187   testFolderA.events.addListener("move", onFolderMove);
   188   testFolderA.parent = testFolderB;
   189   is(testFolderA.parent.title, "folder-b", "Checking for new parent after moving folder");
   190   is(gLastFolderAction, "move", "Checking for event handler after moving folder");
   192   // test events on the root
   193   root.events.addListener("add", onRootAdd);
   194   root.events.addListener("remove", onRootRemove);
   195   root.events.addListener("change", onRootChange);
   196   var testFolderC = root.addFolder("folder-c");
   197   is(gLastRootAction, "add");
   199   root.events.removeListener("add", onRootAdd);
   200   gLastRootAction = "";
   201   var testFolderD = root.addFolder("folder-d");
   202   is(gLastRootAction, "");
   204   testFolderC.remove();
   205   is(gLastRootAction, "remove");
   207   testFolderD.description = "Foo";
   208   is(gLastRootAction, "bookmarkProperties/description");
   209 }
   211 function onFolderChange(evt) {
   212   gLastFolderAction = evt.data;
   213 }
   215 function onFolderRemove(evt) {
   216   gLastFolderAction = evt.type;
   217 }
   219 function onFolderAddChild(evt) {
   220   gLastFolderAction = evt.type;
   221 }
   223 function onFolderRemoveChild(evt) {
   224   gLastFolderAction = evt.type;
   225 }
   227 function onFolderMove(evt) {
   228   gLastFolderAction = evt.type;
   229 }
   231 function onBookmarkChange(evt) {
   232   gLastBookmarkAction = evt.data;
   233 }
   235 function onBookmarkRemove(evt) {
   236   gLastBookmarkAction = evt.type;
   237 }
   239 function onBookmarkMove(evt) {
   240   gLastBookmarkAction = evt.type;
   241 }
   243 function onRootAdd(evt) {
   244   gLastRootAction = evt.type;
   245 }
   247 function onRootRemove(evt) {
   248   gLastRootAction = evt.type;
   249 }
   251 function onRootChange(evt) {
   252   gLastRootAction = evt.data;
   253 }

mercurial