c029181615467387a92c6c5715b35b19cfcd8aaf
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / src / tracing / importer / task_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 tvcm.require('tracing.importer.task');
8
9 tvcm.unittest.testSuite('tracing.importer.task_test', function() {
10   var Task = tracing.importer.Task;
11
12   test('basicAllStepsPass', function() {
13     var results = [];
14
15     var startingTask = new Task(function(task) {
16       results.push('a');
17       task.subTask(function() {
18         results.push('a/1');
19       }, this);
20       task.subTask(function() {
21         results.push('a/2');
22       }, this);
23     }, this);
24     startingTask.after(function() {
25       results.push('b');
26     }, this).after(function() {
27       results.push('c');
28     }, this);
29
30     Task.RunSynchronously(startingTask);
31     assertArrayEquals(['a', 'a/1', 'a/2', 'b', 'c'],
32                       results);
33   });
34
35   test('basicAllStepsPassAsync', function() {
36     var results = [];
37
38     var startingTask = new Task(function(task) {
39       results.push('a');
40       task.subTask(function() {
41         results.push('a/1');
42       }, this);
43       task.subTask(function() {
44         results.push('a/2');
45       }, this);
46     }, this);
47     startingTask.after(function() {
48       results.push('b');
49     }, this).after(function() {
50       results.push('c');
51     }, this);
52
53     var promise = Task.RunWhenIdle(startingTask);
54     promise.then(function() {
55       assertArrayEquals(['a', 'a/1', 'a/2', 'b', 'c'],
56                         results);
57     });
58     return promise;
59   });
60
61   test('taskThatThrowsShouldRejectItsPromise', function() {
62     var startingTask = new Task(function(task) {
63       throw new Errror('Expected error');
64     }, this);
65
66     var taskPromise = Task.RunWhenIdle(startingTask);
67
68     return new Promise(function(resolver) {
69       taskPromise.then(function() {
70         resolver.reject(new Error('Should have thrown'));
71       }, function(err) {
72         resolver.resolve();
73       });
74     });
75   });
76
77 });