Commit 35cea0d4 authored by Shanmuga Pandi M's avatar Shanmuga Pandi M Committed by Commit Bot

[css-typed-om] CSSUrlImageValue should set attributes to null if there was an error

As per spec[1], intrinsicWidth, intrinsicHeight, and intrinsicRatio should
return NULL , if state is other than "loaded".

[1] https://drafts.css-houdini.org/css-typed-om-1/#cssimagevalue

Bug: 792328
Change-Id: I9d3c7014136f6f2a7bd6b350ff4083389436cc54
Reviewed-on: https://chromium-review.googlesource.com/810288Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Commit-Queue: Shanmuga Pandi <shanmuga.m@samsung.com>
Cr-Commit-Position: refs/heads/master@{#522346}
parent 0794bed5
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
test(function() { test(function() {
testElement.attributeStyleMap.set('background-image', new CSSURLImageValue('')); testElement.attributeStyleMap.set('background-image', new CSSURLImageValue(''));
document.body.offsetTop; document.body.offsetTop;
assert_equals(testElement.attributeStyleMap.get('background-image').intrinsicHeight, 0); assert_equals(testElement.attributeStyleMap.get('background-image').intrinsicHeight, null);
assert_equals(testElement.attributeStyleMap.get('background-image').intrinsicWidth, 0); assert_equals(testElement.attributeStyleMap.get('background-image').intrinsicWidth, null);
}, "Check that setting background-image to CSSURLImageValue('') doesn't cause a crash"); }, "Check that setting background-image to CSSURLImageValue('') doesn't cause a crash");
runInlineStylePropertyMapTests( { runInlineStylePropertyMapTests( {
......
This is a testharness.js-based test.
PASS Constructing a CSSURLImageValue with an invalid URL throws a TypeError
PASS Constructing a CSSURLImageValue with a valid URL puts it in an unloaded state
PASS CSSURLImageValue.url is readonly
PASS Loading a CSSURLImageValue from a URL sets its state to loaded
PASS Loading a CSSURLImageValue from a base64 URL sets its state to loaded
FAIL Loading a CSSURLImageValue from a URL to an invalid image sets its state to error assert_equals: expected (object) null but got (number) 0
Harness: the test ran to completion.
...@@ -7,21 +7,21 @@ ...@@ -7,21 +7,21 @@
namespace blink { namespace blink {
double CSSStyleImageValue::intrinsicWidth(bool& is_null) const { double CSSStyleImageValue::intrinsicWidth(bool& is_null) const {
is_null = IsCachePending(); is_null = Status() != ResourceStatus::kCached;
if (is_null) if (is_null)
return 0; return 0;
return ImageSize().Width(); return ImageSize().Width();
} }
double CSSStyleImageValue::intrinsicHeight(bool& is_null) const { double CSSStyleImageValue::intrinsicHeight(bool& is_null) const {
is_null = IsCachePending(); is_null = Status() != ResourceStatus::kCached;
if (is_null) if (is_null)
return 0; return 0;
return ImageSize().Height(); return ImageSize().Height();
} }
double CSSStyleImageValue::intrinsicRatio(bool& is_null) { double CSSStyleImageValue::intrinsicRatio(bool& is_null) {
is_null = IsCachePending(); is_null = Status() != ResourceStatus::kCached;
if (is_null || intrinsicHeight(is_null) == 0) { if (is_null || intrinsicHeight(is_null) == 0) {
is_null = true; is_null = true;
return 0; return 0;
......
...@@ -22,6 +22,12 @@ class FakeCSSStyleImageValue : public CSSStyleImageValue { ...@@ -22,6 +22,12 @@ class FakeCSSStyleImageValue : public CSSStyleImageValue {
bool IsCachePending() const override { return cache_pending_; } bool IsCachePending() const override { return cache_pending_; }
IntSize ImageSize() const override { return size_; } IntSize ImageSize() const override { return size_; }
ResourceStatus Status() const override {
if (IsCachePending())
return ResourceStatus::kNotStarted;
return ResourceStatus::kCached;
}
const CSSValue* ToCSSValue(SecureContextMode) const override { const CSSValue* ToCSSValue(SecureContextMode) const override {
return nullptr; return nullptr;
} }
......
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