Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / src / base / unittest_test.js
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 'use strict';
6
7 base.require('base.unittest');
8 base.require('base.raf');
9
10 base.unittest.testSuite('base.unittest', function() {
11   test('dpiAware', function() {
12     var currentDevicePixelRatio = window.devicePixelRatio;
13     var alternateDevicePixelRatio =
14         currentDevicePixelRatio > 1 ? currentDevicePixelRatio : 2;
15
16     var dpi = [];
17     var names = [];
18     var suite = function() {
19       test('dpiTest', function() {
20         dpi.push(window.devicePixelRatio);
21         names.push(this.name);
22       }, {dpiAware: true});
23     };
24
25     var ts = new base.unittest.TestSuite_('dpiTest Suite', suite);
26     ts.displayInfo();
27     ts.runTests([]).then(function(ignored) {
28       assertEquals(2, ts.testCount);
29       assertArrayEquals([1, alternateDevicePixelRatio], dpi.sort());
30       assertArrayEquals(['dpiTest_hiDPI', 'dpiTest_loDPI'], names.sort());
31
32       // Verify we reset back to the default value.
33       assertEquals(currentDevicePixelRatio, window.devicePixelRatio);
34     });
35   });
36
37   test('promise', function() {
38     return new Promise(function(r) {
39       r.resolve();
40     });
41   });
42
43   test('async', function() {
44     return new Promise(function(r) {
45       base.requestAnimationFrame(function() {
46         r.resolve();
47       });
48     });
49   });
50
51   /* To test failures remove comments
52   test('fail', function() {
53     assertEquals(true, false);
54   });
55
56   test('rejected-promise', function() {
57     return new Promise(function(resolver){
58       resolver.reject("Failure by rejection");
59     });
60   });
61
62    test('promise-that-throws-after-resolver', function() {
63     return new Promise(function(resolver){
64       throw new Error('blah');
65     });
66   });
67
68   */
69 });