Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
Bug 672090 - Remove toolkit/content/tests/browser/common/_loadAll.js,…
Browse files Browse the repository at this point in the history
… testRunner.js, toolkitFunctions.js. r=gavin

--HG--
rename : toolkit/content/tests/browser/common/mockTransferForContinuing.js => toolkit/content/tests/browser/common/mockTransfer.js
  • Loading branch information
daogottwald committed Jul 20, 2011
1 parent 276d1f2 commit d2db96d
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 611 deletions.
162 changes: 70 additions & 92 deletions browser/base/content/test/browser_save_video.js
Expand Up @@ -6,105 +6,83 @@
* <https://bugzilla.mozilla.org/show_bug.cgi?id=564387>
*/
function test() {
waitForExplicitFinish();

// --- Testing support library ---
gBrowser.loadURI("http://mochi.test:8888/browser/browser/base/content/test/bug564387.html");

// Import the toolkit test support library in the scope of the current test.
// This operation also defines the common constants Cc, Ci, Cu, Cr and Cm.
Components.classes["@mozilla.org/moz/jssubscript-loader;1"].
getService(Components.interfaces.mozIJSSubScriptLoader).loadSubScript(
"chrome://mochitests/content/browser/toolkit/content/tests/browser/common/_loadAll.js",
this);
registerCleanupFunction(function () {
gBrowser.addTab();
gBrowser.removeCurrentTab();
});

// --- Test implementation ---
gBrowser.addEventListener("pageshow", function pageShown(event) {
if (event.target.location == "about:blank")
return;
gBrowser.removeEventListener("pageshow", pageShown);

const kBaseUrl =
"http://mochi.test:8888/browser/browser/base/content/test/";
document.addEventListener("popupshown", contextMenuOpened);

function pageShown(event) {
if (event.target.location != "about:blank")
testRunner.continueTest();
var video1 = gBrowser.contentDocument.getElementById("video1");
EventUtils.synthesizeMouseAtCenter(video1,
{ type: "contextmenu", button: 2 },
gBrowser.contentWindow);
});

function contextMenuOpened(event) {
event.currentTarget.removeEventListener("popupshown", contextMenuOpened);

// Create the folder the video will be saved into.
var destDir = createTemporarySaveDirectory();

mockFilePickerSettings.destDir = destDir;
mockFilePickerSettings.filterIndex = 1; // kSaveAsType_URL
mockFilePickerRegisterer.register();

mockTransferCallback = onTransferComplete;
mockTransferRegisterer.register();

registerCleanupFunction(function () {
mockTransferRegisterer.unregister();
mockFilePickerRegisterer.unregister();
destDir.remove(true);
});

// Select "Save Video As" option from context menu
var saveVideoCommand = document.getElementById("context-savevideo");
saveVideoCommand.doCommand();

event.target.hidePopup();
}

function saveVideoAs_TestGenerator() {
// Load Test page
gBrowser.addEventListener("pageshow", pageShown, false);
gBrowser.loadURI(kBaseUrl + "bug564387.html");
yield;
gBrowser.removeEventListener("pageshow", pageShown, false);

// Ensure that the window is focused.
SimpleTest.waitForFocus(testRunner.continueTest);
yield;

try {
// get the video element
var video1 = gBrowser.contentDocument.getElementById("video1");

// Synthesize the right click on the context menu, and
// wait for it to be shown
document.addEventListener("popupshown", testRunner.continueTest, false);
EventUtils.synthesizeMouseAtCenter(video1,
{ type: "contextmenu", button: 2 },
gBrowser.contentWindow);
yield;

// Create the folder the video will be saved into.
var destDir = createTemporarySaveDirectory();
try {
// Call the appropriate save function defined in contentAreaUtils.js.
mockFilePickerSettings.destDir = destDir;
mockFilePickerSettings.filterIndex = 1; // kSaveAsType_URL

// register mock file picker object
mockFilePickerRegisterer.register();
try {
// register mock download progress listener
mockTransferForContinuingRegisterer.register();
try {
// Select "Save Video As" option from context menu
var saveVideoCommand = document.getElementById("context-savevideo");
saveVideoCommand.doCommand();

// Unregister the popupshown listener
document.removeEventListener("popupshown",
testRunner.continueTest, false);
// Close the context menu
document.getElementById("placesContext").hidePopup();

// Wait for the download to finish, and exit if it wasn't successful.
var downloadSuccess = yield;
if (!downloadSuccess)
throw "Unexpected failure in downloading Video file!";
}
finally {
// unregister download progress listener
mockTransferForContinuingRegisterer.unregister();
}
}
finally {
// unregister mock file picker object
mockFilePickerRegisterer.unregister();
}

// Read the name of the saved file.
var fileName = mockFilePickerResults.selectedFile.leafName;

is(fileName, "Bug564387-expectedName.ogv",
"Video File Name is correctly retrieved from Content-Disposition http header");
}
finally {
// Clean up the saved file.
destDir.remove(true);
}
}
finally {
// Replace the current tab with a clean one.
gBrowser.addTab().linkedBrowser.stop();
gBrowser.removeCurrentTab();
}
function onTransferComplete(downloadSuccess) {
ok(downloadSuccess, "Video file should have been downloaded successfully");

// Read the name of the saved file.
var fileName = mockFilePickerResults.selectedFile.leafName;

is(fileName, "Bug564387-expectedName.ogv",
"Video file name is correctly retrieved from Content-Disposition http header");

finish();
}
}

// --- Run the test ---
testRunner.runTest(saveVideoAs_TestGenerator);
Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader)
.loadSubScript("chrome://mochitests/content/browser/toolkit/content/tests/browser/common/mockTransfer.js",
this);

Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader)
.loadSubScript("chrome://mochitests/content/browser/toolkit/content/tests/browser/common/mockFilePicker.js",
this);

function createTemporarySaveDirectory() {
var saveDir = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("TmpD", Ci.nsIFile);
saveDir.append("testsavedir");
if (!saveDir.exists())
saveDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0755);
return saveDir;
}

0 comments on commit d2db96d

Please sign in to comment.