diff options
Diffstat (limited to 'toolkit/components/places/tests/chrome')
18 files changed, 1143 insertions, 0 deletions
diff --git a/toolkit/components/places/tests/chrome/.eslintrc.js b/toolkit/components/places/tests/chrome/.eslintrc.js new file mode 100644 index 000000000..bf379df8d --- /dev/null +++ b/toolkit/components/places/tests/chrome/.eslintrc.js @@ -0,0 +1,8 @@ +"use strict"; + +module.exports = { + "extends": [ + "../../../../../testing/mochitest/chrome.eslintrc.js", + "../../../../../testing/mochitest/mochitest.eslintrc.js" + ] +}; diff --git a/toolkit/components/places/tests/chrome/bad_links.atom b/toolkit/components/places/tests/chrome/bad_links.atom new file mode 100644 index 000000000..446927252 --- /dev/null +++ b/toolkit/components/places/tests/chrome/bad_links.atom @@ -0,0 +1,74 @@ +<?xml version="1.0" encoding="utf-8"?> +<feed xmlns="http://www.w3.org/2005/Atom"> + + <title>Example Feed</title> + <link href="http://example.org/"/> + <updated>2003-12-13T18:30:02Z</updated> + + <author> + <name>John Doe</name> + </author> + <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id> + + <entry> + + <title>First good item</title> + <link href="http://example.org/first"/> + <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> + <updated>2003-12-13T18:30:02Z</updated> + + <summary>Some text.</summary> + </entry> + + <entry> + + <title>data: link</title> + <link href="data:text/plain,Hi"/> + <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6b</id> + <updated>2003-12-13T18:30:03Z</updated> + + <summary>Some text.</summary> + </entry> + + <entry> + + <title>javascript: link</title> + <link href="javascript:alert('Hi')"/> + <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6c</id> + <updated>2003-12-13T18:30:04Z</updated> + + <summary>Some text.</summary> + </entry> + + <entry> + + <title>file: link</title> + <link href="file:///var/"/> + <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6d</id> + <updated>2003-12-13T18:30:05Z</updated> + + <summary>Some text.</summary> + </entry> + + <entry> + + <title>chrome: link</title> + <link href="chrome://browser/content/browser.js"/> + <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6e</id> + <updated>2003-12-13T18:30:06Z</updated> + + <summary>Some text.</summary> + </entry> + + <entry> + + <title>Last good item</title> + <link href="http://example.org/last"/> + <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6b</id> + <updated>2003-12-13T18:30:07Z</updated> + + <summary>Some text.</summary> + </entry> + + +</feed> diff --git a/toolkit/components/places/tests/chrome/browser_disableglobalhistory.xul b/toolkit/components/places/tests/chrome/browser_disableglobalhistory.xul new file mode 100644 index 000000000..d7bbfda67 --- /dev/null +++ b/toolkit/components/places/tests/chrome/browser_disableglobalhistory.xul @@ -0,0 +1,44 @@ +<?xml version="1.0"?> +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> + +<window title="Test disableglobalhistory attribute on remote browsers" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + onload="run_test();"> + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script> + + <browser id="inprocess_disabled" src="about:blank" type="content" disableglobalhistory="true" /> + <browser id="inprocess_enabled" src="about:blank" type="content" /> + + <browser id="remote_disabled" src="about:blank" type="content" disableglobalhistory="true" /> + <browser id="remote_enabled" src="about:blank" type="content" /> + + <script type="text/javascript;version=1.7"> + const {interfaces: Ci, classes: Cc, results: Cr, utils: Cu} = Components; + + Cu.import("resource://testing-common/ContentTask.jsm"); + ContentTask.setTestScope(window.opener.wrappedJSObject); + + function expectUseGlobalHistory(id, expected) { + let browser = document.getElementById(id); + return ContentTask.spawn(browser, {id, expected}, function*({id, expected}) { + Assert.equal(docShell.useGlobalHistory, expected, + "Got the right useGlobalHistory state in the docShell of " + id); + }); + } + + function run_test() { + spawn_task(function*() { + yield expectUseGlobalHistory("inprocess_disabled", false); + yield expectUseGlobalHistory("inprocess_enabled", true); + + yield expectUseGlobalHistory("remote_disabled", false); + yield expectUseGlobalHistory("remote_enabled", true); + window.opener.done(); + }); + }; + + </script> +</window>
\ No newline at end of file diff --git a/toolkit/components/places/tests/chrome/chrome.ini b/toolkit/components/places/tests/chrome/chrome.ini new file mode 100644 index 000000000..5ac753e73 --- /dev/null +++ b/toolkit/components/places/tests/chrome/chrome.ini @@ -0,0 +1,12 @@ +[DEFAULT] + +[test_303567.xul] +[test_341972a.xul] +[test_341972b.xul] +[test_342484.xul] +[test_371798.xul] +[test_381357.xul] +[test_favicon_annotations.xul] +[test_reloadLivemarks.xul] +[test_browser_disableglobalhistory.xul] +support-files = browser_disableglobalhistory.xul
\ No newline at end of file diff --git a/toolkit/components/places/tests/chrome/link-less-items-no-site-uri.rss b/toolkit/components/places/tests/chrome/link-less-items-no-site-uri.rss new file mode 100644 index 000000000..612b0a5c2 --- /dev/null +++ b/toolkit/components/places/tests/chrome/link-less-items-no-site-uri.rss @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="iso-8859-1"?> +<rss version="2.0"> + <channel> + <title>feed title</title> + <ttl>180</ttl> + <item> + <title>linked feed item</title> + <link>http://feed-item-link.com</link> + </item> + <item> + <title>link-less feed item</title> + </item> + <item> + <title>linked feed item</title> + <link>http://feed-item-link.com</link> + </item> + </channel> +</rss> diff --git a/toolkit/components/places/tests/chrome/link-less-items.rss b/toolkit/components/places/tests/chrome/link-less-items.rss new file mode 100644 index 000000000..a30d4a353 --- /dev/null +++ b/toolkit/components/places/tests/chrome/link-less-items.rss @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="iso-8859-1"?> +<rss version="2.0"> + <channel> + <title>feed title</title> + <link>http://feed-link.com</link> + <ttl>180</ttl> + <item> + <title>linked feed item</title> + <link>http://feed-item-link.com</link> + </item> + <item> + <title>link-less feed item</title> + </item> + <item> + <title>linked feed item</title> + <link>http://feed-item-link.com</link> + </item> + </channel> +</rss> diff --git a/toolkit/components/places/tests/chrome/rss_as_html.rss b/toolkit/components/places/tests/chrome/rss_as_html.rss new file mode 100644 index 000000000..e82305035 --- /dev/null +++ b/toolkit/components/places/tests/chrome/rss_as_html.rss @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="ISO-8859-1" ?> +<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"> +<channel> +<title>sadfasdfasdfasfasdf</title> +<link>http://www.example.com</link> +<description>asdfasdfasdf.example.com</description> +<language>de</language> +<copyright>asdfasdfasdfasdf</copyright> +<lastBuildDate>Tue, 11 Mar 2008 18:52:52 +0100</lastBuildDate> +<docs>http://blogs.law.harvard.edu/tech/rss</docs> +<ttl>10</ttl> +<item> +<title>The First Title</title> +<link>http://www.example.com/index.html</link> +<pubDate>Tue, 11 Mar 2008 18:24:43 +0100</pubDate> +<content:encoded> +<![CDATA[ +<p> +askdlfjas;dfkjas;fkdj +</p> +]]> +</content:encoded> +<description>aklsjdhfasdjfahasdfhj</description> +<guid>http://foo.example.com/asdfasdf</guid> +</item> +</channel> +</rss> diff --git a/toolkit/components/places/tests/chrome/rss_as_html.rss^headers^ b/toolkit/components/places/tests/chrome/rss_as_html.rss^headers^ new file mode 100644 index 000000000..04fbaa08f --- /dev/null +++ b/toolkit/components/places/tests/chrome/rss_as_html.rss^headers^ @@ -0,0 +1,2 @@ +HTTP 200 OK +Content-Type: text/html diff --git a/toolkit/components/places/tests/chrome/sample_feed.atom b/toolkit/components/places/tests/chrome/sample_feed.atom new file mode 100644 index 000000000..add75efb4 --- /dev/null +++ b/toolkit/components/places/tests/chrome/sample_feed.atom @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<feed xmlns="http://www.w3.org/2005/Atom"> + + <title>Example Feed</title> + <link href="http://example.org/"/> + <updated>2003-12-13T18:30:02Z</updated> + + <author> + <name>John Doe</name> + </author> + <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id> + + <entry> + + <title>Atom-Powered Robots Run Amok</title> + <link href="http://example.org/2003/12/13/atom03"/> + <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> + <updated>2003-12-13T18:30:02Z</updated> + + <summary>Some text.</summary> + </entry> + +</feed> diff --git a/toolkit/components/places/tests/chrome/test_303567.xul b/toolkit/components/places/tests/chrome/test_303567.xul new file mode 100644 index 000000000..37ae77cbb --- /dev/null +++ b/toolkit/components/places/tests/chrome/test_303567.xul @@ -0,0 +1,122 @@ +<?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 Bad Livemarks" + 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 that for feeds with items that have no link: +// * the link-less items are present in the database. +// * the feed's site URI is substituted for each item's link. +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"); + +const LIVEMARKS = [ + { feedURI: NetUtil.newURI("http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/link-less-items.rss"), + siteURI: NetUtil.newURI("http://mochi.test:8888/"), + urls: [ + "http://feed-item-link.com/", + "http://feed-link.com/", + "http://feed-item-link.com/", + ], + message: "Ensure link-less livemark item picked up site uri.", + }, + { feedURI: NetUtil.newURI("http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/link-less-items-no-site-uri.rss"), + siteURI: null, + urls: [ + "http://feed-item-link.com/", + "http://feed-item-link.com/", + ], + message: "Ensure livemark item links did not inherit site uri." + }, +]; + +function runTest() +{ + let loadCount = 0; + + function testLivemark(aLivemarkData) { + PlacesUtils.livemarks.addLivemark( + { title: "foo" + , parentGuid: PlacesUtils.bookmarks.toolbarGuid + , feedURI: aLivemarkData.feedURI + , siteURI: aLivemarkData.siteURI + }) + .then(function (aLivemark) { + is (aLivemark.feedURI.spec, aLivemarkData.feedURI.spec, + "Get correct feedURI"); + if (aLivemarkData.siteURI) { + is (aLivemark.siteURI.spec, aLivemarkData.siteURI.spec, + "Get correct siteURI"); + } + else { + is (aLivemark.siteURI, null, "Get correct siteURI"); + } + + waitForLivemarkLoad(aLivemark, function (aLivemark) { + let nodes = aLivemark.getNodesForContainer({}); + is(nodes.length, aLivemarkData.urls.length, + "Ensure all the livemark items were created."); + aLivemarkData.urls.forEach(function (aUrl, aIndex) { + let node = nodes[aIndex]; + is(node.uri, aUrl, aLivemarkData.message); + }); + + PlacesUtils.livemarks.removeLivemark(aLivemark).then(() => { + if (++loadCount == LIVEMARKS.length) + SimpleTest.finish(); + }); + }); + }, function () { + is(true, false, "Should not fail adding a livemark"); + } + ); + } + + LIVEMARKS.forEach(testLivemark); +} + +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> diff --git a/toolkit/components/places/tests/chrome/test_341972a.xul b/toolkit/components/places/tests/chrome/test_341972a.xul new file mode 100644 index 000000000..7c78136a9 --- /dev/null +++ b/toolkit/components/places/tests/chrome/test_341972a.xul @@ -0,0 +1,87 @@ +<?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="Update Livemark SiteURI" + 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 updating livemark siteURI to the value from the feed + */ +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/sample_feed.atom"; + const INITIALSITESPEC = "http://mochi.test:8888/"; + const FEEDSITESPEC = "http://example.org/"; + + PlacesUtils.livemarks.addLivemark( + { title: "foo" + , parentGuid: PlacesUtils.bookmarks.toolbarGuid + , feedURI: NetUtil.newURI(FEEDSPEC) + , siteURI: NetUtil.newURI(INITIALSITESPEC) + }) + .then(function (aLivemark) { + is(aLivemark.siteURI.spec, INITIALSITESPEC, + "Has correct initial livemark site URI"); + + waitForLivemarkLoad(aLivemark, function (aLivemark) { + is(aLivemark.siteURI.spec, FEEDSITESPEC, + "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"); + } + ); +} + +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> diff --git a/toolkit/components/places/tests/chrome/test_341972b.xul b/toolkit/components/places/tests/chrome/test_341972b.xul new file mode 100644 index 000000000..86cdc75f3 --- /dev/null +++ b/toolkit/components/places/tests/chrome/test_341972b.xul @@ -0,0 +1,84 @@ +<?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="Update Livemark SiteURI, null to start" + 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 updating livemark siteURI to the value from the feed, when it's null + */ +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/sample_feed.atom"; + const FEEDSITESPEC = "http://example.org/"; + + PlacesUtils.livemarks.addLivemark( + { title: "foo" + , parentGuid: PlacesUtils.bookmarks.toolbarGuid + , feedURI: NetUtil.newURI(FEEDSPEC) + }) + .then(function (aLivemark) { + is(aLivemark.siteURI, null, "Has null livemark site URI"); + + waitForLivemarkLoad(aLivemark, function (aLivemark) { + is(aLivemark.siteURI.spec, FEEDSITESPEC, + "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"); + } + ); +} + +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> diff --git a/toolkit/components/places/tests/chrome/test_342484.xul b/toolkit/components/places/tests/chrome/test_342484.xul new file mode 100644 index 000000000..353313abb --- /dev/null +++ b/toolkit/components/places/tests/chrome/test_342484.xul @@ -0,0 +1,88 @@ +<?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 Bad Livemarks" + 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 items that aren't allowed + */ +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/bad_links.atom"; + const GOOD_URLS = ["http://example.org/first", "http://example.org/last"]; + + 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.length, 2, "Created the two good livemark items"); + for (let i = 0; i < nodes.length; ++i) { + let node = nodes[i]; + ok(GOOD_URLS.includes(node.uri), "livemark item created with bad uri " + node.uri); + } + + PlacesUtils.livemarks.removeLivemark(aLivemark).then(() => { + SimpleTest.finish(); + }); + }); + }, function () { + is(true, false, "Should not fail adding a livemark"); + } + ); +} + +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> diff --git a/toolkit/components/places/tests/chrome/test_371798.xul b/toolkit/components/places/tests/chrome/test_371798.xul new file mode 100644 index 000000000..241db75c3 --- /dev/null +++ b/toolkit/components/places/tests/chrome/test_371798.xul @@ -0,0 +1,101 @@ +<?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 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 the asynchronous live-updating of bookmarks query results +SimpleTest.waitForExplicitFinish(); + +var {utils: Cu, interfaces: Ci} = Components; +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); +Cu.import("resource://gre/modules/NetUtil.jsm"); +Cu.import("resource://gre/modules/Task.jsm"); + +Cu.import("resource://gre/modules/PlacesUtils.jsm"); + +const TEST_URI = NetUtil.newURI("http://foo.com"); + +function promiseOnItemChanged() { + return new Promise(resolve => { + PlacesUtils.bookmarks.addObserver({ + onBeginUpdateBatch() {}, + onEndUpdateBatch() {}, + onItemAdded() {}, + onItemRemoved() {}, + onItemVisited() {}, + onItemMoved() {}, + + onItemChanged() { + PlacesUtils.bookmarks.removeObserver(this); + resolve(); + }, + + QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]) + }, false); + }); +} + +Task.spawn(function* () { + // add 2 bookmarks to the toolbar, same URI, different titles (set later) + let bm1 = yield PlacesUtils.bookmarks.insert({ + parentGuid: PlacesUtils.bookmarks.toolbarGuid, + url: TEST_URI + }); + + let bm2 = yield PlacesUtils.bookmarks.insert({ + parentGuid: PlacesUtils.bookmarks.toolbarGuid, + url: TEST_URI + }); + + // query for bookmarks + let rootNode = PlacesUtils.getFolderContents(PlacesUtils.toolbarFolderId).root; + + // set up observer + let promiseObserved = promiseOnItemChanged(); + + // modify the bookmark's title + yield PlacesUtils.bookmarks.update({ + guid: bm2.guid, title: "foo" + }); + + // wait for notification + yield 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 + yield PlacesUtils.bookmarks.remove(bm1); + yield PlacesUtils.bookmarks.remove(bm2); +}).catch(err => { + ok(false, `uncaught error: ${err}`); +}).then(() => { + SimpleTest.finish(); +}); +]]> +</script> + +</window> diff --git a/toolkit/components/places/tests/chrome/test_381357.xul b/toolkit/components/places/tests/chrome/test_381357.xul new file mode 100644 index 000000000..6bd6cb024 --- /dev/null +++ b/toolkit/components/places/tests/chrome/test_381357.xul @@ -0,0 +1,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> diff --git a/toolkit/components/places/tests/chrome/test_browser_disableglobalhistory.xul b/toolkit/components/places/tests/chrome/test_browser_disableglobalhistory.xul new file mode 100644 index 000000000..3a84f3030 --- /dev/null +++ b/toolkit/components/places/tests/chrome/test_browser_disableglobalhistory.xul @@ -0,0 +1,26 @@ +<?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="Test disableglobalhistory attribute on remote browsers" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + </body> + + <script type="text/javascript;version=1.7"> + SimpleTest.waitForExplicitFinish(); + + let w = window.open('browser_disableglobalhistory.xul', '_blank', 'chrome,resizable=yes,width=400,height=600'); + + function done() { + w.close(); + SimpleTest.finish(); + } + </script> + +</window>
\ No newline at end of file diff --git a/toolkit/components/places/tests/chrome/test_favicon_annotations.xul b/toolkit/components/places/tests/chrome/test_favicon_annotations.xul new file mode 100644 index 000000000..b7647cbc6 --- /dev/null +++ b/toolkit/components/places/tests/chrome/test_favicon_annotations.xul @@ -0,0 +1,168 @@ +<?xml version="1.0"?> +<!-- This Source Code Form is subject to the terms of the Mozilla Public + - License, v. 2.0. If a copy of the MPL was not distributed with this + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> +<!-- + * This file tests the moz-anno protocol, which was added in Bug 316077 and how + * it loads favicons. +--> + +<window title="Favicon Annotation Protocol Test" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + onload="test();"> + + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"/> + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> + + <script type="application/javascript"> + <![CDATA[ + +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cr = Components.results; + +let fs = Cc["@mozilla.org/browser/favicon-service;1"]. + getService(Ci.nsIFaviconService); + +// Test descriptions that will be printed in the case of failure. +let testDescriptions = [ + "moz-anno URI with no data in the database loads default icon", + "URI added to the database is properly loaded", +]; + +// URIs to load (will be compared with expectedURIs of the same index). +let testURIs = [ + "http://mozilla.org/2009/made-up-favicon/places-rocks/", + "http://mozilla.org/should-be-barney/", +]; + +// URIs to load for expected results. +let expectedURIs = [ + fs.defaultFavicon.spec, + "data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%10%00%00%00%10%08%06%00%00%00%1F%F3%FFa%00%00%00%04gAMA%00%00%AF%C87%05%8A%E9%00%00%00%19tEXtSoftware%00Adobe%20ImageReadyq%C9e%3C%00%00%01%D6IDATx%DAb%FC%FF%FF%3F%03%25%00%20%80%98%909%EF%DF%BFg%EF%EC%EC%FC%AD%AC%AC%FC%DF%95%91%F1%BF%89%89%C9%7F%20%FF%D7%EA%D5%AB%B7%DF%BBwO%16%9B%01%00%01%C4%00r%01%08%9F9s%C6%CD%D8%D8%F8%BF%0B%03%C3%FF3%40%BC%0A%88%EF%02q%1A%10%BB%40%F1%AAU%ABv%C1%D4%C30%40%00%81%89%993g%3E%06%1A%F6%3F%14%AA%11D%97%03%F1%7Fc%08%0D%E2%2B))%FD%17%04%89%A1%19%00%10%40%0C%D00%F8%0F3%00%C8%F8%BF%1B%E4%0Ac%88a%E5%60%17%19%FF%0F%0D%0D%05%1B%02v%D9%DD%BB%0A0%03%00%02%08%AC%B9%A3%A3%E3%17%03%D4v%90%01%EF%18%106%C3%0Cz%07%C5%BB%A1%DE%82y%07%20%80%A0%A6%08B%FCn%0C1%60%26%D4%20d%C3VA%C3%06%26%BE%0A%EA-%80%00%82%B9%E0%F7L4%0D%EF%90%F8%C6%60%2F%0A%82%BD%01%13%07%0700%D0%01%02%88%11%E4%02P%B41%DC%BB%C7%D0%014%0D%E8l%06W%20%06%BA%88%A1%1C%1AS%15%40%7C%16%CA6.%2Fgx%BFg%0F%83%CB%D9%B3%0C%7B%80%7C%80%00%02%BB%00%E8%9F%ED%20%1B%3A%A0%A6%9F%81%DA%DC%01%C5%B0%80%ED%80%FA%BF%BC%BC%FC%3F%83%12%90%9D%96%F6%1F%20%80%18%DE%BD%7B%C7%0E%8E%05AD%20%FEGr%A6%A0%A0%E0%7F%25P%80%02%9D%0F%D28%13%18%23%C6%C0%B0%02E%3D%C8%F5%00%01%04%8F%05P%A8%BA%40my%87%E4%12c%A8%8D%20%8B%D0%D3%00%08%03%04%10%9C%01R%E4%82d%3B%C8%A0%99%C6%90%90%C6%A5%19%84%01%02%08%9E%17%80%C9x%F7%7B%A0%DBVC%F9%A0%C0%5C%7D%16%2C%CE%00%F4%C6O%5C%99%09%20%800L%04y%A5%03%1A%95%A0%80%05%05%14.%DBA%18%20%80%18)%CD%CE%00%01%06%00%0C'%94%C7%C0k%C9%2C%00%00%00%00IEND%AEB%60%82", +]; + + +/** + * The event listener placed on our test windows used to determine when it is + * safe to compare the two windows. + */ +let _results = []; +function loadEventHandler() +{ + _results.push(snapshotWindow(window)); + + loadNextTest(); +} + +/** + * This runs the comparison. + */ +function compareResults(aIndex, aImage1, aImage2) +{ + let [correct, data1, data2] = compareSnapshots(aImage1, aImage2, true); + SimpleTest.ok(correct, + "Test '" + testDescriptions[aIndex] + "' matches expectations. " + + "Data from window 1 is '" + data1 + "'. " + + "Data from window 2 is '" + data2 + "'"); +} + +/** + * Loads the next set of URIs to compare against. + */ +let _counter = -1; +function loadNextTest() +{ + _counter++; + // If we have no more tests, finish. + if (_counter / 2 == testDescriptions.length) { + for (let i = 0; i < _results.length; i = i + 2) + compareResults(i / 2, _results[i], _results[i + 1]); + + SimpleTest.finish(); + return; + } + + let nextURI = function() { + let index = Math.floor(_counter / 2); + if ((_counter % 2) == 0) + return "moz-anno:favicon:" + testURIs[index]; + return expectedURIs[index]; + } + + let img = document.getElementById("favicon"); + img.setAttribute("src", nextURI()); +} + +function test() +{ + SimpleTest.waitForExplicitFinish(); + let db = Cc["@mozilla.org/browser/nav-history-service;1"]. + getService(Ci.nsPIPlacesDatabase). + DBConnection; + + // Empty any old favicons + db.executeSimpleSQL("DELETE FROM moz_favicons"); + + let ios = Cc["@mozilla.org/network/io-service;1"]. + getService(Ci.nsIIOService); + let uri = function(aSpec) { + return ios.newURI(aSpec, null, null); + }; + + let pageURI = uri("http://example.com/favicon_annotations"); + let history = Cc["@mozilla.org/browser/history;1"] + .getService(Ci.mozIAsyncHistory); + history.updatePlaces( + { + uri: pageURI, + visits: [{ transitionType: Ci.nsINavHistoryService.TRANSITION_TYPED, + visitDate: Date.now() * 1000 + }], + }, + { + handleError: function UP_handleError() { + ok(false, "Unexpected error in adding visit."); + }, + handleResult: function () {}, + handleCompletion: function UP_handleCompletion() { + // Set the favicon data. Note that the "moz-anno:" protocol requires + // the favicon to be stored in the database, but the + // replaceFaviconDataFromDataURL function will not save the favicon + // unless it is associated with a page. Thus, we must associate the + // icon with a page explicitly in order for it to be visible through + // the protocol. + var systemPrincipal = Cc["@mozilla.org/systemprincipal;1"] + .createInstance(Ci.nsIPrincipal); + + fs.replaceFaviconDataFromDataURL(uri(testURIs[1]), expectedURIs[1], + (Date.now() + 60 * 60 * 24 * 1000) * 1000, + systemPrincipal); + + fs.setAndFetchFaviconForPage(pageURI, uri(testURIs[1]), true, + fs.FAVICON_LOAD_NON_PRIVATE, + null, systemPrincipal); + + // And start our test process. + loadNextTest(); + } + } + ); + + +} + + ]]> + </script> + + <body xmlns="http://www.w3.org/1999/xhtml"> + <img id="favicon" onload="loadEventHandler();"/> + <p id="display"></p> + <div id="content" style="display:none;"></div> + <pre id="test"></pre> + </body> +</window> diff --git a/toolkit/components/places/tests/chrome/test_reloadLivemarks.xul b/toolkit/components/places/tests/chrome/test_reloadLivemarks.xul new file mode 100644 index 000000000..43772d09f --- /dev/null +++ b/toolkit/components/places/tests/chrome/test_reloadLivemarks.xul @@ -0,0 +1,155 @@ +<?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="Reload Livemarks" + xmlns:html="http://www.w3.org/1999/xhtml" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + onload="runTest()" onunload="cleanup()"> + <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 that for concurrent reload of livemarks. + +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"); + +let gLivemarks = [ + { id: -1, + title: "foo", + parentGuid: PlacesUtils.bookmarks.toolbarGuid, + feedURI: NetUtil.newURI("http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/link-less-items.rss") + }, + { id: -1, + title: "bar", + parentGuid: PlacesUtils.bookmarks.toolbarGuid, + feedURI: NetUtil.newURI("http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/link-less-items-no-site-uri.rss") + }, +]; + +function runTest() +{ + addLivemarks(function () { + reloadLivemarks(false, function () { + reloadLivemarks(true, function () { + removeLivemarks(SimpleTest.finish); + }); + }); + // Ensure this normal reload doesn't overwrite the forced one. + PlacesUtils.livemarks.reloadLivemarks(); + }); +} + +function addLivemarks(aCallback) { + info("Adding livemarks"); + let count = gLivemarks.length; + gLivemarks.forEach(function(aLivemarkData) { + PlacesUtils.livemarks.addLivemark(aLivemarkData) + .then(function (aLivemark) { + ok(aLivemark.feedURI.equals(aLivemarkData.feedURI), "Livemark added"); + aLivemarkData.id = aLivemark.id; + if (--count == 0) { + aCallback(); + } + }, + function () { + is(true, false, "Should not fail adding a livemark."); + aCallback(); + }); + }); +} + +function reloadLivemarks(aForceUpdate, aCallback) { + info("Reloading livemarks with forceUpdate: " + aForceUpdate); + let count = gLivemarks.length; + gLivemarks.forEach(function(aLivemarkData) { + PlacesUtils.livemarks.getLivemark(aLivemarkData) + .then(aLivemark => { + ok(aLivemark.feedURI.equals(aLivemarkData.feedURI), "Livemark found"); + aLivemarkData._observer = new resultObserver(aLivemark, function() { + if (++count == gLivemarks.length) { + aCallback(); + } + }); + if (--count == 0) { + PlacesUtils.livemarks.reloadLivemarks(aForceUpdate); + } + }, + function() { + is(true, false, "Should not fail getting a livemark."); + aCallback(); + } + ); + }); +} + +function removeLivemarks(aCallback) { + info("Removing livemarks"); + let count = gLivemarks.length; + gLivemarks.forEach(function(aLivemarkData) { + PlacesUtils.livemarks.removeLivemark(aLivemarkData).then( + function (aLivemark) { + if (--count == 0) { + aCallback(); + } + }, + function() { + is(true, false, "Should not fail adding a livemark."); + aCallback(); + } + ); + }); +} + +function resultObserver(aLivemark, aCallback) { + this._node = {}; + this._livemark = aLivemark; + this._callback = aCallback; + this._livemark.registerForUpdates(this._node, this); +} +resultObserver.prototype = { + nodeInserted: function() {}, + nodeRemoved: function() {}, + nodeAnnotationChanged: function() {}, + nodeTitleChanged: function() {}, + nodeHistoryDetailsChanged: function() {}, + nodeMoved: function() {}, + ontainerStateChanged: function () {}, + sortingChanged: function() {}, + batching: function() {}, + invalidateContainer: function(aContainer) { + // Wait for load finish. + if (this._livemark.status == Ci.mozILivemark.STATUS_LOADING) + return; + + this._terminate(); + this._callback(); + }, + _terminate: function () { + if (!this._terminated) { + this._livemark.unregisterForUpdates(this._node); + this._terminated = true; + } + } +}; + +function cleanup() { + gLivemarks.forEach(function(aLivemarkData) { + if (aLivemarkData._observer) + aLivemarkData._observer._terminate(); + }); +} +]]> +</script> +</window> |