OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/web/webui/mojo_facade.h" | 5 #import "ios/web/webui/mojo_facade.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #import "base/mac/scoped_nsobject.h" | 9 #import "base/mac/scoped_nsobject.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 int watch_id = 0; | 192 int watch_id = 0; |
193 EXPECT_TRUE(base::StringToInt(watch_id_as_string, &watch_id)); | 193 EXPECT_TRUE(base::StringToInt(watch_id_as_string, &watch_id)); |
194 | 194 |
195 // Start waiting for the watch callback. | 195 // Start waiting for the watch callback. |
196 __block bool callback_received = false; | 196 __block bool callback_received = false; |
197 NSString* expected_script = | 197 NSString* expected_script = |
198 [NSString stringWithFormat:@"__crWeb.mojo.signalWatch(%d, %d)", | 198 [NSString stringWithFormat:@"__crWeb.mojo.signalWatch(%d, %d)", |
199 callback_id, MOJO_RESULT_OK]; | 199 callback_id, MOJO_RESULT_OK]; |
200 [[[evaluator() expect] andDo:^(NSInvocation*) { | 200 [[[evaluator() expect] andDo:^(NSInvocation*) { |
201 callback_received = true; | 201 callback_received = true; |
| 202 |
| 203 // Cancel the watch immediately to ensure there are no additional |
| 204 // notifications. |
| 205 NSDictionary* cancel_watch = @{ |
| 206 @"name" : @"support.cancelWatch", |
| 207 @"args" : @{ |
| 208 @"watchId" : @(watch_id), |
| 209 }, |
| 210 }; |
| 211 std::string result_as_string = |
| 212 facade()->HandleMojoMessage(GetJson(cancel_watch)); |
| 213 EXPECT_TRUE(result_as_string.empty()); |
202 }] executeJavaScript:expected_script completionHandler:nil]; | 214 }] executeJavaScript:expected_script completionHandler:nil]; |
203 | 215 |
204 // Write to the other end of the pipe. | 216 // Write to the other end of the pipe. |
205 NSDictionary* write = @{ | 217 NSDictionary* write = @{ |
206 @"name" : @"core.writeMessage", | 218 @"name" : @"core.writeMessage", |
207 @"args" : @{ | 219 @"args" : @{ |
208 @"handle" : handle1, | 220 @"handle" : handle1, |
209 @"handles" : @[], | 221 @"handles" : @[], |
210 @"flags" : @(MOJO_WRITE_MESSAGE_FLAG_NONE), | 222 @"flags" : @(MOJO_WRITE_MESSAGE_FLAG_NONE), |
211 @"buffer" : @{@"0" : @0} | 223 @"buffer" : @{@"0" : @0} |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 NSDictionary* message = GetObject(facade()->HandleMojoMessage(GetJson(read))); | 283 NSDictionary* message = GetObject(facade()->HandleMojoMessage(GetJson(read))); |
272 EXPECT_TRUE([message isKindOfClass:[NSDictionary class]]); | 284 EXPECT_TRUE([message isKindOfClass:[NSDictionary class]]); |
273 EXPECT_TRUE(message); | 285 EXPECT_TRUE(message); |
274 NSArray* expected_message = @[ @9, @2, @216 ]; // 2008 does not fit 8-bit. | 286 NSArray* expected_message = @[ @9, @2, @216 ]; // 2008 does not fit 8-bit. |
275 EXPECT_NSEQ(expected_message, message[@"buffer"]); | 287 EXPECT_NSEQ(expected_message, message[@"buffer"]); |
276 EXPECT_FALSE([message[@"handles"] count]); | 288 EXPECT_FALSE([message[@"handles"] count]); |
277 EXPECT_EQ(MOJO_RESULT_OK, [message[@"result"] unsignedIntValue]); | 289 EXPECT_EQ(MOJO_RESULT_OK, [message[@"result"] unsignedIntValue]); |
278 } | 290 } |
279 | 291 |
280 } // namespace web | 292 } // namespace web |
OLD | NEW |