summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/unit/test_async_in_batchmode.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /toolkit/components/places/tests/unit/test_async_in_batchmode.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/components/places/tests/unit/test_async_in_batchmode.js')
-rw-r--r--toolkit/components/places/tests/unit/test_async_in_batchmode.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/toolkit/components/places/tests/unit/test_async_in_batchmode.js b/toolkit/components/places/tests/unit/test_async_in_batchmode.js
new file mode 100644
index 000000000..b39b26519
--- /dev/null
+++ b/toolkit/components/places/tests/unit/test_async_in_batchmode.js
@@ -0,0 +1,55 @@
+// This is testing the frankenstein situation Sync forces Places into.
+// Sync does runInBatchMode() and before the callback returns the Places async
+// APIs are used (either by Sync itself, or by any other code in the system)
+// As seen in bug 1197856 and bug 1190131.
+
+Cu.import("resource://gre/modules/PlacesUtils.jsm");
+
+// This function "waits" for a promise to resolve by spinning a nested event
+// loop.
+function waitForPromise(promise) {
+ let thread = Cc["@mozilla.org/thread-manager;1"].getService().currentThread;
+
+ let finalResult, finalException;
+
+ promise.then(result => {
+ finalResult = result;
+ }, err => {
+ finalException = err;
+ });
+
+ // Keep waiting until our callback is triggered (unless the app is quitting).
+ while (!finalResult && !finalException) {
+ thread.processNextEvent(true);
+ }
+ if (finalException) {
+ throw finalException;
+ }
+ return finalResult;
+}
+
+add_test(function() {
+ let testCompleted = false;
+ PlacesUtils.bookmarks.runInBatchMode({
+ runBatched() {
+ // create a bookmark.
+ let info = { parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
+ url: "http://example.com/" };
+ let insertPromise = PlacesUtils.bookmarks.insert(info);
+ let bookmark = waitForPromise(insertPromise);
+ // Check we got a bookmark (bookmark creation failed completely in
+ // bug 1190131)
+ equal(bookmark.url, info.url);
+ // Check the promiseItemGuid and promiseItemId helpers - failure in these
+ // was the underlying reason for the failure.
+ let id = waitForPromise(PlacesUtils.promiseItemId(bookmark.guid));
+ let guid = waitForPromise(PlacesUtils.promiseItemGuid(id));
+ equal(guid, bookmark.guid, "id and guid round-tripped correctly");
+ testCompleted = true;
+ }
+ }, null);
+ // make sure we tested what we think we tested.
+ ok(testCompleted);
+ run_next_test();
+});