summaryrefslogtreecommitdiffstats
path: root/security/manager/ssl/tests/mochitest/mixedcontent/test_bug383369.html
blob: b68546d0a7018080167df74af80c933fea636145 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE HTML>
<html>
<head>
  <title>Bug 383369 test</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="mixedContentTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />

  <script class="testbody" type="text/javascript">
  /* sendAsyncMessage isn't actually a global - this just mollifies eslint */
  /* global sendAsyncMessage */
  /* import-globals-from mixedContentTest.js */
  "use strict";

  // We want to start this test from an insecure context
  loadAsInsecure = true;
  // We don't want to go through the navigation back/forward test
  bypassNavigationTest = true;

  function runTest() {
    let script = SpecialPowers.loadChromeScript(function() {
      const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
      // Force download to be w/o user assistance for our testing mime type
      const mimeSvc = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
      let handlerInfo =
        mimeSvc.getFromTypeAndExtension("application/x-auto-download", "auto");
      handlerInfo.preferredAction = Ci.nsIHandlerInfo.saveToDisk;
      handlerInfo.alwaysAskBeforeHandling = false;
      handlerInfo.preferredApplicationHandler = null;

      const handlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"]
                           .getService(Ci.nsIHandlerService);
      handlerSvc.store(handlerInfo);

      let dirProvider = Cc["@mozilla.org/file/directory_service;1"]
                          .getService(Ci.nsIProperties);
      let profileDir = dirProvider.get("ProfDS", Ci.nsIFile);
      profileDir.append("downloads");

      let prefs = Cc["@mozilla.org/preferences-service;1"]
                    .getService(Ci.nsIPrefService);
      let prefBranch = prefs.getBranch("browser.download.");

      prefBranch.setCharPref("dir", profileDir.path);
      prefBranch.setBoolPref("useDownloadDir", true);
      prefBranch.setIntPref("folderList", 2);
      prefBranch.setBoolPref("manager.closeWhenDone", true);
      prefBranch.setBoolPref("manager.showWhenStarting", false);

      const { Downloads } =
        Cu.import("resource://gre/modules/Downloads.jsm", {});
      Downloads.getList(Downloads.PUBLIC).then(list => {
        list.addView({
          onDownloadAdded: function (aDownload) {
            list.removeView(this);
            aDownload.whenSucceeded().then(() => {
              list.removeFinished();
              sendAsyncMessage("navigate", "bug383369step2.html");
            });
          },
        });
        sendAsyncMessage("navigate", "download.auto");
      }).then(null, Cu.reportError);
    });
    script.addMessageListener("navigate", function(url) {
      window.location = url;
    });
  }

  function afterNavigationTest() {}

  testCleanUp = function cleanup() {
    SpecialPowers.loadChromeScript(function() {
      const { classes: Cc, interfaces: Ci } = Components;
      const mimeSvc = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
      let handlerInfo =
        mimeSvc.getFromTypeAndExtension("application/x-auto-download", "auto");

      const handlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"]
                           .getService(Ci.nsIHandlerService);
      handlerSvc.remove(handlerInfo);

      let prefs = Cc["@mozilla.org/preferences-service;1"]
                    .getService(Ci.nsIPrefService);
      let prefBranch = prefs.getBranch("browser.download.");

      const prefKeys = ["dir", "useDownloadDir", "folderList",
                        "manager.closeWhenDone", "manager.showWhenStarting"];
      for (let prefKey of prefKeys) {
        if (prefBranch.prefHasUserValue(prefKey)) {
          prefBranch.clearUserPref(prefKey);
        }
      }
    });
  };

  </script>
</head>

<body>
</body>
</html>