diff options
Diffstat (limited to 'widget/tests/unit')
-rw-r--r-- | widget/tests/unit/test_macsharingservice.js | 29 | ||||
-rw-r--r-- | widget/tests/unit/test_macwebapputils.js | 34 | ||||
-rw-r--r-- | widget/tests/unit/test_taskbar_jumplistitems.js | 328 | ||||
-rw-r--r-- | widget/tests/unit/xpcshell.ini | 9 |
4 files changed, 400 insertions, 0 deletions
diff --git a/widget/tests/unit/test_macsharingservice.js b/widget/tests/unit/test_macsharingservice.js new file mode 100644 index 0000000000..d85b9ae737 --- /dev/null +++ b/widget/tests/unit/test_macsharingservice.js @@ -0,0 +1,29 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* 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/. */ + +// Basic tests to verify that MacSharingService returns expected data + +function test_getSharingProviders() { + let sharingService = Cc["@mozilla.org/widget/macsharingservice;1"].getService( + Ci.nsIMacSharingService + ); + let providers = sharingService.getSharingProviders("http://example.org"); + Assert.greater(providers.length, 1, "There are providers returned"); + providers.forEach(provider => { + Assert.ok("name" in provider, "Provider has name"); + Assert.ok("menuItemTitle" in provider, "Provider has menuItemTitle"); + Assert.ok("image" in provider, "Provider has image"); + + Assert.notEqual( + provider.title, + "Mail", + "Known filtered provider not returned" + ); + }); +} + +function run_test() { + test_getSharingProviders(); +} diff --git a/widget/tests/unit/test_macwebapputils.js b/widget/tests/unit/test_macwebapputils.js new file mode 100644 index 0000000000..8967f8a593 --- /dev/null +++ b/widget/tests/unit/test_macwebapputils.js @@ -0,0 +1,34 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* 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/. */ + +// Basic tests to verify that MacWebAppUtils works + +function test_find_app() { + var mwaUtils = Cc["@mozilla.org/widget/mac-web-app-utils;1"].createInstance( + Ci.nsIMacWebAppUtils + ); + let sig = "com.apple.TextEdit"; + + let path; + path = mwaUtils.pathForAppWithIdentifier(sig); + info("TextEdit path: " + path + "\n"); + Assert.notEqual(path, ""); +} + +function test_dont_find_fake_app() { + var mwaUtils = Cc["@mozilla.org/widget/mac-web-app-utils;1"].createInstance( + Ci.nsIMacWebAppUtils + ); + let sig = "calliope.penitentiary.dramamine"; + + let path; + path = mwaUtils.pathForAppWithIdentifier(sig); + Assert.equal(path, ""); +} + +function run_test() { + test_find_app(); + test_dont_find_fake_app(); +} diff --git a/widget/tests/unit/test_taskbar_jumplistitems.js b/widget/tests/unit/test_taskbar_jumplistitems.js new file mode 100644 index 0000000000..fad9680e02 --- /dev/null +++ b/widget/tests/unit/test_taskbar_jumplistitems.js @@ -0,0 +1,328 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* 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 tests taskbar jump list functionality available on win7 and up. +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); + +function test_basics() { + var item = Cc["@mozilla.org/windows-jumplistitem;1"].createInstance( + Ci.nsIJumpListItem + ); + + var sep = Cc["@mozilla.org/windows-jumplistseparator;1"].createInstance( + Ci.nsIJumpListSeparator + ); + + var shortcut = Cc["@mozilla.org/windows-jumplistshortcut;1"].createInstance( + Ci.nsIJumpListShortcut + ); + + var link = Cc["@mozilla.org/windows-jumplistlink;1"].createInstance( + Ci.nsIJumpListLink + ); + + Assert.ok(!item.equals(sep)); + Assert.ok(!item.equals(shortcut)); + Assert.ok(!item.equals(link)); + + Assert.ok(!sep.equals(item)); + Assert.ok(!sep.equals(shortcut)); + Assert.ok(!sep.equals(link)); + + Assert.ok(!shortcut.equals(item)); + Assert.ok(!shortcut.equals(sep)); + Assert.ok(!shortcut.equals(link)); + + Assert.ok(!link.equals(item)); + Assert.ok(!link.equals(sep)); + Assert.ok(!link.equals(shortcut)); + + Assert.ok(item.equals(item)); + Assert.ok(sep.equals(sep)); + Assert.ok(link.equals(link)); + Assert.ok(shortcut.equals(shortcut)); +} + +function test_separator() { + // separators: + + var item = Cc["@mozilla.org/windows-jumplistseparator;1"].createInstance( + Ci.nsIJumpListSeparator + ); + + Assert.ok(item.type == Ci.nsIJumpListItem.JUMPLIST_ITEM_SEPARATOR); +} + +function test_hashes() { + var link = Cc["@mozilla.org/windows-jumplistlink;1"].createInstance( + Ci.nsIJumpListLink + ); + var uri1 = Cc["@mozilla.org/network/simple-uri-mutator;1"] + .createInstance(Ci.nsIURIMutator) + .setSpec("http://www.123.com/") + .finalize(); + var uri2 = Cc["@mozilla.org/network/simple-uri-mutator;1"] + .createInstance(Ci.nsIURIMutator) + .setSpec("http://www.123.com/") + .finalize(); + + link.uri = uri1; + + Assert.ok(link.compareHash(uri2)); + uri2 = uri2 + .mutate() + .setSpec("http://www.456.com/") + .finalize(); + Assert.ok(!link.compareHash(uri2)); + uri2 = uri2 + .mutate() + .setSpec("http://www.123.com/") + .finalize(); + Assert.ok(link.compareHash(uri2)); + uri2 = uri2 + .mutate() + .setSpec("https://www.123.com/") + .finalize(); + Assert.ok(!link.compareHash(uri2)); + uri2 = uri2 + .mutate() + .setSpec("http://www.123.com/test/") + .finalize(); + Assert.ok(!link.compareHash(uri2)); + uri1 = uri1 + .mutate() + .setSpec("http://www.123.com/test/") + .finalize(); + link.uri = uri1; + uri2 = uri2 + .mutate() + .setSpec("http://www.123.com/test/") + .finalize(); + Assert.ok(link.compareHash(uri2)); + uri1 = uri1 + .mutate() + .setSpec("https://www.123.com/test/") + .finalize(); + link.uri = uri1; + uri2 = uri2 + .mutate() + .setSpec("https://www.123.com/test/") + .finalize(); + Assert.ok(link.compareHash(uri2)); + uri2 = uri2 + .mutate() + .setSpec("ftp://www.123.com/test/") + .finalize(); + Assert.ok(!link.compareHash(uri2)); + uri2 = uri2 + .mutate() + .setSpec("http://123.com/test/") + .finalize(); + Assert.ok(!link.compareHash(uri2)); + uri1 = uri1 + .mutate() + .setSpec("https://www.123.com/test/") + .finalize(); + link.uri = uri1; + uri2 = uri2 + .mutate() + .setSpec("https://www.123.com/Test/") + .finalize(); + Assert.ok(!link.compareHash(uri2)); + + uri1 = uri1 + .mutate() + .setSpec("http://www.123.com/") + .finalize(); + link.uri = uri1; + Assert.equal(link.uriHash, "QGLmWuwuTozr3tOfXSf5mg=="); + uri1 = uri1 + .mutate() + .setSpec("http://www.123.com/test/") + .finalize(); + link.uri = uri1; + Assert.equal(link.uriHash, "AG87Ls+GmaUYSUJFETRr3Q=="); + uri1 = uri1 + .mutate() + .setSpec("https://www.123.com/") + .finalize(); + link.uri = uri1; + Assert.equal(link.uriHash, "iSx6UH1a9enVPzUA9JZ42g=="); +} + +function test_links() { + // links: + var link1 = Cc["@mozilla.org/windows-jumplistlink;1"].createInstance( + Ci.nsIJumpListLink + ); + var link2 = Cc["@mozilla.org/windows-jumplistlink;1"].createInstance( + Ci.nsIJumpListLink + ); + + var uri1 = Cc["@mozilla.org/network/simple-uri-mutator;1"] + .createInstance(Ci.nsIURIMutator) + .setSpec("http://www.test.com/") + .finalize(); + var uri2 = Cc["@mozilla.org/network/simple-uri-mutator;1"] + .createInstance(Ci.nsIURIMutator) + .setSpec("http://www.test.com/") + .finalize(); + + link1.uri = uri1; + link1.uriTitle = "Test"; + link2.uri = uri2; + link2.uriTitle = "Test"; + + Assert.ok(link1.equals(link2)); + + link2.uriTitle = "Testing"; + + Assert.ok(!link1.equals(link2)); + + link2.uriTitle = "Test"; + uri2 = uri2 + .mutate() + .setSpec("http://www.testing.com/") + .finalize(); + link2.uri = uri2; + + Assert.ok(!link1.equals(link2)); +} + +function test_shortcuts() { + // shortcuts: + var sc = Cc["@mozilla.org/windows-jumplistshortcut;1"].createInstance( + Ci.nsIJumpListShortcut + ); + + var handlerApp = Cc[ + "@mozilla.org/uriloader/local-handler-app;1" + ].createInstance(Ci.nsILocalHandlerApp); + + handlerApp.name = "TestApp"; + handlerApp.detailedDescription = "TestApp detailed description."; + handlerApp.appendParameter("-test"); + + sc.iconIndex = 1; + Assert.equal(sc.iconIndex, 1); + + var faviconPageUri = Cc["@mozilla.org/network/simple-uri-mutator;1"] + .createInstance(Ci.nsIURIMutator) + .setSpec("http://www.123.com/") + .finalize(); + sc.faviconPageUri = faviconPageUri; + Assert.equal(sc.faviconPageUri, faviconPageUri); + + var notepad = Services.dirsvc.get("WinD", Ci.nsIFile); + notepad.append("notepad.exe"); + if (notepad.exists()) { + handlerApp.executable = notepad; + sc.app = handlerApp; + Assert.equal(sc.app.detailedDescription, "TestApp detailed description."); + Assert.equal(sc.app.name, "TestApp"); + Assert.ok(sc.app.parameterExists("-test")); + Assert.ok(!sc.app.parameterExists("-notset")); + } +} + +async function test_jumplist() { + // Jump lists can't register links unless the application is the default + // protocol handler for the protocol of the link, so we skip off testing + // those in these tests. We'll init the jump list for the xpc shell harness, + // add a task item, and commit it. + + // not compiled in + if (Ci.nsIWinTaskbar == null) { + return; + } + + var taskbar = Cc["@mozilla.org/windows-taskbar;1"].getService( + Ci.nsIWinTaskbar + ); + + var builder = taskbar.createJumpListBuilder(); + + Assert.notEqual(builder, null); + + // Win7 and up only + try { + var ver = parseFloat(Services.sysinfo.getProperty("version")); + if (ver < 6.1) { + Assert.ok(!builder.available); + return; + } + } catch (ex) {} + + Assert.ok(taskbar.available); + + builder.deleteActiveList(); + + var items = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray); + + var sc = Cc["@mozilla.org/windows-jumplistshortcut;1"].createInstance( + Ci.nsIJumpListShortcut + ); + + var handlerApp = Cc[ + "@mozilla.org/uriloader/local-handler-app;1" + ].createInstance(Ci.nsILocalHandlerApp); + + handlerApp.name = "Notepad"; + handlerApp.detailedDescription = "Testing detailed description."; + + var notepad = Services.dirsvc.get("WinD", Ci.nsIFile); + notepad.append("notepad.exe"); + if (notepad.exists()) { + // To ensure "profile-before-change" will fire before + // "xpcom-shutdown-threads" + do_get_profile(); + + handlerApp.executable = notepad; + sc.app = handlerApp; + items.appendElement(sc); + + var removed = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray); + Assert.ok(builder.initListBuild(removed)); + Assert.ok(builder.addListToBuild(builder.JUMPLIST_CATEGORY_TASKS, items)); + Assert.ok(builder.addListToBuild(builder.JUMPLIST_CATEGORY_RECENT)); + Assert.ok(builder.addListToBuild(builder.JUMPLIST_CATEGORY_FREQUENT)); + let rv = new Promise(resolve => { + builder.commitListBuild(resolve); + }); + Assert.ok(await rv); + + builder.deleteActiveList(); + + Assert.ok(builder.initListBuild(removed)); + Assert.ok( + builder.addListToBuild( + builder.JUMPLIST_CATEGORY_CUSTOMLIST, + items, + "Custom List" + ) + ); + rv = new Promise(resolve => { + builder.commitListBuild(resolve); + }); + Assert.ok(await rv); + + builder.deleteActiveList(); + } +} + +function run_test() { + if (mozinfo.os != "win") { + return; + } + test_basics(); + test_separator(); + test_hashes(); + test_links(); + test_shortcuts(); + + run_next_test(); +} + +add_task(test_jumplist); diff --git a/widget/tests/unit/xpcshell.ini b/widget/tests/unit/xpcshell.ini new file mode 100644 index 0000000000..46beea87e0 --- /dev/null +++ b/widget/tests/unit/xpcshell.ini @@ -0,0 +1,9 @@ +[DEFAULT] +head = + +[test_taskbar_jumplistitems.js] +skip-if = os == "win" && os_version == "10.0" # Bug 1457329 +[test_macsharingservice.js] +skip-if = os != "mac" +[test_macwebapputils.js] +skip-if = os != "mac" |