xpcom/tests/unit/test_windows_shortcut.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:set ts=2 sw=2 sts=2 et: */
     4 /* This Source Code Form is subject to the terms of the Mozilla Public
     5  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     6  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     8 const Cr = Components.results;
     9 const Ci = Components.interfaces;
    10 const Cc = Components.classes;
    11 const Cu = Components.utils;
    12 const CC = Components.Constructor;
    14 const LocalFile = CC("@mozilla.org/file/local;1", "nsILocalFile", "initWithPath");
    16 Cu.import("resource://gre/modules/Services.jsm");
    18 function run_test()
    19 {
    20   // This test makes sense only on Windows, so skip it on other platforms
    21   if ("nsILocalFileWin" in Ci
    22    && do_get_cwd() instanceof Ci.nsILocalFileWin) {
    24     let tempDir = Services.dirsvc.get("TmpD", Ci.nsILocalFile);
    25     tempDir.append("shortcutTesting");
    26     tempDir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0666);
    28     test_create_noargs(tempDir);
    29     test_create_notarget(tempDir);
    30     test_create_targetonly(tempDir);
    31     test_create_normal(tempDir);
    32     test_create_unicode(tempDir);
    34     test_update_noargs(tempDir);
    35     test_update_notarget(tempDir);
    36     test_update_targetonly(tempDir);
    37     test_update_normal(tempDir);
    38     test_update_unicode(tempDir);
    39   }
    40 }
    42 function test_create_noargs(tempDir)
    43 {
    44   let shortcutFile = tempDir.clone();
    45   shortcutFile.append("shouldNeverExist.lnk");
    46   shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
    48   let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin);
    50   try
    51   {
    52     win.setShortcut();
    53     do_throw("Creating a shortcut with no args (no target) should throw");
    54   }
    55   catch(e if (e instanceof Ci.nsIException
    56              && e.result == Cr.NS_ERROR_FILE_TARGET_DOES_NOT_EXIST))
    57   {
    59   }
    60 }
    62 function test_create_notarget(tempDir)
    63 {
    64   let shortcutFile = tempDir.clone();
    65   shortcutFile.append("shouldNeverExist2.lnk");
    66   shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
    68   let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin);
    70   try
    71   {
    72     win.setShortcut(null,
    73                     do_get_cwd(),
    74                     "arg1 arg2",
    75                     "Shortcut with no target");
    76     do_throw("Creating a shortcut with no target should throw");
    77   }
    78   catch(e if (e instanceof Ci.nsIException
    79              && e.result == Cr.NS_ERROR_FILE_TARGET_DOES_NOT_EXIST))
    80   {
    82   }
    83 }
    85 function test_create_targetonly(tempDir)
    86 {
    87   let shortcutFile = tempDir.clone();
    88   shortcutFile.append("createdShortcut.lnk");
    89   shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
    91   let targetFile = tempDir.clone();
    92   targetFile.append("shortcutTarget.exe");
    93   targetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
    95   let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin);
    97   win.setShortcut(targetFile);
    99   let shortcutTarget = LocalFile(shortcutFile.target);
   100   do_check_true(shortcutTarget.equals(targetFile));
   101 }
   103 function test_create_normal(tempDir)
   104 {
   105   let shortcutFile = tempDir.clone();
   106   shortcutFile.append("createdShortcut.lnk");
   107   shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   109   let targetFile = tempDir.clone();
   110   targetFile.append("shortcutTarget.exe");
   111   targetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   113   let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin);
   115   win.setShortcut(targetFile,
   116                   do_get_cwd(),
   117                   "arg1 arg2",
   118                   "Ordinary shortcut");
   120   let shortcutTarget = LocalFile(shortcutFile.target);
   121   do_check_true(shortcutTarget.equals(targetFile))
   122 }
   124 function test_create_unicode(tempDir)
   125 {
   126   let shortcutFile = tempDir.clone();
   127   shortcutFile.append("createdShortcut.lnk");
   128   shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   130   let targetFile = tempDir.clone();
   131   targetFile.append("ṩhогТϾừ†Target.exe");
   132   targetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   134   let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin);
   136   win.setShortcut(targetFile,
   137                   do_get_cwd(), // XXX: This should probably be a unicode dir
   138                   "ᾶṟǵ1 ᾶṟǵ2",
   139                   "ῧṋіḉѻₑ");
   141   let shortcutTarget = LocalFile(shortcutFile.target);
   142   do_check_true(shortcutTarget.equals(targetFile))
   143 }
   145 function test_update_noargs(tempDir)
   146 {
   147   let shortcutFile = tempDir.clone();
   148   shortcutFile.append("createdShortcut.lnk");
   149   shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   151   let targetFile = tempDir.clone();
   152   targetFile.append("shortcutTarget.exe");
   153   targetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   155   let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin);
   157   win.setShortcut(targetFile,
   158                   do_get_cwd(),
   159                   "arg1 arg2",
   160                   "A sample shortcut");
   162   win.setShortcut();
   164   let shortcutTarget = LocalFile(shortcutFile.target);
   165   do_check_true(shortcutTarget.equals(targetFile))
   166 }
   168 function test_update_notarget(tempDir)
   169 {
   170   let shortcutFile = tempDir.clone();
   171   shortcutFile.append("createdShortcut.lnk");
   172   shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   174   let targetFile = tempDir.clone();
   175   targetFile.append("shortcutTarget.exe");
   176   targetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   178   let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin);
   180   win.setShortcut(targetFile,
   181                   do_get_cwd(),
   182                   "arg1 arg2",
   183                   "A sample shortcut");
   185   win.setShortcut(null,
   186                   do_get_profile(),
   187                   "arg3 arg4",
   188                   "An UPDATED shortcut");
   190   let shortcutTarget = LocalFile(shortcutFile.target);
   191   do_check_true(shortcutTarget.equals(targetFile))
   192 }
   194 function test_update_targetonly(tempDir)
   195 {
   196   let shortcutFile = tempDir.clone();
   197   shortcutFile.append("createdShortcut.lnk");
   198   shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   200   let targetFile = tempDir.clone();
   201   targetFile.append("shortcutTarget.exe");
   202   targetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   204   let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin);
   206   win.setShortcut(targetFile,
   207                   do_get_cwd(),
   208                   "arg1 arg2",
   209                   "A sample shortcut");
   211   let newTargetFile = tempDir.clone();
   212   newTargetFile.append("shortcutTarget.exe");
   213   shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   215   win.setShortcut(newTargetFile);
   217   let shortcutTarget = LocalFile(shortcutFile.target);
   218   do_check_true(shortcutTarget.equals(newTargetFile))
   219 }
   221 function test_update_normal(tempDir)
   222 {
   223   let shortcutFile = tempDir.clone();
   224   shortcutFile.append("createdShortcut.lnk");
   225   shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   227   let targetFile = tempDir.clone();
   228   targetFile.append("shortcutTarget.exe");
   229   targetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   231   let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin);
   233   win.setShortcut(targetFile,
   234                   do_get_cwd(),
   235                   "arg1 arg2",
   236                   "A sample shortcut");
   238   let newTargetFile = tempDir.clone();
   239   newTargetFile.append("shortcutTarget.exe");
   240   newTargetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   242   win.setShortcut(newTargetFile,
   243                   do_get_profile(),
   244                   "arg3 arg4",
   245                   "An UPDATED shortcut");
   247   let shortcutTarget = LocalFile(shortcutFile.target);
   248   do_check_true(shortcutTarget.equals(newTargetFile))
   249 }
   251 function test_update_unicode(tempDir)
   252 {
   253   let shortcutFile = tempDir.clone();
   254   shortcutFile.append("createdShortcut.lnk");
   255   shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   257   let targetFile = tempDir.clone();
   258   targetFile.append("shortcutTarget.exe");
   259   targetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   261   let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin);
   263   win.setShortcut(targetFile,
   264                   do_get_cwd(),
   265                   "arg1 arg2",
   266                   "A sample shortcut");
   268   let newTargetFile = tempDir.clone();
   269   newTargetFile.append("ṩhогТϾừ†Target.exe");
   270   shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   272   win.setShortcut(newTargetFile,
   273                   do_get_profile(), // XXX: This should probably be unicode
   274                   "ᾶṟǵ3 ᾶṟǵ4",
   275                   "A ῧṋіḉѻₑ shortcut");
   277   let shortcutTarget = LocalFile(shortcutFile.target);
   278   do_check_true(shortcutTarget.equals(newTargetFile))
   279 }

mercurial