Index: ios/chrome/browser/crash_loop_detection_util_unittest.mm |
diff --git a/ios/chrome/browser/crash_loop_detection_util_unittest.mm b/ios/chrome/browser/crash_loop_detection_util_unittest.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c36670a08bcaa16247c5a3d9af769eb408ce541f |
--- /dev/null |
+++ b/ios/chrome/browser/crash_loop_detection_util_unittest.mm |
@@ -0,0 +1,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 |