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

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/host/chrome/tts_background_test.extjs

Issue 2506203002: Fix language switching (Closed)
Patch Set: No tts lang. Created 4 years 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
« no previous file with comments | « chrome/browser/resources/chromeos/chromevox/host/chrome/tts_background.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // E2E tests for TtsBackground. 9 // E2E tests for TtsBackground.
10 10
(...skipping 24 matching lines...) Expand all
35 assertEquals('A', preprocess('A')); 35 assertEquals('A', preprocess('A'));
36 assertEquals('a.', preprocess('a.')); 36 assertEquals('a.', preprocess('a.'));
37 assertEquals('.a', preprocess('.a')); 37 assertEquals('.a', preprocess('.a'));
38 38
39 assertEquals('10 equal signs', preprocess('==========')); 39 assertEquals('10 equal signs', preprocess('=========='));
40 40
41 assertEquals('new line', preprocess('\n')); 41 assertEquals('new line', preprocess('\n'));
42 assertEquals('return', preprocess('\r')); 42 assertEquals('return', preprocess('\r'));
43 }); 43 });
44 44
45 SYNC_TEST_F('CvoxTtsBackgroundTest', 'UpdateVoice', function() { 45 TEST_F('CvoxTtsBackgroundTest', 'UpdateVoice', function() {
46 var tts = new cvox.TtsBackground(false); 46 var tts = new cvox.TtsBackground(false);
47 var voices = [ 47 var voices = [
48 {lang: 'zh-CN', voiceName: 'Chinese'}, 48 {lang: 'zh-CN', voiceName: 'Chinese'},
49 {lang: 'zh-TW', voiceName: 'Chinese (Taiwan)'}, 49 {lang: 'zh-TW', voiceName: 'Chinese (Taiwan)'},
50 {lang: 'es', voiceName: 'Spanish'},
50 {lang: 'en-US', voiceName: 'U.S. English'} 51 {lang: 'en-US', voiceName: 'U.S. English'}
51 ]; 52 ];
52 53
53 chrome.tts.getVoices = function(callback) { 54 chrome.tts.getVoices = function(callback) {
54 callback(voices); 55 callback(voices);
55 }; 56 };
56 57
58 // Asks this test to process the next task immediately.
59 var flushNextTask = function() {
60 var task = tasks.shift();
61 if (!task) return;
62
63 if (task.setup)
64 task.setup();
65 tts.updateVoice_(task.testVoice, this.newCallback(function(actualVoice) {
66 assertEquals(task.expectedVoice, actualVoice);
67 flushNextTask();
68 }));
69 }.bind(this);
70
57 assertTrue(!tts.currentVoice); 71 assertTrue(!tts.currentVoice);
58
59 tts.updateVoice_('');
60 assertEquals('U.S. English', tts.currentVoice);
61 72
62 voices[2].lang = 'en'; 73 var tasks = [
63 tts.updateVoice_(''); 74 {testVoice: '', expectedVoice: 'U.S. English'},
64 assertEquals('U.S. English', tts.currentVoice);
65 75
66 voices[2].lang = 'fr-FR'; 76 {setup: function() {
67 voices[2].voiceName = 'French'; 77 voices[3].lang = 'en';
68 tts.updateVoice_(''); 78 },
69 assertEquals('Chinese', tts.currentVoice); 79 testVoice: '', expectedVoice: 'U.S. English'},
70 80
71 tts.updateVoice_('French'); 81 {setup: function() {
72 assertEquals('French', tts.currentVoice); 82 voices[3].lang = 'fr-FR';
83 voices[3].voiceName = 'French';
84 },
85 testVoice: '', expectedVoice: 'Chinese'},
86
87 {testVoice: 'French', expectedVoice: 'French'},
88
89 {setup: function() {
90 chrome.i18n.getUILanguage = function() { return 'es-ES'; };
91 chrome.i18n.getAcceptLanguages = function(callback) {
92 callback([]);
93 };
94 },
95 testVoice: '', expectedVoice: 'Spanish'},
96
97 {setup: function() {
98 chrome.i18n.getUILanguage = function() { return ''; };
99 chrome.i18n.getAcceptLanguages = function(callback) {
100 callback(['zh-TW']);
101 };
102 },
103 testVoice: '', expectedVoice: 'Chinese (Taiwan)'}
104 ];
105
106 flushNextTask();
73 }); 107 });
74 108
75 // This test only works if Google tts is installed. Run it locally. 109 // This test only works if Google tts is installed. Run it locally.
76 TEST_F( 110 TEST_F(
77 'CvoxTtsBackgroundTest', 'DISABLED_EmptyStringCallsCallbacks', function() { 111 'CvoxTtsBackgroundTest', 'DISABLED_EmptyStringCallsCallbacks', function() {
78 var tts = new cvox.TtsBackground(false); 112 var tts = new cvox.TtsBackground(false);
79 var startCalls = 0, endCalls = 0; 113 var startCalls = 0, endCalls = 0;
80 assertCallsCallbacks = function(text, speakCalls) { 114 assertCallsCallbacks = function(text, speakCalls) {
81 tts.speak(text, cvox.QueueMode.QUEUE, 115 tts.speak(text, cvox.QueueMode.QUEUE,
82 {startCallback: function() { ++startCalls; }, 116 {startCallback: function() { ++startCalls; },
83 endCallback: this.newCallback(function() { 117 endCallback: this.newCallback(function() {
84 ++endCalls; 118 ++endCalls;
85 assertEquals(speakCalls, endCalls); 119 assertEquals(speakCalls, endCalls);
86 assertEquals(endCalls, startCalls); 120 assertEquals(endCalls, startCalls);
87 })} 121 })}
88 ); 122 );
89 }.bind(this); 123 }.bind(this);
90 124
91 assertCallsCallbacks('', 1); 125 assertCallsCallbacks('', 1);
92 assertCallsCallbacks(' ', 2); 126 assertCallsCallbacks(' ', 2);
93 assertCallsCallbacks(' \u00a0 ', 3); 127 assertCallsCallbacks(' \u00a0 ', 3);
94 }); 128 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/chromeos/chromevox/host/chrome/tts_background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698