OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import <Foundation/Foundation.h> |
| 6 |
| 7 #import "ios/chrome/browser/voice/text_to_speech_parser.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #import "third_party/google_toolbox_for_mac/src/Foundation/GTMStringEncoding.h" |
| 10 |
| 11 // Expose internal parser function for testing. |
| 12 NSData* ExtractVoiceSearchAudioDataFromPageHTML(NSString* pageHTML); |
| 13 |
| 14 namespace { |
| 15 NSString* const kValidVoiceSearchHTML = |
| 16 @"<script>(function(){var _a_tts='dGVzdGF1ZG8zMm9pbw==';var _m_tts= {}}"; |
| 17 NSString* const kInvalidVoiceSearchHTML = @"no TTS data"; |
| 18 } // namespace |
| 19 |
| 20 TEST(TextToSpeechParser, ExtractAudioDataValid) { |
| 21 NSData* result = |
| 22 ExtractVoiceSearchAudioDataFromPageHTML(kValidVoiceSearchHTML); |
| 23 |
| 24 EXPECT_TRUE(result != nil); |
| 25 |
| 26 GTMStringEncoding* base64 = [GTMStringEncoding rfc4648Base64StringEncoding]; |
| 27 NSData* expectedData = [base64 decode:@"dGVzdGF1ZG8zMm9pbw=="]; |
| 28 EXPECT_TRUE([expectedData isEqualToData:result]); |
| 29 } |
| 30 |
| 31 TEST(TextToSpeechParser, ExtractAudioDataNotFound) { |
| 32 NSData* result = |
| 33 ExtractVoiceSearchAudioDataFromPageHTML(kInvalidVoiceSearchHTML); |
| 34 EXPECT_TRUE(result == nil); |
| 35 } |
OLD | NEW |