Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: chrome/test/data/webui/async_gen.js

Issue 7645007: WebUI Testing: async support - global mocking, deferred runs, continued run. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Create an enum to describe when testDone should be called. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 /**
6 * Test fixture for generated async tests.
7 * @extends {testing.Test}
8 */
9 function WebUIBrowserAsyncGenTest() {}
10
11 WebUIBrowserAsyncGenTest.prototype = {
12 __proto__: testing.Test.prototype,
13
14 /**
15 * Define the C++ class and include it.
16 * @type {?string}
17 * @override
18 */
19 typedefCppFixture: null,
20
21 /** @inheritDoc */
22 tearDown: function() {
23 expectFalse(this.tornDown);
24 expectFalse(this.running);
25 this.tornDown = true;
26 chrome.send('tornDown');
27 testing.Test.prototype.tearDown.call(this);
28 },
29
30 /** @inheritDoc */
31 browsePreload: DUMMY_URL,
32
33 /** @inheritDoc */
34 isAsync: true,
35
36 /**
37 * True when the tearDown method is called.
38 * @type {boolean}
39 */
40 tornDown: false,
41
42 /**
43 * True when running sync portion of test.
44 * @type {boolean}
45 */
46 running: false,
47 };
48
49 GEN('#include "chrome/test/data/webui/async_gen-inl.h"');
50 GEN('');
51 GEN('WebUIBrowserAsyncGenTest::WebUIBrowserAsyncGenTest() {}');
52 GEN('WebUIBrowserAsyncGenTest::~WebUIBrowserAsyncGenTest() {}');
53 GEN('WebUIBrowserAsyncGenTest::AsyncWebUIMessageHandler::');
54 GEN(' AsyncWebUIMessageHandler() {}');
55 GEN('WebUIBrowserAsyncGenTest::AsyncWebUIMessageHandler::');
56 GEN(' ~AsyncWebUIMessageHandler() {}');
mmenke 2011/08/23 15:26:29 Couldn't these go in the inl file?
Sheridan Rawlins 2011/08/24 02:33:53 Sadly, clang bots hork it up unless it's in a .cc
mmenke 2011/08/24 15:27:50 Might want to add a comment along those lines. On
Sheridan Rawlins 2011/08/24 21:15:45 Done.
57 GEN('');
58
59 /**
60 * Will be set to continuation test #1.
61 * @type {Function}
62 * @this {WebUIBrowserAsyncGenTest}
63 */
64 var continueTest;
65
66 /**
67 * Will be set to continuation test #2.
68 * @type {Function}
69 * @this {WebUIBrowserAsyncGenTest}
70 */
71 var continueTest2;
72
73 // Test that tearDown isn't called until the callback test runs.
74 TEST_F('WebUIBrowserAsyncGenTest', 'TestTearDown', function() {
75 assertFalse(this.tornDown);
76 this.running = true;
77 continueTest = this.continueTest(WhenTestDone.ALWAYS, function() {
78 this.running = false;
79 });
80 chrome.send('callJS', ['continueTest']);
81 });
82
83 // Test that continuing can be done multiple times and have access to closure
84 // variables.
85 TEST_F('WebUIBrowserAsyncGenTest', 'TestContinue', function() {
86 var xyz = false;
87 continueTest = this.continueTest(WhenTestDone.DEFAULT, function() {
88 assertFalse(xyz);
89 xyz = true;
90 chrome.send('callJS', ['continueTest2']);
91 });
92 continueTest2 = this.continueTest(WhenTestDone.ALWAYS, function() {
93 assertTrue(xyz);
94 });
95 chrome.send('callJS', ['continueTest']);
96 });
97
98 /**
99 * Will be set to the runTest continuation by the following test fixture.
100 * @type {Function}
101 */
102 var deferRunTest;
103
104 /**
105 * Test fixture for testing deferred async tests.
106 * @extends {WebUIBrowserAsyncGenTest}
107 */
108 function WebUIBrowserAsyncGenDeferredTest() {}
109
110 WebUIBrowserAsyncGenDeferredTest.prototype = {
111 __proto__: WebUIBrowserAsyncGenTest.prototype,
112
113 /** @inheritDoc */
114 typedefCppFixture: 'WebUIBrowserAsyncGenTest',
115
116 /**
117 * True when runTest is called.
118 * @type {boolean}
119 * @private
120 */
121 ranTest_: false,
122
123 /** @inheritDoc */
124 setUp: function() {
125 deferRunTest = this.deferRunTest(WhenTestDone.DEFAULT);
126 continueTest = this.continueTest(WhenTestDone.DEFAULT, function() {
127 expectFalse(this.ranTest_);
128 chrome.send('callJS', ['deferRunTest']);
129 });
130 chrome.send('callJS', ['continueTest']);
131 },
132
133 /** @inheritDoc */
134 runTest: function() {
135 this.ranTest_ = true;
136 WebUIBrowserAsyncGenTest.prototype.runTest.apply(this, arguments);
137 },
138 };
139
140 // Test that the test can be deferred appropriately.
141 TEST_F('WebUIBrowserAsyncGenDeferredTest', 'TestDeferRunTest', function() {
142 expectTrue(this.ranTest_);
143 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698