diff --git a/ooniprobe/Test/RunningTest.h b/ooniprobe/Test/RunningTest.h index da0becbf..57daecd5 100644 --- a/ooniprobe/Test/RunningTest.h +++ b/ooniprobe/Test/RunningTest.h @@ -16,6 +16,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, strong) AbstractSuite *testSuite; @property (nonatomic, strong) AbstractTest *testRunning; @property (nonatomic) BOOL isTestRunning; +@property (nonatomic) NSMutableArray *iTestSuites; @end diff --git a/ooniprobe/Test/RunningTest.m b/ooniprobe/Test/RunningTest.m index b6b2e24c..0deed59b 100644 --- a/ooniprobe/Test/RunningTest.m +++ b/ooniprobe/Test/RunningTest.m @@ -27,6 +27,7 @@ -(void)clearSuites { } -(void)setAndRun:(NSMutableArray*)testSuites { + self.iTestSuites= [testSuites mutableCopy]; @synchronized(self) { currentTest.testSuites = testSuites; diff --git a/ooniprobe/View/RunTest/ProgressViewController.m b/ooniprobe/View/RunTest/ProgressViewController.m index 4188a554..d03b30c1 100644 --- a/ooniprobe/View/RunTest/ProgressViewController.m +++ b/ooniprobe/View/RunTest/ProgressViewController.m @@ -46,13 +46,28 @@ -(void)testStarted:(NSNotification *)notification{ -(void)updateProgress:(NSNotification *)notification{ NSDictionary *userInfo = notification.userInfo; NSNumber *prog = [userInfo objectForKey:@"prog"]; + int totalRuntime = 0; + for (AbstractSuite *n in [RunningTest currentTest].iTestSuites) { + totalRuntime += n.getRuntime; + } + + float previousProgress = 0; + for (AbstractSuite *n in [RunningTest currentTest].iTestSuites) { + if (![[RunningTest currentTest].testSuites containsObject:n]) { + previousProgress += n.getRuntime; + } + } float totalTests = [RunningTest currentTest].testSuite.totalTests; int index = [RunningTest currentTest].testSuite.measurementIdx; float prevProgress = index/totalTests; - float progress = ([prog floatValue]/totalTests)+prevProgress; - dispatch_async(dispatch_get_main_queue(), ^{ - [self.progressBar setProgress:progress animated:YES]; - }); + if (totalRuntime > 0){ + float ratio = [RunningTest currentTest].testSuite.getRuntime/(float)totalRuntime; + float progress = ([prog floatValue]/totalTests)+prevProgress; + progress = ((previousProgress/(float)totalRuntime)+(progress*ratio)); + dispatch_async(dispatch_get_main_queue(), ^{ + [self.progressBar setProgress:progress animated:YES]; + }); + } } -(void)networkTestEndedUI{ diff --git a/ooniprobe/View/RunTest/TestRunningViewController.m b/ooniprobe/View/RunTest/TestRunningViewController.m index 8a81f79b..ba4b76c9 100644 --- a/ooniprobe/View/RunTest/TestRunningViewController.m +++ b/ooniprobe/View/RunTest/TestRunningViewController.m @@ -37,9 +37,6 @@ - (void)viewDidLoad { [[UIApplication sharedApplication] setIdleTimerDisabled:YES]; if ([RunningTest currentTest].isTestRunning) [self testStart]; - if ([[ReachabilityManager sharedManager] isVPNConnected]) - [MessageUtility alertWithTitle:NSLocalizedString(@"Modal.DisableVPN.Title", nil) - message:NSLocalizedString(@"Modal.DisableVPN.Message", nil) inView:self]; } -(void)viewDidAppear:(BOOL)animated{ @@ -73,7 +70,11 @@ -(void)testStart{ -(void)setRuntime{ dispatch_async(dispatch_get_main_queue(), ^{ - self.totalRuntime = [[RunningTest currentTest].testSuite getRuntime]; + int sum = 0; + for (AbstractSuite *n in [RunningTest currentTest].iTestSuites) { + sum += n.getRuntime; + } + self.totalRuntime = sum; //We don't want to show -1 seconds before downloading the URL list if (self.totalRuntime <= [MAX_RUNTIME_DISABLED intValue]) return; @@ -121,21 +122,31 @@ -(void)updateProgress:(NSNotification *)notification{ NSNumber *prog = [userInfo objectForKey:@"prog"]; //TODO-2.1 this doesn't take in consideration different test runtimes, only the total //But still fixes https://github.com/ooni/probe/issues/805 + float previousProgress = 0; + for (AbstractSuite *n in [RunningTest currentTest].iTestSuites) { + if (![[RunningTest currentTest].testSuites containsObject:n]) { + previousProgress += n.getRuntime; + } + } float totalTests = [RunningTest currentTest].testSuite.totalTests; int index = [RunningTest currentTest].testSuite.measurementIdx; float prevProgress = index/totalTests; - float progress = ([prog floatValue]/totalTests)+prevProgress; - long eta = self.totalRuntime; - if (progress > 0) { - eta = lroundf(self.totalRuntime - progress * self.totalRuntime); - } + if (self.totalRuntime > 0){ + float ratio = [RunningTest currentTest].testSuite.getRuntime/(float)self.totalRuntime; + float progress = ([prog floatValue]/totalTests)+prevProgress; + progress = ((previousProgress/(float)self.totalRuntime)+(progress*ratio)); + long eta = self.totalRuntime; + if (progress > 0) { + eta = lroundf(self.totalRuntime - progress * self.totalRuntime); + } - dispatch_async(dispatch_get_main_queue(), ^{ - [self.progressBar setProgress:progress animated:YES]; - NSString *time = NSLocalizedFormatString(@"Dashboard.Running.Seconds", [NSString stringWithFormat:@"%ld", eta]); - [self.timeLabel setText:time]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self.progressBar setProgress:progress animated:YES]; + NSString *time = NSLocalizedFormatString(@"Dashboard.Running.Seconds", [NSString stringWithFormat:@"%ld", eta]); + [self.timeLabel setText:time]; - }); + }); + } [self.animation playWithCompletion:^(BOOL animationFinished) {}]; } @@ -164,11 +175,11 @@ -(void)networkTestEndedUI{ -(void)showError{ UIAlertAction* okButton = [UIAlertAction - actionWithTitle:NSLocalizedString(@"Modal.OK", nil) - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { - [self dismissViewControllerAnimated:YES completion:nil]; - }]; + actionWithTitle:NSLocalizedString(@"Modal.OK", nil) + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { + [self dismissViewControllerAnimated:YES completion:nil]; + }]; [MessageUtility alertWithTitle:NSLocalizedString(@"Modal.Error", nil) message:NSLocalizedString(@"Modal.Error.CantDownloadURLs", nil) okButton:okButton @@ -178,11 +189,11 @@ -(void)showError{ -(IBAction)cancelTest:(id)sender{ UIAlertAction* okButton = [UIAlertAction - actionWithTitle:NSLocalizedString(@"Modal.OK", nil) - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { - [[NSNotificationCenter defaultCenter] postNotificationName:@"interruptTest" object:nil]; - }]; + actionWithTitle:NSLocalizedString(@"Modal.OK", nil) + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { + [[NSNotificationCenter defaultCenter] postNotificationName:@"interruptTest" object:nil]; + }]; [MessageUtility alertWithTitle:NSLocalizedString(@"Modal.InterruptTest.Title", nil) message:NSLocalizedString(@"Modal.InterruptTest.Paragraph", nil) okButton:okButton