1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/chrome/test_342484.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,88 @@ 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 +/* 1.20 + Test loading feeds with items that aren't allowed 1.21 + */ 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 +function runTest() { 1.33 + const FEEDSPEC = "http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/bad_links.atom"; 1.34 + const GOOD_URLS = ["http://example.org/first", "http://example.org/last"]; 1.35 + 1.36 + PlacesUtils.livemarks.addLivemark( 1.37 + { title: "foo" 1.38 + , parentId: PlacesUtils.toolbarFolderId 1.39 + , index: PlacesUtils.bookmarks.DEFAULT_INDEX 1.40 + , feedURI: NetUtil.newURI(FEEDSPEC) 1.41 + , siteURI: NetUtil.newURI("http:/mochi.test/") 1.42 + }) 1.43 + .then(function (aLivemark) { 1.44 + waitForLivemarkLoad(aLivemark, function (aLivemark) { 1.45 + let nodes = aLivemark.getNodesForContainer({}); 1.46 + 1.47 + is(nodes.length, 2, "Created the two good livemark items"); 1.48 + for (let i = 0; i < nodes.length; ++i) { 1.49 + let node = nodes[i]; 1.50 + ok(GOOD_URLS.indexOf(node.uri) != -1, "livemark item created with bad uri " + node.uri); 1.51 + } 1.52 + 1.53 + PlacesUtils.bookmarks.removeItem(aLivemark.id); 1.54 + SimpleTest.finish(); 1.55 + }); 1.56 + }, function () { 1.57 + is(true, false, "Should not fail adding a livemark"); 1.58 + } 1.59 + ); 1.60 +} 1.61 + 1.62 +function waitForLivemarkLoad(aLivemark, aCallback) { 1.63 + // Don't need a real node here. 1.64 + let node = {}; 1.65 + let resultObserver = { 1.66 + nodeInserted: function() {}, 1.67 + nodeRemoved: function() {}, 1.68 + nodeAnnotationChanged: function() {}, 1.69 + nodeTitleChanged: function() {}, 1.70 + nodeHistoryDetailsChanged: function() {}, 1.71 + nodeMoved: function() {}, 1.72 + ontainerStateChanged: function () {}, 1.73 + sortingChanged: function() {}, 1.74 + batching: function() {}, 1.75 + invalidateContainer: function(node) { 1.76 + isnot(aLivemark.status, Ci.mozILivemark.STATUS_FAILED, 1.77 + "Loading livemark should success"); 1.78 + if (aLivemark.status == Ci.mozILivemark.STATUS_READY) { 1.79 + aLivemark.unregisterForUpdates(node, resultObserver); 1.80 + aCallback(aLivemark); 1.81 + } 1.82 + } 1.83 + }; 1.84 + aLivemark.registerForUpdates(node, resultObserver); 1.85 + aLivemark.reload(); 1.86 +} 1.87 + 1.88 +]]> 1.89 +</script> 1.90 + 1.91 +</window>