aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/script/dom/htmltablecellelement.rs35
-rw-r--r--components/script/dom/htmltableelement.rs4
-rw-r--r--components/script/dom/macros.rs13
-rw-r--r--components/script/dom/webidls/HTMLTableCellElement.webidl2
-rw-r--r--components/style/attr.rs7
-rw-r--r--components/util/str.rs12
-rw-r--r--tests/wpt/metadata/MANIFEST.json44
-rw-r--r--tests/wpt/metadata/html/dom/interfaces.html.ini9
-rw-r--r--tests/wpt/metadata/html/dom/reflection-tabular.html.ini258
-rw-r--r--tests/wpt/web-platform-tests/html/rendering/non-replaced-elements/tables/table-cell-width-ref.html37
-rw-r--r--tests/wpt/web-platform-tests/html/rendering/non-replaced-elements/tables/table-cell-width.html54
-rw-r--r--tests/wpt/web-platform-tests/html/rendering/non-replaced-elements/tables/table-width-ref.html13
-rw-r--r--tests/wpt/web-platform-tests/html/rendering/non-replaced-elements/tables/table-width.html30
13 files changed, 227 insertions, 291 deletions
diff --git a/components/script/dom/htmltablecellelement.rs b/components/script/dom/htmltablecellelement.rs
index f73ebd6a72c..81378a5a985 100644
--- a/components/script/dom/htmltablecellelement.rs
+++ b/components/script/dom/htmltablecellelement.rs
@@ -3,27 +3,25 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cssparser::RGBA;
-use dom::attr::{Attr, AttrValue};
+use dom::attr::AttrValue;
use dom::bindings::codegen::Bindings::HTMLTableCellElementBinding::HTMLTableCellElementMethods;
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::inheritance::Castable;
use dom::bindings::js::LayoutJS;
use dom::document::Document;
-use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
+use dom::element::{Element, RawLayoutElementHelpers};
use dom::htmlelement::HTMLElement;
use dom::htmltablerowelement::HTMLTableRowElement;
use dom::node::Node;
use dom::virtualmethods::VirtualMethods;
-use std::cell::Cell;
use string_cache::Atom;
-use util::str::{self, DOMString, LengthOrPercentageOrAuto};
+use util::str::{DOMString, LengthOrPercentageOrAuto};
const DEFAULT_COLSPAN: u32 = 1;
#[dom_struct]
pub struct HTMLTableCellElement {
htmlelement: HTMLElement,
- width: Cell<LengthOrPercentageOrAuto>,
}
impl HTMLTableCellElement {
@@ -33,7 +31,6 @@ impl HTMLTableCellElement {
-> HTMLTableCellElement {
HTMLTableCellElement {
htmlelement: HTMLElement::new_inherited(tag_name, prefix, document),
- width: Cell::new(LengthOrPercentageOrAuto::Auto),
}
}
@@ -56,6 +53,12 @@ impl HTMLTableCellElementMethods for HTMLTableCellElement {
// https://html.spec.whatwg.org/multipage/#dom-tdth-bgcolor
make_legacy_color_setter!(SetBgColor, "bgcolor");
+ // https://html.spec.whatwg.org/multipage/#dom-tdth-width
+ make_getter!(Width, "width");
+
+ // https://html.spec.whatwg.org/multipage/#dom-tdth-width
+ make_nonzero_dimension_setter!(SetWidth, "width");
+
// https://html.spec.whatwg.org/multipage/#dom-tdth-cellindex
fn CellIndex(&self) -> i32 {
let self_node = self.upcast::<Node>();
@@ -101,7 +104,11 @@ impl HTMLTableCellElementLayoutHelpers for LayoutJS<HTMLTableCellElement> {
fn get_width(&self) -> LengthOrPercentageOrAuto {
unsafe {
- (*self.unsafe_get()).width.get()
+ (&*self.upcast::<Element>().unsafe_get())
+ .get_attr_for_layout(&ns!(), &atom!("width"))
+ .map(AttrValue::as_dimension)
+ .cloned()
+ .unwrap_or(LengthOrPercentageOrAuto::Auto)
}
}
}
@@ -111,23 +118,11 @@ impl VirtualMethods for HTMLTableCellElement {
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
}
- fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
- self.super_type().unwrap().attribute_mutated(attr, mutation);
- match *attr.local_name() {
- atom!("width") => {
- let width = mutation.new_value(attr).map(|value| {
- str::parse_length(&value)
- });
- self.width.set(width.unwrap_or(LengthOrPercentageOrAuto::Auto));
- },
- _ => {},
- }
- }
-
fn parse_plain_attribute(&self, local_name: &Atom, value: DOMString) -> AttrValue {
match *local_name {
atom!("colspan") => AttrValue::from_u32(value, DEFAULT_COLSPAN),
atom!("bgcolor") => AttrValue::from_legacy_color(value),
+ atom!("width") => AttrValue::from_nonzero_dimension(value),
_ => self.super_type().unwrap().parse_plain_attribute(local_name, value),
}
}
diff --git a/components/script/dom/htmltableelement.rs b/components/script/dom/htmltableelement.rs
index 0de4c81fd9d..acc43beff9b 100644
--- a/components/script/dom/htmltableelement.rs
+++ b/components/script/dom/htmltableelement.rs
@@ -120,7 +120,7 @@ impl HTMLTableElementMethods for HTMLTableElement {
make_getter!(Width, "width");
// https://html.spec.whatwg.org/multipage/#dom-table-width
- make_dimension_setter!(SetWidth, "width");
+ make_nonzero_dimension_setter!(SetWidth, "width");
}
pub trait HTMLTableElementLayoutHelpers {
@@ -195,7 +195,7 @@ impl VirtualMethods for HTMLTableElement {
fn parse_plain_attribute(&self, local_name: &Atom, value: DOMString) -> AttrValue {
match *local_name {
atom!("border") => AttrValue::from_u32(value, 1),
- atom!("width") => AttrValue::from_dimension(value),
+ atom!("width") => AttrValue::from_nonzero_dimension(value),
_ => self.super_type().unwrap().parse_plain_attribute(local_name, value),
}
}
diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs
index 99b4e484752..ec639d6f6b5 100644
--- a/components/script/dom/macros.rs
+++ b/components/script/dom/macros.rs
@@ -236,6 +236,19 @@ macro_rules! make_dimension_setter(
);
);
+#[macro_export]
+macro_rules! make_nonzero_dimension_setter(
+ ( $attr:ident, $htmlname:tt ) => (
+ fn $attr(&self, value: DOMString) {
+ use dom::bindings::inheritance::Castable;
+ use dom::element::Element;
+ let element = self.upcast::<Element>();
+ let value = AttrValue::from_nonzero_dimension(value);
+ element.set_attribute(&atom!($htmlname), value)
+ }
+ );
+);
+
/// For use on non-jsmanaged types
/// Use #[derive(JSTraceable)] on JS managed types
macro_rules! no_jsmanaged_fields(
diff --git a/components/script/dom/webidls/HTMLTableCellElement.webidl b/components/script/dom/webidls/HTMLTableCellElement.webidl
index b259d9ff6a3..c1ee341749b 100644
--- a/components/script/dom/webidls/HTMLTableCellElement.webidl
+++ b/components/script/dom/webidls/HTMLTableCellElement.webidl
@@ -19,7 +19,7 @@ partial interface HTMLTableCellElement {
// attribute DOMString align;
// attribute DOMString axis;
// attribute DOMString height;
- // attribute DOMString width;
+ attribute DOMString width;
// attribute DOMString ch;
// attribute DOMString chOff;
diff --git a/components/style/attr.rs b/components/style/attr.rs
index 0569b235a9c..aa7eb621839 100644
--- a/components/style/attr.rs
+++ b/components/style/attr.rs
@@ -6,7 +6,7 @@ use cssparser::RGBA;
use std::ops::Deref;
use string_cache::{Atom, Namespace};
use util::str::{DOMString, LengthOrPercentageOrAuto, parse_unsigned_integer, parse_legacy_color, parse_length};
-use util::str::{split_html_space_chars, str_join, parse_integer};
+use util::str::{parse_nonzero_length, split_html_space_chars, str_join, parse_integer};
use values::specified::{Length};
// Duplicated from script::dom::values.
@@ -96,6 +96,11 @@ impl AttrValue {
AttrValue::Dimension(string, parsed)
}
+ pub fn from_nonzero_dimension(string: DOMString) -> AttrValue {
+ let parsed = parse_nonzero_length(&string);
+ AttrValue::Dimension(string, parsed)
+ }
+
/// Assumes the `AttrValue` is a `TokenList` and returns its tokens
///
/// ## Panics
diff --git a/components/util/str.rs b/components/util/str.rs
index 9978464ee0d..f00dd8e3ea7 100644
--- a/components/util/str.rs
+++ b/components/util/str.rs
@@ -4,6 +4,7 @@
use app_units::Au;
use cssparser::{self, Color, RGBA};
+use euclid::num::Zero;
use js::conversions::{FromJSValConvertible, ToJSValConvertible, latin1_to_string};
use js::jsapi::{JSContext, JSString, HandleValue, MutableHandleValue};
use js::jsapi::{JS_GetTwoByteStringCharsAndLength, JS_StringHasLatin1Chars};
@@ -372,6 +373,17 @@ pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto {
}
}
+/// HTML5 § 2.4.4.5.
+///
+/// https://html.spec.whatwg.org/multipage/#rules-for-parsing-non-zero-dimension-values
+pub fn parse_nonzero_length(value: &str) -> LengthOrPercentageOrAuto {
+ match parse_length(value) {
+ LengthOrPercentageOrAuto::Length(x) if x == Au::zero() => LengthOrPercentageOrAuto::Auto,
+ LengthOrPercentageOrAuto::Percentage(0.) => LengthOrPercentageOrAuto::Auto,
+ x => x,
+ }
+}
+
/// https://html.spec.whatwg.org/multipage/#rules-for-parsing-a-legacy-font-size
pub fn parse_legacy_font_size(mut input: &str) -> Option<&'static str> {
// Steps 1 & 2 are not relevant
diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json
index 8b59b3dd2f2..75246d19151 100644
--- a/tests/wpt/metadata/MANIFEST.json
+++ b/tests/wpt/metadata/MANIFEST.json
@@ -4590,6 +4590,16 @@
"url": "/html/rendering/non-replaced-elements/tables/table-border-2.html"
},
{
+ "path": "html/rendering/non-replaced-elements/tables/table-cell-width.html",
+ "references": [
+ [
+ "/html/rendering/non-replaced-elements/tables/table-cell-width-ref.html",
+ "=="
+ ]
+ ],
+ "url": "/html/rendering/non-replaced-elements/tables/table-cell-width.html"
+ },
+ {
"path": "html/rendering/non-replaced-elements/tables/table-layout.html",
"references": [
[
@@ -4610,6 +4620,16 @@
"url": "/html/rendering/non-replaced-elements/tables/table-width-150percent.html"
},
{
+ "path": "html/rendering/non-replaced-elements/tables/table-width.html",
+ "references": [
+ [
+ "/html/rendering/non-replaced-elements/tables/table-width-ref.html",
+ "=="
+ ]
+ ],
+ "url": "/html/rendering/non-replaced-elements/tables/table-width.html"
+ },
+ {
"path": "html/rendering/non-replaced-elements/the-fieldset-element-0/min-width-not-important.html",
"references": [
[
@@ -32268,6 +32288,18 @@
"url": "/html/rendering/non-replaced-elements/tables/table-border-2.html"
}
],
+ "html/rendering/non-replaced-elements/tables/table-cell-width.html": [
+ {
+ "path": "html/rendering/non-replaced-elements/tables/table-cell-width.html",
+ "references": [
+ [
+ "/html/rendering/non-replaced-elements/tables/table-cell-width-ref.html",
+ "=="
+ ]
+ ],
+ "url": "/html/rendering/non-replaced-elements/tables/table-cell-width.html"
+ }
+ ],
"html/rendering/non-replaced-elements/tables/table-layout.html": [
{
"path": "html/rendering/non-replaced-elements/tables/table-layout.html",
@@ -32292,6 +32324,18 @@
"url": "/html/rendering/non-replaced-elements/tables/table-width-150percent.html"
}
],
+ "html/rendering/non-replaced-elements/tables/table-width.html": [
+ {
+ "path": "html/rendering/non-replaced-elements/tables/table-width.html",
+ "references": [
+ [
+ "/html/rendering/non-replaced-elements/tables/table-width-ref.html",
+ "=="
+ ]
+ ],
+ "url": "/html/rendering/non-replaced-elements/tables/table-width.html"
+ }
+ ],
"html/rendering/non-replaced-elements/the-fieldset-element-0/min-width-not-important.html": [
{
"path": "html/rendering/non-replaced-elements/the-fieldset-element-0/min-width-not-important.html",
diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini
index 644c9e789c7..cea11350d0d 100644
--- a/tests/wpt/metadata/html/dom/interfaces.html.ini
+++ b/tests/wpt/metadata/html/dom/interfaces.html.ini
@@ -4683,9 +4683,6 @@
[HTMLTableCellElement interface: document.createElement("td") must inherit property "height" with the proper type (6)]
expected: FAIL
- [HTMLTableCellElement interface: document.createElement("td") must inherit property "width" with the proper type (7)]
- expected: FAIL
-
[HTMLTableCellElement interface: document.createElement("td") must inherit property "ch" with the proper type (8)]
expected: FAIL
@@ -4740,9 +4737,6 @@
[HTMLTableCellElement interface: document.createElement("th") must inherit property "height" with the proper type (6)]
expected: FAIL
- [HTMLTableCellElement interface: document.createElement("th") must inherit property "width" with the proper type (7)]
- expected: FAIL
-
[HTMLTableCellElement interface: document.createElement("th") must inherit property "ch" with the proper type (8)]
expected: FAIL
@@ -4773,9 +4767,6 @@
[HTMLTableCellElement interface: attribute height]
expected: FAIL
- [HTMLTableCellElement interface: attribute width]
- expected: FAIL
-
[HTMLTableCellElement interface: attribute ch]
expected: FAIL
diff --git a/tests/wpt/metadata/html/dom/reflection-tabular.html.ini b/tests/wpt/metadata/html/dom/reflection-tabular.html.ini
index d811878a489..045c23235d3 100644
--- a/tests/wpt/metadata/html/dom/reflection-tabular.html.ini
+++ b/tests/wpt/metadata/html/dom/reflection-tabular.html.ini
@@ -11721,135 +11721,6 @@
[td.height: IDL set to object "test-valueOf" followed by IDL get]
expected: FAIL
- [td.width: typeof IDL attribute]
- expected: FAIL
-
- [td.width: IDL get with DOM attribute unset]
- expected: FAIL
-
- [td.width: setAttribute() to "" followed by IDL get]
- expected: FAIL
-
- [td.width: setAttribute() to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo " followed by IDL get]
- expected: FAIL
-
- [td.width: setAttribute() to undefined followed by IDL get]
- expected: FAIL
-
- [td.width: setAttribute() to 7 followed by IDL get]
- expected: FAIL
-
- [td.width: setAttribute() to 1.5 followed by IDL get]
- expected: FAIL
-
- [td.width: setAttribute() to true followed by IDL get]
- expected: FAIL
-
- [td.width: setAttribute() to false followed by IDL get]
- expected: FAIL
-
- [td.width: setAttribute() to object "[object Object\]" followed by IDL get]
- expected: FAIL
-
- [td.width: setAttribute() to NaN followed by IDL get]
- expected: FAIL
-
- [td.width: setAttribute() to Infinity followed by IDL get]
- expected: FAIL
-
- [td.width: setAttribute() to -Infinity followed by IDL get]
- expected: FAIL
-
- [td.width: setAttribute() to "\\0" followed by IDL get]
- expected: FAIL
-
- [td.width: setAttribute() to null followed by IDL get]
- expected: FAIL
-
- [td.width: setAttribute() to object "test-toString" followed by IDL get]
- expected: FAIL
-
- [td.width: setAttribute() to object "test-valueOf" followed by IDL get]
- expected: FAIL
-
- [td.width: IDL set to "" followed by getAttribute()]
- expected: FAIL
-
- [td.width: IDL set to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo " followed by getAttribute()]
- expected: FAIL
-
- [td.width: IDL set to undefined followed by getAttribute()]
- expected: FAIL
-
- [td.width: IDL set to undefined followed by IDL get]
- expected: FAIL
-
- [td.width: IDL set to 7 followed by getAttribute()]
- expected: FAIL
-
- [td.width: IDL set to 7 followed by IDL get]
- expected: FAIL
-
- [td.width: IDL set to 1.5 followed by getAttribute()]
- expected: FAIL
-
- [td.width: IDL set to 1.5 followed by IDL get]
- expected: FAIL
-
- [td.width: IDL set to true followed by getAttribute()]
- expected: FAIL
-
- [td.width: IDL set to true followed by IDL get]
- expected: FAIL
-
- [td.width: IDL set to false followed by getAttribute()]
- expected: FAIL
-
- [td.width: IDL set to false followed by IDL get]
- expected: FAIL
-
- [td.width: IDL set to object "[object Object\]" followed by getAttribute()]
- expected: FAIL
-
- [td.width: IDL set to object "[object Object\]" followed by IDL get]
- expected: FAIL
-
- [td.width: IDL set to NaN followed by getAttribute()]
- expected: FAIL
-
- [td.width: IDL set to NaN followed by IDL get]
- expected: FAIL
-
- [td.width: IDL set to Infinity followed by getAttribute()]
- expected: FAIL
-
- [td.width: IDL set to Infinity followed by IDL get]
- expected: FAIL
-
- [td.width: IDL set to -Infinity followed by getAttribute()]
- expected: FAIL
-
- [td.width: IDL set to -Infinity followed by IDL get]
- expected: FAIL
-
- [td.width: IDL set to "\\0" followed by getAttribute()]
- expected: FAIL
-
- [td.width: IDL set to null followed by getAttribute()]
- expected: FAIL
-
- [td.width: IDL set to null followed by IDL get]
- expected: FAIL
-
- [td.width: IDL set to object "test-toString" followed by getAttribute()]
- expected: FAIL
-
- [td.width: IDL set to object "test-toString" followed by IDL get]
- expected: FAIL
-
- [td.width: IDL set to object "test-valueOf" followed by IDL get]
- expected: FAIL
-
[td.ch (<td char>): typeof IDL attribute]
expected: FAIL
@@ -13776,135 +13647,6 @@
[th.height: IDL set to object "test-valueOf" followed by IDL get]
expected: FAIL
- [th.width: typeof IDL attribute]
- expected: FAIL
-
- [th.width: IDL get with DOM attribute unset]
- expected: FAIL
-
- [th.width: setAttribute() to "" followed by IDL get]
- expected: FAIL
-
- [th.width: setAttribute() to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo " followed by IDL get]
- expected: FAIL
-
- [th.width: setAttribute() to undefined followed by IDL get]
- expected: FAIL
-
- [th.width: setAttribute() to 7 followed by IDL get]
- expected: FAIL
-
- [th.width: setAttribute() to 1.5 followed by IDL get]
- expected: FAIL
-
- [th.width: setAttribute() to true followed by IDL get]
- expected: FAIL
-
- [th.width: setAttribute() to false followed by IDL get]
- expected: FAIL
-
- [th.width: setAttribute() to object "[object Object\]" followed by IDL get]
- expected: FAIL
-
- [th.width: setAttribute() to NaN followed by IDL get]
- expected: FAIL
-
- [th.width: setAttribute() to Infinity followed by IDL get]
- expected: FAIL
-
- [th.width: setAttribute() to -Infinity followed by IDL get]
- expected: FAIL
-
- [th.width: setAttribute() to "\\0" followed by IDL get]
- expected: FAIL
-
- [th.width: setAttribute() to null followed by IDL get]
- expected: FAIL
-
- [th.width: setAttribute() to object "test-toString" followed by IDL get]
- expected: FAIL
-
- [th.width: setAttribute() to object "test-valueOf" followed by IDL get]
- expected: FAIL
-
- [th.width: IDL set to "" followed by getAttribute()]
- expected: FAIL
-
- [th.width: IDL set to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo " followed by getAttribute()]
- expected: FAIL
-
- [th.width: IDL set to undefined followed by getAttribute()]
- expected: FAIL
-
- [th.width: IDL set to undefined followed by IDL get]
- expected: FAIL
-
- [th.width: IDL set to 7 followed by getAttribute()]
- expected: FAIL
-
- [th.width: IDL set to 7 followed by IDL get]
- expected: FAIL
-
- [th.width: IDL set to 1.5 followed by getAttribute()]
- expected: FAIL
-
- [th.width: IDL set to 1.5 followed by IDL get]
- expected: FAIL
-
- [th.width: IDL set to true followed by getAttribute()]
- expected: FAIL
-
- [th.width: IDL set to true followed by IDL get]
- expected: FAIL
-
- [th.width: IDL set to false followed by getAttribute()]
- expected: FAIL
-
- [th.width: IDL set to false followed by IDL get]
- expected: FAIL
-
- [th.width: IDL set to object "[object Object\]" followed by getAttribute()]
- expected: FAIL
-
- [th.width: IDL set to object "[object Object\]" followed by IDL get]
- expected: FAIL
-
- [th.width: IDL set to NaN followed by getAttribute()]
- expected: FAIL
-
- [th.width: IDL set to NaN followed by IDL get]
- expected: FAIL
-
- [th.width: IDL set to Infinity followed by getAttribute()]
- expected: FAIL
-
- [th.width: IDL set to Infinity followed by IDL get]
- expected: FAIL
-
- [th.width: IDL set to -Infinity followed by getAttribute()]
- expected: FAIL
-
- [th.width: IDL set to -Infinity followed by IDL get]
- expected: FAIL
-
- [th.width: IDL set to "\\0" followed by getAttribute()]
- expected: FAIL
-
- [th.width: IDL set to null followed by getAttribute()]
- expected: FAIL
-
- [th.width: IDL set to null followed by IDL get]
- expected: FAIL
-
- [th.width: IDL set to object "test-toString" followed by getAttribute()]
- expected: FAIL
-
- [th.width: IDL set to object "test-toString" followed by IDL get]
- expected: FAIL
-
- [th.width: IDL set to object "test-valueOf" followed by IDL get]
- expected: FAIL
-
[th.ch (<th char>): typeof IDL attribute]
expected: FAIL
diff --git a/tests/wpt/web-platform-tests/html/rendering/non-replaced-elements/tables/table-cell-width-ref.html b/tests/wpt/web-platform-tests/html/rendering/non-replaced-elements/tables/table-cell-width-ref.html
new file mode 100644
index 00000000000..b5ba0443f3c
--- /dev/null
+++ b/tests/wpt/web-platform-tests/html/rendering/non-replaced-elements/tables/table-cell-width-ref.html
@@ -0,0 +1,37 @@
+<style>
+body {
+ margin: 0;
+}
+
+.row {
+ clear: both;
+}
+
+.row div {
+ float: left;
+}
+
+.red {
+ background-color: red;
+}
+</style>
+
+<div class="row">
+ <div class="red" style="width: 200px">a</div>
+ <div style="width: 200px">a</div>
+</div>
+
+<div class="row">
+ <div class="red" style="width: 200px">a</div>
+ <div style="width: 200px">a</div>
+</div>
+
+<div class="row">
+ <div class="red" style="width: 100px">a</div>
+ <div style="width: 300px">a</div>
+</div>
+
+<div class="row">
+ <div class="red" style="width: 100px">a</div>
+ <div style="width: 300px">a</div>
+</div>
diff --git a/tests/wpt/web-platform-tests/html/rendering/non-replaced-elements/tables/table-cell-width.html b/tests/wpt/web-platform-tests/html/rendering/non-replaced-elements/tables/table-cell-width.html
new file mode 100644
index 00000000000..f66244ab10f
--- /dev/null
+++ b/tests/wpt/web-platform-tests/html/rendering/non-replaced-elements/tables/table-cell-width.html
@@ -0,0 +1,54 @@
+<link rel="match" href="table-cell-width-ref.html">
+<style>
+body {
+ margin: 0;
+}
+
+table {
+ width: 400px;
+ border-collapse: collapse;
+}
+
+th {
+ font-weight: normal;
+ text-align: left;
+}
+
+td, th {
+ padding: 0;
+}
+
+td:first-child, th:first-child {
+ background-color: red;
+}
+</style>
+
+<!-- width=0 should be treated as 'auto' -->
+<table>
+ <tr>
+ <th width=0>a</th>
+ <th>a</th>
+ </tr>
+</table>
+
+<table>
+ <tr>
+ <td width=0>a</td>
+ <td>a</td>
+ </tr>
+</table>
+
+<!-- test valid width attribute value-->
+<table>
+ <tr>
+ <th width=100>a</th>
+ <th>a</th>
+ </tr>
+</table>
+
+<table>
+ <tr>
+ <td width=100>a</td>
+ <td>a</td>
+ </tr>
+</table>
diff --git a/tests/wpt/web-platform-tests/html/rendering/non-replaced-elements/tables/table-width-ref.html b/tests/wpt/web-platform-tests/html/rendering/non-replaced-elements/tables/table-width-ref.html
new file mode 100644
index 00000000000..2b0f9e445c2
--- /dev/null
+++ b/tests/wpt/web-platform-tests/html/rendering/non-replaced-elements/tables/table-width-ref.html
@@ -0,0 +1,13 @@
+<style>
+p {
+ padding: 0;
+ margin: 0;
+}
+</style>
+
+<p>a b</p>
+
+<hr>
+
+<p>a</p>
+<p>b</p>
diff --git a/tests/wpt/web-platform-tests/html/rendering/non-replaced-elements/tables/table-width.html b/tests/wpt/web-platform-tests/html/rendering/non-replaced-elements/tables/table-width.html
new file mode 100644
index 00000000000..59c5ca70d41
--- /dev/null
+++ b/tests/wpt/web-platform-tests/html/rendering/non-replaced-elements/tables/table-width.html
@@ -0,0 +1,30 @@
+<link rel="match" href="table-width-ref.html">
+
+<style>
+table {
+ border-collapse: collapse;
+}
+
+td {
+ padding: 0;
+}
+</style>
+
+<!-- width=0 should be treated as 'auto' -->
+<table width=0>
+ <tr>
+ <td>
+ a b
+ </td>
+ </tr>
+</table>
+
+<hr>
+
+<table width=1>
+ <tr>
+ <td>
+ a b
+ </td>
+ </tr>
+</table>