| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2015 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. |
| --> |
| |
| <link rel="import" href="/tracing/base/task.html"> |
| <link rel="import" href="/tracing/ui/base/resize_sensor.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tr.b.unittest.testSuite(function() { |
| function forceLayout(element) { |
| element.offsetHeight; |
| } |
| |
| test('instantiate', function() { |
| var sensor = document.createElement('tr-ui-b-resize-sensor'); |
| sensor.appendChild(document.createTextNode('hello')); |
| |
| var resizeCount = 0; |
| function onResize(event) { |
| resizeCount += 1; |
| } |
| |
| this.addHTMLOutput(sensor); |
| forceLayout(sensor); |
| sensor.addEventListener('resize', onResize); |
| |
| // Trigger a resize: |
| sensor.style.fontSize = '20pt'; |
| forceLayout(sensor); |
| |
| // The event doesn't fire synchronously, so return a Promise that will |
| // resolve whenever the test is done. |
| return new Promise(function(resolve, reject) { |
| // The resize event fires when the sensor is re-laid-out. |
| // Use requestAnimationFrame to wait until after the sensor is |
| // re-laid-out. |
| // This doesn't work if the page becomes invisible. |
| window.requestAnimationFrame(function() { |
| assert.equal(1, resizeCount); |
| sensor.removeEventListener('resize', onResize); |
| sensor.style.fontSize = '12pt'; |
| forceLayout(sensor); |
| window.requestAnimationFrame(function() { |
| assert.equal(1, resizeCount); |
| resolve(); |
| }); |
| }); |
| }); |
| }); |
| }); |
| </script> |