Bug 496832 - Disable media entries in context menu when media source is invalid. r=gavin.sharp

This commit is contained in:
Justin Dolske 2009-07-09 18:26:35 -07:00
Родитель dac487a917
Коммит e661da9b22
5 изменённых файлов: 175 добавлений и 104 удалений

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

@ -180,10 +180,14 @@ nsContextMenu.prototype = {
this.showItem("context-saveimage", this.onLoadedImage || this.onCanvas); this.showItem("context-saveimage", this.onLoadedImage || this.onCanvas);
this.showItem("context-savevideo", this.onVideo); this.showItem("context-savevideo", this.onVideo);
this.showItem("context-saveaudio", this.onAudio); this.showItem("context-saveaudio", this.onAudio);
this.setItemAttr("context-savevideo", "disabled", !this.mediaURL);
this.setItemAttr("context-saveaudio", "disabled", !this.mediaURL);
// Send media URL (but not for canvas, since it's a big data: URL) // Send media URL (but not for canvas, since it's a big data: URL)
this.showItem("context-sendimage", this.onImage); this.showItem("context-sendimage", this.onImage);
this.showItem("context-sendvideo", this.onVideo); this.showItem("context-sendvideo", this.onVideo);
this.showItem("context-sendaudio", this.onAudio); this.showItem("context-sendaudio", this.onAudio);
this.setItemAttr("context-sendvideo", "disabled", !this.mediaURL);
this.setItemAttr("context-sendaudio", "disabled", !this.mediaURL);
}, },
initViewItems: function CM_initViewItems() { initViewItems: function CM_initViewItems() {
@ -231,6 +235,7 @@ nsContextMenu.prototype = {
(!this.onStandaloneImage || this.inFrame)) || this.onCanvas); (!this.onStandaloneImage || this.inFrame)) || this.onCanvas);
this.showItem("context-viewvideo", this.onVideo); this.showItem("context-viewvideo", this.onVideo);
this.setItemAttr("context-viewvideo", "disabled", !this.mediaURL);
// View background image depends on whether there is one. // View background image depends on whether there is one.
this.showItem("context-viewbgimage", shouldShow); this.showItem("context-viewbgimage", shouldShow);
@ -380,6 +385,8 @@ nsContextMenu.prototype = {
this.showItem("context-copyimage", this.onImage); this.showItem("context-copyimage", this.onImage);
this.showItem("context-copyvideourl", this.onVideo); this.showItem("context-copyvideourl", this.onVideo);
this.showItem("context-copyaudiourl", this.onAudio); this.showItem("context-copyaudiourl", this.onAudio);
this.setItemAttr("context-copyvideourl", "disabled", !this.mediaURL);
this.setItemAttr("context-copyaudiourl", "disabled", !this.mediaURL);
this.showItem("context-sep-copyimage", this.onImage || this.showItem("context-sep-copyimage", this.onImage ||
this.onVideo || this.onAudio); this.onVideo || this.onAudio);
}, },
@ -398,6 +405,16 @@ nsContextMenu.prototype = {
this.showItem("context-media-unmute", onMedia && this.target.muted); this.showItem("context-media-unmute", onMedia && this.target.muted);
this.showItem("context-media-showcontrols", onMedia && !this.target.controls) this.showItem("context-media-showcontrols", onMedia && !this.target.controls)
this.showItem("context-media-hidecontrols", onMedia && this.target.controls) this.showItem("context-media-hidecontrols", onMedia && this.target.controls)
// Disable them when there isn't a valid media source loaded.
if (onMedia) {
var hasError = (this.target.error != null);
this.setItemAttr("context-media-play", "disabled", hasError);
this.setItemAttr("context-media-pause", "disabled", hasError);
this.setItemAttr("context-media-mute", "disabled", hasError);
this.setItemAttr("context-media-unmute", "disabled", hasError);
this.setItemAttr("context-media-showcontrols", "disabled", hasError);
this.setItemAttr("context-media-hidecontrols", "disabled", hasError);
}
this.showItem("context-media-sep-commands", onMedia); this.showItem("context-media-sep-commands", onMedia);
}, },
@ -468,11 +485,11 @@ nsContextMenu.prototype = {
} }
else if (this.target instanceof HTMLVideoElement) { else if (this.target instanceof HTMLVideoElement) {
this.onVideo = true; this.onVideo = true;
this.mediaURL = this.target.currentSrc; this.mediaURL = this.target.currentSrc || this.target.src;
} }
else if (this.target instanceof HTMLAudioElement) { else if (this.target instanceof HTMLAudioElement) {
this.onAudio = true; this.onAudio = true;
this.mediaURL = this.target.currentSrc; this.mediaURL = this.target.currentSrc || this.target.src;
} }
else if (this.target instanceof HTMLInputElement ) { else if (this.target instanceof HTMLInputElement ) {
this.onTextInput = this.isTargetATextBox(this.target); this.onTextInput = this.isTargetATextBox(this.target);

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

@ -51,6 +51,7 @@ _TEST_FILES = \
test_contextmenu.html \ test_contextmenu.html \
subtst_contextmenu.html \ subtst_contextmenu.html \
ctxmenu-image.png \ ctxmenu-image.png \
video.ogg \
test_offlineNotification.html \ test_offlineNotification.html \
offlineChild.html \ offlineChild.html \
offlineChild.cacheManifest \ offlineChild.cacheManifest \

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

@ -12,7 +12,11 @@ Browser context menu subtest.
<input id="test-input"><br> <input id="test-input"><br>
<img id="test-image" src="ctxmenu-image.png"> <img id="test-image" src="ctxmenu-image.png">
<canvas id="test-canvas" width="100" height="100" style="background-color: blue"></canvas> <canvas id="test-canvas" width="100" height="100" style="background-color: blue"></canvas>
<video id="test-video" width="100" height="100" style="background-color: orange"></video> <video id="test-video-ok" src="video.ogg" width="100" height="100" style="background-color: green"></video>
<video id="test-video-bad" src="bogus.duh" width="100" height="100" style="background-color: orange"></video>
<video id="test-video-bad2" width="100" height="100" style="background-color: yellow">
<source src="bogus.duh" type="video/durrrr;">
</video>
<iframe id="test-iframe" width="98" height="98" style="border: 1px solid black"></iframe> <iframe id="test-iframe" width="98" height="98" style="border: 1px solid black"></iframe>
</body> </body>

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

@ -76,9 +76,11 @@ function getVisibleMenuItems(aMenu) {
else else
accessKeys[key] = item.id accessKeys[key] = item.id
items.push(item.id); items.push(item.id);
items.push(!item.disabled);
} else if (item.nodeName == "menuseparator") { } else if (item.nodeName == "menuseparator") {
ok(true, "--- seperator id is " + item.id); ok(true, "--- seperator id is " + item.id);
items.push("---"); items.push("---");
items.push(null);
} else if (item.nodeName == "menu") { } else if (item.nodeName == "menu") {
ok(item.id, "child menu #" + i + " has an ID"); ok(item.id, "child menu #" + i + " has an ID");
ok(key, "menu has an access key"); ok(key, "menu has an access key");
@ -87,9 +89,11 @@ function getVisibleMenuItems(aMenu) {
else else
accessKeys[key] = item.id accessKeys[key] = item.id
items.push(item.id); items.push(item.id);
items.push(!item.disabled);
// Add a dummy item to that the indexes in checkMenu are the same // Add a dummy item to that the indexes in checkMenu are the same
// for expectedItems and actualItems. // for expectedItems and actualItems.
items.push([]); items.push([]);
items.push(null);
} else { } else {
ok(false, "child #" + i + " of menu ID " + aMenu.id + ok(false, "child #" + i + " of menu ID " + aMenu.id +
" has an unknown type (" + item.nodeName + ")"); " has an unknown type (" + item.nodeName + ")");
@ -105,24 +109,37 @@ function checkContextMenu(expectedItems) {
/* /*
* checkMenu - checks to see if the specified <menupopup> contains the * checkMenu - checks to see if the specified <menupopup> contains the
* expected items, as specified by an array of element IDs. To check the * expected items and state.
* contents of a submenu, include a nested array after the expected <menu> ID. * expectedItems is a array of (1) item IDs and (2) a boolean specifying if
* For example: ["foo, "submenu", ["sub1", "sub2"], "bar"] * the item is enabled or not (or null to ignore it). Submenus can be checked
* by providing a nested array entry after the expected <menu> ID.
* For example: ["blah", true, // item enabled
* "submenu", null, // submenu
* ["sub1", true, // submenu contents
* "sub2", false], null, // submenu contents
* "lol", false] // item disabled
* *
*/ */
function checkMenu(menu, expectedItems) { function checkMenu(menu, expectedItems) {
var actualItems = getVisibleMenuItems(menu); var actualItems = getVisibleMenuItems(menu);
//ok(false, "Items are: " + actualItems); //ok(false, "Items are: " + actualItems);
for (var i = 0; i < expectedItems.length; i++) { for (var i = 0; i < expectedItems.length; i+=2) {
if (expectedItems[i] instanceof Array) { var actualItem = actualItems[i];
var actualEnabled = actualItems[i + 1];
var expectedItem = expectedItems[i];
var expectedEnabled = expectedItems[i + 1];
if (expectedItem instanceof Array) {
ok(true, "Checking submenu..."); ok(true, "Checking submenu...");
var menuID = expectedItems[i - 1]; // The last item was the menu ID. var menuID = expectedItems[i - 2]; // The last item was the menu ID.
var submenu = menu.getElementsByAttribute("id", menuID)[0]; var submenu = menu.getElementsByAttribute("id", menuID)[0];
ok(submenu && submenu.nodeName == "menu", "got expected submenu element"); ok(submenu && submenu.nodeName == "menu", "got expected submenu element");
checkMenu(submenu.menupopup, expectedItems[i]); checkMenu(submenu.menupopup, expectedItem);
} else { } else {
is(actualItems[i], expectedItems[i], is(actualItem, expectedItem,
"checking item #" + i + " (" + expectedItems[i] + ")"); "checking item #" + i/2 + " (" + expectedItem + ") name");
if (expectedEnabled != null)
is(actualEnabled, expectedEnabled,
"checking item #" + i/2 + " (" + expectedItem + ") enabled state");
} }
} }
// Could find unexpected extra items at the end... // Could find unexpected extra items at the end...
@ -150,136 +167,166 @@ function runTest(testNum) {
case 2: case 2:
// Context menu for plain text // Context menu for plain text
checkContextMenu(["context-back", checkContextMenu(["context-back", false,
"context-forward", "context-forward", false,
"context-reload", "context-reload", true,
"context-stop", "context-stop", false,
"---", "---", null,
"context-bookmarkpage", "context-bookmarkpage", true,
"context-savepage", "context-savepage", true,
"context-sendpage", "context-sendpage", true,
"---", "---", null,
"context-viewbgimage", "context-viewbgimage", false,
"context-selectall", "context-selectall", true,
"---", "---", null,
"context-viewsource", "context-viewsource", true,
"context-viewinfo"]); "context-viewinfo", true]);
closeContextMenu() closeContextMenu()
openContextMenuFor(link); // Invoke context menu for next test. openContextMenuFor(link); // Invoke context menu for next test.
break; break;
case 3: case 3:
// Context menu for text link // Context menu for text link
checkContextMenu(["context-openlink", checkContextMenu(["context-openlink", true,
"context-openlinkintab", "context-openlinkintab", true,
"---", "---", null,
"context-bookmarklink", "context-bookmarklink", true,
"context-savelink", "context-savelink", true,
"context-sendlink", "context-sendlink", true,
"context-copylink", "context-copylink", true,
"---", "---", null,
"context-metadata"]); "context-metadata", true]);
closeContextMenu() closeContextMenu()
openContextMenuFor(mailto); // Invoke context menu for next test. openContextMenuFor(mailto); // Invoke context menu for next test.
break; break;
case 4: case 4:
// Context menu for text mailto-link // Context menu for text mailto-link
checkContextMenu(["context-copyemail", checkContextMenu(["context-copyemail", true,
"---", "---", null,
"context-metadata"]); "context-metadata", true]);
closeContextMenu() closeContextMenu()
openContextMenuFor(input); // Invoke context menu for next test. openContextMenuFor(input); // Invoke context menu for next test.
break; break;
case 5: case 5:
// Context menu for text input field // Context menu for text input field
checkContextMenu(["context-undo", checkContextMenu(["context-undo", false,
"---", "---", null,
"context-cut", "context-cut", false,
"context-copy", "context-copy", false,
"context-paste", "context-paste", null, // ignore clipboard state
"context-delete", "context-delete", false,
"---", "---", null,
"context-selectall", "context-selectall", true,
"---", "---", null,
"spell-check-enabled"]); "spell-check-enabled", true]);
closeContextMenu() closeContextMenu()
openContextMenuFor(img); // Invoke context menu for next test. openContextMenuFor(img); // Invoke context menu for next test.
break; break;
case 6: case 6:
// Context menu for an image // Context menu for an image
checkContextMenu(["context-viewimage", checkContextMenu(["context-viewimage", true,
"context-copyimage-contents", "context-copyimage-contents", true,
"context-copyimage", "context-copyimage", true,
"---", "---", null,
"context-saveimage", "context-saveimage", true,
"context-sendimage", "context-sendimage", true,
"context-setDesktopBackground", "context-setDesktopBackground", true,
"context-blockimage", "context-blockimage", true,
"---", "---", null,
"context-metadata"]); "context-metadata", true]);
closeContextMenu(); closeContextMenu();
openContextMenuFor(canvas); // Invoke context menu for next test. openContextMenuFor(canvas); // Invoke context menu for next test.
break; break;
case 7: case 7:
// Context menu for a canvas // Context menu for a canvas
checkContextMenu(["context-viewimage", checkContextMenu(["context-viewimage", true,
"context-saveimage", "context-saveimage", true,
"context-bookmarkpage", "context-bookmarkpage", true,
"context-selectall"]); "context-selectall", true]);
closeContextMenu(); closeContextMenu();
openContextMenuFor(video); // Invoke context menu for next test. openContextMenuFor(video_ok); // Invoke context menu for next test.
break; break;
case 8: case 8:
// Context menu for a video // Context menu for a video (with a VALID media source)
checkContextMenu(["context-media-play", checkContextMenu(["context-media-play", true,
"context-media-mute", "context-media-mute", true,
"context-media-showcontrols", "context-media-showcontrols", true,
"---", "---", null,
"context-viewvideo", "context-viewvideo", true,
"context-copyvideourl", "context-copyvideourl", true,
"---", "---", null,
"context-savevideo", "context-savevideo", true,
"context-sendvideo"]); "context-sendvideo", true]);
closeContextMenu();
openContextMenuFor(video_bad); // Invoke context menu for next test.
break;
case 9:
// Context menu for a video (with a INVALID media source)
checkContextMenu(["context-media-play", false,
"context-media-mute", false,
"context-media-showcontrols", false,
"---", null,
"context-viewvideo", true,
"context-copyvideourl", true,
"---", null,
"context-savevideo", true,
"context-sendvideo", true]);
closeContextMenu();
openContextMenuFor(video_bad2); // Invoke context menu for next test.
break;
case 10:
// Context menu for a video (with a INVALID media source)
checkContextMenu(["context-media-play", false,
"context-media-mute", false,
"context-media-showcontrols", false,
"---", null,
"context-viewvideo", false,
"context-copyvideourl", false,
"---", null,
"context-savevideo", false,
"context-sendvideo", false]);
closeContextMenu(); closeContextMenu();
openContextMenuFor(iframe); // Invoke context menu for next test. openContextMenuFor(iframe); // Invoke context menu for next test.
break; break;
case 9: case 11:
// Context menu for an iframe // Context menu for an iframe
checkContextMenu(["context-back", checkContextMenu(["context-back", false,
"context-forward", "context-forward", false,
"context-reload", "context-reload", true,
"context-stop", "context-stop", false,
"---", "---", null,
"context-bookmarkpage", "context-bookmarkpage", true,
"context-savepage", "context-savepage", true,
"context-sendpage", "context-sendpage", true,
"---", "---", null,
"context-viewbgimage", "context-viewbgimage", false,
"context-selectall", "context-selectall", true,
"---", "---", null,
"frame", "frame", null,
["context-showonlythisframe", ["context-showonlythisframe", true,
"context-openframe", "context-openframe", true,
"context-openframeintab", "context-openframeintab", true,
"---", "---", null,
"context-reloadframe", "context-reloadframe", true,
"---", "---", null,
"context-bookmarkframe", "context-bookmarkframe", true,
"context-saveframe", "context-saveframe", true,
"---", "---", null,
"context-printframe", "context-printframe", true,
"---", "---", null,
"context-viewframesource", "context-viewframesource", true,
"context-viewframeinfo"], "context-viewframeinfo", true], null,
"---", "---", null,
"context-viewsource", "context-viewsource", true,
"context-viewinfo"]); "context-viewinfo", true]);
closeContextMenu(); closeContextMenu();
subwindow.close(); subwindow.close();
@ -327,7 +374,9 @@ function startTest() {
input = subwindow.document.getElementById("test-input"); input = subwindow.document.getElementById("test-input");
img = subwindow.document.getElementById("test-image"); img = subwindow.document.getElementById("test-image");
canvas = subwindow.document.getElementById("test-canvas"); canvas = subwindow.document.getElementById("test-canvas");
video = subwindow.document.getElementById("test-video"); video_ok = subwindow.document.getElementById("test-video-ok");
video_bad = subwindow.document.getElementById("test-video-bad");
video_bad2 = subwindow.document.getElementById("test-video-bad2");
iframe = subwindow.document.getElementById("test-iframe"); iframe = subwindow.document.getElementById("test-iframe");
contextMenu.addEventListener("popupshown", function() { runTest(++testNum); }, false); contextMenu.addEventListener("popupshown", function() { runTest(++testNum); }, false);

Двоичные данные
browser/base/content/test/video.ogg Normal file

Двоичный файл не отображается.