Commit f188c70c authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] Add cpe metrics util test

Bug: 1066804
Change-Id: I9b16c33790d0a68305e2b6041d41ddda064f4c35
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2209052
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770483}
parent 0342f0f0
......@@ -100,10 +100,15 @@ generate_localizable_strings("system_strings") {
source_set("unit_tests") {
testonly = true
sources = [ "password_util_unittest.mm" ]
sources = [
"metrics_util_unittest.mm",
"password_util_unittest.mm",
]
deps = [
":metrics_util",
":password_util",
"//base",
"//ios/chrome/common/app_group",
"//testing/gtest",
]
configs += [ "//build/config/compiler:enable_arc" ]
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
#include "ios/chrome/credential_provider_extension/metrics_util.h"
#import <Foundation/Foundation.h>
#import <Security/Security.h>
#include "ios/chrome/common/app_group/app_group_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest_mac.h"
#include "testing/platform_test.h"
namespace credential_provider_extension {
NSString* kMetric1 = @"CpeMetricTest1";
NSString* kMetric2 = @"CpeMetricTest2";
void RemoveMetricForKey(NSString* key) {
NSUserDefaults* sharedDefaults = app_group::GetGroupUserDefaults();
[sharedDefaults removeObjectForKey:key];
}
void VerifyMetricForKey(NSString* key, int valueExpected) {
NSUserDefaults* sharedDefaults = app_group::GetGroupUserDefaults();
NSInteger value = [sharedDefaults integerForKey:key];
ASSERT_EQ(value, valueExpected);
}
class MetricsUtilTest : public PlatformTest {
public:
void SetUp() override;
void TearDown() override;
};
void MetricsUtilTest::SetUp() {
RemoveMetricForKey(kMetric1);
RemoveMetricForKey(kMetric2);
}
void MetricsUtilTest::TearDown() {
RemoveMetricForKey(kMetric1);
RemoveMetricForKey(kMetric2);
}
// Tests increase and reset of metrics.
TEST_F(MetricsUtilTest, CheckUMACountUpdatesAsExpected) {
VerifyMetricForKey(kMetric1, 0);
VerifyMetricForKey(kMetric2, 0);
UpdateUMACountForKey(kMetric1);
VerifyMetricForKey(kMetric1, 1);
VerifyMetricForKey(kMetric2, 0);
UpdateUMACountForKey(kMetric2);
UpdateUMACountForKey(kMetric2);
VerifyMetricForKey(kMetric1, 1);
VerifyMetricForKey(kMetric2, 2);
RemoveMetricForKey(kMetric2);
VerifyMetricForKey(kMetric1, 1);
VerifyMetricForKey(kMetric2, 0);
}
} // credential_provider_extension
// Copyright 2018 The Chromium Authors. All rights reserved.
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment