Skip to content

Commit

Permalink
Revert "Log MobileDownloadFileUIInstallGoogleDrive in New Download Ma…
Browse files Browse the repository at this point in the history
…nager."

This reverts commit 247dee2.

Reason for revert: Failing on iOS 10 32-bit builder.

Original change's description:
> Log MobileDownloadFileUIInstallGoogleDrive in New Download Manager.
> 
> This CL also changes InstallationNotifier class to be compatible
> with OCMock (UIApplication shared instance is not stored in ivar anymore)
> and adds resetDispatcher method to allow restoring InstallationNotifier
> to its default state.
> 
> Bug: 791806
> Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
> Change-Id: Iaee0d80938639d23862b254732eb49c97ddd4e86
> Reviewed-on: https://chromium-review.googlesource.com/958123
> Commit-Queue: Eugene But <eugenebut@chromium.org>
> Reviewed-by: Peter Lee <pkl@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#543515}

TBR=eugenebut@chromium.org,pkl@chromium.org

Change-Id: I4c90614507c14322c6ab946ac4f8caeedc214cc3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 791806
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Reviewed-on: https://chromium-review.googlesource.com/966682
Reviewed-by: Eugene But <eugenebut@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543721}
  • Loading branch information
Eugene But authored and Commit Bot committed Mar 16, 2018
1 parent 31afadd commit 84b7b56
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 145 deletions.
1 change: 0 additions & 1 deletion ios/chrome/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ source_set("unit_tests") {
"//net",
"//net:test_support",
"//testing/gtest",
"//third_party/ocmock",
"//url",
]
}
2 changes: 0 additions & 2 deletions ios/chrome/browser/download/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ source_set("download") {
"browser_download_service_factory.mm",
"download_directory_util.cc",
"download_directory_util.h",
"download_manager_metric_names.cc",
"download_manager_metric_names.h",
"download_manager_tab_helper.h",
"download_manager_tab_helper.mm",
"download_manager_tab_helper_delegate.h",
Expand Down
8 changes: 0 additions & 8 deletions ios/chrome/browser/download/download_manager_metric_names.cc

This file was deleted.

12 changes: 0 additions & 12 deletions ios/chrome/browser/download/download_manager_metric_names.h

This file was deleted.

13 changes: 10 additions & 3 deletions ios/chrome/browser/installation_notifier.mm
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ - (void)dispatchInstallationNotifierBlock;
@interface InstallationNotifier (Testing)
// Sets the dispatcher.
- (void)setDispatcher:(id<DispatcherProtocol>)dispatcher;
// Sets the UIApplication used to determine if a scheme can be opened by an
// application.
- (void)setSharedApplication:(UIApplication*)sharedApplication;
@end

@implementation InstallationNotifier {
Expand Down Expand Up @@ -86,6 +89,7 @@ - (instancetype)init {
_dispatcher = [[DefaultDispatcher alloc] init];
_installedAppObservers = [[NSMutableDictionary alloc] init];
_notificationCenter = [NSNotificationCenter defaultCenter];
sharedApplication_ = [UIApplication sharedApplication];
_backoffEntry.reset(new net::BackoffEntry([self backOffPolicy]));
}
return self;
Expand Down Expand Up @@ -182,7 +186,7 @@ - (void)pollForTheInstallationOfApps {
DCHECK([observers count] > 0);
NSURL* testSchemeURL =
[NSURL URLWithString:[NSString stringWithFormat:@"%@:", scheme]];
if ([[UIApplication sharedApplication] canOpenURL:testSchemeURL]) {
if ([sharedApplication_ canOpenURL:testSchemeURL]) {
[_notificationCenter postNotificationName:scheme object:self];
for (id weakReferenceToObserver in observers) {
id observer = [weakReferenceToObserver nonretainedObjectValue];
Expand Down Expand Up @@ -212,8 +216,11 @@ - (void)setDispatcher:(id<DispatcherProtocol>)dispatcher {
_dispatcher = dispatcher;
}

- (void)resetDispatcher {
_dispatcher = [[DefaultDispatcher alloc] init];
- (void)setSharedApplication:(id)sharedApplication {
// Verify that the test application object responds to all the selectors that
// will be called on it.
CHECK([sharedApplication respondsToSelector:@selector(canOpenURL:)]);
sharedApplication_ = (UIApplication*)sharedApplication;
}

@end
57 changes: 35 additions & 22 deletions ios/chrome/browser/installation_notifier_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "ios/web/public/test/test_web_thread.h"
#include "net/base/backoff_entry.h"
#include "testing/platform_test.h"
#import "third_party/ocmock/OCMock/OCMock.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
Expand Down Expand Up @@ -79,9 +78,27 @@ - (void)receivedNotification {

@end

@interface MockUIApplication : NSObject
// Mocks UIApplication's canOpenURL.
@end

@implementation MockUIApplication {
BOOL canOpen_;
}

- (void)setCanOpenURL:(BOOL)canOpen {
canOpen_ = canOpen;
}

- (BOOL)canOpenURL:(NSURL*)url {
return canOpen_;
}

@end

@interface InstallationNotifier (Testing)
- (void)setDispatcher:(id<DispatcherProtocol>)dispatcher;
- (void)resetDispatcher;
- (void)setSharedApplication:(id)sharedApplication;
- (void)dispatchInstallationNotifierBlock;
- (void)registerForInstallationNotifications:(id)observer
withSelector:(SEL)notificationSelector
Expand All @@ -103,16 +120,12 @@ void SetUp() override {
dispatcher_ = dispatcher;
notificationReceiver1_ = ([[MockNotificationReceiver alloc] init]);
notificationReceiver2_ = ([[MockNotificationReceiver alloc] init]);
application_ = OCMClassMock([UIApplication class]);
OCMStub([application_ sharedApplication]).andReturn(application_);
sharedApplication_ = [[MockUIApplication alloc] init];
[installationNotifier_ setSharedApplication:sharedApplication_];
[installationNotifier_ setDispatcher:dispatcher_];
histogramTester_.reset(new base::HistogramTester());
}

~InstallationNotifierTest() override {
[installationNotifier_ resetDispatcher];
}

void VerifyHistogramValidity(int expectedYes, int expectedNo) {
histogramTester_->ExpectTotalCount("NativeAppLauncher.InstallationDetected",
expectedYes + expectedNo);
Expand Down Expand Up @@ -141,12 +154,12 @@ void VerifyDelay(int pollingIteration) {
__weak FakeDispatcher* dispatcher_;
MockNotificationReceiver* notificationReceiver1_;
MockNotificationReceiver* notificationReceiver2_;
id application_;
MockUIApplication* sharedApplication_;
std::unique_ptr<base::HistogramTester> histogramTester_;
};

TEST_F(InstallationNotifierTest, RegisterWithAppAlreadyInstalled) {
OCMStub([application_ canOpenURL:[OCMArg any]]).andReturn(YES);
[sharedApplication_ setCanOpenURL:YES];
[installationNotifier_
registerForInstallationNotifications:notificationReceiver1_
withSelector:@selector(receivedNotification)
Expand All @@ -161,11 +174,11 @@ void VerifyDelay(int pollingIteration) {
}

TEST_F(InstallationNotifierTest, RegisterWithAppInstalledAfterSomeTime) {
[dispatcher_
executeAfter:10
block:^{
OCMStub([application_ canOpenURL:[OCMArg any]]).andReturn(YES);
}];
[sharedApplication_ setCanOpenURL:NO];
[dispatcher_ executeAfter:10
block:^{
[sharedApplication_ setCanOpenURL:YES];
}];
[installationNotifier_
registerForInstallationNotifications:notificationReceiver1_
withSelector:@selector(receivedNotification)
Expand All @@ -175,11 +188,11 @@ void VerifyDelay(int pollingIteration) {
}

TEST_F(InstallationNotifierTest, RegisterForTwoInstallations) {
[dispatcher_
executeAfter:10
block:^{
OCMStub([application_ canOpenURL:[OCMArg any]]).andReturn(YES);
}];
[sharedApplication_ setCanOpenURL:NO];
[dispatcher_ executeAfter:10
block:^{
[sharedApplication_ setCanOpenURL:YES];
}];
[installationNotifier_
registerForInstallationNotifications:notificationReceiver1_
withSelector:@selector(receivedNotification)
Expand All @@ -202,7 +215,7 @@ void VerifyDelay(int pollingIteration) {
}

TEST_F(InstallationNotifierTest, RegisterAndThenUnregister) {
OCMStub([application_ canOpenURL:[OCMArg any]]).andReturn(NO);
[sharedApplication_ setCanOpenURL:NO];
[dispatcher_ executeAfter:10
block:^{
[installationNotifier_
Expand All @@ -217,7 +230,7 @@ void VerifyDelay(int pollingIteration) {
}

TEST_F(InstallationNotifierTest, TestExponentialBackoff) {
OCMStub([application_ canOpenURL:[OCMArg any]]).andReturn(NO);
[sharedApplication_ setCanOpenURL:NO];
// Making sure that delay is multiplied by |multiplyFactor| every time.
[dispatcher_ executeAfter:0
block:^{
Expand Down
1 change: 0 additions & 1 deletion ios/chrome/browser/ui/download/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ source_set("unit_tests") {
"//ios/chrome/browser/ui:ui_util",
"//ios/chrome/browser/web:test_support",
"//ios/chrome/test:test_support",
"//ios/chrome/test/app:test_support",
"//ios/chrome/test/fakes",
"//ios/testing:ios_test_support",
"//ios/web/public/test",
Expand Down
19 changes: 0 additions & 19 deletions ios/chrome/browser/ui/download/download_manager_coordinator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@
#include <memory>

#import "base/logging.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/strings/sys_string_conversions.h"
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/download/download_manager_metric_names.h"
#import "ios/chrome/browser/download/download_manager_tab_helper.h"
#import "ios/chrome/browser/download/google_drive_app_util.h"
#import "ios/chrome/browser/installation_notifier.h"
#import "ios/chrome/browser/store_kit/store_kit_coordinator.h"
#import "ios/chrome/browser/ui/download/download_manager_mediator.h"
#import "ios/chrome/browser/ui/download/download_manager_view_controller.h"
Expand Down Expand Up @@ -49,10 +45,6 @@ @implementation DownloadManagerCoordinator
@synthesize animatesPresentation = _animatesPresentation;
@synthesize downloadTask = _downloadTask;

- (void)dealloc {
[[InstallationNotifier sharedInstance] unregisterForNotifications:self];
}

- (void)start {
DCHECK(self.presenter);

Expand Down Expand Up @@ -179,11 +171,6 @@ - (void)installDriveForDownloadManagerViewController:
}
[_storeKitCoordinator start];
[controller setInstallDriveButtonVisible:NO animated:YES];

[[InstallationNotifier sharedInstance]
registerForInstallationNotifications:self
withSelector:@selector(didInstallGoogleDriveApp)
forScheme:kGoogleDriveAppURLScheme];
}

- (void)downloadManagerViewControllerDidStartDownload:
Expand Down Expand Up @@ -249,10 +236,4 @@ - (void)runConfirmationDialogWithTitle:(NSString*)title
completion:nil];
}

// Called when Google Drive app is installed after starting StoreKitCoordinator.
- (void)didInstallGoogleDriveApp {
base::RecordAction(
base::UserMetricsAction(kDownloadManagerGoogleDriveInstalled));
}

@end
Loading

0 comments on commit 84b7b56

Please sign in to comment.