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

Unified Diff: ios/chrome/browser/crash_loop_detection_util_unittest.mm

Issue 1147703002: [iOS] Upstream crash loop detection utilities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 7 months 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
« no previous file with comments | « ios/chrome/browser/crash_loop_detection_util.mm ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « ios/chrome/browser/crash_loop_detection_util.mm ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698