OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "ios/chrome/browser/voice/text_to_speech_listener.h" | 5 #import "ios/chrome/browser/voice/text_to_speech_listener.h" |
6 | 6 |
7 #import "base/mac/scoped_nsobject.h" | 7 #import "base/mac/scoped_nsobject.h" |
8 #import "ios/web/public/web_state/web_state.h" | 8 #import "ios/web/public/web_state/web_state.h" |
9 #include "ios/web/public/test/web_test_with_web_state.h" | 9 #include "ios/web/public/test/web_test_with_web_state.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "testing/gtest_mac.h" | 11 #include "testing/gtest_mac.h" |
12 #import "third_party/google_toolbox_for_mac/src/Foundation/GTMStringEncoding.h" | 12 #import "third_party/google_toolbox_for_mac/src/Foundation/GTMStringEncoding.h" |
13 | 13 |
| 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 15 #error "This file requires ARC support." |
| 16 #endif |
| 17 |
14 namespace { | 18 namespace { |
15 NSString* const kHTMLFormat = | 19 NSString* const kHTMLFormat = |
16 @"<html><head><script>%@</script></head><body></body></html>"; | 20 @"<html><head><script>%@</script></head><body></body></html>"; |
17 NSString* const kValidVoiceSearchScript = | 21 NSString* const kValidVoiceSearchScript = |
18 @"(function(){var _a_tts='dGVzdGF1ZG8zMm9pbw==';var _m_tts= {}})"; | 22 @"(function(){var _a_tts='dGVzdGF1ZG8zMm9pbw==';var _m_tts= {}})"; |
19 } // namespace | 23 } // namespace |
20 | 24 |
21 #pragma mark - TestTTSListenerDelegate | 25 #pragma mark - TestTTSListenerDelegate |
22 | 26 |
23 @interface TestTTSListenerDelegate : NSObject<TextToSpeechListenerDelegate> { | 27 @interface TestTTSListenerDelegate : NSObject<TextToSpeechListenerDelegate> { |
24 // Backing objects for properties of the same name. | 28 // Backing objects for properties of the same name. |
25 base::scoped_nsobject<NSData> _expectedAudioData; | 29 base::scoped_nsobject<NSData> _expectedAudioData; |
26 } | 30 } |
27 | 31 |
28 // The expected audio data to be returned by the TextToSpeechListener. | 32 // The expected audio data to be returned by the TextToSpeechListener. |
29 @property(nonatomic, retain) NSData* expectedAudioData; | 33 @property(nonatomic, strong) NSData* expectedAudioData; |
30 | 34 |
31 // Whether |-textToSpeechListener:didReceiveResult:| was called. | 35 // Whether |-textToSpeechListener:didReceiveResult:| was called. |
32 @property(nonatomic, assign) BOOL audioDataReceived; | 36 @property(nonatomic, assign) BOOL audioDataReceived; |
33 | 37 |
34 @end | 38 @end |
35 | 39 |
36 @implementation TestTTSListenerDelegate | 40 @implementation TestTTSListenerDelegate |
37 | 41 |
38 @synthesize audioDataReceived = _audioDataReceived; | 42 @synthesize audioDataReceived = _audioDataReceived; |
39 | 43 |
40 - (void)setExpectedAudioData:(NSData*)expectedAudioData { | 44 - (void)setExpectedAudioData:(NSData*)expectedAudioData { |
41 _expectedAudioData.reset([expectedAudioData retain]); | 45 _expectedAudioData.reset(expectedAudioData); |
42 } | 46 } |
43 | 47 |
44 - (NSData*)expectedAudioData { | 48 - (NSData*)expectedAudioData { |
45 return _expectedAudioData; | 49 return _expectedAudioData; |
46 } | 50 } |
47 | 51 |
48 - (void)textToSpeechListener:(TextToSpeechListener*)listener | 52 - (void)textToSpeechListener:(TextToSpeechListener*)listener |
49 didReceiveResult:(NSData*)result { | 53 didReceiveResult:(NSData*)result { |
50 EXPECT_NSEQ(self.expectedAudioData, result); | 54 EXPECT_NSEQ(self.expectedAudioData, result); |
51 self.audioDataReceived = YES; | 55 self.audioDataReceived = YES; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 NSString* html = | 95 NSString* html = |
92 [NSString stringWithFormat:kHTMLFormat, kValidVoiceSearchScript]; | 96 [NSString stringWithFormat:kHTMLFormat, kValidVoiceSearchScript]; |
93 NSData* expected_audio_data = | 97 NSData* expected_audio_data = |
94 [encoder decode:@"dGVzdGF1ZG8zMm9pbw==" error:nullptr]; | 98 [encoder decode:@"dGVzdGF1ZG8zMm9pbw==" error:nullptr]; |
95 TestExtraction(html, expected_audio_data); | 99 TestExtraction(html, expected_audio_data); |
96 } | 100 } |
97 | 101 |
98 TEST_F(TextToSpeechListenerTest, InvalidAudioDataTest) { | 102 TEST_F(TextToSpeechListenerTest, InvalidAudioDataTest) { |
99 TestExtraction([NSString stringWithFormat:kHTMLFormat, @""], nil); | 103 TestExtraction([NSString stringWithFormat:kHTMLFormat, @""], nil); |
100 } | 104 } |
OLD | NEW |