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

Unified Diff: ios/chrome/browser/ui/ntp/notification_promo_whats_new_unittest.mm

Issue 2592173002: Fix ios_chrome_unittests to crash on DCHECK failure. (Closed)
Patch Set: Address comments 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/ntp/notification_promo_whats_new_unittest.mm
diff --git a/ios/chrome/browser/ui/ntp/notification_promo_whats_new_unittest.mm b/ios/chrome/browser/ui/ntp/notification_promo_whats_new_unittest.mm
index 538e52e7915b167b6806f42dfacae49ef0f837e9..a03f7b7679bd6ca8a38f5523e724743cdae561c5 100644
--- a/ios/chrome/browser/ui/ntp/notification_promo_whats_new_unittest.mm
+++ b/ios/chrome/browser/ui/ntp/notification_promo_whats_new_unittest.mm
@@ -6,8 +6,9 @@
#include <map>
+#include "base/bind.h"
#include "base/metrics/field_trial.h"
-#include "base/test/user_action_tester.h"
+#include "base/metrics/user_metrics.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/metrics/metrics_pref_names.h"
@@ -28,12 +29,17 @@ class NotificationPromoWhatsNewTest : public PlatformTest {
public:
NotificationPromoWhatsNewTest()
: promo_(&local_state_),
+ action_callback_(
+ base::Bind(&NotificationPromoWhatsNewTest::OnUserAction,
+ base::Unretained(this))),
field_trial_list_(new base::FieldTrialList(NULL)) {
ios::NotificationPromo::RegisterPrefs(local_state_.registry());
local_state_.registry()->RegisterInt64Pref(metrics::prefs::kInstallDate, 0);
+ base::AddActionCallback(action_callback_);
}
~NotificationPromoWhatsNewTest() override {
+ base::RemoveActionCallback(action_callback_);
variations::testing::ClearAllVariationParams();
}
@@ -98,9 +104,19 @@ class NotificationPromoWhatsNewTest : public PlatformTest {
EXPECT_EQ(icon, promo_.icon());
}
+ void OnUserAction(const std::string& user_action) {
+ user_action_count_map_[user_action]++;
+ }
+
+ int GetUserActionCount(const std::string& user_action) {
+ return user_action_count_map_[user_action];
+ }
+
protected:
TestingPrefServiceSimple local_state_;
NotificationPromoWhatsNew promo_;
+ base::ActionCallback action_callback_;
+ std::map<std::string, int> user_action_count_map_;
private:
std::unique_ptr<base::FieldTrialList> field_trial_list_;
@@ -203,20 +219,16 @@ TEST_F(NotificationPromoWhatsNewTest, NotificationPromoMetricTest) {
"IDS_IOS_APP_RATING_PROMO_STRING", "0", "chrome_command", "",
"ratethisapp", "RateThisAppPromo", "logo", "0", "0");
- base::UserActionTester user_action_tester;
// Assert that promo is appropriately set up to be viewed.
ASSERT_TRUE(promo_.CanShow());
promo_.HandleViewed();
- EXPECT_EQ(1, user_action_tester.GetActionCount(
- "WhatsNewPromoViewed_RateThisAppPromo"));
+ EXPECT_EQ(1, GetUserActionCount("WhatsNewPromoViewed_RateThisAppPromo"));
// Verify that the promo closed user action count is 0 before |HandleClosed()|
// is called.
- EXPECT_EQ(0, user_action_tester.GetActionCount(
- "WhatsNewPromoClosed_RateThisAppPromo"));
+ EXPECT_EQ(0, GetUserActionCount("WhatsNewPromoClosed_RateThisAppPromo"));
promo_.HandleClosed();
- EXPECT_EQ(1, user_action_tester.GetActionCount(
- "WhatsNewPromoClosed_RateThisAppPromo"));
+ EXPECT_EQ(1, GetUserActionCount("WhatsNewPromoClosed_RateThisAppPromo"));
}
} // namespace
« no previous file with comments | « ios/chrome/browser/ui/collection_view/collection_view_model_unittest.mm ('k') | ios/chrome/browser/ui/settings/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698