summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/bookmarks/test_424958-json-quoted-folders.js
blob: 73a7023e45a7c47e400b80ae408caf83e0e3adb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

const FOLDER_TITLE = '"quoted folder"';

function checkQuotedFolder() {
  let toolbar = PlacesUtils.getFolderContents(PlacesUtils.bookmarks.toolbarGuid)
    .root;

  // test for our quoted folder
  Assert.equal(toolbar.childCount, 1);
  var folderNode = toolbar.getChild(0);
  Assert.equal(folderNode.type, folderNode.RESULT_TYPE_FOLDER);
  Assert.equal(folderNode.title, FOLDER_TITLE);

  // clean up
  toolbar.containerOpen = false;
}

add_task(async function() {
  // make json file
  let jsonFile = PathUtils.join(PathUtils.profileDir, "bookmarks.json");

  let folder = await PlacesUtils.bookmarks.insert({
    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
    title: FOLDER_TITLE,
    type: PlacesUtils.bookmarks.TYPE_FOLDER,
  });

  checkQuotedFolder();

  // export json to file
  await BookmarkJSONUtils.exportToFile(jsonFile);

  await PlacesUtils.bookmarks.remove(folder.guid);

  // restore json file
  await BookmarkJSONUtils.importFromFile(jsonFile, { replace: true });

  checkQuotedFolder();

  // clean up
  await IOUtils.remove(jsonFile);
});