1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/chrome/test_341972a.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,87 @@ 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="Update Livemark SiteURI" 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 updating livemark siteURI to the value from the feed 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/sample_feed.atom"; 1.34 + const INITIALSITESPEC = "http://mochi.test:8888/"; 1.35 + const FEEDSITESPEC = "http://example.org/"; 1.36 + 1.37 + PlacesUtils.livemarks.addLivemark( 1.38 + { title: "foo" 1.39 + , parentId: PlacesUtils.toolbarFolderId 1.40 + , index: PlacesUtils.bookmarks.DEFAULT_INDEX 1.41 + , feedURI: NetUtil.newURI(FEEDSPEC) 1.42 + , siteURI: NetUtil.newURI(INITIALSITESPEC) 1.43 + }) 1.44 + .then(function (aLivemark) { 1.45 + is(aLivemark.siteURI.spec, INITIALSITESPEC, 1.46 + "Has correct initial livemark site URI"); 1.47 + 1.48 + waitForLivemarkLoad(aLivemark, function (aLivemark) { 1.49 + is(aLivemark.siteURI.spec, FEEDSITESPEC, 1.50 + "livemark site URI set to value in feed"); 1.51 + 1.52 + PlacesUtils.bookmarks.removeItem(aLivemark.id); 1.53 + SimpleTest.finish(); 1.54 + }); 1.55 + }, function () { 1.56 + is(true, false, "Should not fail adding a livemark"); 1.57 + } 1.58 + ); 1.59 +} 1.60 + 1.61 +function waitForLivemarkLoad(aLivemark, aCallback) { 1.62 + // Don't need a real node here. 1.63 + let node = {}; 1.64 + let resultObserver = { 1.65 + nodeInserted: function() {}, 1.66 + nodeRemoved: function() {}, 1.67 + nodeAnnotationChanged: function() {}, 1.68 + nodeTitleChanged: function() {}, 1.69 + nodeHistoryDetailsChanged: function() {}, 1.70 + nodeMoved: function() {}, 1.71 + ontainerStateChanged: function () {}, 1.72 + sortingChanged: function() {}, 1.73 + batching: function() {}, 1.74 + invalidateContainer: function(node) { 1.75 + isnot(aLivemark.status, Ci.mozILivemark.STATUS_FAILED, 1.76 + "Loading livemark should success"); 1.77 + if (aLivemark.status == Ci.mozILivemark.STATUS_READY) { 1.78 + aLivemark.unregisterForUpdates(node, resultObserver); 1.79 + aCallback(aLivemark); 1.80 + } 1.81 + } 1.82 + }; 1.83 + aLivemark.registerForUpdates(node, resultObserver); 1.84 + aLivemark.reload(); 1.85 +} 1.86 + 1.87 +]]> 1.88 +</script> 1.89 + 1.90 +</window>