<!DOCTYPE html>
<title>Tests that ::before and ::after pseudo elements use originating element's implicit anchor</title>
<link rel="help" href="https://github.com/whatwg/html/pull/9144">
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/8913">
<link rel="author" href="mailto:xiaochengh@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<style>
body {
  margin: 0;
}
#anchor {
  width: 100px;
  height: 100px;
  margin-left: 150px;
  margin-top: 50px;
  background: orange;
}
#target::before, #target::after {
  position: absolute;
  width: 100px;
  height: 100px;
  background: lime;
}
#target::before{
  content: '';
  right: anchor(left);
  top: anchor(top);
}
#target::after{
  content: '';
  left: anchor(right);
  top: anchor(top);
}
</style>
<div id="anchor"></div>
<div id="target" anchor="anchor"></div>

<script>
test(() => {
  let style = getComputedStyle(target, '::before');
  assert_equals(style.left, '50px');
  assert_equals(style.top, '50px');
}, "::before uses originating element's implicit anchor");

test(() => {
  let style = getComputedStyle(target, '::after');
  assert_equals(style.left, '250px');
  assert_equals(style.top, '50px');
}, "::after uses originating element's implicit anchor");
</script>
