FIRCLSReportManagerTests.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. // Copyright 2019 Google
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import <Foundation/Foundation.h>
  15. #import <XCTest/XCTest.h>
  16. #import <FirebaseCore/FIRLogger.h>
  17. #if __has_include(<FBLPromises/FBLPromises.h>)
  18. #import <FBLPromises/FBLPromises.h>
  19. #else
  20. #import "FBLPromises.h"
  21. #endif
  22. #include "FIRAEvent+Internal.h"
  23. #include "FIRCLSContext.h"
  24. #import "FIRCLSDataCollectionArbiter.h"
  25. #include "FIRCLSDefines.h"
  26. #import "FIRCLSInternalReport.h"
  27. #import "FIRCLSSettings.h"
  28. #import "FABMockApplicationIdentifierModel.h"
  29. #import "FIRAppFake.h"
  30. #import "FIRCLSMockFileManager.h"
  31. #import "FIRCLSMockReportManager.h"
  32. #import "FIRCLSMockReportUploader.h"
  33. #import "FIRMockInstanceID.h"
  34. #define TEST_API_KEY (@"DB5C8FA65C0D43419120FB96CFDBDE0C")
  35. #define TEST_GOOGLE_APP_ID (@"1:632950151350:ios:d5b0d08d4f00f4b1")
  36. #define TEST_INSTALL_ID (@"DC352568-33A7-4830-A9D8-20EA708F1905")
  37. #define TEST_API_ENDPOINT (@"http://test.com")
  38. #define TEST_BUNDLE_ID (@"com.crashlytics.test")
  39. #define TEST_ANALYTICS_JSON \
  40. (@"{\"name\":\"some_name\",\"nested\":{\"object\":\"with_stuff\"},\"price\":100}")
  41. @interface FIRCLSReportManagerTests : XCTestCase
  42. @property(nonatomic, strong) FIRCLSMockFileManager *fileManager;
  43. @property(nonatomic, strong) FIRCLSMockReportManager *reportManager;
  44. @property(nonatomic, strong) FIRCLSDataCollectionArbiter *dataArbiter;
  45. @end
  46. @implementation FIRCLSReportManagerTests
  47. - (void)setUp {
  48. [super setUp];
  49. FIRSetLoggerLevel(FIRLoggerLevelMax);
  50. FIRCLSContextBaseInit();
  51. id fakeApp = [[FIRAppFake alloc] init];
  52. self.dataArbiter = [[FIRCLSDataCollectionArbiter alloc] initWithApp:fakeApp withAppInfo:@{}];
  53. self.fileManager = [[FIRCLSMockFileManager alloc] init];
  54. [self.fileManager setPathNamespace:TEST_BUNDLE_ID];
  55. // Delete cached settings
  56. [self.fileManager removeItemAtPath:_fileManager.settingsFilePath];
  57. FIRMockInstanceID *iid = [[FIRMockInstanceID alloc] initWithIID:@"test_token"];
  58. FABMockApplicationIdentifierModel *appIDModel = [[FABMockApplicationIdentifierModel alloc] init];
  59. appIDModel.bundleID = TEST_BUNDLE_ID;
  60. self.reportManager = [[FIRCLSMockReportManager alloc] initWithFileManager:self.fileManager
  61. instanceID:iid
  62. analytics:nil
  63. googleAppID:TEST_GOOGLE_APP_ID
  64. dataArbiter:self.dataArbiter
  65. appIDModel:appIDModel];
  66. self.reportManager.bundleIdentifier = TEST_BUNDLE_ID;
  67. }
  68. - (void)tearDown {
  69. self.reportManager = nil;
  70. if ([[NSFileManager defaultManager] fileExistsAtPath:[self.fileManager rootPath]]) {
  71. assert([self.fileManager removeItemAtPath:[self.fileManager rootPath]]);
  72. }
  73. FIRCLSContextBaseDeinit();
  74. [super tearDown];
  75. }
  76. #pragma mark - Path Helpers
  77. - (NSString *)resourcePath {
  78. return [[NSBundle bundleForClass:[self class]] resourcePath];
  79. }
  80. - (NSArray *)contentsOfActivePath {
  81. return [[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.fileManager.activePath
  82. error:nil];
  83. }
  84. - (NSArray *)contentsOfPreparedPath {
  85. return [[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.fileManager.preparedPath
  86. error:nil];
  87. }
  88. - (NSArray *)contentsOfProcessingPath {
  89. return [[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.fileManager.processingPath
  90. error:nil];
  91. }
  92. #pragma mark - Report Helpers
  93. - (FIRCLSInternalReport *)createActiveReport {
  94. NSString *reportPath =
  95. [self.fileManager.activePath stringByAppendingPathComponent:@"my_session_id"];
  96. FIRCLSInternalReport *report = [[FIRCLSInternalReport alloc] initWithPath:reportPath
  97. executionIdentifier:@"my_session_id"];
  98. if (![self.fileManager createDirectoryAtPath:report.path]) {
  99. return nil;
  100. }
  101. if (![self createMetadata:
  102. @"{\"identity\":{\"api_key\":\"my_key\",\"session_id\":\"my_session_id\"}}\n"
  103. forReport:report]) {
  104. return nil;
  105. }
  106. return report;
  107. }
  108. - (BOOL)createFileWithContents:(NSString *)contents atPath:(NSString *)path {
  109. NSLog(@"path: %@", path);
  110. return [self.fileManager.underlyingFileManager
  111. createFileAtPath:path
  112. contents:[contents dataUsingEncoding:NSUTF8StringEncoding]
  113. attributes:nil];
  114. }
  115. - (BOOL)createMetadata:(NSString *)value forReport:(FIRCLSInternalReport *)report {
  116. return [self createFileWithContents:value atPath:[report metadataPath]];
  117. }
  118. #pragma mark - Property Helpers
  119. - (NSArray *)prepareAndSubmitReportArray {
  120. return self.reportManager.uploader.prepareAndSubmitReportArray;
  121. }
  122. - (NSArray *)uploadReportArray {
  123. return self.reportManager.uploader.uploadReportArray;
  124. }
  125. - (NSString *)installID {
  126. return TEST_INSTALL_ID;
  127. }
  128. - (nonnull NSString *)bundleIdentifier {
  129. return TEST_BUNDLE_ID;
  130. }
  131. - (nonnull NSString *)googleAppID {
  132. return TEST_GOOGLE_APP_ID;
  133. }
  134. #pragma mark - File/Directory Handling
  135. - (void)testCreatesNewReportOnStart {
  136. FBLPromise<NSNumber *> *promise = [self->_reportManager startWithProfilingMark:0];
  137. XCTestExpectation *expectation =
  138. [[XCTestExpectation alloc] initWithDescription:@"waiting on promise"];
  139. [promise then:^id _Nullable(NSNumber *_Nullable value) {
  140. XCTAssertTrue([value boolValue]);
  141. XCTAssertEqual([[self contentsOfActivePath] count], 1);
  142. [expectation fulfill];
  143. return value;
  144. }];
  145. [self waitForExpectations:@[ expectation ] timeout:1.0];
  146. }
  147. - (void)waitForPromise:(FBLPromise<NSNumber *> *)promise {
  148. __block NSNumber *value = nil;
  149. __block NSError *error = nil;
  150. XCTestExpectation *expectation =
  151. [[XCTestExpectation alloc] initWithDescription:@"waiting on promise"];
  152. [[promise then:^id _Nullable(NSNumber *_Nullable innerValue) {
  153. value = innerValue;
  154. [expectation fulfill];
  155. return nil;
  156. }] catch:^(NSError *_Nonnull innerError) {
  157. error = innerError;
  158. [expectation fulfill];
  159. }];
  160. [self waitForExpectations:@[ expectation ] timeout:1.0];
  161. XCTAssertNil(error);
  162. XCTAssertTrue([value boolValue]);
  163. }
  164. - (void)startReportManager {
  165. [self waitForPromise:[self startReportManagerWithDataCollectionEnabled:YES]];
  166. }
  167. - (FBLPromise<NSNumber *> *)startReportManagerWithDataCollectionEnabled:(BOOL)enabled {
  168. [self.dataArbiter setCrashlyticsCollectionEnabled:enabled];
  169. return [self.reportManager startWithProfilingMark:0];
  170. }
  171. - (void)processReports:(BOOL)send andExpectReports:(BOOL)reportsExpected {
  172. XCTestExpectation *processReportsComplete =
  173. [[XCTestExpectation alloc] initWithDescription:@"processReports: complete"];
  174. __block BOOL reportsAvailable = NO;
  175. [[[self.reportManager checkForUnsentReports] then:^id _Nullable(NSNumber *_Nullable value) {
  176. reportsAvailable = [value boolValue];
  177. if (!reportsAvailable) {
  178. return nil;
  179. }
  180. if (send) {
  181. return [self->_reportManager sendUnsentReports];
  182. } else {
  183. return [self->_reportManager deleteUnsentReports];
  184. }
  185. }] then:^id _Nullable(id _Nullable ignored) {
  186. [processReportsComplete fulfill];
  187. return nil;
  188. }];
  189. [self waitForExpectations:@[ processReportsComplete ] timeout:1.0];
  190. if (reportsExpected) {
  191. XCTAssertTrue(reportsAvailable, "should have unsent reports");
  192. } else {
  193. XCTAssertFalse(reportsAvailable, "should not have unsent reports");
  194. }
  195. }
  196. - (void)processReports:(BOOL)send {
  197. [self processReports:send andExpectReports:YES];
  198. }
  199. - (void)testExistingUnimportantReportOnStart {
  200. // create a report and put it in place
  201. [self createActiveReport];
  202. // Report should get deleted, and nothing else specials should happen.
  203. [self startReportManager];
  204. XCTAssertEqual([[self contentsOfActivePath] count], 1);
  205. XCTAssertEqual([self.prepareAndSubmitReportArray count], 0);
  206. XCTAssertEqual([self.uploadReportArray count], 0);
  207. }
  208. - (void)testExistingUnimportantReportOnStartWithDataCollectionDisabled {
  209. // create a report and put it in place
  210. [self createActiveReport];
  211. // Report should get deleted, and nothing else specials should happen.
  212. FBLPromise<NSNumber *> *promise = [self startReportManagerWithDataCollectionEnabled:NO];
  213. // It should not be necessary to call processReports, since there are no reports.
  214. [self waitForPromise:promise];
  215. XCTAssertEqual([[self contentsOfActivePath] count], 1);
  216. XCTAssertEqual([self.prepareAndSubmitReportArray count], 0);
  217. XCTAssertEqual([self.uploadReportArray count], 0);
  218. }
  219. - (void)testExistingReportOnStart {
  220. // create a report and put it in place
  221. FIRCLSInternalReport *report = [self createActiveReport];
  222. // create a signal file so it is considering worth reporting
  223. XCTAssertTrue([self createFileWithContents:@"signal"
  224. atPath:[report pathForContentFile:FIRCLSReportSignalFile]]);
  225. XCTAssertEqual([[self contentsOfActivePath] count], 1);
  226. [self startReportManager];
  227. // verify that processReports won't get called.
  228. [self processReports:YES andExpectReports:NO];
  229. XCTAssertEqual([[self contentsOfActivePath] count], 1, @"should contain only the current report");
  230. // should call report manager once for that report
  231. XCTAssertEqual([self.prepareAndSubmitReportArray count], 1);
  232. XCTAssertEqualObjects(self.prepareAndSubmitReportArray[0][@"process"], @(YES));
  233. XCTAssertEqualObjects(self.prepareAndSubmitReportArray[0][@"urgent"], @(NO));
  234. }
  235. - (void)testExistingReportOnStartWithDataCollectionDisabledThenEnabled {
  236. // create a report and put it in place
  237. FIRCLSInternalReport *report = [self createActiveReport];
  238. // create a signal file so it is considering worth reporting
  239. XCTAssertTrue([self createFileWithContents:@"signal"
  240. atPath:[report pathForContentFile:FIRCLSReportSignalFile]]);
  241. XCTAssertEqual([[self contentsOfActivePath] count], 1);
  242. FBLPromise<NSNumber *> *promise = [self startReportManagerWithDataCollectionEnabled:NO];
  243. XCTAssertEqual([[self contentsOfActivePath] count], 2,
  244. @"should contain the current and old reports");
  245. // should call report manager once for that report
  246. XCTAssertEqual([self.prepareAndSubmitReportArray count], 0);
  247. // We can turn data collection on instead of calling processReports.
  248. [self.dataArbiter setCrashlyticsCollectionEnabled:YES];
  249. [self waitForPromise:promise];
  250. XCTAssertEqual([[self contentsOfActivePath] count], 1, @"should contain only the current report");
  251. // should call report manager once for that report
  252. XCTAssertEqual([self.prepareAndSubmitReportArray count], 1);
  253. XCTAssertEqualObjects(self.prepareAndSubmitReportArray[0][@"process"], @(YES));
  254. XCTAssertEqualObjects(self.prepareAndSubmitReportArray[0][@"urgent"], @(NO));
  255. }
  256. - (void)testExistingReportOnStartWithDataCollectionDisabledAndSend {
  257. // create a report and put it in place
  258. FIRCLSInternalReport *report = [self createActiveReport];
  259. // create a signal file so it is considering worth reporting
  260. XCTAssertTrue([self createFileWithContents:@"signal"
  261. atPath:[report pathForContentFile:FIRCLSReportSignalFile]]);
  262. XCTAssertEqual([[self contentsOfActivePath] count], 1);
  263. [self startReportManagerWithDataCollectionEnabled:NO];
  264. XCTAssertEqual([[self contentsOfActivePath] count], 2,
  265. @"should contain the current and old reports");
  266. // should call report manager once for that report
  267. XCTAssertEqual([self.prepareAndSubmitReportArray count], 0);
  268. [self processReports:YES];
  269. XCTAssertEqual([[self contentsOfActivePath] count], 1, @"should contain only the current report");
  270. // should call report manager once for that report
  271. XCTAssertEqual([self.prepareAndSubmitReportArray count], 1);
  272. XCTAssertEqualObjects(self.prepareAndSubmitReportArray[0][@"process"], @(YES));
  273. XCTAssertEqualObjects(self.prepareAndSubmitReportArray[0][@"urgent"], @(NO));
  274. // Calling processReports again should not call the callback.
  275. // Technically, the behavior is unspecified.
  276. [self processReports:YES andExpectReports:NO];
  277. }
  278. - (void)testExistingReportOnStartWithDataCollectionDisabledAndDelete {
  279. // create a report and put it in place
  280. FIRCLSInternalReport *report = [self createActiveReport];
  281. // create a signal file so it is considering worth reporting
  282. XCTAssertTrue([self createFileWithContents:@"signal"
  283. atPath:[report pathForContentFile:FIRCLSReportSignalFile]]);
  284. XCTAssertEqual([[self contentsOfActivePath] count], 1);
  285. [self startReportManagerWithDataCollectionEnabled:NO];
  286. XCTAssertEqual([[self contentsOfActivePath] count], 2,
  287. @"should contain the current and old reports");
  288. // should call report manager once for that report
  289. XCTAssertEqual([self.prepareAndSubmitReportArray count], 0);
  290. [self processReports:NO];
  291. XCTAssertEqual([[self contentsOfActivePath] count], 1, @"should contain only the current report");
  292. // Should not call report manager for that report.
  293. XCTAssertEqual([self.prepareAndSubmitReportArray count], 0);
  294. }
  295. - (void)testExistingUrgentReportOnStart {
  296. // create a report and put it in place
  297. FIRCLSInternalReport *report = [self createActiveReport];
  298. // create a signal file so it is considering worth reporting
  299. XCTAssertTrue([self createFileWithContents:@"signal"
  300. atPath:[report pathForContentFile:FIRCLSReportSignalFile]]);
  301. XCTAssertEqual([[self contentsOfActivePath] count], 1);
  302. // Put the launch marker in place
  303. [self.reportManager createLaunchFailureMarker];
  304. // should call back to the delegate on start
  305. [self startReportManager];
  306. XCTAssertEqual([[self contentsOfActivePath] count], 1, @"should contain only the current report");
  307. // should call report manager once for that report
  308. XCTAssertEqual([self.prepareAndSubmitReportArray count], 1);
  309. XCTAssertEqualObjects(self.prepareAndSubmitReportArray[0][@"process"], @(YES));
  310. XCTAssertEqualObjects(self.prepareAndSubmitReportArray[0][@"urgent"], @(YES));
  311. }
  312. - (void)testExistingUrgentReportOnStartWithDataCollectionDisabled {
  313. // create a report and put it in place
  314. FIRCLSInternalReport *report = [self createActiveReport];
  315. // create a signal file so it is considering worth reporting
  316. XCTAssertTrue([self createFileWithContents:@"signal"
  317. atPath:[report pathForContentFile:FIRCLSReportSignalFile]]);
  318. XCTAssertEqual([[self contentsOfActivePath] count], 1);
  319. // Put the launch marker in place
  320. [self.reportManager createLaunchFailureMarker];
  321. // Should wait for processReports: to be called.
  322. [self startReportManagerWithDataCollectionEnabled:NO];
  323. XCTAssertEqual([[self contentsOfActivePath] count], 2, @"the report hasn't been sent");
  324. XCTAssertEqual([self.prepareAndSubmitReportArray count], 0);
  325. [self processReports:YES];
  326. XCTAssertEqual([[self contentsOfActivePath] count], 1, @"should contain only current report");
  327. XCTAssertEqual([self.prepareAndSubmitReportArray count], 1);
  328. XCTAssertEqualObjects(self.prepareAndSubmitReportArray[0][@"process"], @(YES));
  329. // If data collection is disabled, you can never send the report urgently / blocking
  330. // startup because you need to call a method after startup to send the report
  331. XCTAssertEqualObjects(self.prepareAndSubmitReportArray[0][@"urgent"], @(NO));
  332. }
  333. - (void)testFilesLeftInProcessing {
  334. // put report in processing
  335. FIRCLSInternalReport *report = [self createActiveReport];
  336. XCTAssert([_fileManager createDirectoryAtPath:_fileManager.processingPath]);
  337. XCTAssert([_fileManager moveItemAtPath:[report path] toDirectory:_fileManager.processingPath]);
  338. [self startReportManager];
  339. // we should not process reports left over in processing
  340. XCTAssertEqual([[self contentsOfProcessingPath] count], 0, @"Processing should be cleared");
  341. XCTAssertEqual([self.prepareAndSubmitReportArray count], 1);
  342. XCTAssertEqualObjects(self.prepareAndSubmitReportArray[0][@"process"], @(NO));
  343. XCTAssertEqualObjects(self.prepareAndSubmitReportArray[0][@"urgent"], @(NO));
  344. }
  345. - (void)testFilesLeftInProcessingWithDataCollectionDisabled {
  346. // Put report in processing.
  347. FIRCLSInternalReport *report = [self createActiveReport];
  348. XCTAssert([_fileManager createDirectoryAtPath:_fileManager.processingPath]);
  349. XCTAssert([_fileManager moveItemAtPath:[report path] toDirectory:_fileManager.processingPath]);
  350. [self startReportManagerWithDataCollectionEnabled:NO];
  351. // Nothing should have happened yet.
  352. XCTAssertEqual([[self contentsOfProcessingPath] count], 1,
  353. @"Processing should still have the report");
  354. XCTAssertEqual([self.prepareAndSubmitReportArray count], 0);
  355. [self processReports:YES];
  356. // We should not process reports left over in processing.
  357. XCTAssertEqual([[self contentsOfProcessingPath] count], 0, @"Processing should be cleared");
  358. XCTAssertEqual([self.prepareAndSubmitReportArray count], 1);
  359. XCTAssertEqualObjects(self.prepareAndSubmitReportArray[0][@"process"], @(NO));
  360. XCTAssertEqualObjects(self.prepareAndSubmitReportArray[0][@"urgent"], @(NO));
  361. }
  362. - (void)testFilesLeftInPrepared {
  363. // Drop a phony multipart-mime file in here, with non-zero contents.
  364. XCTAssert([_fileManager createDirectoryAtPath:_fileManager.preparedPath]);
  365. NSString *path = [_fileManager.preparedPath stringByAppendingPathComponent:@"phony-report"];
  366. path = [path stringByAppendingPathExtension:@".multipart-mime"];
  367. XCTAssertTrue([[_fileManager underlyingFileManager]
  368. createFileAtPath:path
  369. contents:[@"contents" dataUsingEncoding:NSUTF8StringEncoding]
  370. attributes:nil]);
  371. [self startReportManager];
  372. // We should not process reports left over in prepared.
  373. XCTAssertEqual([[self contentsOfPreparedPath] count], 0, @"Prepared should be cleared");
  374. XCTAssertEqual([self.prepareAndSubmitReportArray count], 0);
  375. XCTAssertEqual([self.uploadReportArray count], 1);
  376. XCTAssertEqualObjects(self.uploadReportArray[0][@"path"], path);
  377. }
  378. - (void)testFilesLeftInPreparedWithDataCollectionDisabled {
  379. // drop a phony multipart-mime file in here, with non-zero contents
  380. XCTAssert([_fileManager createDirectoryAtPath:_fileManager.preparedPath]);
  381. NSString *path = [_fileManager.preparedPath stringByAppendingPathComponent:@"phony-report"];
  382. path = [path stringByAppendingPathExtension:@".multipart-mime"];
  383. XCTAssertTrue([[_fileManager underlyingFileManager]
  384. createFileAtPath:path
  385. contents:[@"contents" dataUsingEncoding:NSUTF8StringEncoding]
  386. attributes:nil]);
  387. [self startReportManagerWithDataCollectionEnabled:NO];
  388. // Nothing should have happened yet.
  389. XCTAssertEqual([[self contentsOfPreparedPath] count], 1,
  390. @"Prepared should still have the report");
  391. XCTAssertEqual([self.prepareAndSubmitReportArray count], 0);
  392. [self processReports:YES];
  393. // we should not process reports left over in processing
  394. XCTAssertEqual([[self contentsOfPreparedPath] count], 0, @"Prepared should be cleared");
  395. XCTAssertEqual([self.prepareAndSubmitReportArray count], 0);
  396. XCTAssertEqual([self.uploadReportArray count], 1);
  397. XCTAssertEqualObjects(self.uploadReportArray[0][@"path"], path);
  398. }
  399. - (void)testSuccessfulSubmission {
  400. // drop a phony multipart-mime file in here, with non-zero contents
  401. XCTAssert([_fileManager createDirectoryAtPath:_fileManager.preparedPath]);
  402. NSString *path = [_fileManager.preparedPath stringByAppendingPathComponent:@"phony-report"];
  403. path = [path stringByAppendingPathExtension:@".multipart-mime"];
  404. XCTAssertTrue([[_fileManager underlyingFileManager]
  405. createFileAtPath:path
  406. contents:[@"contents" dataUsingEncoding:NSUTF8StringEncoding]
  407. attributes:nil]);
  408. [self startReportManager];
  409. // we should not process reports left over in processing
  410. XCTAssertEqual([[self contentsOfProcessingPath] count], 0, @"Processing should be cleared");
  411. XCTAssertEqual([self.prepareAndSubmitReportArray count], 0);
  412. XCTAssertEqual([self.uploadReportArray count], 1);
  413. XCTAssertEqualObjects(self.uploadReportArray[0][@"path"], path);
  414. // fake out the delegate callbacks
  415. [self.reportManager.operationQueue addOperationWithBlock:^{
  416. [self.reportManager didCompletePackageSubmission:path dataCollectionToken:nil error:nil];
  417. }];
  418. [self.reportManager.operationQueue addOperationWithBlock:^{
  419. [self.reportManager didCompleteAllSubmissions];
  420. }];
  421. [self.reportManager.operationQueue waitUntilAllOperationsAreFinished];
  422. // not 100% sure what to verify here
  423. }
  424. - (void)testLogInvalidJSONAnalyticsEvents {
  425. NSDictionary *eventAsDict = @{
  426. @"price" : @(NAN),
  427. @"count" : @(INFINITY),
  428. };
  429. NSString *json = FIRCLSFIRAEventDictionaryToJSON(eventAsDict);
  430. XCTAssertEqualObjects(json, nil);
  431. }
  432. @end