| 1 |
// Copyright 2011 The Closure Library Authors. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
goog.provide('goog.debug.FpsDisplayTest'); |
| 16 |
goog.setTestOnly('goog.debug.FpsDisplayTest'); |
| 17 |
|
| 18 |
goog.require('goog.Timer'); |
| 19 |
goog.require('goog.debug.FpsDisplay'); |
| 20 |
goog.require('goog.testing.TestCase'); |
| 21 |
goog.require('goog.testing.jsunit'); |
| 22 |
|
| 23 |
var fpsDisplay; |
| 24 |
|
| 25 |
function shouldRunTests() { |
| 26 |
// Disable tests when being run as a part of open-source repo as the test |
| 27 |
// mysteriously times out way before 5s. See http://b/26132213. |
| 28 |
return !(/closure\/goog\/ui/.test(location.pathname)); |
| 29 |
} |
| 30 |
|
| 31 |
function setUpPage() { |
| 32 |
goog.testing.TestCase.getActiveTestCase().promiseTimeout = 5000; // 5s |
| 33 |
} |
| 34 |
|
| 35 |
function setUp() { |
| 36 |
fpsDisplay = new goog.debug.FpsDisplay(); |
| 37 |
} |
| 38 |
|
| 39 |
function tearDown() { |
| 40 |
goog.dispose(fpsDisplay); |
| 41 |
} |
| 42 |
|
| 43 |
function testRendering() { |
| 44 |
fpsDisplay.render(); |
| 45 |
|
| 46 |
var elem = fpsDisplay.getElement(); |
| 47 |
assertHTMLEquals('', elem.innerHTML); |
| 48 |
|
| 49 |
return goog.Timer.promise(2000).then(function() { |
| 50 |
var fps = parseInt(elem.innerHTML, 10); |
| 51 |
assertTrue('FPS of ' + fps + ' should be non-negative', fps >= 0); |
| 52 |
assertTrue('FPS of ' + fps + ' too big', fps < 1000); |
| 53 |
}); |
| 54 |
} |