<commit_before><!doctype html>
<!--
@license
Copyright (c) 2017 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>
  <meta charset="utf-8">
  <script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
  <script src="../../../web-component-tester/browser.js"></script>
  <link rel="import" href="../../polymer.html">
<body>

<x-foo prop1="a" prop2="b"></x-foo>

<script>
  HTMLImports.whenReady(function() {
    class XFoo extends Polymer.PropertyAccessors(HTMLElement) {
      static get observedAttributes() {
        return ['prop1', 'prop2']
      }
      constructor() {
        super();
        this._propertiesChanged = sinon.spy();
      }
      connectedCallback() {
        this._enableProperties();
      }
    }
    XFoo.createPropertiesForAttributes();
    window.XFoo = XFoo;
    customElements.define('x-foo', XFoo);
  });
</script>

<script>

suite('property-accessors', function() {

  test('createPropertiesForAttributes creates accessors', function() {
    assert.ok(Object.getOwnPropertyDescriptor(window.XFoo.prototype, 'prop1'));
    assert.ok(Object.getOwnPropertyDescriptor(window.XFoo.prototype, 'prop2'));
  });

  test('attributes reflected to properties via upgrade', function() {
    var el = document.querySelector('x-foo');
    assert.equal(el.prop1, 'a');
    assert.equal(el.prop2, 'b');
  });

  test('setting properties results in _propertiesChanged', function(done) {
    var el = document.createElement('x-foo');
    document.body.appendChild(el);
    el.prop1 = 'a';
    el.prop2 = 'b';
    assert.equal(el._propertiesChanged.callCount, 0, '_propertiesChanged is not async');
    setTimeout(function() {
      assert.isTrue(el._propertiesChanged.calledOnce);
      assert.equal(el._propertiesChanged.getCall(0).args[0].prop1, 'a');
      assert.equal(el._propertiesChanged.getCall(0).args[0].prop2, 'b');
      assert.equal(el._propertiesChanged.getCall(0).args[1].prop1, 'a');
      assert.equal(el._propertiesChanged.getCall(0).args[1].prop2, 'b');
      assert.equal(el._propertiesChanged.getCall(0).args[2].prop1, undefined);
      assert.equal(el._propertiesChanged.getCall(0).args[2].prop2, undefined);
      assert.equal(el.prop1, 'a');
      assert.equal(el.prop2, 'b');
      el.prop1 = 'aa';
      setTimeout(function() {
        assert.isTrue(el._propertiesChanged.calledTwice);
        assert.equal(el._propertiesChanged.getCall(1).args[0].prop1, 'aa');
        assert.equal(el._propertiesChanged.getCall(1).args[0].prop2, 'b');
        assert.equal(el._propertiesChanged.getCall(1).args[1].prop1, 'aa');
        assert.equal(el._propertiesChanged.getCall(1).args[2].prop1, 'a');
        assert.isFalse('prop2' in el._propertiesChanged.getCall(1).args[1]);
        assert.isFalse('prop2' in el._propertiesChanged.getCall(1).args[2]);
        done();
      });
    })
  });

  test('setting attributes results in _propertiesChanged', function(done) {
    var el = document.createElement('x-foo');
    document.body.appendChild(el);
    el.setAttribute('prop1', 'a');
    el.setAttribute('prop2', 'b');
    setTimeout(function() {
      assert.isTrue(el._propertiesChanged.calledOnce);
      assert.equal(el._propertiesChanged.getCall(0).args[0].prop1, 'a');
      assert.equal(el._propertiesChanged.getCall(0).args[0].prop2, 'b');
      assert.equal(el._propertiesChanged.getCall(0).args[1].prop1, 'a');
      assert.equal(el._propertiesChanged.getCall(0).args[1].prop2, 'b');
      assert.equal(el._propertiesChanged.getCall(0).args[2].prop1, undefined);
      assert.equal(el._propertiesChanged.getCall(0).args[2].prop2, undefined);
      assert.equal(el.prop1, 'a');
      assert.equal(el.prop2, 'b');
      el.setAttribute('prop1', 'aa');
      setTimeout(function() {
        assert.isTrue(el._propertiesChanged.calledTwice);
        assert.equal(el._propertiesChanged.getCall(1).args[0].prop1, 'aa');
        assert.equal(el._propertiesChanged.getCall(1).args[0].prop2, 'b');
        assert.equal(el._propertiesChanged.getCall(1).args[1].prop1, 'aa');
        assert.equal(el._propertiesChanged.getCall(1).args[2].prop1, 'a');
        assert.isFalse('prop2' in el._propertiesChanged.getCall(1).args[1]);
        assert.isFalse('prop2' in el._propertiesChanged.getCall(1).args[2]);
        done();
      });

    })
  });

});

</script>

</body>
</html>
<commit_msg>adding test case for 4696 4706<commit_after><!doctype html>
<!--
@license
Copyright (c) 2017 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>
  <meta charset="utf-8">
  <script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
  <script src="../../../web-component-tester/browser.js"></script>
  <link rel="import" href="../../polymer.html">
<body>

<x-foo prop1="a" prop2="b"></x-foo>

<script>
  HTMLImports.whenReady(function() {
    class XFoo extends Polymer.PropertyAccessors(HTMLElement) {
      static get observedAttributes() {
        return ['prop1', 'prop2']
      }
      constructor() {
        super();
        this._propertiesChanged = sinon.spy();
      }
      connectedCallback() {
        this._enableProperties();
      }
    }
    XFoo.createPropertiesForAttributes();
    window.XFoo = XFoo;
    customElements.define('x-foo', XFoo);
  });
</script>

<script>

suite('property-accessors', function() {

  test('createPropertiesForAttributes creates accessors', function() {
    assert.ok(Object.getOwnPropertyDescriptor(window.XFoo.prototype, 'prop1'));
    assert.ok(Object.getOwnPropertyDescriptor(window.XFoo.prototype, 'prop2'));
  });

  test('attributes reflected to properties via upgrade', function() {
    var el = document.querySelector('x-foo');
    assert.equal(el.prop1, 'a');
    assert.equal(el.prop2, 'b');
  });

  test('setting properties results in _propertiesChanged', function(done) {
    var el = document.createElement('x-foo');
    document.body.appendChild(el);
    el.prop1 = 'a';
    el.prop2 = 'b';
    assert.equal(el._propertiesChanged.callCount, 0, '_propertiesChanged is not async');
    setTimeout(function() {
      assert.isTrue(el._propertiesChanged.calledOnce);
      assert.equal(el._propertiesChanged.getCall(0).args[0].prop1, 'a');
      assert.equal(el._propertiesChanged.getCall(0).args[0].prop2, 'b');
      assert.equal(el._propertiesChanged.getCall(0).args[1].prop1, 'a');
      assert.equal(el._propertiesChanged.getCall(0).args[1].prop2, 'b');
      assert.equal(el._propertiesChanged.getCall(0).args[2].prop1, undefined);
      assert.equal(el._propertiesChanged.getCall(0).args[2].prop2, undefined);
      assert.equal(el.prop1, 'a');
      assert.equal(el.prop2, 'b');
      el.prop1 = 'aa';
      setTimeout(function() {
        assert.isTrue(el._propertiesChanged.calledTwice);
        assert.equal(el._propertiesChanged.getCall(1).args[0].prop1, 'aa');
        assert.equal(el._propertiesChanged.getCall(1).args[0].prop2, 'b');
        assert.equal(el._propertiesChanged.getCall(1).args[1].prop1, 'aa');
        assert.equal(el._propertiesChanged.getCall(1).args[2].prop1, 'a');
        assert.isFalse('prop2' in el._propertiesChanged.getCall(1).args[1]);
        assert.isFalse('prop2' in el._propertiesChanged.getCall(1).args[2]);
        done();
      });
    })
  });

  test('setting attributes results in _propertiesChanged', function(done) {
    var el = document.createElement('x-foo');
    document.body.appendChild(el);
    el.setAttribute('prop1', 'a');
    el.setAttribute('prop2', 'b');
    setTimeout(function() {
      assert.isTrue(el._propertiesChanged.calledOnce);
      assert.equal(el._propertiesChanged.getCall(0).args[0].prop1, 'a');
      assert.equal(el._propertiesChanged.getCall(0).args[0].prop2, 'b');
      assert.equal(el._propertiesChanged.getCall(0).args[1].prop1, 'a');
      assert.equal(el._propertiesChanged.getCall(0).args[1].prop2, 'b');
      assert.equal(el._propertiesChanged.getCall(0).args[2].prop1, undefined);
      assert.equal(el._propertiesChanged.getCall(0).args[2].prop2, undefined);
      assert.equal(el.prop1, 'a');
      assert.equal(el.prop2, 'b');
      el.setAttribute('prop1', 'aa');
      setTimeout(function() {
        assert.isTrue(el._propertiesChanged.calledTwice);
        assert.equal(el._propertiesChanged.getCall(1).args[0].prop1, 'aa');
        assert.equal(el._propertiesChanged.getCall(1).args[0].prop2, 'b');
        assert.equal(el._propertiesChanged.getCall(1).args[1].prop1, 'aa');
        assert.equal(el._propertiesChanged.getCall(1).args[2].prop1, 'a');
        assert.isFalse('prop2' in el._propertiesChanged.getCall(1).args[1]);
        assert.isFalse('prop2' in el._propertiesChanged.getCall(1).args[2]);
        done();
      });

    })
  });
  test('testing for deserialization of date', function(done) {
    var dateArr = [];
    dateArr[0] = new Date();
    dateArr[1] = String(dateArr[0].getTime()); //string timestamp
    dateArr[2] = dateArr[0].getTime(); //number timestamp
    dateArr[3] = dateArr[0].toString(); //full date
    setTimeout(function(){
      let ser = [];
      ser[0] = window.XFoo.prototype._deserializeValue(dateArr[1], Date);
      ser[1] = window.XFoo.prototype._deserializeValue(dateArr[2], Date);
      ser[2] = window.XFoo.prototype._deserializeValue(dateArr[3], Date);
      assert.equal(ser[0].getTime(), ser[1].getTime());
      assert.equal(ser[0].toString(), dateArr[3]);
      done();
    });
  });

});

</script>

</body>
</html>

{'fraction_non_alphanumeric': 0.1711334177955365, 'fraction_numerical': 0.021148036253776436, 'mean_word_length': 3.744336569579288, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2956492', 'n_tokens_mistral': 3285, 'n_tokens_neox': 3235, 'n_words': 533}