Bug 1406590 - support single-dash arguments with values; r=mossop

This commit is contained in:
Myk Melez 2017-10-23 10:08:26 -07:00
Родитель 2b9fe286fc
Коммит 1fa0f82151
2 изменённых файлов: 37 добавлений и 5 удалений

Просмотреть файл

@ -9,6 +9,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1378010
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<script type="application/javascript">
Components.utils.import("resource://gre/modules/AppConstants.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/Subprocess.jsm");
Components.utils.import("resource://gre/modules/osfile.jsm");
@ -100,15 +101,47 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1378010
(async function() {
SimpleTest.waitForExplicitFinish();
// On Windows, nsICommandLine doesn't support double-dash arguments,
// nor single-dash arguments whose value is specified via an equals sign,
// so we only test those variations on non-Windows platforms.
// Test all four basic variations of the "screenshot" argument
// when a file path is specified.
await testFileCreationPositive(["-url", "http://mochi.test:8888/headless.html", "-screenshot", screenshotPath], screenshotPath);
if (AppConstants.platform != "win") {
await testFileCreationPositive(["-url", "http://mochi.test:8888/headless.html", `-screenshot=${screenshotPath}`], screenshotPath);
await testFileCreationPositive(["-url", "http://mochi.test:8888/headless.html", "--screenshot", screenshotPath], screenshotPath);
await testFileCreationPositive(["-url", "http://mochi.test:8888/headless.html", `--screenshot=${screenshotPath}`], screenshotPath);
}
// Test variations of the "screenshot" argument when a file path
// isn't specified.
await testFileCreationPositive(["-screenshot", "http://mochi.test:8888/headless.html"], "screenshot.png");
await testFileCreationPositive(["http://mochi.test:8888/headless.html", "-screenshot"], "screenshot.png");
if (AppConstants.platform != "win") {
await testFileCreationPositive(["--screenshot", "http://mochi.test:8888/headless.html"], "screenshot.png");
await testFileCreationPositive(["http://mochi.test:8888/headless.html", "--screenshot"], "screenshot.png");
}
// Test invalid URL arguments (either no argument or too many arguments).
await testFileCreationNegative(["-screenshot"], "screenshot.png");
await testFileCreationNegative(["http://mochi.test:8888/headless.html", "http://mochi.test:8888/headless.html", "-screenshot"], "screenshot.png");
// Test all four basic variations of the "window-size" argument.
await testFileCreationPositive(["-url", "http://mochi.test:8888/headless.html", "-screenshot", "-window-size", "800"], "screenshot.png");
if (AppConstants.platform != "win") {
await testFileCreationPositive(["-url", "http://mochi.test:8888/headless.html", "-screenshot", "-window-size=800"], "screenshot.png");
await testFileCreationPositive(["-url", "http://mochi.test:8888/headless.html", "-screenshot", "--window-size", "800"], "screenshot.png");
await testFileCreationPositive(["-url", "http://mochi.test:8888/headless.html", "-screenshot", "--window-size=800"], "screenshot.png");
}
// Test other variations of the "window-size" argument.
await testWindowSizePositive(800, 600);
await testWindowSizePositive(1234);
await testFileCreationNegative(["-url", "http://mochi.test:8888/headless.html", "-screenshot", screenshotPath, "-window-size", "hello"], screenshotPath);
await testFileCreationNegative(["-url", "http://mochi.test:8888/headless.html", "-screenshot", screenshotPath, "-window-size", "800,"], screenshotPath);
await testFileCreationNegative(["-url", "http://mochi.test:8888/headless.html", "-screenshot", "-window-size", "hello"], "screenshot.png");
await testFileCreationNegative(["-url", "http://mochi.test:8888/headless.html", "-screenshot", "-window-size", "800,"], "screenshot.png");
SimpleTest.finish();
})();
</script>

Просмотреть файл

@ -455,9 +455,8 @@ nsCommandLine::Init(int32_t argc, const char* const* argv, nsIFile* aWorkingDir,
}
#endif
#ifdef XP_UNIX
if (*curarg == '-' &&
*(curarg+1) == '-') {
++curarg;
if (*curarg == '-') {
if (*(curarg+1) == '-') ++curarg;
char* dup = PL_strdup(curarg);
if (!dup) return NS_ERROR_OUT_OF_MEMORY;