Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: ios/chrome/app/application_delegate/background_activity_unittest.mm

Issue 2580363002: Upstream Chrome on iOS source code [1/11]. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/chrome/app/application_delegate/background_activity.h"
6
7 #import "ios/chrome/app/application_delegate/browser_launcher.h"
8 #import "ios/chrome/app/application_delegate/metrics_mediator.h"
9 #import "ios/chrome/browser/crash_report/crash_report_background_uploader.h"
10 #import "ios/chrome/browser/metrics/previous_session_info.h"
11 #import "ios/chrome/browser/metrics/previous_session_info_private.h"
12 #import "ios/chrome/test/base/scoped_block_swizzler.h"
13 #include "testing/platform_test.h"
14 #import "third_party/ocmock/OCMock/OCMock.h"
15 #import "third_party/ocmock/gtest_support.h"
16
17 // Verifies that -application:performFetchWithCompletionHandler: calls the
18 // browser launcher in background state and uploads the report.
19 TEST(BackgroundActivityTest, performFetchWithCompletionHandler) {
20 // Setup.
21 [[PreviousSessionInfo sharedInstance] setIsFirstSessionAfterUpgrade:NO];
22
23 // MetricsMediator mock.
24 id metrics_mediator_mock =
25 [OCMockObject mockForClass:[MetricsMediator class]];
26 [[[metrics_mediator_mock stub] andReturnValue:@YES] areMetricsEnabled];
27 [[[metrics_mediator_mock stub] andReturnValue:@YES] isUploadingEnabled];
28
29 // BrowserLauncher mock.
30 id browser_launcher =
31 [OCMockObject mockForProtocol:@protocol(BrowserLauncher)];
32 [[browser_launcher expect]
33 startUpBrowserToStage:INITIALIZATION_STAGE_BACKGROUND];
34
35 // CrashReportBackgroundUploader swizzle.
36 __block BOOL crash_report_completion_handler_has_been_called = NO;
37 id implementation_block = ^(id self) {
38 crash_report_completion_handler_has_been_called = YES;
39 };
40 ScopedBlockSwizzler crash_report_completion_handler_swizzler(
41 [CrashReportBackgroundUploader class],
42 @selector(performFetchWithCompletionHandler:), implementation_block);
43
44 // Test.
45 [BackgroundActivity application:nil
46 performFetchWithCompletionHandler:nil
47 metricsMediator:metrics_mediator_mock
48 browserLauncher:browser_launcher];
49
50 // Check.
51 EXPECT_OCMOCK_VERIFY(browser_launcher);
52 EXPECT_TRUE(crash_report_completion_handler_has_been_called);
53 }
54
55 // Verifies that -handleEventsForBackgroundURLSession:completionHandler: calls
56 // the browser launcher in background state.
57 TEST(BackgroundActivityTest, handleEventsForBackgroundURLSession) {
58 // Setup.
59 // BrowserLauncher mock.
60 id browser_launcher =
61 [OCMockObject mockForProtocol:@protocol(BrowserLauncher)];
62 [[browser_launcher expect]
63 startUpBrowserToStage:INITIALIZATION_STAGE_BACKGROUND];
64
65 // Test.
66 [BackgroundActivity handleEventsForBackgroundURLSession:nil
67 completionHandler:^{
68 }
69 browserLauncher:browser_launcher];
70
71 // Check.
72 EXPECT_OCMOCK_VERIFY(browser_launcher);
73 }
OLDNEW
« no previous file with comments | « ios/chrome/app/application_delegate/background_activity.mm ('k') | ios/chrome/app/application_delegate/browser_launcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698