mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-02 22:30:31 +00:00
LibWeb: Use double type in ProgressEvent
loaded and total should be double as per spec https://xhr.spec.whatwg.org/#progressevent
This commit is contained in:
parent
d56f6805d3
commit
eb165554e1
Notes:
github-actions[bot]
2025-04-17 12:29:50 +00:00
Author: https://github.com/vishalbiswas
Commit: eb165554e1
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4382
Reviewed-by: https://github.com/trflynn89 ✅
4 changed files with 102 additions and 10 deletions
|
@ -14,8 +14,8 @@ namespace Web::XHR {
|
||||||
|
|
||||||
struct ProgressEventInit : public DOM::EventInit {
|
struct ProgressEventInit : public DOM::EventInit {
|
||||||
bool length_computable { false };
|
bool length_computable { false };
|
||||||
WebIDL::UnsignedLongLong loaded { 0 };
|
WebIDL::Double loaded { 0 };
|
||||||
WebIDL::UnsignedLongLong total { 0 };
|
WebIDL::Double total { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
class ProgressEvent final : public DOM::Event {
|
class ProgressEvent final : public DOM::Event {
|
||||||
|
@ -29,8 +29,8 @@ public:
|
||||||
virtual ~ProgressEvent() override;
|
virtual ~ProgressEvent() override;
|
||||||
|
|
||||||
bool length_computable() const { return m_length_computable; }
|
bool length_computable() const { return m_length_computable; }
|
||||||
WebIDL::UnsignedLongLong loaded() const { return m_loaded; }
|
WebIDL::Double loaded() const { return m_loaded; }
|
||||||
WebIDL::UnsignedLongLong total() const { return m_total; }
|
WebIDL::Double total() const { return m_total; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ProgressEvent(JS::Realm&, FlyString const& event_name, ProgressEventInit const& event_init);
|
ProgressEvent(JS::Realm&, FlyString const& event_name, ProgressEventInit const& event_init);
|
||||||
|
@ -38,8 +38,8 @@ private:
|
||||||
virtual void initialize(JS::Realm&) override;
|
virtual void initialize(JS::Realm&) override;
|
||||||
|
|
||||||
bool m_length_computable { false };
|
bool m_length_computable { false };
|
||||||
WebIDL::UnsignedLongLong m_loaded { 0 };
|
WebIDL::Double m_loaded { 0 };
|
||||||
WebIDL::UnsignedLongLong m_total { 0 };
|
WebIDL::Double m_total { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,12 @@ interface ProgressEvent : Event {
|
||||||
constructor(DOMString type, optional ProgressEventInit eventInitDict = {});
|
constructor(DOMString type, optional ProgressEventInit eventInitDict = {});
|
||||||
|
|
||||||
readonly attribute boolean lengthComputable;
|
readonly attribute boolean lengthComputable;
|
||||||
readonly attribute unsigned long long loaded;
|
readonly attribute double loaded;
|
||||||
readonly attribute unsigned long long total;
|
readonly attribute double total;
|
||||||
};
|
};
|
||||||
|
|
||||||
dictionary ProgressEventInit : EventInit {
|
dictionary ProgressEventInit : EventInit {
|
||||||
boolean lengthComputable = false;
|
boolean lengthComputable = false;
|
||||||
unsigned long long loaded = 0;
|
double loaded = 0;
|
||||||
unsigned long long total = 0;
|
double total = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
Harness status: OK
|
||||||
|
|
||||||
|
Found 10 tests
|
||||||
|
|
||||||
|
10 Pass
|
||||||
|
Pass Default event values.
|
||||||
|
Pass There must not be a initProgressEvent().
|
||||||
|
Pass Basic test.
|
||||||
|
Pass ECMAScript value conversion test.
|
||||||
|
Pass Positive integer number test.
|
||||||
|
Pass Zero test.
|
||||||
|
Pass Decimal number test.
|
||||||
|
Pass Mixed integer and decimal number test.
|
||||||
|
Pass Negative number.
|
||||||
|
Pass ProgressEventInit members must be matched case-sensitively.
|
|
@ -0,0 +1,77 @@
|
||||||
|
<!doctype html>
|
||||||
|
<title>ProgressEvent constructor</title>
|
||||||
|
<link rel="help" href="https://xhr.spec.whatwg.org/#interface-progressevent">
|
||||||
|
<link rel="help" href="https://dom.spec.whatwg.org/#concept-event-constructor">
|
||||||
|
<link rel="help" href="https://dom.spec.whatwg.org/#interface-event">
|
||||||
|
<script src=../resources/testharness.js></script>
|
||||||
|
<script src=../resources/testharnessreport.js></script>
|
||||||
|
<div id=log></div>
|
||||||
|
<script>
|
||||||
|
test(function() {
|
||||||
|
var ev = new ProgressEvent("test")
|
||||||
|
assert_equals(ev.type, "test")
|
||||||
|
assert_equals(ev.target, null)
|
||||||
|
assert_equals(ev.currentTarget, null)
|
||||||
|
assert_equals(ev.eventPhase, Event.NONE)
|
||||||
|
assert_equals(ev.bubbles, false)
|
||||||
|
assert_equals(ev.cancelable, false)
|
||||||
|
assert_equals(ev.defaultPrevented, false)
|
||||||
|
assert_equals(ev.isTrusted, false)
|
||||||
|
assert_true(ev.timeStamp > 0)
|
||||||
|
assert_true("initEvent" in ev)
|
||||||
|
assert_equals(ev.lengthComputable, false)
|
||||||
|
assert_equals(ev.loaded, 0)
|
||||||
|
assert_equals(ev.total, 0)
|
||||||
|
}, "Default event values.")
|
||||||
|
test(function() {
|
||||||
|
var ev = new ProgressEvent("test")
|
||||||
|
assert_equals(ev["initProgressEvent"], undefined)
|
||||||
|
}, "There must not be a initProgressEvent().")
|
||||||
|
test(function() {
|
||||||
|
var ev = new ProgressEvent("I am an event", { type: "trololol", bubbles: true, cancelable: false})
|
||||||
|
assert_equals(ev.type, "I am an event")
|
||||||
|
assert_equals(ev.bubbles, true)
|
||||||
|
assert_equals(ev.cancelable, false)
|
||||||
|
}, "Basic test.")
|
||||||
|
test(function() {
|
||||||
|
var ev = new ProgressEvent(null, { lengthComputable: "hah", loaded: "2" })
|
||||||
|
assert_equals(ev.type, "null")
|
||||||
|
assert_equals(ev.lengthComputable, true)
|
||||||
|
assert_equals(ev.loaded, 2)
|
||||||
|
}, "ECMAScript value conversion test.")
|
||||||
|
test(function() {
|
||||||
|
var ev = new ProgressEvent(null, { loaded: 1, total: 2 })
|
||||||
|
assert_equals(ev.type, "null")
|
||||||
|
assert_equals(ev.loaded, 1)
|
||||||
|
assert_equals(ev.total, 2)
|
||||||
|
}, "Positive integer number test.")
|
||||||
|
test(function () {
|
||||||
|
var ev = new ProgressEvent(null, { loaded: 0, total: 1 })
|
||||||
|
assert_equals(ev.type, "null")
|
||||||
|
assert_equals(ev.loaded, 0)
|
||||||
|
assert_equals(ev.total, 1)
|
||||||
|
}, "Zero test.")
|
||||||
|
test(function () {
|
||||||
|
var ev = new ProgressEvent(null, { loaded: 1.5, total: 3.5 })
|
||||||
|
assert_equals(ev.type, "null")
|
||||||
|
assert_equals(ev.loaded, 1.5)
|
||||||
|
assert_equals(ev.total, 3.5)
|
||||||
|
}, "Decimal number test.")
|
||||||
|
test(function () {
|
||||||
|
var ev = new ProgressEvent(null, { loaded: 1.5, total: 5 })
|
||||||
|
assert_equals(ev.type, "null")
|
||||||
|
assert_equals(ev.loaded, 1.5)
|
||||||
|
assert_equals(ev.total, 5)
|
||||||
|
}, "Mixed integer and decimal number test.")
|
||||||
|
test(function () {
|
||||||
|
var ev = new ProgressEvent(null, { loaded: -1, total: -5.5 })
|
||||||
|
assert_equals(ev.type, "null")
|
||||||
|
assert_equals(ev.loaded, -1)
|
||||||
|
assert_equals(ev.total, -5.5)
|
||||||
|
}, "Negative number.")
|
||||||
|
test(function () {
|
||||||
|
var ev = new ProgressEvent("Xx", { lengthcomputable: true})
|
||||||
|
assert_equals(ev.type, "Xx")
|
||||||
|
assert_equals(ev.lengthComputable, false)
|
||||||
|
}, "ProgressEventInit members must be matched case-sensitively.")
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue