Commit 520469a7 authored by stkhapugin's avatar stkhapugin Committed by Commit bot

[ObjC ARC] Converts ios/chrome/browser/ui/voice:unit_tests to ARC.

Automatically generated ARCMigrate commit
Notable issues:None
BUG=624363
TEST=None

Review-Url: https://codereview.chromium.org/2516663002
Cr-Commit-Position: refs/heads/master@{#436295}
parent baf4f1f0
...@@ -20,6 +20,7 @@ source_set("voice") { ...@@ -20,6 +20,7 @@ source_set("voice") {
} }
source_set("unit_tests") { source_set("unit_tests") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true testonly = true
sources = [ sources = [
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#import "base/mac/scoped_nsobject.h"
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#include "base/time/time.h" #include "base/time/time.h"
#import "ios/chrome/browser/ui/voice/voice_search_notification_names.h" #import "ios/chrome/browser/ui/voice/voice_search_notification_names.h"
...@@ -17,13 +16,17 @@ ...@@ -17,13 +16,17 @@
#include "testing/platform_test.h" #include "testing/platform_test.h"
#include "url/gurl.h" #include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
#pragma mark - TTSPlayerObserver #pragma mark - TTSPlayerObserver
// Test object that listens for TTS notifications. // Test object that listens for TTS notifications.
@interface TTSPlayerObserver : NSObject @interface TTSPlayerObserver : NSObject
// The TextToSpeechPlayer passed on initialization. // The TextToSpeechPlayer passed on initialization.
@property(nonatomic, retain) TextToSpeechPlayer* player; @property(nonatomic, strong) TextToSpeechPlayer* player;
// Whether notifications have been received. // Whether notifications have been received.
@property(nonatomic, readonly) BOOL readyNotificationReceived; @property(nonatomic, readonly) BOOL readyNotificationReceived;
...@@ -37,23 +40,20 @@ ...@@ -37,23 +40,20 @@
@end @end
@implementation TTSPlayerObserver { @implementation TTSPlayerObserver
base::scoped_nsobject<TextToSpeechPlayer> _player; @synthesize player = _player;
}
@synthesize readyNotificationReceived = _readyNotificationReceived; @synthesize readyNotificationReceived = _readyNotificationReceived;
@synthesize willStartNotificationReceived = _willStartNotificationReceived; @synthesize willStartNotificationReceived = _willStartNotificationReceived;
@synthesize didStopNotificationReceived = _didStopNotificationReceived; @synthesize didStopNotificationReceived = _didStopNotificationReceived;
- (void)dealloc { - (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
} }
- (void)setPlayer:(TextToSpeechPlayer*)player { - (void)setPlayer:(TextToSpeechPlayer*)player {
NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter removeObserver:self]; [defaultCenter removeObserver:self];
_player.reset([player retain]); _player = player;
if (player) { if (player) {
[defaultCenter addObserver:self [defaultCenter addObserver:self
selector:@selector(handleReadyNotification:) selector:@selector(handleReadyNotification:)
...@@ -96,21 +96,20 @@ ...@@ -96,21 +96,20 @@
class TextToSpeechPlayerTest : public PlatformTest { class TextToSpeechPlayerTest : public PlatformTest {
protected: protected:
void SetUp() override { void SetUp() override {
tts_player_.reset([[TextToSpeechPlayer alloc] init]); tts_player_ = [[TextToSpeechPlayer alloc] init];
tts_player_observer_.reset([[TTSPlayerObserver alloc] init]); tts_player_observer_ = [[TTSPlayerObserver alloc] init];
[tts_player_observer_ setPlayer:tts_player_]; [tts_player_observer_ setPlayer:tts_player_];
} }
base::scoped_nsobject<TextToSpeechPlayer> tts_player_; TextToSpeechPlayer* tts_player_;
base::scoped_nsobject<TTSPlayerObserver> tts_player_observer_; TTSPlayerObserver* tts_player_observer_;
web::TestWebThreadBundle web_thread_bundle_; web::TestWebThreadBundle web_thread_bundle_;
}; };
// Tests that kTTSAudioReadyForPlaybackNotification is received and that // Tests that kTTSAudioReadyForPlaybackNotification is received and that
// TTSPlayer state is updated. // TTSPlayer state is updated.
TEST_F(TextToSpeechPlayerTest, ReadyForPlayback) { TEST_F(TextToSpeechPlayerTest, ReadyForPlayback) {
base::scoped_nsobject<NSData> audio_data( NSData* audio_data = [@"audio_data" dataUsingEncoding:NSUTF8StringEncoding];
[[@"audio_data" dataUsingEncoding:NSUTF8StringEncoding] retain]);
[tts_player_ prepareToPlayAudioData:audio_data]; [tts_player_ prepareToPlayAudioData:audio_data];
EXPECT_TRUE([tts_player_observer_ readyNotificationReceived]); EXPECT_TRUE([tts_player_observer_ readyNotificationReceived]);
EXPECT_TRUE([tts_player_ isReadyForPlayback]); EXPECT_TRUE([tts_player_ isReadyForPlayback]);
...@@ -119,8 +118,7 @@ TEST_F(TextToSpeechPlayerTest, ReadyForPlayback) { ...@@ -119,8 +118,7 @@ TEST_F(TextToSpeechPlayerTest, ReadyForPlayback) {
// Tests that kTTSAudioReadyForPlaybackNotification is received and that // Tests that kTTSAudioReadyForPlaybackNotification is received and that
// TTSPlayer's |-readyForPlayback| is NO for empty data. // TTSPlayer's |-readyForPlayback| is NO for empty data.
TEST_F(TextToSpeechPlayerTest, ReadyForPlaybackEmtpyData) { TEST_F(TextToSpeechPlayerTest, ReadyForPlaybackEmtpyData) {
base::scoped_nsobject<NSData> audio_data( NSData* audio_data = [@"" dataUsingEncoding:NSUTF8StringEncoding];
[[@"" dataUsingEncoding:NSUTF8StringEncoding] retain]);
[tts_player_ prepareToPlayAudioData:audio_data]; [tts_player_ prepareToPlayAudioData:audio_data];
EXPECT_TRUE([tts_player_observer_ readyNotificationReceived]); EXPECT_TRUE([tts_player_observer_ readyNotificationReceived]);
EXPECT_FALSE([tts_player_ isReadyForPlayback]); EXPECT_FALSE([tts_player_ isReadyForPlayback]);
...@@ -135,8 +133,7 @@ TEST_F(TextToSpeechPlayerTest, DISABLED_ValidPlaybackNotifications) { ...@@ -135,8 +133,7 @@ TEST_F(TextToSpeechPlayerTest, DISABLED_ValidPlaybackNotifications) {
[[NSBundle mainBundle] pathForResource:@"test_sound" [[NSBundle mainBundle] pathForResource:@"test_sound"
ofType:@"m4a" ofType:@"m4a"
inDirectory:@"ios/chrome/test/data/voice"]; inDirectory:@"ios/chrome/test/data/voice"];
base::scoped_nsobject<NSData> audio_data( NSData* audio_data = [[NSData alloc] initWithContentsOfFile:path];
[[NSData alloc] initWithContentsOfFile:path]);
[tts_player_ prepareToPlayAudioData:audio_data]; [tts_player_ prepareToPlayAudioData:audio_data];
[tts_player_ beginPlayback]; [tts_player_ beginPlayback];
EXPECT_TRUE([tts_player_observer_ willStartNotificationReceived]); EXPECT_TRUE([tts_player_observer_ willStartNotificationReceived]);
...@@ -155,8 +152,7 @@ TEST_F(TextToSpeechPlayerTest, DISABLED_BackgroundNotification) { ...@@ -155,8 +152,7 @@ TEST_F(TextToSpeechPlayerTest, DISABLED_BackgroundNotification) {
[[NSBundle mainBundle] pathForResource:@"test_sound" [[NSBundle mainBundle] pathForResource:@"test_sound"
ofType:@"m4a" ofType:@"m4a"
inDirectory:@"ios/chrome/test/data/voice"]; inDirectory:@"ios/chrome/test/data/voice"];
base::scoped_nsobject<NSData> audio_data( NSData* audio_data = [[NSData alloc] initWithContentsOfFile:path];
[[NSData alloc] initWithContentsOfFile:path]);
[tts_player_ prepareToPlayAudioData:audio_data]; [tts_player_ prepareToPlayAudioData:audio_data];
[tts_player_ beginPlayback]; [tts_player_ beginPlayback];
EXPECT_TRUE([tts_player_observer_ willStartNotificationReceived]); EXPECT_TRUE([tts_player_observer_ willStartNotificationReceived]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment