fpsdisplay_test.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. goog.provide('goog.debug.FpsDisplayTest');
  15. goog.setTestOnly('goog.debug.FpsDisplayTest');
  16. goog.require('goog.Timer');
  17. goog.require('goog.debug.FpsDisplay');
  18. goog.require('goog.testing.TestCase');
  19. goog.require('goog.testing.jsunit');
  20. var fpsDisplay;
  21. function shouldRunTests() {
  22. // Disable tests when being run as a part of open-source repo as the test
  23. // mysteriously times out way before 5s. See http://b/26132213.
  24. return !(/closure\/goog\/ui/.test(location.pathname));
  25. }
  26. function setUpPage() {
  27. goog.testing.TestCase.getActiveTestCase().promiseTimeout = 5000; // 5s
  28. }
  29. function setUp() {
  30. fpsDisplay = new goog.debug.FpsDisplay();
  31. }
  32. function tearDown() {
  33. goog.dispose(fpsDisplay);
  34. }
  35. function testRendering() {
  36. fpsDisplay.render();
  37. var elem = fpsDisplay.getElement();
  38. assertHTMLEquals('', elem.innerHTML);
  39. return goog.Timer.promise(2000).then(function() {
  40. var fps = parseInt(elem.innerHTML, 10);
  41. assertTrue('FPS of ' + fps + ' should be non-negative', fps >= 0);
  42. assertTrue('FPS of ' + fps + ' too big', fps < 1000);
  43. });
  44. }