1 <!doctype html> 2 <!-- 3 @license 4 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. 5 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt 6 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 7 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt 8 Code distributed by Google as part of the polymer project is also 9 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt 10 --> 11 <html> 12 <head> 13 <meta charset="UTF-8"> 14 <title>iron-dropdown-scroll-manager tests</title> 15 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> 16 17 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> 18 <script src="../../web-component-tester/browser.js"></script> 19 <script src="../../test-fixture/test-fixture-mocha.js"></script> 20 <script src="../../iron-test-helpers/mock-interactions.js"></script> 21 22 <link rel="import" href="../iron-dropdown-scroll-manager.html"> 23 <link rel="import" href="../../test-fixture/test-fixture.html"> 24 <link rel="import" href="x-scrollable-element.html"> 25 </head> 26 <body> 27 28 <test-fixture id="DOMSubtree"> 29 <template> 30 <x-scrollable-element id="Parent"></x-scrollable-element> 31 </template> 32 </test-fixture> 33 <script> 34 suite('IronDropdownScrollManager', function() { 35 var parent; 36 var childOne; 37 var childTwo; 38 var grandchildOne; 39 var grandchildTwo; 40 var ancestor; 41 42 setup(function() { 43 parent = fixture('DOMSubtree'); 44 childOne = parent.$$('#ChildOne'); 45 childTwo = parent.$$('#ChildTwo'); 46 grandChildOne = parent.$$('#GrandchildOne'); 47 grandChildTwo = parent.$$('#GrandchildTwo'); 48 ancestor = document.body; 49 }); 50 51 suite('constraining scroll in the DOM', function() { 52 setup(function() { 53 Polymer.IronDropdownScrollManager.pushScrollLock(childOne); 54 }); 55 56 teardown(function() { 57 Polymer.IronDropdownScrollManager.removeScrollLock(childOne); 58 }); 59 60 test('recognizes sibling as locked', function() { 61 expect(Polymer.IronDropdownScrollManager.elementIsScrollLocked(childTwo)) 62 .to.be.equal(true); 63 }); 64 65 test('recognizes neice as locked', function() { 66 expect(Polymer.IronDropdownScrollManager.elementIsScrollLocked(grandChildTwo)) 67 .to.be.equal(true); 68 }); 69 70 test('recognizes parent as locked', function() { 71 expect(Polymer.IronDropdownScrollManager.elementIsScrollLocked(parent)) 72 .to.be.equal(true); 73 }); 74 75 test('recognizes ancestor as locked', function() { 76 expect(Polymer.IronDropdownScrollManager.elementIsScrollLocked(ancestor)) 77 .to.be.equal(true); 78 }); 79 80 test('recognizes locking child as unlocked', function() { 81 expect(Polymer.IronDropdownScrollManager.elementIsScrollLocked(childOne)) 82 .to.be.equal(false); 83 }); 84 85 test('recognizes descendant of locking child as unlocked', function() { 86 expect(Polymer.IronDropdownScrollManager.elementIsScrollLocked(grandChildOne)) 87 .to.be.equal(false); 88 }); 89 90 test('unlocks locked elements when there are no locking elements', function() { 91 Polymer.IronDropdownScrollManager.removeScrollLock(childOne); 92 93 expect(Polymer.IronDropdownScrollManager.elementIsScrollLocked(parent)) 94 .to.be.equal(false); 95 }); 96 97 test('does not check locked elements when there are no locking elements', function() { 98 sinon.spy(Polymer.IronDropdownScrollManager, 'elementIsScrollLocked'); 99 childOne.dispatchEvent(new CustomEvent('wheel', { 100 bubbles: true, 101 cancelable: true 102 })); 103 expect(Polymer.IronDropdownScrollManager 104 .elementIsScrollLocked.callCount).to.be.eql(1); 105 Polymer.IronDropdownScrollManager.removeScrollLock(childOne); 106 childOne.dispatchEvent(new CustomEvent('wheel', { 107 bubbles: true, 108 cancelable: true 109 })); 110 expect(Polymer.IronDropdownScrollManager 111 .elementIsScrollLocked.callCount).to.be.eql(1); 112 }); 113 114 suite('various scroll events', function() { 115 var scrollEvents; 116 var events; 117 118 setup(function() { 119 scrollEvents = [ 120 'wheel', 121 'mousewheel', 122 'DOMMouseScroll', 123 'touchmove' 124 ]; 125 126 events = scrollEvents.map(function(scrollEvent) { 127 return new CustomEvent(scrollEvent, { 128 bubbles: true, 129 cancelable: true 130 }); 131 }); 132 }); 133 134 test('prevents wheel events from locked elements', function() { 135 events.forEach(function(event) { 136 childTwo.dispatchEvent(event); 137 expect(event.defaultPrevented).to.be.eql(true); 138 }); 139 }); 140 141 test('allows wheel events from unlocked elements', function() { 142 events.forEach(function(event) { 143 childOne.dispatchEvent(event); 144 expect(event.defaultPrevented).to.be.eql(false); 145 }); 146 }); 147 }); 148 }); 149 }); 150 </script> 151 </body> 152 </html> 153