OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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/ui/ntp/notification_promo_whats_new.h" | 5 #import "ios/chrome/browser/ui/ntp/notification_promo_whats_new.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 TEST_F(NotificationPromoWhatsNewTest, NotificationPromoCommandTest) { | 130 TEST_F(NotificationPromoWhatsNewTest, NotificationPromoCommandTest) { |
131 Init("3 Aug 1999 9:26:06 GMT", "3 Aug 2199 9:26:06 GMT", | 131 Init("3 Aug 1999 9:26:06 GMT", "3 Aug 2199 9:26:06 GMT", |
132 "IDS_IOS_APP_RATING_PROMO_STRING", "0", "chrome_command", "", | 132 "IDS_IOS_APP_RATING_PROMO_STRING", "0", "chrome_command", "", |
133 "ratethisapp", "RateThisAppPromo", "logo", "0", "0"); | 133 "ratethisapp", "RateThisAppPromo", "logo", "0", "0"); |
134 RunTests(l10n_util::GetStringUTF8(IDS_IOS_APP_RATING_PROMO_STRING), | 134 RunTests(l10n_util::GetStringUTF8(IDS_IOS_APP_RATING_PROMO_STRING), |
135 "chrome_command", "", IDC_RATE_THIS_APP, WHATS_NEW_LOGO, true); | 135 "chrome_command", "", IDC_RATE_THIS_APP, WHATS_NEW_LOGO, true); |
136 } | 136 } |
137 | 137 |
138 // Test that a url-based, valid promo is shown with the correct text and icon. | 138 // Test that a url-based, valid promo is shown with the correct text and icon. |
139 TEST_F(NotificationPromoWhatsNewTest, NotificationPromoURLTest) { | 139 TEST_F(NotificationPromoWhatsNewTest, NotificationPromoURLTest) { |
140 Init("3 Aug 1999 9:26:06 GMT", "3 Aug 2199 9:26:06 GMT", "Test URL", "0", | 140 Init("3 Aug 1999 9:26:06 GMT", "3 Aug 2199 9:26:06 GMT", |
141 "url", "http://blog.chromium.org", "", "TestURLPromo", "", "0", "0"); | 141 "IDS_IOS_MOVE_TO_DOCK_TIP", "0", "url", "http://blog.chromium.org", "", |
142 RunTests("Test URL", "url", "http://blog.chromium.org/", 0, WHATS_NEW_INFO, | 142 "TestURLPromo", "", "0", "0"); |
143 true); | 143 RunTests(l10n_util::GetStringUTF8(IDS_IOS_MOVE_TO_DOCK_TIP), "url", |
| 144 "http://blog.chromium.org/", 0, WHATS_NEW_INFO, true); |
144 } | 145 } |
145 | 146 |
146 // Test that an invalid promo is not shown. | 147 // Test that a promo without a valid promo type is not shown. |
147 TEST_F(NotificationPromoWhatsNewTest, NotificationPromoInvalidTest) { | 148 TEST_F(NotificationPromoWhatsNewTest, NotificationPromoNoTypeTest) { |
148 Init("3 Aug 1999 9:26:06 GMT", "3 Aug 2199 9:26:06 GMT", "Test URL", "0", | 149 Init("3 Aug 1999 9:26:06 GMT", "3 Aug 2199 9:26:06 GMT", |
149 "url", "", "", "TestURLPromo", "", "0", "0"); | 150 "IDS_IOS_MOVE_TO_DOCK_TIP", "0", "invalid type", |
150 RunTests("Test URL", "url", "", 0, WHATS_NEW_INFO, false); | 151 "http://blog.chromium.org", "", "TestPromo", "", "0", "0"); |
| 152 EXPECT_FALSE(promo_.CanShow()); |
| 153 } |
| 154 |
| 155 // Test that a url promo with an empty url is not shown. |
| 156 TEST_F(NotificationPromoWhatsNewTest, NotificationPromoEmptyURLTest) { |
| 157 Init("3 Aug 1999 9:26:06 GMT", "3 Aug 2199 9:26:06 GMT", |
| 158 "IDS_IOS_MOVE_TO_DOCK_TIP", "0", "url", "", "", "TestURLPromo", "", "0", |
| 159 "0"); |
| 160 EXPECT_FALSE(promo_.CanShow()); |
| 161 } |
| 162 |
| 163 // Test that a url promo with an invalid url is not shown. |
| 164 TEST_F(NotificationPromoWhatsNewTest, NotificationPromoInvalidURLTest) { |
| 165 Init("3 Aug 1999 9:26:06 GMT", "3 Aug 2199 9:26:06 GMT", |
| 166 "IDS_IOS_MOVE_TO_DOCK_TIP", "0", "url", "INVALID URL", "", |
| 167 "TestURLPromo", "", "0", "0"); |
| 168 EXPECT_FALSE(promo_.CanShow()); |
| 169 } |
| 170 |
| 171 // Test that a command-based promo with an invalid command is not shown. |
| 172 TEST_F(NotificationPromoWhatsNewTest, NotificationPromoInvalidCommandTest) { |
| 173 Init("3 Aug 1999 9:26:06 GMT", "3 Aug 2199 9:26:06 GMT", |
| 174 "IDS_IOS_APP_RATING_PROMO_STRING", "0", "chrome_command", "", |
| 175 "INVALID COMMAND", "CommandPromo", "logo", "0", "0"); |
| 176 EXPECT_FALSE(promo_.CanShow()); |
| 177 } |
| 178 |
| 179 // Test that a promo without a metric name is not shown. |
| 180 TEST_F(NotificationPromoWhatsNewTest, NotificationPromoNoMetricTest) { |
| 181 Init("3 Aug 1999 9:26:06 GMT", "3 Aug 2199 9:26:06 GMT", |
| 182 "IDS_IOS_MOVE_TO_DOCK_TIP", "0", "url", "http://blog.chromium.org", "", |
| 183 "", "", "0", "0"); |
| 184 EXPECT_FALSE(promo_.CanShow()); |
| 185 } |
| 186 |
| 187 // Test that if no localized text is found, the promo is not shown. |
| 188 TEST_F(NotificationPromoWhatsNewTest, NotificationPromoNoLocalizedTextTest) { |
| 189 Init("3 Aug 1999 9:26:06 GMT", "3 Aug 2199 9:26:06 GMT", "TEST BAD STRING", |
| 190 "0", "url", "http://blog.chromium.org", "", "TestURLPromo", "", "0", |
| 191 "0"); |
| 192 EXPECT_FALSE(promo_.CanShow()); |
151 } | 193 } |
152 | 194 |
153 // Test that if max_seconds_since_install is set, and the current time is before | 195 // Test that if max_seconds_since_install is set, and the current time is before |
154 // the cut off, the promo still shows. | 196 // the cut off, the promo still shows. |
155 TEST_F(NotificationPromoWhatsNewTest, MaxSecondsSinceInstallSuccessTest) { | 197 TEST_F(NotificationPromoWhatsNewTest, MaxSecondsSinceInstallSuccessTest) { |
156 // Init with max_seconds_since_install set to 2 days. | 198 // Init with max_seconds_since_install set to 2 days. |
157 Init("3 Aug 1999 9:26:06 GMT", "3 Aug 2199 9:26:06 GMT", | 199 Init("3 Aug 1999 9:26:06 GMT", "3 Aug 2199 9:26:06 GMT", |
158 "IDS_IOS_APP_RATING_PROMO_STRING", "0", "chrome_command", "", | 200 "IDS_IOS_APP_RATING_PROMO_STRING", "0", "chrome_command", "", |
159 "ratethisapp", "RateThisAppPromo", "logo", "0", "172800"); | 201 "ratethisapp", "RateThisAppPromo", "logo", "0", "172800"); |
160 // Set install date to one day before now. | 202 // Set install date to one day before now. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 EXPECT_EQ(1, GetUserActionCount("WhatsNewPromoViewed_RateThisAppPromo")); | 271 EXPECT_EQ(1, GetUserActionCount("WhatsNewPromoViewed_RateThisAppPromo")); |
230 | 272 |
231 // Verify that the promo closed user action count is 0 before |HandleClosed()| | 273 // Verify that the promo closed user action count is 0 before |HandleClosed()| |
232 // is called. | 274 // is called. |
233 EXPECT_EQ(0, GetUserActionCount("WhatsNewPromoClosed_RateThisAppPromo")); | 275 EXPECT_EQ(0, GetUserActionCount("WhatsNewPromoClosed_RateThisAppPromo")); |
234 promo_.HandleClosed(); | 276 promo_.HandleClosed(); |
235 EXPECT_EQ(1, GetUserActionCount("WhatsNewPromoClosed_RateThisAppPromo")); | 277 EXPECT_EQ(1, GetUserActionCount("WhatsNewPromoClosed_RateThisAppPromo")); |
236 } | 278 } |
237 | 279 |
238 } // namespace | 280 } // namespace |
OLD | NEW |