- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / webui / assertions.js
1 // Copyright (c) 2011 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 function WebUIAssertionsTest() {}
6
7 WebUIAssertionsTest.prototype = {
8   __proto__: testing.Test.prototype,
9   browsePreload: DUMMY_URL,
10 };
11
12 function testTwoExpects() {
13   expectTrue(false);
14   expectTrue(0);
15 }
16
17 TEST_F('WebUIAssertionsTest', 'testTwoExpects', function() {
18   var result = runTestFunction('testTwoExpects', testTwoExpects, []);
19   resetTestState();
20
21   expectFalse(result[0]);
22   expectTrue(!!result[1].match(/expectTrue\(false\): false/));
23   expectTrue(!!result[1].match(/expectTrue\(0\): 0/));
24 });
25
26 function twoExpects() {
27   expectTrue(false, 'message1');
28   expectTrue(false, 'message2');
29 }
30
31 function testCallTestTwice() {
32   twoExpects();
33   twoExpects();
34 }
35
36 TEST_F('WebUIAssertionsTest', 'testCallTestTwice', function() {
37   var result = runTestFunction('testCallTestTwice', testCallTestTwice, []);
38   resetTestState();
39
40   expectFalse(result[0]);
41   expectEquals(2, result[1].match(
42       /expectTrue\(false, 'message1'\): message1: false/g).length);
43   expectEquals(2, result[1].match(
44       /expectTrue\(false, 'message2'\): message2: false/g).length);
45 });
46
47 function testConstructMessage() {
48   var message = 1 + ' ' + 2;
49   assertTrue(false, message);
50 }
51
52 TEST_F('WebUIAssertionsTest', 'testConstructedMessage', function() {
53   var result = runTestFunction(
54       'testConstructMessage', testConstructMessage, []);
55   resetTestState();
56
57   expectEquals(
58       1, result[1].match(/assertTrue\(false, message\): 1 2: false/g).length);
59 });
60
61 /**
62  * Failing version of WebUIAssertionsTest.
63  * @extends WebUIAssertionsTest
64  * @constructor
65  */
66 function WebUIAssertionsTestFail() {}
67
68 WebUIAssertionsTestFail.prototype = {
69   __proto__: WebUIAssertionsTest.prototype,
70
71   /** @inheritDoc */
72   testShouldFail: true,
73 };
74
75 // Test that an assertion failure fails test.
76 TEST_F('WebUIAssertionsTestFail', 'testAssertFailFails', function() {
77   assertNotReached();
78 });
79
80 // Test that an expect failure fails test.
81 TEST_F('WebUIAssertionsTestFail', 'testExpectFailFails', function() {
82   expectNotReached();
83 });
84
85 /**
86  * Async version of WebUIAssertionsTestFail.
87  * @extends WebUIAssertionsTest
88  * @constructor
89  */
90 function WebUIAssertionsTestAsyncFail() {}
91
92 WebUIAssertionsTestAsyncFail.prototype = {
93   __proto__: WebUIAssertionsTestFail.prototype,
94
95   /** @inheritDoc */
96   isAsync: true,
97 };
98
99 // Test that an assertion failure doesn't hang forever.
100 TEST_F('WebUIAssertionsTestAsyncFail', 'testAsyncFailCallsDone', function() {
101   assertNotReached();
102 });