Bug 90976

Summary: If value for responseType defined as type that not supported, it should not throw an exception in XHR 2
Product: WebKit Reporter: Oleg <markelog>
Component: WebKit Misc.Assignee: Kinuko Yasuda <kinuko>
Status: RESOLVED FIXED    
Severity: Normal CC: ap, cmarrin, crogers, dglazkov, jarred, kinuko, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Archive of layout-test-results from gce-cr-linux-05
none
Patch
none
Patch
none
Archive of layout-test-results from gce-cr-linux-05
none
Patch
ap: review+
Patch for submit none

Description Oleg 2012-07-11 05:50:04 PDT
If responseType="bla" (or "json" for that matter) it will throw an exception "SYNTAX_ERR: DOM Exception 12".
This exception is not defined by spec and no other browser is throwing it on value it did not recognize.
Comment 1 Kinuko Yasuda 2012-07-17 06:45:45 PDT
Created attachment 152753 [details]
Patch
Comment 2 Jarred Nicholls 2012-07-17 06:55:25 PDT
Comment on attachment 152753 [details]
Patch

I recommend using the test harness code instead of manually doing dumpAsText() and log()'s.
Comment 3 Kinuko Yasuda 2012-07-17 07:15:05 PDT
(In reply to comment #2)
> (From update of attachment 152753 [details])
> I recommend using the test harness code instead of manually doing dumpAsText() and log()'s.

Thanks for your comment.  I'll update the patch assuming you meant using the test utility methods like the ones defined in fast/js/resources/js-test-pre.js.
Comment 4 Kinuko Yasuda 2012-07-17 07:17:20 PDT
Created attachment 152758 [details]
Patch
Comment 5 Jarred Nicholls 2012-07-17 07:26:55 PDT
Comment on attachment 152758 [details]
Patch

LGTM
Comment 6 WebKit Review Bot 2012-07-17 09:52:49 PDT
Comment on attachment 152758 [details]
Patch

Attachment 152758 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/13272177

New failing tests:
fast/xmlhttprequest/xmlhttprequest-responsetype-arraybuffer.html
Comment 7 WebKit Review Bot 2012-07-17 09:52:52 PDT
Created attachment 152773 [details]
Archive of layout-test-results from gce-cr-linux-05

The attached test failures were seen while running run-webkit-tests on the chromium-ews.
Bot: gce-cr-linux-05  Port: <class 'webkitpy.common.config.ports.ChromiumXVFBPort'>  Platform: Linux-2.6.39-gcg-201203291735-x86_64-with-Ubuntu-10.04-lucid
Comment 8 Kinuko Yasuda 2012-07-18 02:37:43 PDT
Created attachment 152971 [details]
Patch
Comment 9 Alexey Proskuryakov 2012-07-18 15:14:41 PDT
Comment on attachment 152971 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=152971&action=review

> Source/WebCore/ChangeLog:9
> +        The spec doesn't say it should throw an exception when a non-supported type is set, or other browsers does not throw it either.

s/ or / and /
s/ does / do /

> Source/WebCore/xml/XMLHttpRequest.cpp:347
> +    // http://www.w3.org/TR/XMLHttpRequest2/#the-responsetype-attribute
> +    // An attempt to set an invalid type is silently discarded (does not change the value).

Please remove this comment. It just re-states what the code below does, and gives a link to a spec anyone working on this code knows about.

> Source/WebCore/xml/XMLHttpRequest.cpp:-357
> -    else
> -        ec = SYNTAX_ERR;

I think that we should log to Inspector when an unsupported type is used. It's something that is going to break sites, and would be incredibly hard to debug without an exception or any diagnostic logging.

> LayoutTests/fast/xmlhttprequest/xmlhttprequest-responsetype-set-types-expected.txt:5
> +PASS No exception.

This is not the best way to write a test. Ideally, the output would be self-explanatory - it's hard to correlate output lines with subtests here.

In this particular case, you can consider two approaches:
1. Use shouldNotThrow() function provided by js-test-pre.js;
2. Put preparation code inside shouldBe, like shouldBe("xhr.responseType = 'text'; xhr.responseType", "'text'");

> LayoutTests/fast/xmlhttprequest/xmlhttprequest-responsetype-set-types.html:9
> +function setResponseType(type, expected)

This function doesn't just set the response type, so the name is misleading.

> LayoutTests/fast/xmlhttprequest/xmlhttprequest-responsetype-set-types.html:27
> +setResponseType('arraybuffer', 'arraybuffer');
> +setResponseType('blob', 'blob');

Aren't these under ifdefs? We'll need platform specific results because of these sub-tests, and they don't really check anything changed in this patch.
Comment 10 Kinuko Yasuda 2012-07-19 05:41:07 PDT
Created attachment 153236 [details]
Patch
Comment 11 Kinuko Yasuda 2012-07-19 06:01:42 PDT
Comment on attachment 152971 [details]
Patch

Thanks for reviewing,

View in context: https://bugs.webkit.org/attachment.cgi?id=152971&action=review

>> Source/WebCore/ChangeLog:9
>> +        The spec doesn't say it should throw an exception when a non-supported type is set, or other browsers does not throw it either.
> 
> s/ or / and /
> s/ does / do /

Done.

>> Source/WebCore/xml/XMLHttpRequest.cpp:347
>> +    // An attempt to set an invalid type is silently discarded (does not change the value).
> 
> Please remove this comment. It just re-states what the code below does, and gives a link to a spec anyone working on this code knows about.

Done.

>> Source/WebCore/xml/XMLHttpRequest.cpp:-357
>> -        ec = SYNTAX_ERR;
> 
> I think that we should log to Inspector when an unsupported type is used. It's something that is going to break sites, and would be incredibly hard to debug without an exception or any diagnostic logging.

Good point... added logging.

>> LayoutTests/fast/xmlhttprequest/xmlhttprequest-responsetype-set-types-expected.txt:5
>> +PASS No exception.
> 
> This is not the best way to write a test. Ideally, the output would be self-explanatory - it's hard to correlate output lines with subtests here.
> 
> In this particular case, you can consider two approaches:
> 1. Use shouldNotThrow() function provided by js-test-pre.js;
> 2. Put preparation code inside shouldBe, like shouldBe("xhr.responseType = 'text'; xhr.responseType", "'text'");

Makes sense, updated the code.  I added two subtests using each approach, to make it clearer what we are testing.

>> LayoutTests/fast/xmlhttprequest/xmlhttprequest-responsetype-set-types.html:9
>> +function setResponseType(type, expected)
> 
> This function doesn't just set the response type, so the name is misleading.

I've removed this function.

>> LayoutTests/fast/xmlhttprequest/xmlhttprequest-responsetype-set-types.html:27
>> +setResponseType('blob', 'blob');
> 
> Aren't these under ifdefs? We'll need platform specific results because of these sub-tests, and they don't really check anything changed in this patch.

They are no longer ifdef'ed. I thought it might be good to have a test for setting responseType but similar tests seem to be included in xmlhttprequest-responsetype-arraybuffer.html.

I removed them and renamed this test to '...-set-invalidtype.html'.
Comment 12 WebKit Review Bot 2012-07-19 06:46:23 PDT
Comment on attachment 153236 [details]
Patch

Attachment 153236 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/13281906

New failing tests:
fast/xmlhttprequest/xmlhttprequest-responsetype-set-invalidtype.html
Comment 13 WebKit Review Bot 2012-07-19 06:46:28 PDT
Created attachment 153248 [details]
Archive of layout-test-results from gce-cr-linux-05

The attached test failures were seen while running run-webkit-tests on the chromium-ews.
Bot: gce-cr-linux-05  Port: <class 'webkitpy.common.config.ports.ChromiumXVFBPort'>  Platform: Linux-2.6.39-gcg-201203291735-x86_64-with-Ubuntu-10.04-lucid
Comment 14 Kinuko Yasuda 2012-07-19 06:58:04 PDT
Created attachment 153253 [details]
Patch
Comment 15 Alexey Proskuryakov 2012-07-19 08:59:12 PDT
Comment on attachment 153253 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=153253&action=review

r=me, but please double check why cross-platform results don't need CONSOLE MESSAGE lines. I think that it's a mistake.

> Source/WebCore/xml/XMLHttpRequest.cpp:357
> +        logConsoleError(scriptExecutionContext(), "\"" + responseType + "\" is not a valid XMLHttpRequest.responseType.");

I would have said "supported", not "valid", because new types can be added to the spec in the future, and lack of support for them in a certain release of a WebKit based browser doesn't make such invalid. But it's not a big deal.

> LayoutTests/ChangeLog:14
> +        * fast/xmlhttprequest/xmlhttprequest-responsetype-arraybuffer.html: Removed a line which tries to set invalid type (since we now have a separate test)
> +        * platform/chromium/fast/xmlhttprequest/xmlhttprequest-responsetype-set-invalidtype-expected.txt: Added (since chromium expectation includes CONSOLE messages).

This surprises me - I think that every port does this. Looking at Mac DumpRenderTree source code, I do see console messages printed.
Comment 16 Kinuko Yasuda 2012-07-19 23:44:17 PDT
(In reply to comment #15)
> (From update of attachment 153253 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=153253&action=review
> 
> r=me, but please double check why cross-platform results don't need CONSOLE MESSAGE lines. I think that it's a mistake.

You're right, resetting the results got the expected CONSOLE message on Mac too.

> > Source/WebCore/xml/XMLHttpRequest.cpp:357
> > +        logConsoleError(scriptExecutionContext(), "\"" + responseType + "\" is not a valid XMLHttpRequest.responseType.");
> 
> I would have said "supported", not "valid", because new types can be added to the spec in the future, and lack of support for them in a certain release of a WebKit based browser doesn't make such invalid. But it's not a big deal.

Will fix the line together with the expectation before submitting.
Comment 17 Kinuko Yasuda 2012-07-19 23:45:25 PDT
Created attachment 153428 [details]
Patch for submit
Comment 18 Kinuko Yasuda 2012-07-20 01:45:52 PDT
Committed r123194: <http://trac.webkit.org/changeset/123194>