Index: third_party/WebKit/LayoutTests/fast/js/put-forwards.html |
diff --git a/third_party/WebKit/LayoutTests/fast/js/put-forwards.html b/third_party/WebKit/LayoutTests/fast/js/put-forwards.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cb6fdcdd7d42f9eff8c0cdf235df02194ef020e2 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/fast/js/put-forwards.html |
@@ -0,0 +1,106 @@ |
+<!DOCTYPE html> |
+<script src="../../resources/testharness.js"></script> |
+<script src="../../resources/testharnessreport.js"></script> |
+<script> |
+ test(() => { |
+ var getter_called = false; |
+ var element = document.createElement("div"); |
+ var element_style = element.style; |
+ var descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "style"); |
+ |
+ Object.defineProperty(element, "style", { |
+ get: function () { |
+ getter_called = true; |
+ return element_style; |
+ }, |
+ set: descriptor.set |
+ }); |
+ |
+ element.style = "color: green"; |
+ |
+ assert_true(getter_called, "Overridden getter should be called"); |
+ assert_equals(element_style.color, "green", "Put forwarding still works"); |
+ }, "Overriding getter of [PutForwards] attribute"); |
+ |
+ test(() => { |
+ var setter_called = false; |
+ var element = document.createElement("div"); |
+ var element_style = element.style; |
+ var descriptor = Object.getOwnPropertyDescriptor(CSSStyleDeclaration.prototype, "cssText"); |
+ |
+ Object.defineProperty(element_style, "cssText", { |
+ get: descriptor.get, |
+ set: function (v) { |
+ setter_called = true; |
+ descriptor.set.call(this, v); |
+ } |
+ }); |
+ |
+ element.style = "color: green"; |
+ |
+ assert_true(setter_called, "Overridden setter should be called"); |
+ assert_equals(element_style.color, "green", "Put forwarding still works"); |
+ }, "Overriding setter of [PutForwards] target attribute"); |
+ |
+ test(() => { |
+ var element = document.createElement("div"); |
+ var element_style = element.style; |
+ var fake_style = { cssText: "original" }; |
+ var descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "style"); |
+ |
+ Object.defineProperty(element, "style", { |
+ get: function () { |
+ return fake_style; |
+ }, |
+ set: descriptor.set |
+ }); |
+ |
+ element.style = "color: green"; |
+ |
+ assert_equals(element_style.cssText, "", "Original value intact"); |
+ assert_equals(fake_style.cssText, "color: green", "Fake style object updated"); |
+ }, "Overriding target of [PutForwards] attribute"); |
+ |
+ test(() => { |
+ var element = document.createElement("div"); |
+ var descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "style"); |
+ |
+ Object.defineProperty(element, "style", { |
+ get: function () { |
+ throw "exception"; |
+ }, |
+ set: descriptor.set |
+ }); |
+ |
+ assert_throws(null, () => element.style = "color: green"); |
+ }, "Exception propagation from getter of [PutForwards] attribute"); |
+ |
+ test(() => { |
+ var element = document.createElement("div"); |
+ var element_style = element.style; |
+ var descriptor = Object.getOwnPropertyDescriptor(CSSStyleDeclaration.prototype, "cssText"); |
+ |
+ Object.defineProperty(element_style, "cssText", { |
+ get: descriptor.get, |
+ set: function (v) { |
+ throw "exception"; |
+ } |
+ }); |
+ |
+ assert_throws(null, () => element.style = "color: green"); |
+ }, "Exception propagation from setter of [PutForwards] target attribute"); |
+ |
+ test(() => { |
+ var element = document.createElement("div"); |
+ var descriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "style"); |
+ |
+ Object.defineProperty(element, "style", { |
+ get: function () { |
+ return null; |
+ }, |
+ set: descriptor.set |
+ }); |
+ |
+ assert_throws(new TypeError, () => element.style = "color: green"); |
+ }, "TypeError when getter of [PutForwards] attribute returns non-object"); |
+</script> |