summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/chrome/test_371798.xhtml
blob: 33e866e51e1992d35694ac4c317e05184a4566ea (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet
  href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window title="Bug 371798"
  xmlns:html="http://www.w3.org/1999/xhtml"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="head.js" />

<body xmlns="http://www.w3.org/1999/xhtml" />

<script type="application/javascript">
<![CDATA[
// Test the asynchronous live-updating of bookmarks query results
SimpleTest.waitForExplicitFinish();

const TEST_URI = Services.io.newURI("http://foo.com");

(async function() {
  // add 2 bookmarks to the toolbar, same URI, different titles (set later)
  let bm1 = await PlacesUtils.bookmarks.insert({
    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
    url: TEST_URI
  });

  let bm2 = await PlacesUtils.bookmarks.insert({
    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
    url: TEST_URI
  });

  // query for bookmarks
  let rootNode = PlacesUtils.getFolderContents(PlacesUtils.bookmarks.toolbarGuid).root;

  // set up observer
  const promiseObserved = PlacesTestUtils.waitForNotification(
    "bookmark-title-changed"
  );

  // modify the bookmark's title
  await PlacesUtils.bookmarks.update({
    guid: bm2.guid, title: "foo"
  });

  // wait for notification
  await promiseObserved;

  // Continue after our observer gets notified of onItemChanged
  // which is triggered by updating the item's title.
  // After receiving the notification, our original query should also
  // have been live-updated, so we can iterate through its children,
  // to check that only the modified bookmark has changed.

  // result node should be updated
  let cc = rootNode.childCount;
  for (let i = 0; i < cc; ++i) {
    let node = rootNode.getChild(i);
    // test that bm1 does not have new title
    if (node.bookmarkGuid == bm1.guid)
      ok(node.title != "foo",
         "Changing a bookmark's title did not affect the title of other bookmarks with the same URI");
  }
  rootNode.containerOpen = false;

  // clean up
  await PlacesUtils.bookmarks.remove(bm1);
  await PlacesUtils.bookmarks.remove(bm2);
})().catch(err => {
  ok(false, `uncaught error: ${err}`);
}).then(() => {
  SimpleTest.finish();
});
]]>
</script>

</window>