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

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/braille/braille_translator_manager_test.extjs

Issue 938623003: Fix ChromeVox next tests to fail instead of timing out where applicable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify async callback handling in the tests. Created 5 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Include test fixture. 5 // Include test fixture.
6 GEN_INCLUDE(['../testing/chromevox_e2e_test_base.js', 6 GEN_INCLUDE(['../testing/chromevox_e2e_test_base.js',
7 '../testing/assert_additions.js']); 7 '../testing/assert_additions.js']);
8 8
9 /** 9 /**
10 * Test fixture for cvox.BrailleTranslatorManager tests. 10 * Test fixture for cvox.BrailleTranslatorManager tests.
11 * This is an E2E test because there's no easy way to load a data file in 11 * This is an E2E test because there's no easy way to load a data file in
12 * a webui-style test. 12 * a webui-style test.
13 * @constructor 13 * @constructor
14 * @extends {ChromeVoxE2ETest} 14 * @extends {ChromeVoxE2ETest}
15 */ 15 */
16 function CvoxBrailleTranslatorManagerTest() {} 16 function CvoxBrailleTranslatorManagerTest() {
17 ChromeVoxE2ETest.call(this);
18 }
17 19
18 CvoxBrailleTranslatorManagerTest.prototype = { 20 CvoxBrailleTranslatorManagerTest.prototype = {
19 __proto__: ChromeVoxE2ETest.prototype, 21 __proto__: ChromeVoxE2ETest.prototype,
20 22
21 /** @override */ 23 /** @override */
22 setUp: function() { 24 setUp: function() {
23 this.liblouis = new FakeLibLouis(); 25 this.liblouis = new FakeLibLouis();
24 this.manager = new cvox.BrailleTranslatorManager(this.liblouis); 26 this.manager = new cvox.BrailleTranslatorManager(this.liblouis);
25 this.liblouis.translatorManager = this.manager; 27 this.liblouis.translatorManager = this.manager;
26 // This is called by an event handler in production, but we don't rely 28 // This is called by an event handler in production, but we don't rely
27 // on that for this test. 29 // on that for this test.
28 this.manager.loadLiblouis_(); 30 this.manager.loadLiblouis_();
29 }, 31 },
30 32
31 addChangeListener: function(callback) { 33 addChangeListener: function(callback) {
32 return this.manager.addChangeListener(this.continueTest( 34 return this.manager.addChangeListener(callOnce(this.newCallback(callback)));
33 WhenTestDone.ASSERT, callback));
34 }, 35 },
35 }; 36 };
36 37
37 /** @extends {cvox.LibLouis} */ 38 /** @extends {cvox.LibLouis} */
38 function FakeLibLouis() { 39 function FakeLibLouis() {
39 } 40 }
40 41
41 FakeLibLouis.prototype = { 42 FakeLibLouis.prototype = {
42 /** @override */ 43 /** @override */
43 attachToElement: function() {}, 44 attachToElement: function() {},
(...skipping 20 matching lines...) Expand all
64 * @constructor 65 * @constructor
65 */ 66 */
66 function FakeTranslator(table) { 67 function FakeTranslator(table) {
67 this.table = table; 68 this.table = table;
68 } 69 }
69 70
70 function callOnce(callback) { 71 function callOnce(callback) {
71 var called = false; 72 var called = false;
72 return function() { 73 return function() {
73 if (!called) { 74 if (!called) {
75 called = true;
74 callback.apply(null, arguments); 76 callback.apply(null, arguments);
75 called = true;
76 } 77 }
77 }; 78 };
78 } 79 }
79 80
80 TEST_F('CvoxBrailleTranslatorManagerTest', 'testInitial', function() { 81 TEST_F('CvoxBrailleTranslatorManagerTest', 'testInitial', function() {
81 assertEquals(null, this.manager.getExpandingTranslator()); 82 assertEquals(null, this.manager.getExpandingTranslator());
82 assertEquals(null, this.manager.getDefaultTranslator()); 83 assertEquals(null, this.manager.getDefaultTranslator());
83 assertEquals(null, this.manager.getUncontractedTranslator()); 84 assertEquals(null, this.manager.getUncontractedTranslator());
84 this.addChangeListener(function() { 85 this.addChangeListener(function() {
85 assertNotEquals(null, this.manager.getExpandingTranslator()); 86 assertNotEquals(null, this.manager.getExpandingTranslator());
86 assertEquals('en-US-comp8', this.manager.getDefaultTranslator().table.id); 87 assertEquals('en-US-comp8', this.manager.getDefaultTranslator().table.id);
87 assertEquals(null, this.manager.getUncontractedTranslator()); 88 assertEquals(null, this.manager.getUncontractedTranslator());
88 testDone(); 89 });
89 }.bind(this));
90 }); 90 });
91 91
92 TEST_F('CvoxBrailleTranslatorManagerTest', 'testRefreshWithoutChange', 92 TEST_F('CvoxBrailleTranslatorManagerTest', 'testRefreshWithoutChange',
93 function() { 93 function() {
94 this.addChangeListener(callOnce(function() { 94 this.addChangeListener(function() {
95 assertNotEquals(null, this.manager.getExpandingTranslator()); 95 assertNotEquals(null, this.manager.getExpandingTranslator());
96 // This works because the fake liblouis is actually not asynchonous. 96 // This works because the fake liblouis is actually not asynchonous.
97 this.addChangeListener(function() { 97 this.manager.addChangeListener(function() {
98 throw Error('Should not be called.'); 98 assertNotReached('Refresh should not be called without a change.');
99 }); 99 });
100 this.manager.refresh(); 100 this.manager.refresh();
101 testDone(); 101 });
102 }.bind(this)));
103 }); 102 });
104 103
105 TEST_F('CvoxBrailleTranslatorManagerTest', 'testRefreshWithChange', 104 TEST_F('CvoxBrailleTranslatorManagerTest', 'testRefreshWithChange',
106 function() { 105 function() {
107 this.addChangeListener(callOnce(function() { 106 this.addChangeListener(function() {
108 assertNotEquals(null, this.manager.getExpandingTranslator()); 107 assertNotEquals(null, this.manager.getExpandingTranslator());
109 this.addChangeListener(function() { 108 this.addChangeListener(function() {
110 assertEquals('en-UEB-g2', this.manager.getDefaultTranslator().table.id); 109 assertEquals('en-UEB-g2', this.manager.getDefaultTranslator().table.id);
111 assertEquals('en-US-comp8', 110 assertEquals('en-US-comp8',
112 this.manager.getUncontractedTranslator().table.id); 111 this.manager.getUncontractedTranslator().table.id);
113 testDone(); 112 });
114 }.bind(this));
115 localStorage['brailleTable'] = 'en-UEB-g2'; 113 localStorage['brailleTable'] = 'en-UEB-g2';
116 this.manager.refresh(); 114 this.manager.refresh();
117 }.bind(this))); 115 });
118 }); 116 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698