Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / libjingle / source / talk / app / webrtc / objctests / RTCPeerConnectionSyncObserver.m
index 6568403..c3f898a 100644 (file)
@@ -42,6 +42,9 @@
   NSMutableArray* _receivedICECandidates;
   NSMutableArray* _expectedICEConnectionChanges;
   NSMutableArray* _expectedICEGatheringChanges;
+  NSMutableArray* _expectedDataChannels;
+  NSMutableArray* _expectedStateChanges;
+  NSMutableArray* _expectedMessages;
 }
 
 - (id)init {
@@ -54,6 +57,9 @@
     _receivedICECandidates = [NSMutableArray array];
     _expectedICEConnectionChanges = [NSMutableArray array];
     _expectedICEGatheringChanges = [NSMutableArray array];
+    _expectedDataChannels = [NSMutableArray array];
+    _expectedMessages = [NSMutableArray array];
+    _expectedStateChanges = [NSMutableArray array];
   }
   return self;
 }
          [_expectedICEConnectionChanges count] == 0 &&
          [_expectedICEGatheringChanges count] == 0 &&
          [_expectedAddStreamLabels count] == 0 &&
-         [_expectedRemoveStreamLabels count] == 0;
+         [_expectedRemoveStreamLabels count] == 0 &&
+         [_expectedDataChannels count] == 0 &&
+         [_expectedStateChanges count] == 0 &&
+         [_expectedMessages count] == 0;
   // TODO(hughv): Test video state here too.
 }
 
   [_expectedICEGatheringChanges addObject:@((int)state)];
 }
 
+- (void)expectDataChannel:(NSString*)label {
+  [_expectedDataChannels addObject:label];
+}
+
+- (void)expectStateChange:(RTCDataChannelState)state {
+  [_expectedStateChanges addObject:@(state)];
+}
+
+- (void)expectMessage:(NSData*)message isBinary:(BOOL)isBinary {
+  RTCDataBuffer* buffer = [[RTCDataBuffer alloc] initWithData:message
+                                                     isBinary:isBinary];
+  [_expectedMessages addObject:buffer];
+}
+
 - (void)waitForAllExpectationsToBeSatisfied {
   // TODO (fischman):  Revisit.  Keeping in sync with the Java version, but
   // polling is not optimal.
   NSAssert(expectedState == (int)newState, @"Empty expectation array");
 }
 
+- (void)peerConnection:(RTCPeerConnection*)peerConnection
+    didOpenDataChannel:(RTCDataChannel*)dataChannel {
+  NSString* expectedLabel =
+      [self popFirstElementAsNSString:_expectedDataChannels];
+  NSAssert([expectedLabel isEqual:dataChannel.label],
+           @"Data channel not expected");
+  self.dataChannel = dataChannel;
+  dataChannel.delegate = self;
+  NSAssert(kRTCDataChannelStateConnecting == dataChannel.state,
+           @"Unexpected state");
+}
+
+#pragma mark - RTCDataChannelDelegate
+
+- (void)channelDidChangeState:(RTCDataChannel*)channel {
+  NSAssert([_expectedStateChanges count] > 0,
+           @"Unexpected state change");
+  int expectedState = [self popFirstElementAsInt:_expectedStateChanges];
+  NSAssert(expectedState == channel.state, @"Channel state should match");
+}
+
+- (void)channel:(RTCDataChannel*)channel
+    didReceiveMessageWithBuffer:(RTCDataBuffer*)buffer {
+  NSAssert([_expectedMessages count] > 0,
+           @"Unexpected message received");
+  RTCDataBuffer* expectedBuffer = [_expectedMessages objectAtIndex:0];
+  NSAssert(expectedBuffer.isBinary == buffer.isBinary,
+           @"Buffer isBinary should match");
+  NSAssert([expectedBuffer.data isEqual:buffer.data],
+           @"Buffer data should match");
+  [_expectedMessages removeObjectAtIndex:0];
+}
+
 @end