| Index: ios/chrome/browser/voice/text_to_speech_parser_unittest.mm
|
| diff --git a/ios/chrome/browser/voice/text_to_speech_parser_unittest.mm b/ios/chrome/browser/voice/text_to_speech_parser_unittest.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..67cc9223346f58c58d96ab4185c6ad709823dfa6
|
| --- /dev/null
|
| +++ b/ios/chrome/browser/voice/text_to_speech_parser_unittest.mm
|
| @@ -0,0 +1,35 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#import <Foundation/Foundation.h>
|
| +
|
| +#import "ios/chrome/browser/voice/text_to_speech_parser.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#import "third_party/google_toolbox_for_mac/src/Foundation/GTMStringEncoding.h"
|
| +
|
| +// Expose internal parser function for testing.
|
| +NSData* ExtractVoiceSearchAudioDataFromPageHTML(NSString* pageHTML);
|
| +
|
| +namespace {
|
| +NSString* const kValidVoiceSearchHTML =
|
| + @"<script>(function(){var _a_tts='dGVzdGF1ZG8zMm9pbw==';var _m_tts= {}}";
|
| +NSString* const kInvalidVoiceSearchHTML = @"no TTS data";
|
| +} // namespace
|
| +
|
| +TEST(TextToSpeechParser, ExtractAudioDataValid) {
|
| + NSData* result =
|
| + ExtractVoiceSearchAudioDataFromPageHTML(kValidVoiceSearchHTML);
|
| +
|
| + EXPECT_TRUE(result != nil);
|
| +
|
| + GTMStringEncoding* base64 = [GTMStringEncoding rfc4648Base64StringEncoding];
|
| + NSData* expectedData = [base64 decode:@"dGVzdGF1ZG8zMm9pbw=="];
|
| + EXPECT_TRUE([expectedData isEqualToData:result]);
|
| +}
|
| +
|
| +TEST(TextToSpeechParser, ExtractAudioDataNotFound) {
|
| + NSData* result =
|
| + ExtractVoiceSearchAudioDataFromPageHTML(kInvalidVoiceSearchHTML);
|
| + EXPECT_TRUE(result == nil);
|
| +}
|
|
|