Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Unified Diff: chrome/test/data/webui/cr_elements/cr_scrollable_behavior_tests.js

Issue 2670223002: Add cr_scrollable_behavior tests (Closed)
Patch Set: Rebase + @constructor comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/data/webui/cr_elements/cr_elements_browsertest.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/webui/cr_elements/cr_scrollable_behavior_tests.js
diff --git a/chrome/test/data/webui/cr_elements/cr_scrollable_behavior_tests.js b/chrome/test/data/webui/cr_elements/cr_scrollable_behavior_tests.js
new file mode 100644
index 0000000000000000000000000000000000000000..160f5c231f2b45afec7a72a976dedace60879e00
--- /dev/null
+++ b/chrome/test/data/webui/cr_elements/cr_scrollable_behavior_tests.js
@@ -0,0 +1,95 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+suite('cr-scrollable-behavior', function() {
+ /** @type {CrScrollableListElement} */ var testElement;
+ /** @type {HTMLDivElement} */ var container;
+ /** @type {IronListElement} */ var ironList;
+
+ suiteSetup(function() {
+ document.body.innerHTML = `
+ <dom-module is="test-element">
+ <template>
+ <style>
+ #container {
+ height: 30px;
+ overflow-y: auto;
+ }
+ </style>
+ <div id="container" scrollable>
+ <iron-list scroll-target="container" items=[[items]]>
+ <template>
+ <div>[[item]]</div>
+ </template>
+ </iron-list>
+ </div>
+ </template>
+ </dom-module>
+ `;
+
+ Polymer({
+ is: 'test-element',
+
+ properties: {
+ items: {
+ type: Array,
+ value: function() {
+ return ['apple', 'bannana', 'cucumber', 'doughnut'];
+ },
+ },
+ },
+
+ behaviors: [CrScrollableBehavior],
+ });
+ });
+
+ setup(function(done) {
+ PolymerTest.clearBody();
+
+ testElement = document.createElement('test-element');
+ document.body.appendChild(testElement);
+ container = testElement.$$('#container');
+ ironList = testElement.$$('iron-list');
+
+ // Wait for requestAnimationFrame for CrScrollableBehavior to set the
+ // initial scrollable class properties.
+ window.requestAnimationFrame(function() {
+ done();
+ });
+ });
+
+ // There is no MockInteractions scroll event, and simlating a scroll is messy,
+ // so instead scroll ironList and send a 'scroll' event to the container.
+ function scrollToIndex(index) {
+ ironList.scrollToIndex(index);
+ container.dispatchEvent(new CustomEvent('scroll'));
+ Polymer.dom.flush();
+ };
+
+ test('scroll', function() {
+ assertTrue(container.classList.contains('can-scroll'));
+ assertFalse(container.classList.contains('is-scrolled'));
+ assertFalse(container.classList.contains('scrolled-to-bottom'));
+ scrollToIndex(1);
+ assertTrue(container.classList.contains('is-scrolled'));
+ assertFalse(container.classList.contains('scrolled-to-bottom'));
+ scrollToIndex(3);
+ assertTrue(container.classList.contains('scrolled-to-bottom'));
+ });
+
+ test('save scroll', function(done) {
+ scrollToIndex(2);
+ assertTrue(container.classList.contains('can-scroll'));
+ assertTrue(container.classList.contains('is-scrolled'));
+ var scrollTop = container.scrollTop;
+ testElement.saveScroll(ironList);
+ testElement.items = ['apple', 'bannana', 'cactus', 'cucumber', 'doughnut'];
+ testElement.restoreScroll(ironList);
+ Polymer.dom.flush();
+ Polymer.Base.async(function() {
+ assertEquals(scrollTop, container.scrollTop);
+ done();
+ });
+ });
+});
« no previous file with comments | « chrome/test/data/webui/cr_elements/cr_elements_browsertest.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698