diff options
Diffstat (limited to 'widget/tests/unit')
-rw-r--r-- | widget/tests/unit/test_macsharingservice.js | 61 | ||||
-rw-r--r-- | widget/tests/unit/test_macwebapputils.js | 34 | ||||
-rw-r--r-- | widget/tests/unit/test_taskbar_jumplistitems.js | 282 | ||||
-rw-r--r-- | widget/tests/unit/xpcshell.ini | 11 |
4 files changed, 388 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..f6b0a8e3fc --- /dev/null +++ b/widget/tests/unit/test_macsharingservice.js @@ -0,0 +1,61 @@ +/* -*- 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 + ); + + // Ensure these URL's are accepted without error by the getSharingProviders() + // method. This does not test if the URL's are interpreted correctly by + // the platform implementation and does not test that the URL will be + // successfully shared to the target application if the shareURL method is + // used. It does indicate the Mac API's used to get the sharing providers + // successfully created a URL object for the URL provided and returned at + // least one provider. + let urls = [ + "http://example.org", + "http://example.org/#", + "http://example.org/dkl??", + "http://example.org/dkl?a=b;c=d#thisisaref", + "http://example.org/dkl?a=b;c=d#thisisaref#double", + "http://example.org/#/", + "http://example.org/#/#", + "http://example.org/#/#/", + // This test fails due to the '|' in the path which needs additional + // encoding before conversion to NSURL. See bug 1740565. + // "http://example.org/foo/bar/x|page.html#this_is_a_fragment", + "http://example.org/page.html#this_is_a_fragment", + "http://example.org/page.html#this_is_a_fragment#and_another", + "http://example.org/foo/bar;#foo", + "http://example.org/a file with spaces.html", + "https://chat.mozilla.org/#/room/#macdev:mozilla.org", + "https://chat.mozilla.org/#/room/%23macdev:mozilla.org", + ]; + + urls.forEach(url => testGetSharingProvidersForUrl(sharingService, url)); +} + +function testGetSharingProvidersForUrl(sharingService, url) { + let providers = sharingService.getSharingProviders(url); + 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..f839160bde --- /dev/null +++ b/widget/tests/unit/test_taskbar_jumplistitems.js @@ -0,0 +1,282 @@ +/* -*- 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. + +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 + ); + + // Since we're only testing the general functionality of the JumpListBuilder + // et. al, we can just test the non-private browsing version. + // (The only difference between the two at this level is the App User Model ID.) + var builder = taskbar.createJumpListBuilder(false); + + 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..e6fafa44f0 --- /dev/null +++ b/widget/tests/unit/xpcshell.ini @@ -0,0 +1,11 @@ +[DEFAULT] +head = + +[test_taskbar_jumplistitems.js] +skip-if = + os == "win" && os_version == "10.0" # Bug 1457329 + os == "win" && os_version == "6.1" # Skip on Azure - frequent failure +[test_macsharingservice.js] +skip-if = os != "mac" +[test_macwebapputils.js] +skip-if = os != "mac" |