widget/tests/unit/test_taskbar_jumplistitems.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/tests/unit/test_taskbar_jumplistitems.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,262 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +// This tests taskbar jump list functionality available on win7 and up.
    1.10 +
    1.11 +const Cc = Components.classes;
    1.12 +const Ci = Components.interfaces;
    1.13 +
    1.14 +function test_basics()
    1.15 +{
    1.16 +  var item = Cc["@mozilla.org/windows-jumplistitem;1"].
    1.17 +  createInstance(Ci.nsIJumpListItem);
    1.18 +
    1.19 +  var sep = Cc["@mozilla.org/windows-jumplistseparator;1"].
    1.20 +  createInstance(Ci.nsIJumpListSeparator);
    1.21 +
    1.22 +  var shortcut = Cc["@mozilla.org/windows-jumplistshortcut;1"].
    1.23 +  createInstance(Ci.nsIJumpListShortcut);
    1.24 +
    1.25 +  var link = Cc["@mozilla.org/windows-jumplistlink;1"].
    1.26 +  createInstance(Ci.nsIJumpListLink);
    1.27 +
    1.28 +  do_check_false(item.equals(sep));
    1.29 +  do_check_false(item.equals(shortcut));
    1.30 +  do_check_false(item.equals(link));
    1.31 +
    1.32 +  do_check_false(sep.equals(item));
    1.33 +  do_check_false(sep.equals(shortcut));
    1.34 +  do_check_false(sep.equals(link));
    1.35 +
    1.36 +  do_check_false(shortcut.equals(item));
    1.37 +  do_check_false(shortcut.equals(sep));
    1.38 +  do_check_false(shortcut.equals(link));
    1.39 +
    1.40 +  do_check_false(link.equals(item));
    1.41 +  do_check_false(link.equals(sep));
    1.42 +  do_check_false(link.equals(shortcut));
    1.43 +
    1.44 +  do_check_true(item.equals(item));
    1.45 +  do_check_true(sep.equals(sep));
    1.46 +  do_check_true(link.equals(link));
    1.47 +  do_check_true(shortcut.equals(shortcut));
    1.48 +}
    1.49 +
    1.50 +function test_separator()
    1.51 +{
    1.52 +  // separators:
    1.53 +
    1.54 +  var item = Cc["@mozilla.org/windows-jumplistseparator;1"].
    1.55 +  createInstance(Ci.nsIJumpListSeparator);
    1.56 +
    1.57 +  do_check_true(item.type == Ci.nsIJumpListItem.JUMPLIST_ITEM_SEPARATOR);
    1.58 +}
    1.59 +
    1.60 +function test_hashes()
    1.61 +{
    1.62 +  var link = Cc["@mozilla.org/windows-jumplistlink;1"]
    1.63 +             .createInstance(Ci.nsIJumpListLink);
    1.64 +  var uri1 = Cc["@mozilla.org/network/simple-uri;1"]
    1.65 +            .createInstance(Ci.nsIURI);
    1.66 +  var uri2 = Cc["@mozilla.org/network/simple-uri;1"]
    1.67 +            .createInstance(Ci.nsIURI);
    1.68 +
    1.69 +  uri1.spec = "http://www.123.com/";
    1.70 +  uri2.spec = "http://www.123.com/";
    1.71 +
    1.72 +  link.uri = uri1;
    1.73 +
    1.74 +  do_check_true(link.compareHash(uri2))
    1.75 +  uri2.spec = "http://www.456.com/";
    1.76 +  do_check_false(link.compareHash(uri2))
    1.77 +  uri2.spec = "http://www.123.com/";
    1.78 +  do_check_true(link.compareHash(uri2))
    1.79 +  uri2.spec = "https://www.123.com/";
    1.80 +  do_check_false(link.compareHash(uri2))
    1.81 +  uri2.spec = "http://www.123.com/test/";
    1.82 +  do_check_false(link.compareHash(uri2))
    1.83 +  uri1.spec = "http://www.123.com/test/";
    1.84 +  uri2.spec = "http://www.123.com/test/";
    1.85 +  do_check_true(link.compareHash(uri2))
    1.86 +  uri1.spec = "https://www.123.com/test/";
    1.87 +  uri2.spec = "https://www.123.com/test/";
    1.88 +  do_check_true(link.compareHash(uri2))
    1.89 +  uri2.spec = "ftp://www.123.com/test/";
    1.90 +  do_check_false(link.compareHash(uri2))
    1.91 +  uri2.spec = "http://123.com/test/";
    1.92 +  do_check_false(link.compareHash(uri2))
    1.93 +  uri1.spec = "https://www.123.com/test/";
    1.94 +  uri2.spec = "https://www.123.com/Test/";
    1.95 +  do_check_false(link.compareHash(uri2))
    1.96 +
    1.97 +  uri1.spec = "http://www.123.com/";
    1.98 +  do_check_eq(link.uriHash, "QGLmWuwuTozr3tOfXSf5mg==");
    1.99 +  uri1.spec = "http://www.123.com/test/";
   1.100 +  do_check_eq(link.uriHash, "AG87Ls+GmaUYSUJFETRr3Q==");
   1.101 +  uri1.spec = "https://www.123.com/";
   1.102 +  do_check_eq(link.uriHash, "iSx6UH1a9enVPzUA9JZ42g==");
   1.103 +
   1.104 +  var uri3 = Cc["@mozilla.org/network/simple-uri;1"]
   1.105 +            .createInstance(Ci.nsIURI);
   1.106 +  link.uri = uri3;
   1.107 +  do_check_eq(link.uriHash, "hTrpDwNRMkvXPqYV5kh1Fw==");
   1.108 +}
   1.109 +
   1.110 +function test_links()
   1.111 +{
   1.112 +  // links:
   1.113 +  var link1 = Cc["@mozilla.org/windows-jumplistlink;1"]
   1.114 +             .createInstance(Ci.nsIJumpListLink);
   1.115 +  var link2 = Cc["@mozilla.org/windows-jumplistlink;1"]
   1.116 +              .createInstance(Ci.nsIJumpListLink);
   1.117 +
   1.118 +  var uri1 = Cc["@mozilla.org/network/simple-uri;1"]
   1.119 +            .createInstance(Ci.nsIURI);
   1.120 +  var uri2 = Cc["@mozilla.org/network/simple-uri;1"]
   1.121 +            .createInstance(Ci.nsIURI);
   1.122 +
   1.123 +  uri1.spec = "http://www.test.com/";
   1.124 +  uri2.spec = "http://www.test.com/";
   1.125 +
   1.126 +  link1.uri = uri1;
   1.127 +  link1.uriTitle = "Test";
   1.128 +  link2.uri = uri2;
   1.129 +  link2.uriTitle = "Test";
   1.130 +
   1.131 +  do_check_true(link1.equals(link2));
   1.132 +
   1.133 +  link2.uriTitle = "Testing";
   1.134 +
   1.135 +  do_check_false(link1.equals(link2));
   1.136 +
   1.137 +  link2.uriTitle = "Test";
   1.138 +  uri2.spec = "http://www.testing.com/";
   1.139 +
   1.140 +  do_check_false(link1.equals(link2));
   1.141 +}
   1.142 +
   1.143 +function test_shortcuts()
   1.144 +{
   1.145 +  // shortcuts:
   1.146 +  var sc = Cc["@mozilla.org/windows-jumplistshortcut;1"]
   1.147 +           .createInstance(Ci.nsIJumpListShortcut);
   1.148 +
   1.149 +  var handlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"]
   1.150 +                   .createInstance(Ci.nsILocalHandlerApp);
   1.151 +
   1.152 +  handlerApp.name = "TestApp";
   1.153 +  handlerApp.detailedDescription = "TestApp detailed description.";
   1.154 +  handlerApp.appendParameter("-test");
   1.155 +
   1.156 +  sc.iconIndex = 1;
   1.157 +  do_check_eq(sc.iconIndex, 1);
   1.158 +
   1.159 +  var faviconPageUri = Cc["@mozilla.org/network/simple-uri;1"]
   1.160 +                    .createInstance(Ci.nsIURI);
   1.161 +  faviconPageUri.spec = "http://www.123.com/";
   1.162 +  sc.faviconPageUri = faviconPageUri;
   1.163 +  do_check_eq(sc.faviconPageUri, faviconPageUri);
   1.164 +
   1.165 +  var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
   1.166 +                  getService(Ci.nsIProperties).
   1.167 +                  QueryInterface(Ci.nsIDirectoryService);
   1.168 +  var notepad = dirSvc.get("WinD", Ci.nsIFile);
   1.169 +  notepad.append("notepad.exe");
   1.170 +  if (notepad.exists()) {
   1.171 +    handlerApp.executable = notepad;
   1.172 +    sc.app = handlerApp;
   1.173 +    do_check_eq(sc.app.detailedDescription, "TestApp detailed description.");
   1.174 +    do_check_eq(sc.app.name, "TestApp");
   1.175 +    do_check_true(sc.app.parameterExists("-test"));
   1.176 +    do_check_false(sc.app.parameterExists("-notset"));
   1.177 +  }
   1.178 +}
   1.179 +
   1.180 +function test_jumplist()
   1.181 +{
   1.182 +  // Jump lists can't register links unless the application is the default
   1.183 +  // protocol handler for the protocol of the link, so we skip off testing
   1.184 +  // those in these tests. We'll init the jump list for the xpc shell harness,
   1.185 +  // add a task item, and commit it.
   1.186 + 
   1.187 +  // not compiled in
   1.188 +  if (Ci.nsIWinTaskbar == null)
   1.189 +    return;
   1.190 +
   1.191 +  var taskbar = Cc["@mozilla.org/windows-taskbar;1"]
   1.192 +                .getService(Ci.nsIWinTaskbar);
   1.193 +
   1.194 +  var builder = taskbar.createJumpListBuilder();
   1.195 +
   1.196 +  do_check_neq(builder, null);
   1.197 +
   1.198 +  // Win7 and up only
   1.199 +  try {
   1.200 +    var sysInfo = Cc["@mozilla.org/system-info;1"].
   1.201 +                  getService(Ci.nsIPropertyBag2);
   1.202 +    var ver = parseFloat(sysInfo.getProperty("version"));
   1.203 +    if (ver < 6.1) {
   1.204 +      do_check_false(builder.available, false);
   1.205 +      return;
   1.206 +    }
   1.207 +  } catch (ex) { }
   1.208 +
   1.209 +  do_check_true(taskbar.available);
   1.210 +
   1.211 +  builder.deleteActiveList();
   1.212 +
   1.213 +  var items = Cc["@mozilla.org/array;1"]
   1.214 +              .createInstance(Ci.nsIMutableArray);
   1.215 +
   1.216 +  var sc = Cc["@mozilla.org/windows-jumplistshortcut;1"]
   1.217 +           .createInstance(Ci.nsIJumpListShortcut);
   1.218 +
   1.219 +  var handlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"]
   1.220 +                   .createInstance(Ci.nsILocalHandlerApp);
   1.221 +
   1.222 +  handlerApp.name = "Notepad";
   1.223 +  handlerApp.detailedDescription = "Testing detailed description.";
   1.224 +
   1.225 +  var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
   1.226 +                  getService(Ci.nsIProperties).
   1.227 +                  QueryInterface(Ci.nsIDirectoryService);
   1.228 +  var notepad = dirSvc.get("WinD", Ci.nsIFile);
   1.229 +  notepad.append("notepad.exe");
   1.230 +  if (notepad.exists()) {
   1.231 +    handlerApp.executable = notepad;
   1.232 +    sc.app = handlerApp;
   1.233 +    items.appendElement(sc, false);
   1.234 +
   1.235 +    var removed = Cc["@mozilla.org/array;1"]
   1.236 +                  .createInstance(Ci.nsIMutableArray);
   1.237 +    do_check_true(builder.initListBuild(removed));
   1.238 +    do_check_true(builder.addListToBuild(builder.JUMPLIST_CATEGORY_TASKS, items));
   1.239 +    do_check_true(builder.addListToBuild(builder.JUMPLIST_CATEGORY_RECENT));
   1.240 +    do_check_true(builder.addListToBuild(builder.JUMPLIST_CATEGORY_FREQUENT));
   1.241 +    do_check_true(builder.commitListBuild());
   1.242 +
   1.243 +    builder.deleteActiveList();
   1.244 +
   1.245 +    do_check_true(builder.initListBuild(removed));
   1.246 +    do_check_true(builder.addListToBuild(builder.JUMPLIST_CATEGORY_CUSTOM, items, "Custom List"));
   1.247 +    do_check_true(builder.commitListBuild());
   1.248 +
   1.249 +    builder.deleteActiveList();
   1.250 +  }
   1.251 +}
   1.252 +
   1.253 +function run_test()
   1.254 +{
   1.255 +  var isWindows = ("@mozilla.org/windows-registry-key;1" in Components.classes);
   1.256 +  if (!isWindows)
   1.257 +    return;
   1.258 +
   1.259 +  test_basics();
   1.260 +  test_separator();
   1.261 +  test_hashes();
   1.262 +  test_links();
   1.263 +  test_shortcuts();
   1.264 +  test_jumplist();
   1.265 +}

mercurial