|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 var MockFilePicker = SpecialPowers.MockFilePicker; |
|
5 MockFilePicker.init(window); |
|
6 |
|
7 /** |
|
8 * TestCase for bug 564387 |
|
9 * <https://bugzilla.mozilla.org/show_bug.cgi?id=564387> |
|
10 */ |
|
11 function test() { |
|
12 waitForExplicitFinish(); |
|
13 var fileName; |
|
14 |
|
15 gBrowser.loadURI("http://mochi.test:8888/browser/browser/base/content/test/general/bug564387.html"); |
|
16 |
|
17 gBrowser.addEventListener("pageshow", function pageShown(event) { |
|
18 if (event.target.location == "about:blank") |
|
19 return; |
|
20 gBrowser.removeEventListener("pageshow", pageShown); |
|
21 |
|
22 executeSoon(function () { |
|
23 document.addEventListener("popupshown", contextMenuOpened); |
|
24 |
|
25 var video1 = gBrowser.contentDocument.getElementById("video1"); |
|
26 EventUtils.synthesizeMouseAtCenter(video1, |
|
27 { type: "contextmenu", button: 2 }, |
|
28 gBrowser.contentWindow); |
|
29 }); |
|
30 }); |
|
31 |
|
32 function contextMenuOpened(event) { |
|
33 event.currentTarget.removeEventListener("popupshown", contextMenuOpened); |
|
34 |
|
35 // Create the folder the video will be saved into. |
|
36 var destDir = createTemporarySaveDirectory(); |
|
37 var destFile = destDir.clone(); |
|
38 |
|
39 MockFilePicker.displayDirectory = destDir; |
|
40 MockFilePicker.showCallback = function(fp) { |
|
41 fileName = fp.defaultString; |
|
42 destFile.append (fileName); |
|
43 MockFilePicker.returnFiles = [destFile]; |
|
44 MockFilePicker.filterIndex = 1; // kSaveAsType_URL |
|
45 }; |
|
46 |
|
47 mockTransferCallback = onTransferComplete; |
|
48 mockTransferRegisterer.register(); |
|
49 |
|
50 registerCleanupFunction(function () { |
|
51 mockTransferRegisterer.unregister(); |
|
52 MockFilePicker.cleanup(); |
|
53 destDir.remove(true); |
|
54 }); |
|
55 |
|
56 // Select "Save Video As" option from context menu |
|
57 var saveVideoCommand = document.getElementById("context-savevideo"); |
|
58 saveVideoCommand.doCommand(); |
|
59 |
|
60 event.target.hidePopup(); |
|
61 } |
|
62 |
|
63 function onTransferComplete(downloadSuccess) { |
|
64 ok(downloadSuccess, "Video file should have been downloaded successfully"); |
|
65 |
|
66 is(fileName, "Bug564387-expectedName.ogv", |
|
67 "Video file name is correctly retrieved from Content-Disposition http header"); |
|
68 |
|
69 finish(); |
|
70 } |
|
71 } |
|
72 |
|
73 Cc["@mozilla.org/moz/jssubscript-loader;1"] |
|
74 .getService(Ci.mozIJSSubScriptLoader) |
|
75 .loadSubScript("chrome://mochitests/content/browser/toolkit/content/tests/browser/common/mockTransfer.js", |
|
76 this); |
|
77 |
|
78 function createTemporarySaveDirectory() { |
|
79 var saveDir = Cc["@mozilla.org/file/directory_service;1"] |
|
80 .getService(Ci.nsIProperties) |
|
81 .get("TmpD", Ci.nsIFile); |
|
82 saveDir.append("testsavedir"); |
|
83 if (!saveDir.exists()) |
|
84 saveDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0755); |
|
85 return saveDir; |
|
86 } |