<!doctype html> <!– @license Copyright © 2015 The Polymer Project Authors. All rights reserved. This code may only be used under the BSD style license found at polymer.github.io/LICENSE The complete set of authors may be found at polymer.github.io/AUTHORS The complete set of contributors may be found at polymer.github.io/CONTRIBUTORS Code distributed by Google as part of the polymer project is also subject to an additional IP rights grant found at polymer.github.io/PATENTS –> <html> <head>

<meta charset="UTF-8">
<title>scroll</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">

<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../web-component-tester/browser.js"></script>
<script src="../../../test-fixture/test-fixture-mocha.js"></script>
<link rel="import" href="../../../test-fixture/test-fixture.html">
<link rel="import" href="../helpers.html">

<style>
  #region {
    height: 500px;
    overflow: hidden;
  }

  .content {
    height: 10000px;
    width: 10000px;
  }
</style>

</head> <body>

<div id="region">
  <div class="content"></div>
</div>
<div class="content"></div>

<script>

  suite('Polymer.AppLayout.scroll', function() {

    test('document scrolling', function(done) {
      var x = 500;
      var y = 500;
      var region = document.querySelector('#region');

      Polymer.AppLayout.scroll({left: x, top: y});

      Polymer.Base.async(function() {
        assert.equal(window.pageXOffset, x, 'document scrollLeft');
        assert.equal(window.pageYOffset, y, 'document scrollTop');
        done();
      }, 100);

    });

    test('scrolling region', function(done) {
      var x = 500;
      var y = 500;
      var region = document.querySelector('#region');

      Polymer.AppLayout.scroll({left: x, top: y, target: region});

      Polymer.Base.async(function() {
        assert.equal(region.scrollLeft, x, 'region scrollLeft');
        assert.equal(region.scrollTop, y, 'region scrollTop');
        done();
      }, 100);

    });

    test('behavior: silent', function() {
      Polymer.AppLayout.scroll({left: 100, top: 200, behavior: 'silent'});

      assert.isTrue(document.documentElement.classList.contains('app-layout-silent-scroll'));
    });

    test('behavior: smooth', function(done) {
      var scrollSpy = sinon.spy();
      window.addEventListener('scroll', scrollSpy);
      Polymer.AppLayout.scroll({top: 0});
      Polymer.AppLayout.scroll({top: 500, behavior: 'smooth'});

      window.setTimeout(function() {
        assert.isAbove(scrollSpy.callCount, 1, 'scroll top should be fired multiple times');
        done();
      }, 300);
    });

    test('smooth scrolling to the top', function(done) {
      Polymer.AppLayout.scroll({top: 1000});
      Polymer.AppLayout.scroll({top: 0, behavior: 'smooth'});

      var timer;

      window.addEventListener('scroll', function() {
        clearInterval(timer);
        timer = setTimeout(function() {
          assert.equal(window.pageYOffset, 0, 'document scrollTop');
          done();
        }, 200);
      });
    });

  });

</script>

</body> </html>