OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <Foundation/Foundation.h> | 5 #import <Foundation/Foundation.h> |
6 | 6 |
7 #import "ios/chrome/browser/voice/text_to_speech_parser.h" | 7 #import "ios/chrome/browser/voice/text_to_speech_parser.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #import "third_party/google_toolbox_for_mac/src/Foundation/GTMStringEncoding.h" | 9 #import "third_party/google_toolbox_for_mac/src/Foundation/GTMStringEncoding.h" |
10 | 10 |
| 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 12 #error "This file requires ARC support." |
| 13 #endif |
| 14 |
11 // Expose internal parser function for testing. | 15 // Expose internal parser function for testing. |
12 NSData* ExtractVoiceSearchAudioDataFromPageHTML(NSString* pageHTML); | 16 NSData* ExtractVoiceSearchAudioDataFromPageHTML(NSString* pageHTML); |
13 | 17 |
14 namespace { | 18 namespace { |
15 NSString* const kValidVoiceSearchHTML = | 19 NSString* const kValidVoiceSearchHTML = |
16 @"<script>(function(){var _a_tts='dGVzdGF1ZG8zMm9pbw==';var _m_tts= {}}"; | 20 @"<script>(function(){var _a_tts='dGVzdGF1ZG8zMm9pbw==';var _m_tts= {}}"; |
17 NSString* const kInvalidVoiceSearchHTML = @"no TTS data"; | 21 NSString* const kInvalidVoiceSearchHTML = @"no TTS data"; |
18 } // namespace | 22 } // namespace |
19 | 23 |
20 TEST(TextToSpeechParser, ExtractAudioDataValid) { | 24 TEST(TextToSpeechParser, ExtractAudioDataValid) { |
21 NSData* result = | 25 NSData* result = |
22 ExtractVoiceSearchAudioDataFromPageHTML(kValidVoiceSearchHTML); | 26 ExtractVoiceSearchAudioDataFromPageHTML(kValidVoiceSearchHTML); |
23 | 27 |
24 EXPECT_TRUE(result != nil); | 28 EXPECT_TRUE(result != nil); |
25 | 29 |
26 GTMStringEncoding* base64 = [GTMStringEncoding rfc4648Base64StringEncoding]; | 30 GTMStringEncoding* base64 = [GTMStringEncoding rfc4648Base64StringEncoding]; |
27 NSData* expectedData = [base64 decode:@"dGVzdGF1ZG8zMm9pbw==" error:nullptr]; | 31 NSData* expectedData = [base64 decode:@"dGVzdGF1ZG8zMm9pbw==" error:nullptr]; |
28 EXPECT_TRUE([expectedData isEqualToData:result]); | 32 EXPECT_TRUE([expectedData isEqualToData:result]); |
29 } | 33 } |
30 | 34 |
31 TEST(TextToSpeechParser, ExtractAudioDataNotFound) { | 35 TEST(TextToSpeechParser, ExtractAudioDataNotFound) { |
32 NSData* result = | 36 NSData* result = |
33 ExtractVoiceSearchAudioDataFromPageHTML(kInvalidVoiceSearchHTML); | 37 ExtractVoiceSearchAudioDataFromPageHTML(kInvalidVoiceSearchHTML); |
34 EXPECT_TRUE(result == nil); | 38 EXPECT_TRUE(result == nil); |
35 } | 39 } |
OLD | NEW |