浏览代码

LibWeb: Allow progress element value to be set higher than the max value

Previously, we returned from the value setter if the specified value
was above the max value. This is not required, as the getter clamps the
returned value to the max value.
Tim Ledbetter 1 年之前
父节点
当前提交
ecbc686bc8

+ 8 - 0
Tests/LibWeb/Text/expected/HTML/HTMLProgressElement-set-attributes.txt

@@ -0,0 +1,8 @@
+value attribute initial value: 0
+max attribute initial value: 1
+value attribute after setting value attribute to -1: 0
+max attribute after setting max attribute to -1: 1
+value attribute after setting value attribute to 50: 1
+value attribute after setting max attribute to 100: 50
+max attribute after setting max attribute to 100: 100
+value attribute after setting max attribute to 101: 100

+ 20 - 0
Tests/LibWeb/Text/input/HTML/HTMLProgressElement-set-attributes.html

@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<script>
+    test(() => {
+        const progressElement = document.createElement("progress");
+        println(`value attribute initial value: ${progressElement.value}`);
+        println(`max attribute initial value: ${progressElement.max}`);
+        progressElement.value = -1;
+        println(`value attribute after setting value attribute to -1: ${progressElement.value}`);
+        progressElement.max = -1;
+        println(`max attribute after setting max attribute to -1: ${progressElement.max}`);
+        progressElement.value = 50;
+        println(`value attribute after setting value attribute to 50: ${progressElement.value}`);
+        progressElement.max = 100;
+        println(`value attribute after setting max attribute to 100: ${progressElement.value}`);
+        println(`max attribute after setting max attribute to 100: ${progressElement.max}`);
+        progressElement.value = 101;
+        println(`value attribute after setting max attribute to 101: ${progressElement.value}`);
+    });
+</script>

+ 1 - 1
Userland/Libraries/LibWeb/HTML/HTMLProgressElement.cpp

@@ -48,7 +48,7 @@ double HTMLProgressElement::value() const
 
 WebIDL::ExceptionOr<void> HTMLProgressElement::set_value(double value)
 {
-    if (value < 0 || value > max())
+    if (value < 0)
         return {};
 
     TRY(set_attribute(HTML::AttributeNames::value, MUST(String::number(value))));