chromium/third_party/blink/web_tests/external/wpt/svg/types/scripted/SVGAnimatedEnumeration-SVGFECompositeElement.html

<!DOCTYPE HTML>
<title>Use of SVGAnimatedEnumeration within SVGFECompositeElement</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(function() {
  // This test checks the use of SVGAnimatedEnumeration within SVGFECompositeElement.

  var feCompositeElement = document.createElementNS("http://www.w3.org/2000/svg", "feComposite");
  feCompositeElement.setAttribute("operator", "over");

  // Check initial 'operator' value.
  assert_true(feCompositeElement.operator instanceof SVGAnimatedEnumeration);
  assert_equals(typeof(feCompositeElement.operator.baseVal), "number");
  assert_equals(feCompositeElement.operator.baseVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_OVER);

  // Switch to 'in'.
  feCompositeElement.operator.baseVal = SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_IN;
  assert_equals(feCompositeElement.operator.baseVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_IN);
  assert_equals(feCompositeElement.getAttribute('operator'), "in");

  // Switch to 'out'.
  feCompositeElement.operator.baseVal = SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_OUT;
  assert_equals(feCompositeElement.operator.baseVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_OUT);
  assert_equals(feCompositeElement.getAttribute('operator'), "out");

  // Switch to 'atop'.
  feCompositeElement.operator.baseVal = SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_ATOP;
  assert_equals(feCompositeElement.operator.baseVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_ATOP);
  assert_equals(feCompositeElement.getAttribute('operator'), "atop");

  // Switch to 'xor'
  feCompositeElement.operator.baseVal = SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_XOR;
  assert_equals(feCompositeElement.operator.baseVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_XOR);
  assert_equals(feCompositeElement.getAttribute('operator'), "xor");

  // Switch to 'lighter'.
  feCompositeElement.operator.baseVal = SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_LIGHTER;
  assert_equals(feCompositeElement.operator.baseVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_LIGHTER);
  assert_equals(feCompositeElement.getAttribute('operator'), "lighter");

  // Switch to 'arithmetic'.
  feCompositeElement.operator.baseVal = SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_ARITHMETIC;
  assert_equals(feCompositeElement.operator.baseVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_ARITHMETIC);
  assert_equals(feCompositeElement.getAttribute('operator'), "arithmetic");

  // Try setting invalid values.
  assert_throws_js(TypeError, function() { feCompositeElement.operator.baseVal = 8; });
  assert_equals(feCompositeElement.operator.baseVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_ARITHMETIC);
  assert_equals(feCompositeElement.getAttribute('operator'), "arithmetic");

  assert_throws_js(TypeError, function() { feCompositeElement.operator.baseVal = -1; });
  assert_equals(feCompositeElement.operator.baseVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_ARITHMETIC);
  assert_equals(feCompositeElement.getAttribute('operator'), "arithmetic");

  assert_throws_js(TypeError, function() { feCompositeElement.operator.baseVal = 0; });
  assert_equals(feCompositeElement.operator.baseVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_ARITHMETIC);
  assert_equals(feCompositeElement.getAttribute('operator'), "arithmetic");

  // Switch to 'over'.
  feCompositeElement.operator.baseVal = SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_OVER;
  assert_equals(feCompositeElement.operator.baseVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_OVER);
  assert_equals(feCompositeElement.getAttribute('operator'), "over");
});
</script>