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

Side by Side Diff: ios/chrome/browser/crash_loop_detection_util_unittest.mm

Issue 2592173002: Fix ios_chrome_unittests to crash on DCHECK failure. (Closed)
Patch Set: Address comments Created 3 years, 12 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <Foundation/Foundation.h> 5 #include <Foundation/Foundation.h>
6 6
7 #include "ios/chrome/browser/crash_loop_detection_util.h" 7 #include "ios/chrome/browser/crash_loop_detection_util.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "testing/platform_test.h" 9 #include "testing/platform_test.h"
10 10
11 namespace { 11 namespace {
12 // The key used to store the count in the implementation. 12 // The key used to store the count in the implementation.
13 NSString* const kAppStartupAttemptCountKey = @"AppStartupFailureCount"; 13 NSString* const kAppStartupAttemptCountKey = @"AppStartupFailureCount";
14 14
15 typedef PlatformTest CrashLoopDetectionUtilTest; 15 typedef PlatformTest CrashLoopDetectionUtilTest;
16 16
17 TEST_F(CrashLoopDetectionUtilTest, FullCycle) { 17 TEST_F(CrashLoopDetectionUtilTest, FullCycle) {
18 crash_util::ResetFailedStartupAttemptCountForTests();
19
18 // Simulate one prior crash. 20 // Simulate one prior crash.
19 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; 21 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
20 [defaults setInteger:1 forKey:kAppStartupAttemptCountKey]; 22 [defaults setInteger:1 forKey:kAppStartupAttemptCountKey];
21 23
22 EXPECT_EQ(1, crash_util::GetFailedStartupAttemptCount()); 24 EXPECT_EQ(1, crash_util::GetFailedStartupAttemptCount());
23 25
24 crash_util::IncrementFailedStartupAttemptCount(false); 26 crash_util::IncrementFailedStartupAttemptCount(false);
25 27
26 // It should still report 1, since it's reporting failures prior to this 28 // It should still report 1, since it's reporting failures prior to this
27 // launch. 29 // launch.
28 EXPECT_EQ(1, crash_util::GetFailedStartupAttemptCount()); 30 EXPECT_EQ(1, crash_util::GetFailedStartupAttemptCount());
29 // ... but under the hood the value should now be 2. 31 // ... but under the hood the value should now be 2.
30 EXPECT_EQ(2, [defaults integerForKey:kAppStartupAttemptCountKey]); 32 EXPECT_EQ(2, [defaults integerForKey:kAppStartupAttemptCountKey]);
31 33
32 // If it's mistakenly incerement again, nothing should change. 34 // If it's mistakenly incerement again, nothing should change.
33 crash_util::IncrementFailedStartupAttemptCount(false); 35 crash_util::IncrementFailedStartupAttemptCount(false);
34 EXPECT_EQ(2, [defaults integerForKey:kAppStartupAttemptCountKey]); 36 EXPECT_EQ(2, [defaults integerForKey:kAppStartupAttemptCountKey]);
35 37
36 // After a reset it should be 0 internally, but the same via the API. 38 // After a reset it should be 0 internally, but the same via the API.
37 crash_util::ResetFailedStartupAttemptCount(); 39 crash_util::ResetFailedStartupAttemptCount();
38 EXPECT_EQ(1, crash_util::GetFailedStartupAttemptCount()); 40 EXPECT_EQ(1, crash_util::GetFailedStartupAttemptCount());
39 EXPECT_EQ(0, [defaults integerForKey:kAppStartupAttemptCountKey]); 41 EXPECT_EQ(0, [defaults integerForKey:kAppStartupAttemptCountKey]);
40 } 42 }
41 43
42 } // namespace 44 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/crash_loop_detection_util.mm ('k') | ios/chrome/browser/metrics/first_user_action_recorder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698