security/manager/ssl/tests/mochitest/mixedcontent/test_bug383369.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/manager/ssl/tests/mochitest/mixedcontent/test_bug383369.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,133 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Bug 383369 test</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="text/javascript" src="mixedContentTest.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.11 +
    1.12 +  <script class="testbody" type="text/javascript">
    1.13 +
    1.14 +  // We want to start this test from an insecure context
    1.15 +  loadAsInsecure = true;
    1.16 +  // We don't want to go through the navigation back/forward test
    1.17 +  bypassNavigationTest = true;
    1.18 +
    1.19 +  function runTest()
    1.20 +  {
    1.21 +    // Force download to be w/o user assistance for our testing mime type
    1.22 +    const mimeSvc = SpecialPowers.Cc["@mozilla.org/mime;1"]
    1.23 +      .getService(SpecialPowers.Ci.nsIMIMEService);
    1.24 +    var handlerInfo = mimeSvc.getFromTypeAndExtension("application/x-auto-download", "auto");
    1.25 +    handlerInfo.preferredAction = SpecialPowers.Ci.nsIHandlerInfo.saveToDisk;
    1.26 +    handlerInfo.alwaysAskBeforeHandling = false;
    1.27 +    handlerInfo.preferredApplicationHandler = null;
    1.28 +    
    1.29 +    const handlerSvc = SpecialPowers.Cc["@mozilla.org/uriloader/handler-service;1"]
    1.30 +      .getService(SpecialPowers.Ci.nsIHandlerService);
    1.31 +    handlerSvc.store(handlerInfo);
    1.32 +    
    1.33 +    var dirProvider = SpecialPowers.Cc["@mozilla.org/file/directory_service;1"]
    1.34 +      .getService(SpecialPowers.Ci.nsIProperties);
    1.35 +    var profileDir = dirProvider.get("ProfDS", SpecialPowers.Ci.nsIFile);
    1.36 +    profileDir.append("downloads");
    1.37 +    
    1.38 +    var prefs = SpecialPowers.Cc["@mozilla.org/preferences-service;1"]
    1.39 +      .getService(SpecialPowers.Ci.nsIPrefService);
    1.40 +    prefs = prefs.getBranch("browser.download.");
    1.41 +        
    1.42 +    prefs.setCharPref("dir", profileDir.path);
    1.43 +    prefs.setBoolPref("useDownloadDir", true);
    1.44 +    prefs.setIntPref("folderList", 2);
    1.45 +    prefs.setBoolPref("manager.closeWhenDone", true);
    1.46 +    prefs.setBoolPref("manager.showWhenStarting", false);
    1.47 +  
    1.48 +    var theWindow = window;
    1.49 +
    1.50 +    var useJSTransfer = false;
    1.51 +    try {
    1.52 +      // This method throws an exception if the old Download Manager is disabled.
    1.53 +      Services.downloads.activeDownloadCount;
    1.54 +    } catch (ex) {
    1.55 +      useJSTransfer = true;
    1.56 +    }
    1.57 +
    1.58 +    if (useJSTransfer) {
    1.59 +      var Downloads = SpecialPowers.Cu.import("resource://gre/modules/Downloads.jsm").Downloads;
    1.60 +      Downloads.getList(Downloads.PUBLIC).then(list => {
    1.61 +        list = SpecialPowers.wrap(list);
    1.62 +        list.addView({
    1.63 +          onDownloadAdded: function (aDownload) {
    1.64 +            list.removeView(this);
    1.65 +            SpecialPowers.wrap(aDownload).whenSucceeded().then(() => {
    1.66 +              list.removeFinished();
    1.67 +              theWindow.location = "bug383369step2.html";
    1.68 +            });
    1.69 +          },
    1.70 +        });
    1.71 +        window.location = "download.auto";
    1.72 +      }).then(null, SpecialPowers.Cu.reportError);
    1.73 +
    1.74 +      return;
    1.75 +    }
    1.76 +
    1.77 +    var downloadManager = SpecialPowers.Cc["@mozilla.org/download-manager;1"]
    1.78 +      .getService(SpecialPowers.Ci.nsIDownloadManager);
    1.79 +    var observer = {
    1.80 +      observe: function(subject, topic, data) {
    1.81 +        switch (topic) {
    1.82 +        case "dl-done":
    1.83 +        case "dl-failed":
    1.84 +        case "dl-blocked":
    1.85 +        case "dl-dirty":
    1.86 +          downloadManager.cleanUp();
    1.87 +          theWindow.location = "bug383369step2.html";
    1.88 +          observerService.removeObserver(this, "dl-done");
    1.89 +          observerService.removeObserver(this, "dl-failed");
    1.90 +          observerService.removeObserver(this, "dl-blocked");
    1.91 +          observerService.removeObserver(this, "dl-dirty");
    1.92 +          break;
    1.93 +        }
    1.94 +      }
    1.95 +    };
    1.96 +    var observerService = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
    1.97 +      .getService(SpecialPowers.Ci.nsIObserverService);
    1.98 +    observerService.addObserver(observer, "dl-done", false);
    1.99 +    observerService.addObserver(observer, "dl-failed", false);
   1.100 +    observerService.addObserver(observer, "dl-blocked", false);
   1.101 +    observerService.addObserver(observer, "dl-dirty", false);
   1.102 +
   1.103 +    window.location = "download.auto";
   1.104 +  }
   1.105 +
   1.106 +  function afterNavigationTest()
   1.107 +  {
   1.108 +  }
   1.109 +  
   1.110 +  testCleanUp = function cleanup()
   1.111 +  {
   1.112 +    const mimeSvc = SpecialPowers.Cc["@mozilla.org/mime;1"]
   1.113 +      .getService(SpecialPowers.Ci.nsIMIMEService);
   1.114 +    var handlerInfo = mimeSvc.getFromTypeAndExtension("application/x-auto-download", "auto");
   1.115 +    
   1.116 +    const handlerSvc = SpecialPowers.Cc["@mozilla.org/uriloader/handler-service;1"]
   1.117 +      .getService(SpecialPowers.Ci.nsIHandlerService);
   1.118 +    handlerSvc.remove(handlerInfo);
   1.119 +    
   1.120 +    var prefs = SpecialPowers.Cc["@mozilla.org/preferences-service;1"]
   1.121 +      .getService(SpecialPowers.Ci.nsIPrefService);
   1.122 +    prefs = prefs.getBranch("browser.download.");
   1.123 +
   1.124 +    var prefKeys = ["dir", "useDownloadDir", "folderList", 
   1.125 +                    "manager.closeWhenDone", "manager.showWhenStarting"];
   1.126 +    for (var i = 0; i < prefKeys.length; i++)
   1.127 +      if (prefs.prefHasUserValue(prefKeys[i]))
   1.128 +        prefs.clearUserPref(prefKeys[i]);
   1.129 +  }
   1.130 +  
   1.131 +  </script>
   1.132 +</head>
   1.133 +
   1.134 +<body>
   1.135 +</body>
   1.136 +</html>

mercurial