toolkit/components/places/tests/chrome/test_303567.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/chrome/test_303567.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,122 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet
     1.7 +  href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     1.8 +<window title="Add Bad Livemarks"
     1.9 +  xmlns:html="http://www.w3.org/1999/xhtml"
    1.10 +  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    1.11 +  onload="runTest()">
    1.12 +  <script type="application/javascript"
    1.13 +   src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.14 +
    1.15 +  <body xmlns="http://www.w3.org/1999/xhtml" />
    1.16 +
    1.17 +<script type="application/javascript">
    1.18 +<![CDATA[
    1.19 +// Test that for feeds with items that have no link:
    1.20 +//   * the link-less items are present in the database.
    1.21 +//   * the feed's site URI is substituted for each item's link.
    1.22 +SimpleTest.waitForExplicitFinish();
    1.23 +
    1.24 +const Cc = Components.classes;
    1.25 +const Ci = Components.interfaces;
    1.26 +const Cr = Components.results;
    1.27 +
    1.28 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
    1.29 +Components.utils.import("resource://gre/modules/NetUtil.jsm");
    1.30 +Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
    1.31 +
    1.32 +const LIVEMARKS = [
    1.33 +  { feedURI: NetUtil.newURI("http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/link-less-items.rss"),
    1.34 +    siteURI: NetUtil.newURI("http://mochi.test:8888/"),
    1.35 +    urls: [
    1.36 +      "http://feed-item-link.com/",
    1.37 +      "http://feed-link.com/",
    1.38 +      "http://feed-item-link.com/",
    1.39 +    ],
    1.40 +    message: "Ensure link-less livemark item picked up site uri.",
    1.41 +  },
    1.42 +  { feedURI: NetUtil.newURI("http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/link-less-items-no-site-uri.rss"),
    1.43 +    siteURI: null,
    1.44 +    urls: [
    1.45 +      "http://feed-item-link.com/",
    1.46 +      "http://feed-item-link.com/",
    1.47 +    ],
    1.48 +    message: "Ensure livemark item links did not inherit site uri."
    1.49 +  },  
    1.50 +];
    1.51 +
    1.52 +function runTest()
    1.53 +{
    1.54 +  function testLivemark(aLivemarkData) {
    1.55 +    PlacesUtils.livemarks.addLivemark(
    1.56 +      { title: "foo"
    1.57 +      , parentId: PlacesUtils.toolbarFolderId
    1.58 +      , index: PlacesUtils.bookmarks.DEFAULT_INDEX
    1.59 +      , feedURI: aLivemarkData.feedURI
    1.60 +      , siteURI: aLivemarkData.siteURI
    1.61 +      })
    1.62 +      .then(function (aLivemark) {
    1.63 +        is (aLivemark.feedURI.spec, aLivemarkData.feedURI.spec,
    1.64 +            "Get correct feedURI");
    1.65 +        if (aLivemarkData.siteURI) {
    1.66 +          is (aLivemark.siteURI.spec, aLivemarkData.siteURI.spec,
    1.67 +              "Get correct siteURI");
    1.68 +        }
    1.69 +        else {
    1.70 +          is (aLivemark.siteURI, null, "Get correct siteURI");
    1.71 +        }
    1.72 +
    1.73 +        waitForLivemarkLoad(aLivemark, function (aLivemark) {
    1.74 +          let nodes = aLivemark.getNodesForContainer({});
    1.75 +          is(nodes.length, aLivemarkData.urls.length,
    1.76 +             "Ensure all the livemark items were created.");
    1.77 +          aLivemarkData.urls.forEach(function (aUrl, aIndex) {
    1.78 +            let node = nodes[aIndex];
    1.79 +            is(node.uri, aUrl, aLivemarkData.message);
    1.80 +          });
    1.81 +
    1.82 +          PlacesUtils.bookmarks.removeItem(aLivemark.id);
    1.83 +
    1.84 +          if (aLivemark.feedURI.equals(LIVEMARKS[LIVEMARKS.length - 1].feedURI)) {
    1.85 +            SimpleTest.finish();
    1.86 +          }          
    1.87 +        });
    1.88 +      }, function () {
    1.89 +        is(true, false, "Should not fail adding a livemark");
    1.90 +      }
    1.91 +    );
    1.92 +  }
    1.93 +
    1.94 +  LIVEMARKS.forEach(testLivemark);
    1.95 +}
    1.96 +
    1.97 +function waitForLivemarkLoad(aLivemark, aCallback) {
    1.98 +  // Don't need a real node here.
    1.99 +  let node = {};
   1.100 +  let resultObserver = {
   1.101 +    nodeInserted: function() {},
   1.102 +    nodeRemoved: function() {},
   1.103 +    nodeAnnotationChanged: function() {},
   1.104 +    nodeTitleChanged: function() {},
   1.105 +    nodeHistoryDetailsChanged: function() {},
   1.106 +    nodeMoved: function() {},
   1.107 +    ontainerStateChanged: function () {},
   1.108 +    sortingChanged: function() {},
   1.109 +    batching: function() {},
   1.110 +    invalidateContainer: function(node) {
   1.111 +      isnot(aLivemark.status, Ci.mozILivemark.STATUS_FAILED,
   1.112 +            "Loading livemark should success");
   1.113 +      if (aLivemark.status == Ci.mozILivemark.STATUS_READY) {
   1.114 +        aLivemark.unregisterForUpdates(node, resultObserver);
   1.115 +        aCallback(aLivemark);
   1.116 +      }
   1.117 +    }
   1.118 +  };
   1.119 +  aLivemark.registerForUpdates(node, resultObserver);
   1.120 +  aLivemark.reload();
   1.121 +}
   1.122 +
   1.123 +]]>
   1.124 +</script>
   1.125 +</window>

mercurial