Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / importer / task_test.html
1 <!DOCTYPE html>
2 <!--
3 Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
6 -->
7 <link rel="import" href="/tracing/importer/task.html">
8
9 <script>
10 'use strict';
11
12 tvcm.unittest.testSuite(function() {
13   var Task = tracing.importer.Task;
14
15   test('basicAllStepsPass', function() {
16     var results = [];
17
18     var startingTask = new Task(function(task) {
19       results.push('a');
20       task.subTask(function() {
21         results.push('a/1');
22       }, this);
23       task.subTask(function() {
24         results.push('a/2');
25       }, this);
26     }, this);
27     startingTask.after(function() {
28       results.push('b');
29     }, this).after(function() {
30       results.push('c');
31     }, this);
32
33     Task.RunSynchronously(startingTask);
34     assertArrayEquals(['a', 'a/1', 'a/2', 'b', 'c'],
35                       results);
36   });
37
38   test('basicAllStepsPassAsync', function() {
39     var results = [];
40
41     var startingTask = new Task(function(task) {
42       results.push('a');
43       task.subTask(function() {
44         results.push('a/1');
45       }, this);
46       task.subTask(function() {
47         results.push('a/2');
48       }, this);
49     }, this);
50     startingTask.after(function() {
51       results.push('b');
52     }, this).after(function() {
53       results.push('c');
54     }, this);
55
56     var promise = Task.RunWhenIdle(startingTask);
57     promise.then(function() {
58       assertArrayEquals(['a', 'a/1', 'a/2', 'b', 'c'],
59                         results);
60     });
61     return promise;
62   });
63
64   test('taskThatThrowsShouldRejectItsPromise', function() {
65     var startingTask = new Task(function(task) {
66       throw new Error(
67           'IGNORE. This is an expected error to test error handling.');
68     }, this);
69
70     var taskPromise = Task.RunWhenIdle(startingTask);
71
72     return new Promise(function(resolve, reject) {
73       taskPromise.then(function() {
74         reject(new Error('Should have thrown'));
75       }, function(err) {
76         resolve();
77       });
78     });
79   });
80
81 });
82 </script>