Commit b85c0f31 authored by tkent@chromium.org's avatar tkent@chromium.org

Index setters of HTMLSelectElement and HTMLOptionsCollection should do nothing...

Index setters of HTMLSelectElement and HTMLOptionsCollection should do nothing if the requested index is too large.

They should be consistent with their |length| setters.

Also, The index setters and the |length| setters have two behavior
changes as follows:

  * Do not skip processing if an option list has enough size.
    We don't limit an option list length if the options were parsed by the
    HTML parser.  So an option list length can be larger than maxSelectItems.
    There's no reason to skip the processing or shrink the length if
    the list already has enough size.

  * Show console warnings when they do nothing due to the length limitation.

BUG=522802

Review URL: https://codereview.chromium.org/1291263003

git-svn-id: svn://svn.chromium.org/blink/trunk@200893 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent f5815d4f
CONSOLE WARNING: Blocked to expand the option list to 4294967295 items. The maximum list length is 10000.
CONSOLE WARNING: Blocked to expand the option list to 10001 items. The maximum list length is 10000.
1) setting length to a negative length 1) setting length to a negative length
PASS mySelect.options.length is 2 PASS mySelect.options.length is 2
......
CONSOLE WARNING: Blocked to expand the option list to 4294967295 items. The maximum list length is 10000.
CONSOLE WARNING: Blocked to expand the option list to 10001 items. The maximum list length is 10000.
1) setting length to a negative length 1) setting length to a negative length
PASS mySelect.options.length is 2 PASS mySelect.options.length is 2
......
CONSOLE WARNING: Blocked to expand the option list to 20000 items. The maximum list length is 10000.
CONSOLE WARNING: Blocked to expand the option list and set an option at index=20000. The maximum list length is 10000.
CONSOLE WARNING: Blocked to expand the option list and set an option at index=20000. The maximum list length is 10000.
This test that setting HTMLSelectElement.length is capped to 10,000, but that you can add additional Option elements by calling add. This test that setting HTMLSelectElement.length is capped to 10,000, but that you can add additional Option elements by calling add.
Select length is 0 PASS sel.length is 0
Trying: - sel.length = 20000; Trying: - sel.length = 20000;
Select length is 0 PASS sel.length is 0
Trying: - sel.add(new Option, 0); Trying: - sel.add(new Option, 0);
Select length is 1 PASS sel.length is 1
Trying: - sel.length = 0; Trying: - sel.length = 0;
Select length is 0 PASS sel.length is 0
Index setter:
PASS sel[20000] = new Option(); sel.length is 0
PASS sel.options[20000] = new Option(); sel.length is 0
PASS successfullyParsed is true
TEST COMPLETE
<p>This test that setting HTMLSelectElement.length is capped to 10,000, but that you can add additional Option elements by calling add.</p> <p>This test that setting HTMLSelectElement.length is capped to 10,000, but that you can add additional Option elements by calling add.</p>
<pre id="console"></pre> <div id="console"></div>
<select id="theSelect"></select> <select id="theSelect"></select>
<script src="../../resources/js-test.js"></script>
<script> <script>
if (window.testRunner)
testRunner.dumpAsText();
function log(msg)
{
document.getElementById("console").appendChild(document.createTextNode(msg + "\n"));
}
var sel = document.getElementById('theSelect'); var sel = document.getElementById('theSelect');
log("Select length is " + sel.length); shouldBe('sel.length', '0');
log("Trying: - sel.length = 20000;"); debug('Trying: - sel.length = 20000;');
sel.length = 20000; sel.length = 20000;
log("Select length is " + sel.length); shouldBe('sel.length', '0');
log("Trying: - sel.add(new Option, 0);"); debug('Trying: - sel.add(new Option, 0);');
sel.add(new Option, 0); sel.add(new Option, 0);
log("Select length is " + sel.length); shouldBe('sel.length', '1');
log("Trying: - sel.length = 0;"); debug('Trying: - sel.length = 0;');
sel.length = 0; sel.length = 0;
log("Select length is " + sel.length); shouldBe('sel.length', '0');
debug('Index setter:');
shouldBe('sel[20000] = new Option(); sel.length', '0');
shouldBe('sel.options[20000] = new Option(); sel.length', '0');
</script> </script>
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include "core/html/HTMLOptionElement.h" #include "core/html/HTMLOptionElement.h"
#include "core/html/forms/FormController.h" #include "core/html/forms/FormController.h"
#include "core/input/EventHandler.h" #include "core/input/EventHandler.h"
#include "core/inspector/ConsoleMessage.h"
#include "core/layout/HitTestRequest.h" #include "core/layout/HitTestRequest.h"
#include "core/layout/HitTestResult.h" #include "core/layout/HitTestResult.h"
#include "core/layout/LayoutListBox.h" #include "core/layout/LayoutListBox.h"
...@@ -467,8 +468,11 @@ HTMLOptionElement* HTMLSelectElement::item(unsigned index) ...@@ -467,8 +468,11 @@ HTMLOptionElement* HTMLSelectElement::item(unsigned index)
void HTMLSelectElement::setOption(unsigned index, HTMLOptionElement* option, ExceptionState& exceptionState) void HTMLSelectElement::setOption(unsigned index, HTMLOptionElement* option, ExceptionState& exceptionState)
{ {
if (index > maxSelectItems - 1) if (index >= length() && index >= maxSelectItems) {
index = maxSelectItems - 1; document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel,
String::format("Blocked to expand the option list and set an option at index=%u. The maximum list length is %u.", index, maxSelectItems)));
return;
}
int diff = index - length(); int diff = index - length();
HTMLOptionElementOrHTMLOptGroupElement element; HTMLOptionElementOrHTMLOptGroupElement element;
element.setHTMLOptionElement(option); element.setHTMLOptionElement(option);
...@@ -491,8 +495,11 @@ void HTMLSelectElement::setOption(unsigned index, HTMLOptionElement* option, Exc ...@@ -491,8 +495,11 @@ void HTMLSelectElement::setOption(unsigned index, HTMLOptionElement* option, Exc
void HTMLSelectElement::setLength(unsigned newLen, ExceptionState& exceptionState) void HTMLSelectElement::setLength(unsigned newLen, ExceptionState& exceptionState)
{ {
if (newLen > maxSelectItems) if (newLen > length() && newLen > maxSelectItems) {
document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel,
String::format("Blocked to expand the option list to %u items. The maximum list length is %u.", newLen, maxSelectItems)));
return; return;
}
int diff = length() - newLen; int diff = length() - newLen;
if (diff < 0) { // Add dummy elements. if (diff < 0) { // Add dummy elements.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment