toolkit/mozapps/downloads/tests/chrome/test_bug_412360.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <!-- This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 - License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
michael@0 5 <!--
michael@0 6 * This tests bug 412360, which caused problems when trying to save javascript
michael@0 7 * URIs. This is not an xpcshell unit test because it triggers an assertion,
michael@0 8 * which causes xpcshell test cases to fail.
michael@0 9 -->
michael@0 10
michael@0 11 <window title="Download Manager Test"
michael@0 12 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
michael@0 13 onload="test();">
michael@0 14
michael@0 15 <script type="application/javascript"
michael@0 16 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 17 <script type="application/javascript"
michael@0 18 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
michael@0 19 <script type="application/javascript"
michael@0 20 src="utils.js"/>
michael@0 21
michael@0 22 <script type="application/javascript">
michael@0 23 <![CDATA[
michael@0 24
michael@0 25 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 26
michael@0 27 let didFail = false;
michael@0 28 var file;
michael@0 29
michael@0 30 let prefBranch = Cc["@mozilla.org/preferences-service;1"].
michael@0 31 getService(Ci.nsIPrefBranch);
michael@0 32
michael@0 33 let factory = {
michael@0 34 createInstance: function(aOuter, aIid) {
michael@0 35 if (aOuter != null)
michael@0 36 throw Components.results.NS_ERROR_NO_AGGREGATION;
michael@0 37 return promptService.QueryInterface(aIid);
michael@0 38 }
michael@0 39 };
michael@0 40
michael@0 41 let promptService = {
michael@0 42 QueryInterface: XPCOMUtils.generateQI([Ci.nsIPromptService]),
michael@0 43 alert: function() {
michael@0 44 ok(didFail, "javascript: uri failed and showed a message");
michael@0 45 file.remove(false);
michael@0 46
michael@0 47 cleanUpFactory();
michael@0 48 SimpleTest.finish();
michael@0 49 }
michael@0 50 };
michael@0 51
michael@0 52 Components.manager.QueryInterface(Ci.nsIComponentRegistrar).
michael@0 53 registerFactory(Components.ID("{6cc9c9fe-bc0b-432b-a410-253ef8bcc699}"),
michael@0 54 "PromptService", "@mozilla.org/embedcomp/prompt-service;1",
michael@0 55 factory
michael@0 56 );
michael@0 57
michael@0 58 function cleanUpFactory() {
michael@0 59 // Unregister the factory so we do not leak
michael@0 60 Components.manager.QueryInterface(Ci.nsIComponentRegistrar).
michael@0 61 unregisterFactory(
michael@0 62 Components.ID("{6cc9c9fe-bc0b-432b-a410-253ef8bcc699}"),
michael@0 63 factory
michael@0 64 );
michael@0 65 }
michael@0 66
michael@0 67 function test()
michael@0 68 {
michael@0 69 var dmui = getDMUI();
michael@0 70 if (!dmui) {
michael@0 71 cleanUpFactory();
michael@0 72 todo(false, "skip test for toolkit download manager UI");
michael@0 73 return;
michael@0 74 }
michael@0 75
michael@0 76 let dm = Cc["@mozilla.org/download-manager;1"].
michael@0 77 getService(Ci.nsIDownloadManager);
michael@0 78 let db = dm.DBConnection;
michael@0 79
michael@0 80 // Empty any old downloads
michael@0 81 db.executeSimpleSQL("DELETE FROM moz_downloads");
michael@0 82
michael@0 83 let stmt = db.createStatement(
michael@0 84 "INSERT INTO moz_downloads (source, target, state, endTime) " +
michael@0 85 "VALUES (?1, ?2, ?3, ?4)");
michael@0 86
michael@0 87 try {
michael@0 88 // Saving javascript URIs doesn't work
michael@0 89 stmt.bindStringParameter(0, "javascript:5");
michael@0 90
michael@0 91 // Download to a temp local file
michael@0 92 file = Cc["@mozilla.org/file/directory_service;1"].
michael@0 93 getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
michael@0 94 file.append("javascriptURI");
michael@0 95 file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
michael@0 96 stmt.bindStringParameter(1, Cc["@mozilla.org/network/io-service;1"].
michael@0 97 getService(Ci.nsIIOService).newFileURI(file).spec);
michael@0 98
michael@0 99 // Start it as canceled
michael@0 100 stmt.bindInt32Parameter(2, dm.DOWNLOAD_CANCELED);
michael@0 101
michael@0 102 stmt.bindInt32Parameter(3, Date.now() * 1000);
michael@0 103
michael@0 104 // Add it!
michael@0 105 stmt.execute();
michael@0 106 }
michael@0 107 finally {
michael@0 108 stmt.finalize();
michael@0 109 }
michael@0 110
michael@0 111 let listener = {
michael@0 112 onDownloadStateChange: function(aState, aDownload)
michael@0 113 {
michael@0 114 switch (aDownload.state) {
michael@0 115 case dm.DOWNLOAD_FAILED:
michael@0 116 // Remember that we failed for the prompt service
michael@0 117 didFail = true;
michael@0 118
michael@0 119 ok(true, "javascript: uri failed instead of getting stuck");
michael@0 120 dm.removeListener(listener);
michael@0 121 break;
michael@0 122 }
michael@0 123 }
michael@0 124 };
michael@0 125 dm.addListener(listener);
michael@0 126
michael@0 127 // Close the UI if necessary
michael@0 128 let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
michael@0 129 getService(Ci.nsIWindowMediator);
michael@0 130 let win = wm.getMostRecentWindow("Download:Manager");
michael@0 131 if (win) win.close();
michael@0 132
michael@0 133
michael@0 134 let os = Cc["@mozilla.org/observer-service;1"].
michael@0 135 getService(Ci.nsIObserverService);
michael@0 136 const DLMGR_UI_DONE = "download-manager-ui-done";
michael@0 137
michael@0 138 let testObs = {
michael@0 139 observe: function(aSubject, aTopic, aData)
michael@0 140 {
michael@0 141 if (aTopic != DLMGR_UI_DONE)
michael@0 142 return;
michael@0 143
michael@0 144 os.removeObserver(testObs, DLMGR_UI_DONE);
michael@0 145
michael@0 146 SimpleTest.waitForFocus(function () {
michael@0 147 let win = aSubject;
michael@0 148
michael@0 149 // Down arrow to select the download
michael@0 150 synthesizeKey("VK_DOWN", {}, win);
michael@0 151
michael@0 152 // Enter key to retry the download
michael@0 153 synthesizeKey("VK_RETURN", {}, win);
michael@0 154 }, aSubject);
michael@0 155 }
michael@0 156 };
michael@0 157
michael@0 158 // Register with the observer service
michael@0 159 os.addObserver(testObs, DLMGR_UI_DONE, false);
michael@0 160
michael@0 161 // Show the Download Manager UI
michael@0 162 dmui.show();
michael@0 163
michael@0 164 SimpleTest.waitForExplicitFinish();
michael@0 165 }
michael@0 166
michael@0 167 ]]>
michael@0 168 </script>
michael@0 169
michael@0 170 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 171 <p id="display"></p>
michael@0 172 <div id="content" style="display:none;"></div>
michael@0 173 <pre id="test"></pre>
michael@0 174 </body>
michael@0 175 </window>

mercurial