UNPKG

sku-pg

Version:

Skulpt is a Javascript implementation of Python 2.x. Python that runs in your browser!

113 lines (94 loc) 3.09 kB
<!DOCTYPE html> <html> <!-- Copyright 2008 The Closure Library Authors. All Rights Reserved. Use of this source code is governed by the Apache License, Version 2.0. See the COPYING file for details. --> <!-- --> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Closure Unit Tests - goog.debug.ErrorHandler async tests</title> <!-- These paths should be relative to the test --> <script src="../base.js"></script> <script> goog.require('goog.testing.jsunit'); goog.require('goog.testing.AsyncTestCase'); goog.require('goog.debug.ErrorHandler'); goog.require('goog.userAgent'); </script> </head> <body> <script> var testCase = new goog.testing.AsyncTestCase(document.title); testCase.setUpPage = function() { this.waitForAsync('setUpPage'); this.stepTimeout = 5 * 1000; this.oldTimeout = window.setTimeout; this.oldInterval = window.setInterval; this.handler = new goog.debug.ErrorHandler( goog.bind(this.onException, this)); this.handler.protectWindowSetTimeout(); this.handler.protectWindowSetInterval(); this.exceptions = []; this.errors = 0; // Override the error event handler, since we are purposely throwing // exceptions from global functions, and expect them this.oldWindowOnError = window.onerror; window.onerror = goog.bind(this.onError, this); this.add(new goog.testing.TestCase.Test( 'test results', this.testResults, this)); this.timeoutId = window.setTimeout(goog.bind(this.timeOut, this), 10); this.intervalId = window.setInterval(goog.bind(this.interval, this), 20); }; testCase.tearDownPage = function() { window.setTimeout = this.oldTimeout; window.setInterval = this.oldInterval; }; testCase.onException = function(e) { this.exceptions.push(e); if (this.timeoutHit && this.intervalHit) { this.continueTesting(); } }; testCase.onError = function(msg, url, line) { this.errors++; return true; }; testCase.timeOut = function() { this.timeoutHit = true; throw arguments.callee; }; testCase.interval = function() { this.intervalHit = true; window.clearTimeout(this.intervalId); throw arguments.callee; }; testCase.testResults = function() { var timeoutHit, intervalHit; for (var i = 0; i < this.exceptions.length; ++i) { switch (this.exceptions[i]) { case this.timeOut: timeoutHit = true; break; case this.interval: intervalHit = true; break; } } assertTrue('timeout exception not received', timeoutHit); assertTrue('interval exception not received', intervalHit); assertTrue('timeout not called', this.timeoutHit); assertTrue('interval not called', this.intervalHit); if (!goog.userAgent.WEBKIT) { assertEquals('2 exceptions should have been caught and rethrown', 2, this.errors) } }; function setUpPage() { testCase.runTests(); } // Standalone Closure Test Runner. if (typeof G_testRunner != 'undefined') { G_testRunner.initialize(testCase); } </script> </body> </html>