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

Side by Side Diff: ios/chrome/browser/upgrade/upgrade_center_unittest.mm

Issue 2684073007: [ObjC ARC] Converts ios/chrome/browser/upgrade:unit_tests to ARC. (Closed)
Patch Set: Created 3 years, 10 months 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
« no previous file with comments | « ios/chrome/browser/upgrade/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chrome/browser/upgrade/upgrade_center.h" 5 #import "ios/chrome/browser/upgrade/upgrade_center.h"
6 6
7 #include "base/mac/scoped_nsobject.h"
8 #include "ios/chrome/browser/upgrade/upgrade_recommended_details.h" 7 #include "ios/chrome/browser/upgrade/upgrade_recommended_details.h"
9 #include "testing/platform_test.h" 8 #include "testing/platform_test.h"
10 9
10 #if !defined(__has_feature) || !__has_feature(objc_arc)
11 #error "This file requires ARC support."
12 #endif
13
11 namespace { 14 namespace {
12 15
13 class UpgradeCenterTest : public PlatformTest { 16 class UpgradeCenterTest : public PlatformTest {
14 public: 17 public:
15 unsigned int count_; 18 unsigned int count_;
16 19
17 protected: 20 protected:
18 void SetUp() override { 21 void SetUp() override {
19 [[UpgradeCenter sharedInstance] resetForTests]; 22 [[UpgradeCenter sharedInstance] resetForTests];
20 count_ = 0; 23 count_ = 0;
21 }; 24 };
22 25
23 void TearDown() override { [[UpgradeCenter sharedInstance] resetForTests]; } 26 void TearDown() override { [[UpgradeCenter sharedInstance] resetForTests]; }
24 }; 27 };
25 28
26 } // namespace 29 } // namespace
27 30
28 @interface FakeUpgradeCenterClient : NSObject<UpgradeCenterClientProtocol> 31 @interface FakeUpgradeCenterClient : NSObject<UpgradeCenterClientProtocol>
29 - (instancetype)initWithTest:(UpgradeCenterTest*)test; 32 - (instancetype)initWithTest:(UpgradeCenterTest*)test;
30 @end 33 @end
31 34
32 @implementation FakeUpgradeCenterClient { 35 @implementation FakeUpgradeCenterClient {
33 UpgradeCenterTest* test_; // weak 36 UpgradeCenterTest* test_; // weak
sdefresne 2017/02/10 10:17:43 Remove "// weak".
lody 2017/02/13 10:47:14 Done.
34 } 37 }
35 38
36 - (instancetype)initWithTest:(UpgradeCenterTest*)test { 39 - (instancetype)initWithTest:(UpgradeCenterTest*)test {
37 self = [super init]; 40 self = [super init];
38 if (self) { 41 if (self) {
39 test_ = test; 42 test_ = test;
40 } 43 }
41 return self; 44 return self;
42 } 45 }
43 46
44 - (void)showUpgrade:(UpgradeCenter*)center { 47 - (void)showUpgrade:(UpgradeCenter*)center {
45 test_->count_ += 1; 48 test_->count_ += 1;
46 } 49 }
47 50
48 @end 51 @end
49 52
50 namespace { 53 namespace {
51 54
52 TEST_F(UpgradeCenterTest, NoUpgrade) { 55 TEST_F(UpgradeCenterTest, NoUpgrade) {
53 EXPECT_EQ(count_, 0u); 56 EXPECT_EQ(count_, 0u);
54 base::scoped_nsobject<FakeUpgradeCenterClient> fake( 57 FakeUpgradeCenterClient* fake =
55 [[FakeUpgradeCenterClient alloc] initWithTest:this]); 58 [[FakeUpgradeCenterClient alloc] initWithTest:this];
56 [[UpgradeCenter sharedInstance] registerClient:fake]; 59 [[UpgradeCenter sharedInstance] registerClient:fake];
57 EXPECT_EQ(count_, 0u); 60 EXPECT_EQ(count_, 0u);
58 [[UpgradeCenter sharedInstance] unregisterClient:fake]; 61 [[UpgradeCenter sharedInstance] unregisterClient:fake];
59 }; 62 };
60 63
61 TEST_F(UpgradeCenterTest, GoodUpgradeAfterRegistration) { 64 TEST_F(UpgradeCenterTest, GoodUpgradeAfterRegistration) {
62 EXPECT_EQ(count_, 0u); 65 EXPECT_EQ(count_, 0u);
63 base::scoped_nsobject<FakeUpgradeCenterClient> fake( 66 FakeUpgradeCenterClient* fake =
64 [[FakeUpgradeCenterClient alloc] initWithTest:this]); 67 [[FakeUpgradeCenterClient alloc] initWithTest:this];
65 [[UpgradeCenter sharedInstance] registerClient:fake]; 68 [[UpgradeCenter sharedInstance] registerClient:fake];
66 EXPECT_EQ(count_, 0u); 69 EXPECT_EQ(count_, 0u);
67 70
68 UpgradeRecommendedDetails details; 71 UpgradeRecommendedDetails details;
69 details.next_version = "9999.9999.9999.9999"; 72 details.next_version = "9999.9999.9999.9999";
70 details.upgrade_url = GURL("http://foobar.org"); 73 details.upgrade_url = GURL("http://foobar.org");
71 [[UpgradeCenter sharedInstance] upgradeNotificationDidOccur:details]; 74 [[UpgradeCenter sharedInstance] upgradeNotificationDidOccur:details];
72 EXPECT_EQ(count_, 1u); 75 EXPECT_EQ(count_, 1u);
73 [[UpgradeCenter sharedInstance] unregisterClient:fake]; 76 [[UpgradeCenter sharedInstance] unregisterClient:fake];
74 }; 77 };
75 78
76 TEST_F(UpgradeCenterTest, GoodUpgradeBeforeRegistration) { 79 TEST_F(UpgradeCenterTest, GoodUpgradeBeforeRegistration) {
77 UpgradeRecommendedDetails details; 80 UpgradeRecommendedDetails details;
78 details.next_version = "9999.9999.9999.9999"; 81 details.next_version = "9999.9999.9999.9999";
79 details.upgrade_url = GURL("http://foobar.org"); 82 details.upgrade_url = GURL("http://foobar.org");
80 [[UpgradeCenter sharedInstance] upgradeNotificationDidOccur:details]; 83 [[UpgradeCenter sharedInstance] upgradeNotificationDidOccur:details];
81 EXPECT_EQ(count_, 0u); 84 EXPECT_EQ(count_, 0u);
82 base::scoped_nsobject<FakeUpgradeCenterClient> fake( 85 FakeUpgradeCenterClient* fake =
83 [[FakeUpgradeCenterClient alloc] initWithTest:this]); 86 [[FakeUpgradeCenterClient alloc] initWithTest:this];
84 [[UpgradeCenter sharedInstance] registerClient:fake]; 87 [[UpgradeCenter sharedInstance] registerClient:fake];
85 EXPECT_EQ(count_, 1u); 88 EXPECT_EQ(count_, 1u);
86 [[UpgradeCenter sharedInstance] unregisterClient:fake]; 89 [[UpgradeCenter sharedInstance] unregisterClient:fake];
87 }; 90 };
88 91
89 TEST_F(UpgradeCenterTest, NoRepeatedDisplay) { 92 TEST_F(UpgradeCenterTest, NoRepeatedDisplay) {
90 base::scoped_nsobject<FakeUpgradeCenterClient> fake( 93 FakeUpgradeCenterClient* fake =
91 [[FakeUpgradeCenterClient alloc] initWithTest:this]); 94 [[FakeUpgradeCenterClient alloc] initWithTest:this];
92 [[UpgradeCenter sharedInstance] registerClient:fake]; 95 [[UpgradeCenter sharedInstance] registerClient:fake];
93 EXPECT_EQ(count_, 0u); 96 EXPECT_EQ(count_, 0u);
94 97
95 // First notification should display 98 // First notification should display
96 UpgradeRecommendedDetails details; 99 UpgradeRecommendedDetails details;
97 details.next_version = "9999.9999.9999.9999"; 100 details.next_version = "9999.9999.9999.9999";
98 details.upgrade_url = GURL("http://foobar.org"); 101 details.upgrade_url = GURL("http://foobar.org");
99 [[UpgradeCenter sharedInstance] upgradeNotificationDidOccur:details]; 102 [[UpgradeCenter sharedInstance] upgradeNotificationDidOccur:details];
100 EXPECT_EQ(count_, 1u); 103 EXPECT_EQ(count_, 1u);
101 104
102 // Second shouldn't, since it was just displayed. 105 // Second shouldn't, since it was just displayed.
103 [[UpgradeCenter sharedInstance] upgradeNotificationDidOccur:details]; 106 [[UpgradeCenter sharedInstance] upgradeNotificationDidOccur:details];
104 EXPECT_EQ(count_, 1u); 107 EXPECT_EQ(count_, 1u);
105 108
106 // After enough time has elapsed, it should again. 109 // After enough time has elapsed, it should again.
107 [[UpgradeCenter sharedInstance] setLastDisplayToPast]; 110 [[UpgradeCenter sharedInstance] setLastDisplayToPast];
108 [[UpgradeCenter sharedInstance] upgradeNotificationDidOccur:details]; 111 [[UpgradeCenter sharedInstance] upgradeNotificationDidOccur:details];
109 EXPECT_EQ(count_, 2u); 112 EXPECT_EQ(count_, 2u);
110 113
111 [[UpgradeCenter sharedInstance] unregisterClient:fake]; 114 [[UpgradeCenter sharedInstance] unregisterClient:fake];
112 }; 115 };
113 116
114 TEST_F(UpgradeCenterTest, NewVersionResetsInterval) { 117 TEST_F(UpgradeCenterTest, NewVersionResetsInterval) {
115 base::scoped_nsobject<FakeUpgradeCenterClient> fake( 118 FakeUpgradeCenterClient* fake =
116 [[FakeUpgradeCenterClient alloc] initWithTest:this]); 119 [[FakeUpgradeCenterClient alloc] initWithTest:this];
117 [[UpgradeCenter sharedInstance] registerClient:fake]; 120 [[UpgradeCenter sharedInstance] registerClient:fake];
118 EXPECT_EQ(count_, 0u); 121 EXPECT_EQ(count_, 0u);
119 122
120 // First notification should display 123 // First notification should display
121 UpgradeRecommendedDetails details; 124 UpgradeRecommendedDetails details;
122 details.next_version = "9999.9999.9999.9998"; 125 details.next_version = "9999.9999.9999.9998";
123 details.upgrade_url = GURL("http://foobar.org"); 126 details.upgrade_url = GURL("http://foobar.org");
124 [[UpgradeCenter sharedInstance] upgradeNotificationDidOccur:details]; 127 [[UpgradeCenter sharedInstance] upgradeNotificationDidOccur:details];
125 EXPECT_EQ(count_, 1u); 128 EXPECT_EQ(count_, 1u);
126 129
127 // Second shouldn't, since it was just displayed. 130 // Second shouldn't, since it was just displayed.
128 [[UpgradeCenter sharedInstance] upgradeNotificationDidOccur:details]; 131 [[UpgradeCenter sharedInstance] upgradeNotificationDidOccur:details];
129 EXPECT_EQ(count_, 1u); 132 EXPECT_EQ(count_, 1u);
130 133
131 // A new version should show right away though. 134 // A new version should show right away though.
132 details.next_version = "9999.9999.9999.9999"; 135 details.next_version = "9999.9999.9999.9999";
133 [[UpgradeCenter sharedInstance] upgradeNotificationDidOccur:details]; 136 [[UpgradeCenter sharedInstance] upgradeNotificationDidOccur:details];
134 EXPECT_EQ(count_, 2u); 137 EXPECT_EQ(count_, 2u);
135 138
136 [[UpgradeCenter sharedInstance] unregisterClient:fake]; 139 [[UpgradeCenter sharedInstance] unregisterClient:fake];
137 }; 140 };
138 141
139 } // namespace 142 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/upgrade/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698