Disable failing TabsTest to investigate
[chromium-blink-merge.git] / ios / chrome / browser / crash_loop_detection_util_unittest.mm
blobc36670a08bcaa16247c5a3d9af769eb408ce541f
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <Foundation/Foundation.h>
7 #include "ios/chrome/browser/crash_loop_detection_util.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "testing/platform_test.h"
11 namespace {
12 // The key used to store the count in the implementation.
13 NSString* const kAppStartupAttemptCountKey = @"AppStartupFailureCount";
15 typedef PlatformTest CrashLoopDetectionUtilTest;
17 TEST_F(CrashLoopDetectionUtilTest, FullCycle) {
18   // Simulate one prior crash.
19   NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
20   [defaults setInteger:1 forKey:kAppStartupAttemptCountKey];
22   EXPECT_EQ(1, crash_util::GetFailedStartupAttemptCount());
24   crash_util::IncrementFailedStartupAttemptCount(false);
26   // It should still report 1, since it's reporting failures prior to this
27   // launch.
28   EXPECT_EQ(1, crash_util::GetFailedStartupAttemptCount());
29   // ... but under the hood the value should now be 2.
30   EXPECT_EQ(2, [defaults integerForKey:kAppStartupAttemptCountKey]);
32   // If it's mistakenly incerement again, nothing should change.
33   crash_util::IncrementFailedStartupAttemptCount(false);
34   EXPECT_EQ(2, [defaults integerForKey:kAppStartupAttemptCountKey]);
36   // After a reset it should be 0 internally, but the same via the API.
37   crash_util::ResetFailedStartupAttemptCount();
38   EXPECT_EQ(1, crash_util::GetFailedStartupAttemptCount());
39   EXPECT_EQ(0, [defaults integerForKey:kAppStartupAttemptCountKey]);
42 }  // namespace