forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrash_loop_detection_util_unittest.mm
42 lines (31 loc) · 1.56 KB
/
crash_loop_detection_util_unittest.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2013 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.
#include <Foundation/Foundation.h>
#include "ios/chrome/browser/crash_loop_detection_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
namespace {
// The key used to store the count in the implementation.
NSString* const kAppStartupAttemptCountKey = @"AppStartupFailureCount";
typedef PlatformTest CrashLoopDetectionUtilTest;
TEST_F(CrashLoopDetectionUtilTest, FullCycle) {
// Simulate one prior crash.
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
[defaults setInteger:1 forKey:kAppStartupAttemptCountKey];
EXPECT_EQ(1, crash_util::GetFailedStartupAttemptCount());
crash_util::IncrementFailedStartupAttemptCount(false);
// It should still report 1, since it's reporting failures prior to this
// launch.
EXPECT_EQ(1, crash_util::GetFailedStartupAttemptCount());
// ... but under the hood the value should now be 2.
EXPECT_EQ(2, [defaults integerForKey:kAppStartupAttemptCountKey]);
// If it's mistakenly incerement again, nothing should change.
crash_util::IncrementFailedStartupAttemptCount(false);
EXPECT_EQ(2, [defaults integerForKey:kAppStartupAttemptCountKey]);
// After a reset it should be 0 internally, but the same via the API.
crash_util::ResetFailedStartupAttemptCount();
EXPECT_EQ(1, crash_util::GetFailedStartupAttemptCount());
EXPECT_EQ(0, [defaults integerForKey:kAppStartupAttemptCountKey]);
}
} // namespace