<!doctype html>
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
  <title>element script</title>
  <script src="../../../webcomponentsjs/webcomponents.js"></script>
  <link rel="import" href="../../polymer.html">
  <script src="../../../tools/test/htmltest.js"></script>
  <script src="../../../tools/test/chai/chai.js"></script>
  <script src="element-script/elements.js"></script>
</head>
<body>
  <x-foo></x-foo>  
  <hr>
  
  <x-bar></x-bar>
  <hr>
  
  <x-zot></x-zot>
  <hr>

  <x-baz></x-baz>
  <hr>
  
  <x-qux></x-qux>
  <hr>

  <x-quux></x-quux>
  <hr>

  <!-- preloaded external script -->
  <polymer-element name="x-foo">
    <template>
      Hello Light World
    </template>
  </polymer-element>
  
  <!-- external script with super() -->
  <polymer-element name="x-bar" extends="x-foo">
    <template>
      Hello Lighter World [<shadow></shadow>]
    </template>
  </polymer-element>

  <!-- no script -->
  <polymer-element name="x-zot" extends="x-foo" noscript>
    <template>
      Hello Lighter World [<shadow></shadow>]
    </template>
  </polymer-element>

  <!-- inline script -->
  <polymer-element name="x-baz" extends="x-zot">
    <script>
      Polymer('x-baz', {
        ready: function() {
          this.style.padding = '4px';
          this.style.backgroundColor = 'tomato';
          this.super();
        }
      });
    </script>
  </polymer-element>
  
  <!-- inline script before polymer-element -->
  <script>
    Polymer('x-qux', {
      ready: function() {
        this.style.padding = '4px';
        this.style.backgroundColor = 'green';
        this.super();
      }
    });
  </script>
  <polymer-element name="x-qux" extends="x-zot">
  </polymer-element>

  <!-- inline external script -->
  <polymer-element name="x-quux" extends="x-zot">
    <script src="element-script/x-quux.js"></script>
  </polymer-element>
  
  <script>
    var assert = chai.assert;
    document.addEventListener('polymer-ready', function() {
      // TODO(sorvell): under CE polyfill, noscript is not ready at WCR time
      // so need timeout or zot test fails.
      setTimeout(function() {
        var foo = document.querySelector('x-foo');
        assert.equal(getComputedStyle(foo).color, 'rgb(0, 0, 255)');
        //
        var bar = document.querySelector('x-bar');
        assert.equal(getComputedStyle(bar).color, 'rgb(0, 0, 255)');
        assert.equal(getComputedStyle(bar).backgroundColor, 'rgb(255, 165, 0)');
        //
        var zot = document.querySelector('x-zot');
        assert.equal(getComputedStyle(zot).color, 'rgb(0, 0, 255)');
        //
        var baz = document.querySelector('x-baz');
        assert.equal(getComputedStyle(baz).color, 'rgb(0, 0, 255)');
        assert.equal(getComputedStyle(baz).backgroundColor, 'rgb(255, 99, 71)');
        //
        var qux = document.querySelector('x-qux');
        assert.equal(getComputedStyle(qux).color, 'rgb(0, 0, 255)');
        assert.equal(getComputedStyle(qux).backgroundColor, 'rgb(0, 128, 0)');
        //
        var quux = document.querySelector('x-quux');
        assert.equal(getComputedStyle(quux).color, 'rgb(0, 0, 255)');
        assert.equal(getComputedStyle(quux).fontSize, '24px');
        done();
      }, 0);
    });
  </script>
  
</body>
</html>
