summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/chrome/test_381357.xul
blob: 6bd6cb02453071e3d38a1421cb37407f34b8404c (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
77
78
79
80
81
82
83
84
85
<?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="Add Livemarks from RSS feed served as text/html"
  xmlns:html="http://www.w3.org/1999/xhtml"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  onload="runTest()">
  <script type="application/javascript"
   src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>

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

<script type="application/javascript">
<![CDATA[
/*
 Test loading feeds with text/html 
 */
SimpleTest.waitForExplicitFinish();

var Cc = Components.classes;
var Ci = Components.interfaces;
var Cr = Components.results;

Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/NetUtil.jsm");
Components.utils.import("resource://gre/modules/PlacesUtils.jsm");

function runTest() {
  const FEEDSPEC = "http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/rss_as_html.rss";

  PlacesUtils.livemarks.addLivemark(
    { title: "foo"
    , parentGuid: PlacesUtils.bookmarks.toolbarGuid
    , feedURI: NetUtil.newURI(FEEDSPEC)
    , siteURI: NetUtil.newURI("http:/mochi.test/")
    })
    .then(function (aLivemark) {
      waitForLivemarkLoad(aLivemark, function (aLivemark) {
        let nodes = aLivemark.getNodesForContainer({});

        is(nodes[0].title, "The First Title",
           "livemark site URI set to value in feed");

        PlacesUtils.livemarks.removeLivemark(aLivemark).then(() => {
          SimpleTest.finish();
        });
      });
    }, function () {
      is(true, false, "Should not fail adding a livemark");
      SimpleTest.finish();
    }
  );
}

function waitForLivemarkLoad(aLivemark, aCallback) {
  // Don't need a real node here.
  let node = {};
  let resultObserver = {
    nodeInserted: function() {},
    nodeRemoved: function() {},
    nodeAnnotationChanged: function() {},
    nodeTitleChanged: function() {},
    nodeHistoryDetailsChanged: function() {},
    nodeMoved: function() {},
    ontainerStateChanged: function () {},
    sortingChanged: function() {},
    batching: function() {},
    invalidateContainer: function(node) {
      isnot(aLivemark.status, Ci.mozILivemark.STATUS_FAILED,
            "Loading livemark should success");
      if (aLivemark.status == Ci.mozILivemark.STATUS_READY) {
        aLivemark.unregisterForUpdates(node, resultObserver);
        aCallback(aLivemark);
      }
    }
  };
  aLivemark.registerForUpdates(node, resultObserver);
  aLivemark.reload();
}

]]>
</script>

</window>