summaryrefslogtreecommitdiffstats
path: root/services/cloudsync/tests
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 /services/cloudsync/tests
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 'services/cloudsync/tests')
-rw-r--r--services/cloudsync/tests/mochitest/browser.ini5
-rw-r--r--services/cloudsync/tests/mochitest/browser_tabEvents.js79
-rw-r--r--services/cloudsync/tests/mochitest/other_window.html7
-rw-r--r--services/cloudsync/tests/xpcshell/head.js10
-rw-r--r--services/cloudsync/tests/xpcshell/test_bookmarks.js73
-rw-r--r--services/cloudsync/tests/xpcshell/test_lazyload.js18
-rw-r--r--services/cloudsync/tests/xpcshell/test_module.js19
-rw-r--r--services/cloudsync/tests/xpcshell/test_tabs.js29
-rw-r--r--services/cloudsync/tests/xpcshell/xpcshell.ini10
9 files changed, 250 insertions, 0 deletions
diff --git a/services/cloudsync/tests/mochitest/browser.ini b/services/cloudsync/tests/mochitest/browser.ini
new file mode 100644
index 000000000..c9eddbf71
--- /dev/null
+++ b/services/cloudsync/tests/mochitest/browser.ini
@@ -0,0 +1,5 @@
+[DEFAULT]
+support-files=
+ other_window.html
+
+[browser_tabEvents.js] \ No newline at end of file
diff --git a/services/cloudsync/tests/mochitest/browser_tabEvents.js b/services/cloudsync/tests/mochitest/browser_tabEvents.js
new file mode 100644
index 000000000..9d80090a0
--- /dev/null
+++ b/services/cloudsync/tests/mochitest/browser_tabEvents.js
@@ -0,0 +1,79 @@
+/* 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/. */
+
+function test() {
+
+ let local = {};
+
+ Components.utils.import("resource://gre/modules/CloudSync.jsm", local);
+ Components.utils.import("resource:///modules/sessionstore/TabStateFlusher.jsm", local);
+
+ let cloudSync = local.CloudSync();
+ let opentabs = [];
+
+ waitForExplicitFinish();
+
+ let testURL = "chrome://mochitests/content/browser/services/cloudsync/tests/mochitest/other_window.html";
+ let expected = [
+ testURL,
+ testURL+"?x=1",
+ testURL+"?x=%20a",
+ // testURL+"?x=å",
+ ];
+
+ let nevents = 0;
+ let nflushed = 0;
+ function handleTabChangeEvent () {
+ cloudSync.tabs.removeEventListener("change", handleTabChangeEvent);
+ ++ nevents;
+ info("tab change event " + nevents);
+ next();
+ }
+
+ function getLocalTabs() {
+ cloudSync.tabs.getLocalTabs().then(
+ function (tabs) {
+ for (let tab of tabs) {
+ ok(expected.indexOf(tab.url) >= 0, "found an expected tab");
+ }
+
+ is(tabs.length, expected.length, "found the right number of tabs");
+
+ opentabs.forEach(function (tab) {
+ gBrowser.removeTab(tab);
+ });
+
+ is(nevents, 1, "expected number of change events");
+
+ finish();
+ }
+ )
+ }
+
+ cloudSync.tabs.addEventListener("change", handleTabChangeEvent);
+
+ expected.forEach(function(url) {
+ let tab = gBrowser.addTab(url);
+
+ function flush() {
+ tab.linkedBrowser.removeEventListener("load", flush, true);
+ local.TabStateFlusher.flush(tab.linkedBrowser).then(() => {
+ ++ nflushed;
+ info("flushed " + nflushed);
+ next();
+ });
+ }
+
+ tab.linkedBrowser.addEventListener("load", flush, true);
+
+ opentabs.push(tab);
+ });
+
+ function next() {
+ if (nevents == 1 && nflushed == expected.length) {
+ getLocalTabs();
+ }
+ }
+
+}
diff --git a/services/cloudsync/tests/mochitest/other_window.html b/services/cloudsync/tests/mochitest/other_window.html
new file mode 100644
index 000000000..a9ded2bd6
--- /dev/null
+++ b/services/cloudsync/tests/mochitest/other_window.html
@@ -0,0 +1,7 @@
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+</html>
diff --git a/services/cloudsync/tests/xpcshell/head.js b/services/cloudsync/tests/xpcshell/head.js
new file mode 100644
index 000000000..bd517cafa
--- /dev/null
+++ b/services/cloudsync/tests/xpcshell/head.js
@@ -0,0 +1,10 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+var {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
+
+"use strict";
+
+(function initCloudSyncTestingInfrastructure () {
+ do_get_profile();
+}).call(this);
diff --git a/services/cloudsync/tests/xpcshell/test_bookmarks.js b/services/cloudsync/tests/xpcshell/test_bookmarks.js
new file mode 100644
index 000000000..d4e1d2b75
--- /dev/null
+++ b/services/cloudsync/tests/xpcshell/test_bookmarks.js
@@ -0,0 +1,73 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+Cu.import("resource://gre/modules/CloudSync.jsm");
+
+function run_test () {
+ run_next_test();
+}
+
+function cleanup () {
+
+}
+
+add_task(function* test_merge_bookmarks_flat () {
+ try {
+ let rootFolder = yield CloudSync().bookmarks.getRootFolder("TEST");
+ ok(rootFolder.id, "root folder id is ok");
+
+ let items = [
+ {"id":"G_UL4ZhOyX8m","type":rootFolder.BOOKMARK,"title":"reddit: the front page of the internet 1","uri":"http://www.reddit.com",index:2},
+ {"id":"G_UL4ZhOyX8n","type":rootFolder.BOOKMARK,"title":"reddit: the front page of the internet 2","uri":"http://www.reddit.com?1",index:1},
+ ];
+ yield rootFolder.mergeRemoteItems(items);
+
+ let localItems = yield rootFolder.getLocalItems();
+ equal(Object.keys(localItems).length, items.length, "found merged items");
+ } finally {
+ yield CloudSync().bookmarks.deleteRootFolder("TEST");
+ }
+});
+
+add_task(function* test_merge_bookmarks_in_folders () {
+ try {
+ let rootFolder = yield CloudSync().bookmarks.getRootFolder("TEST");
+ ok(rootFolder.id, "root folder id is ok");
+
+ let items = [
+ {"id":"G_UL4ZhOyX8m","type":rootFolder.BOOKMARK,"title":"reddit: the front page of the internet 1","uri":"http://www.reddit.com",index:2},
+ {"id":"G_UL4ZhOyX8n","type":rootFolder.BOOKMARK,parent:"G_UL4ZhOyX8x","title":"reddit: the front page of the internet 2","uri":"http://www.reddit.com/?a=å%20ä%20ö",index:1},
+ {"id":"G_UL4ZhOyX8x","type":rootFolder.FOLDER},
+ ];
+ yield rootFolder.mergeRemoteItems(items);
+
+ let localItems = yield rootFolder.getLocalItems();
+ equal(localItems.length, items.length, "found merged items");
+
+ localItems.forEach(function(item) {
+ ok(item.id == "G_UL4ZhOyX8m" ||
+ item.id == "G_UL4ZhOyX8n" ||
+ item.id == "G_UL4ZhOyX8x");
+ if (item.id == "G_UL4ZhOyX8n") {
+ equal(item.parent, "G_UL4ZhOyX8x")
+ } else {
+ equal(item.parent, rootFolder.id);
+ }
+ });
+
+ let folder = (yield rootFolder.getLocalItemsById(["G_UL4ZhOyX8x"]))[0];
+ equal(folder.id, "G_UL4ZhOyX8x");
+ equal(folder.type, rootFolder.FOLDER);
+
+ let bookmark = (yield rootFolder.getLocalItemsById(["G_UL4ZhOyX8n"]))[0];
+ equal(bookmark.id, "G_UL4ZhOyX8n");
+ equal(bookmark.parent, "G_UL4ZhOyX8x");
+ equal(bookmark.title, "reddit: the front page of the internet 2");
+ equal(bookmark.index, 0);
+ equal(bookmark.uri, "http://www.reddit.com/?a=%C3%A5%20%C3%A4%20%C3%B6");
+ } finally {
+ yield CloudSync().bookmarks.deleteRootFolder("TEST");
+ }
+}); \ No newline at end of file
diff --git a/services/cloudsync/tests/xpcshell/test_lazyload.js b/services/cloudsync/tests/xpcshell/test_lazyload.js
new file mode 100644
index 000000000..5928875d5
--- /dev/null
+++ b/services/cloudsync/tests/xpcshell/test_lazyload.js
@@ -0,0 +1,18 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+Cu.import("resource://gre/modules/CloudSync.jsm");
+
+function run_test() {
+ run_next_test();
+}
+
+add_task(function test_lazyload() {
+ ok(!CloudSync.ready, "CloudSync.ready is false before CloudSync() invoked");
+ let cs1 = CloudSync();
+ ok(CloudSync.ready, "CloudSync.ready is true after CloudSync() invoked");
+ let cs2 = CloudSync();
+ ok(cs1 === cs2, "CloudSync() returns the same instance on multiple invocations");
+});
diff --git a/services/cloudsync/tests/xpcshell/test_module.js b/services/cloudsync/tests/xpcshell/test_module.js
new file mode 100644
index 000000000..6d31345ed
--- /dev/null
+++ b/services/cloudsync/tests/xpcshell/test_module.js
@@ -0,0 +1,19 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+Cu.import("resource://gre/modules/CloudSync.jsm");
+
+function run_test () {
+ run_next_test();
+}
+
+add_task(function test_module_load () {
+ ok(CloudSync);
+ let cloudSync = CloudSync();
+ ok(cloudSync.adapters);
+ ok(cloudSync.bookmarks);
+ ok(cloudSync.local);
+ ok(cloudSync.tabs);
+});
diff --git a/services/cloudsync/tests/xpcshell/test_tabs.js b/services/cloudsync/tests/xpcshell/test_tabs.js
new file mode 100644
index 000000000..50f7a73de
--- /dev/null
+++ b/services/cloudsync/tests/xpcshell/test_tabs.js
@@ -0,0 +1,29 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+Cu.import("resource://gre/modules/CloudSync.jsm");
+
+function run_test () {
+ run_next_test();
+}
+
+add_task(function* test_get_remote_tabs () {
+ let cloudSync = CloudSync();
+ let clients = yield cloudSync.tabs.getRemoteTabs();
+ equal(clients.length, 0);
+
+ yield cloudSync.tabs.mergeRemoteTabs({
+ id: "001",
+ name: "FakeClient",
+ },[
+ {url:"https://www.google.ca?a=å%20ä%20ö",title:"Google Canada",icon:"https://www.google.ca/favicon.ico",lastUsed:0},
+ {url:"http://www.reddit.com",title:"Reddit",icon:"http://www.reddit.com/favicon.ico",lastUsed:1},
+ ]);
+ ok(cloudSync.tabs.hasRemoteTabs());
+
+ clients = yield cloudSync.tabs.getRemoteTabs();
+ equal(clients.length, 1);
+ equal(clients[0].tabs.size, 2);
+});
diff --git a/services/cloudsync/tests/xpcshell/xpcshell.ini b/services/cloudsync/tests/xpcshell/xpcshell.ini
new file mode 100644
index 000000000..08d2eff3a
--- /dev/null
+++ b/services/cloudsync/tests/xpcshell/xpcshell.ini
@@ -0,0 +1,10 @@
+[DEFAULT]
+head = head.js
+tail =
+firefox-appdir = browser
+skip-if = toolkit == 'android'
+
+[test_module.js]
+[test_tabs.js]
+[test_bookmarks.js]
+[test_lazyload.js]