forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1287664 - Replacing useless module HelperApps.js by using nsIHand…
…lerService. r=Paolo --HG-- extra : rebase_source : 8de756d1b9e7c79bff2ee9c144e7efc6bcefb5ea
- Loading branch information
1 parent
115286c
commit bf2f956
Showing
9 changed files
with
178 additions
and
834 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
[DEFAULT] | ||
head = head.js | ||
support-files = | ||
protocolHandler.html | ||
|
||
[browser_download_always_ask_preferred_app.js] | ||
[browser_remember_download_option.js] | ||
[browser_web_protocol_handlers.js] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
uriloader/exthandler/tests/mochitest/browser_remember_download_option.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
add_task(function*() { | ||
// create mocked objects | ||
let launcher = createMockedObjects(true); | ||
|
||
// open helper app dialog with mocked launcher | ||
let dlg = yield* openHelperAppDialog(launcher); | ||
|
||
let doc = dlg.document; | ||
|
||
// Set remember choice | ||
ok(!doc.getElementById("rememberChoice").checked, | ||
"Remember choice checkbox should be not checked."); | ||
doc.getElementById("rememberChoice").checked = true; | ||
|
||
// Make sure the mock handler information is not in nsIHandlerService | ||
ok(!gHandlerSvc.exists(launcher.MIMEInfo), "Should not be in nsIHandlerService."); | ||
|
||
// close the dialog by pushing the ok button. | ||
let dialogClosedPromise = BrowserTestUtils.windowClosed(dlg); | ||
// Make sure the ok button is enabled, since the ok button might be disabled by | ||
// EnableDelayHelper mechanism. Please refer the detailed | ||
// https://dxr.mozilla.org/mozilla-central/source/toolkit/components/prompts/src/SharedPromptUtils.jsm#53 | ||
doc.documentElement.getButton("accept").disabled = false; | ||
doc.documentElement.acceptDialog(); | ||
yield dialogClosedPromise; | ||
|
||
// check the mocked handler information is saved in nsIHandlerService | ||
ok(gHandlerSvc.exists(launcher.MIMEInfo), "Should be in nsIHandlerService."); | ||
// check the extension. | ||
var mimeType = gHandlerSvc.getTypeFromExtension("abc"); | ||
is(mimeType, launcher.MIMEInfo.type, "Got correct mime type."); | ||
var handlerInfos = gHandlerSvc.enumerate(); | ||
while (handlerInfos.hasMoreElements()) { | ||
let handlerInfo = handlerInfos.getNext().QueryInterface(Ci.nsIHandlerInfo); | ||
if (handlerInfo.type == launcher.MIMEInfo.type) { | ||
// check the alwaysAskBeforeHandling | ||
ok(!handlerInfo.alwaysAskBeforeHandling, | ||
"Should turn off the always ask."); | ||
// check the preferredApplicationHandler | ||
ok(handlerInfo.preferredApplicationHandler.equals( | ||
launcher.MIMEInfo.preferredApplicationHandler), | ||
"Should be equal to the mockedHandlerApp."); | ||
// check the perferredAction | ||
is(handlerInfo.preferredAction, launcher.MIMEInfo.preferredAction, | ||
"Should be equal to Ci.nsIHandlerInfo.useHelperApp."); | ||
break; | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
Components.utils.import("resource://gre/modules/FileUtils.jsm"); | ||
Components.utils.import("resource://gre/modules/Task.jsm"); | ||
|
||
var gMimeSvc = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService); | ||
var gHandlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"].getService(Ci.nsIHandlerService); | ||
|
||
function createMockedHandlerApp() { | ||
// Mock the executable | ||
let mockedExecutable = FileUtils.getFile("TmpD", ["mockedExecutable"]); | ||
if (!mockedExecutable.exists()) { | ||
mockedExecutable.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o755); | ||
} | ||
|
||
// Mock the handler app | ||
let mockedHandlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"] | ||
.createInstance(Ci.nsILocalHandlerApp); | ||
mockedHandlerApp.executable = mockedExecutable; | ||
mockedHandlerApp.detailedDescription = "Mocked handler app"; | ||
|
||
registerCleanupFunction(function() { | ||
// remove the mocked executable from disk. | ||
if (mockedExecutable.exists()) { | ||
mockedExecutable.remove(true); | ||
} | ||
}); | ||
|
||
return mockedHandlerApp; | ||
} | ||
|
||
function createMockedObjects(createHandlerApp) { | ||
// Mock the mime info | ||
let internalMockedMIME = gMimeSvc.getFromTypeAndExtension("text/x-test-handler", null); | ||
internalMockedMIME.alwaysAskBeforeHandling = true; | ||
internalMockedMIME.preferredAction = Ci.nsIHandlerInfo.useHelperApp; | ||
internalMockedMIME.appendExtension("abc"); | ||
if (createHandlerApp) { | ||
let mockedHandlerApp = createMockedHandlerApp(); | ||
internalMockedMIME.description = mockedHandlerApp.detailedDescription; | ||
internalMockedMIME.possibleApplicationHandlers.appendElement(mockedHandlerApp, false); | ||
internalMockedMIME.preferredApplicationHandler = mockedHandlerApp; | ||
} | ||
|
||
// Proxy for the mocked MIME info for faking the read-only attributes | ||
let mockedMIME = new Proxy(internalMockedMIME, { | ||
get: function (target, property) { | ||
switch (property) { | ||
case "hasDefaultHandler": | ||
return true; | ||
case "defaultDescription": | ||
return "Default description"; | ||
default: | ||
return target[property]; | ||
} | ||
}, | ||
}); | ||
|
||
// Mock the launcher: | ||
let mockedLauncher = { | ||
MIMEInfo: mockedMIME, | ||
source: Services.io.newURI("http://www.mozilla.org/", null, null), | ||
suggestedFileName: "test_download_dialog.abc", | ||
targetFileIsExecutable: false, | ||
saveToDisk() {}, | ||
cancel() {}, | ||
launchWithApplication() {}, | ||
setWebProgressListener() {}, | ||
saveDestinationAvailable() {}, | ||
contentLength: 42, | ||
targetFile: null, // never read | ||
// PRTime is microseconds since epoch, Date.now() returns milliseconds: | ||
timeDownloadStarted: Date.now() * 1000, | ||
QueryInterface: XPCOMUtils.generateQI([Ci.nsICancelable, Ci.nsIHelperAppLauncher]) | ||
}; | ||
|
||
registerCleanupFunction(function() { | ||
// remove the mocked mime info from database. | ||
let mockHandlerInfo = gMimeSvc.getFromTypeAndExtension("text/x-test-handler", null); | ||
if (gHandlerSvc.exists(mockHandlerInfo)) { | ||
gHandlerSvc.remove(mockHandlerInfo); | ||
} | ||
}); | ||
|
||
return mockedLauncher; | ||
} | ||
|
||
function* openHelperAppDialog(launcher) { | ||
let helperAppDialog = Cc["@mozilla.org/helperapplauncherdialog;1"]. | ||
createInstance(Ci.nsIHelperAppLauncherDialog); | ||
|
||
let helperAppDialogShownPromise = BrowserTestUtils.domWindowOpened(); | ||
try { | ||
helperAppDialog.show(launcher, window, "foopy"); | ||
} catch (ex) { | ||
ok(false, "Trying to show unknownContentType.xul failed with exception: " + ex); | ||
Cu.reportError(ex); | ||
} | ||
let dlg = yield helperAppDialogShownPromise; | ||
|
||
yield BrowserTestUtils.waitForEvent(dlg, "load", false); | ||
|
||
is(dlg.location.href, "chrome://mozapps/content/downloads/unknownContentType.xul", | ||
"Got correct dialog"); | ||
|
||
return dlg; | ||
} |