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

Unified Diff: ios/chrome/browser/voice/text_to_speech_parser_unittest.mm

Issue 2449593002: [ios] Adds support for parsing Text-to-Speech search results. (Closed)
Patch Set: Fix AVFoundation dependency. Created 4 years, 2 months 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 side-by-side diff with in-line comments
Download patch
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);
+}

Powered by Google App Engine
This is Rietveld 408576698