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

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

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

Powered by Google App Engine
This is Rietveld 408576698