Last Comment Bug 456798 - queryCommandSupported throws errors in Firefox 3.0.1
: queryCommandSupported throws errors in Firefox 3.0.1
Status: RESOLVED FIXED
: dev-doc-complete
Product: Core
Classification: Components
Component: Editor (show other bugs)
: unspecified
: All All
: -- enhancement (vote)
: mozilla9
Assigned To: Fabien Cazenave [:kaze]
:
: Makoto Kato [:m_kato]
Mentors:
Depends on:
Blocks: 424615
  Show dependency treegraph
 
Reported: 2008-09-24 10:41 PDT by linda167
Modified: 2011-11-10 06:55 PST (History)
6 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Testcase (3.43 KB, text/html)
2008-09-24 15:30 PDT, Chris Pearce (:cpearce)
no flags Details
patch proposal (195.09 KB, patch)
2011-08-16 06:09 PDT, Fabien Cazenave [:kaze]
no flags Details | Diff | Splinter Review
patch proposal (195.88 KB, patch)
2011-08-16 10:47 PDT, Fabien Cazenave [:kaze]
ehsan: review+
Details | Diff | Splinter Review

Description linda167 2008-09-24 10:41:11 PDT
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1
Build Identifier: Mozilla/5.0, Firefox 3.0.1, OS: Mac OS X 10.5 and Windows NT 5.2

queryCommandSupported(sCmd) throws errors on all commands in Firefox. This method works fine in IE7 and Safari 3.1.2.

I have not found a command that it will not throw an error on. Here's the list of commands that I've tested:

Bold
Italic
Underline
Strikethrough
JustifyLeft
JustifyCenter
JustifyRight
InsertUnorderedList
InsertOrderedList
Outdent
Indent
ForeColor
RemoveFormat
InsertHorizaontalRule
Undo
Redo
CreateLink
Unlink
Superscript
Subscript

Reproducible: Always

Steps to Reproduce:
1. Call queryCommandSupported(sCmd) on any command supported by Mozilla's execCommand


Actual Results:  
Error

Expected Results:  
No error

Function should return true or false.
Comment 1 Chris Pearce (:cpearce) 2008-09-24 15:27:27 PDT
queryCommandSupported() isn't implemented yet, it's throwing an NS_ERROR_NOT_IMPLEMENTED exception.
Comment 2 Chris Pearce (:cpearce) 2008-09-24 15:30:15 PDT
Created attachment 340231 [details]
Testcase

This enumerates return values/exceptions thrown in queryCommandSupported(). Based on similar testcase from bug 408231.
Comment 3 Christopher Blum 2011-01-17 09:37:02 PST
Reproducible for me (with Firefox 3.6 and Firefox 4b7).
Every other browser I tested (Safari, Chrome, Opera, IE6-9) supports it correctly.

Is there any known workaround to see whether a certain command is supported?
Comment 4 Fabien Cazenave [:kaze] 2011-08-13 06:13:39 PDT
Bug confirmed with the latest trunk, `queryCommandSupported' is not implemented.

As Firefox raises an NS_ERROR_NOT_IMPLEMENTED exception on `queryCommandEnabled("foo")', an easy workaround would be to use a try…catch around a `queryCommandEnabled' call:

  var enabled, supported;
  try {
    enabled   = document.queryCommandEnabled(sCmd);
    supported = document.queryCommandSupported(sCmd);
  } catch(e) {}

Implementing `queryCommandSupported' would be neat. I’d suggest to fix both behaviors at the same time:
 • document.queryCommandSupported('foo') should return `false';
 • document.queryCommandEnabled('foo') should return `false' without raising any exception — FWIW, that’s what Chromium does.
Comment 5 :Ehsan Akhgari 2011-08-15 08:46:00 PDT
(In reply to Fabien Cazenave (:kazé) from comment #4)
> Implementing `queryCommandSupported' would be neat. I’d suggest to fix both
> behaviors at the same time:
>  • document.queryCommandSupported('foo') should return `false';
>  • document.queryCommandEnabled('foo') should return `false' without raising
> any exception — FWIW, that’s what Chromium does.

Please!  :-)
Comment 6 Fabien Cazenave [:kaze] 2011-08-16 06:09:40 PDT
Created attachment 553448 [details] [diff] [review]
patch proposal

Rationale: a command is supported if it can be converted to an internal Midas
command.

This gives us +43 points on the Browserscope tests (+3.3%) — we’re reaching 50%! OK, that’s still far from Chrome’s 80% and Safari’s 66%…

The browserscope status (currentStatus.js) has been updated accordingly. I don’t think we need more tests for this patch but I can write some if you wish.
Comment 7 Fabien Cazenave [:kaze] 2011-08-16 10:40:20 PDT
Finally got the TryServer results. I’m afraid I have to submit another patch:

56355 ERROR TEST-UNEXPECTED-FAIL | /tests/content/html/content/test/test_bug408231.html | queryCommandEnabled(not-a-command) result=false expected=exception

Working on it. :-/
Comment 8 Fabien Cazenave [:kaze] 2011-08-16 10:47:38 PDT
Created attachment 553525 [details] [diff] [review]
patch proposal

fixes content/html/content/test/test_bug408231.html so that `document.queryCommandSupported("not-a-command")' is expected to return `false' instead of raising an exception.
Comment 9 :Ehsan Akhgari 2011-08-17 05:02:38 PDT
Comment on attachment 553525 [details] [diff] [review]
patch proposal

Looks great, thanks!
Comment 10 :Ehsan Akhgari 2011-08-17 05:04:38 PDT
Pushed to inbound.
Comment 11 Marco Bonardo [::mak] 2011-08-18 03:44:17 PDT
http://hg.mozilla.org/mozilla-central/rev/be37d0418129
Comment 12 Eric Shepherd [:sheppy] 2011-11-10 06:55:15 PST
Documented, other than needing an example. If someone would like to add one, that would be fantastic:

https://developer.mozilla.org/en/DOM/document.queryCommandSupported

Mentioned on Firefox 9 for developers.

Note You need to log in before you can comment on or make changes to this bug.