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

Side by Side Diff: ios/chrome/app/application_delegate/memory_warning_helper_unittest.mm

Issue 2708683002: [ObjC ARC] Converts ios/chrome/app/application_delegate:unit_tests to ARC. (Closed)
Patch Set: fix compile Created 3 years, 10 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #import "ios/chrome/app/application_delegate/memory_warning_helper.h" 5 #import "ios/chrome/app/application_delegate/memory_warning_helper.h"
6 6
7 #include "base/mac/bind_objc_block.h" 7 #include "base/mac/bind_objc_block.h"
8 #import "base/mac/scoped_nsobject.h"
9 #include "base/memory/memory_pressure_listener.h" 8 #include "base/memory/memory_pressure_listener.h"
10 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 10 #include "base/run_loop.h"
12 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
13 #import "ios/chrome/browser/metrics/previous_session_info.h" 12 #import "ios/chrome/browser/metrics/previous_session_info.h"
14 #include "testing/platform_test.h" 13 #include "testing/platform_test.h"
15 14
15 #if !defined(__has_feature) || !__has_feature(objc_arc)
16 #error "This file requires ARC support."
17 #endif
18
16 using previous_session_info_constants:: 19 using previous_session_info_constants::
17 kDidSeeMemoryWarningShortlyBeforeTerminating; 20 kDidSeeMemoryWarningShortlyBeforeTerminating;
18 21
19 class MemoryWarningHelperTest : public PlatformTest { 22 class MemoryWarningHelperTest : public PlatformTest {
20 protected: 23 protected:
21 MemoryWarningHelperTest() { 24 MemoryWarningHelperTest() {
22 // Set up |memory_pressure_listener_| to invoke |OnMemoryPressure| which 25 // Set up |memory_pressure_listener_| to invoke |OnMemoryPressure| which
23 // will store the memory pressure level sent to the callback in 26 // will store the memory pressure level sent to the callback in
24 // |memory_pressure_level_| so that tests can verify the level is correct. 27 // |memory_pressure_level_| so that tests can verify the level is correct.
25 memory_pressure_listener_.reset(new base::MemoryPressureListener(base::Bind( 28 memory_pressure_listener_.reset(new base::MemoryPressureListener(base::Bind(
26 &MemoryWarningHelperTest::OnMemoryPressure, base::Unretained(this)))); 29 &MemoryWarningHelperTest::OnMemoryPressure, base::Unretained(this))));
27 memory_pressure_level_ = 30 memory_pressure_level_ =
28 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE; 31 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE;
29 } 32 }
30 33
31 base::MemoryPressureListener::MemoryPressureLevel GetMemoryPressureLevel() { 34 base::MemoryPressureListener::MemoryPressureLevel GetMemoryPressureLevel() {
32 return memory_pressure_level_; 35 return memory_pressure_level_;
33 } 36 }
34 37
35 MemoryWarningHelper* GetMemoryHelper() { 38 MemoryWarningHelper* GetMemoryHelper() {
36 if (!memory_helper_) { 39 if (!memory_helper_) {
37 memory_helper_.reset([[MemoryWarningHelper alloc] init]); 40 memory_helper_ = [[MemoryWarningHelper alloc] init];
38 } 41 }
39 return memory_helper_; 42 return memory_helper_;
40 } 43 }
41 44
42 // Callback for |memory_pressure_listener_|. 45 // Callback for |memory_pressure_listener_|.
43 void OnMemoryPressure( 46 void OnMemoryPressure(
44 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { 47 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
45 memory_pressure_level_ = memory_pressure_level; 48 memory_pressure_level_ = memory_pressure_level;
46 run_loop_.QuitWhenIdle(); 49 run_loop_.QuitWhenIdle();
47 } 50 }
48 51
49 void RunMessageLoop() { run_loop_.Run(); } 52 void RunMessageLoop() { run_loop_.Run(); }
50 53
51 private: 54 private:
52 base::MessageLoop message_loop_; 55 base::MessageLoop message_loop_;
53 base::RunLoop run_loop_; 56 base::RunLoop run_loop_;
54 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level_; 57 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level_;
55 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; 58 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
56 base::scoped_nsobject<MemoryWarningHelper> memory_helper_; 59 MemoryWarningHelper* memory_helper_;
57 60
58 DISALLOW_COPY_AND_ASSIGN(MemoryWarningHelperTest); 61 DISALLOW_COPY_AND_ASSIGN(MemoryWarningHelperTest);
59 }; 62 };
60 63
61 // Invokes resetForegroundMemoryWarningCount and verifies the 64 // Invokes resetForegroundMemoryWarningCount and verifies the
62 // foregroundMemoryWarningCount is setted to 0. 65 // foregroundMemoryWarningCount is setted to 0.
63 TEST_F(MemoryWarningHelperTest, VerifyForegroundMemoryWarningCountReset) { 66 TEST_F(MemoryWarningHelperTest, VerifyForegroundMemoryWarningCountReset) {
64 // Setup. 67 // Setup.
65 [GetMemoryHelper() handleMemoryPressure]; 68 [GetMemoryHelper() handleMemoryPressure];
66 ASSERT_TRUE(GetMemoryHelper().foregroundMemoryWarningCount != 0); 69 ASSERT_TRUE(GetMemoryHelper().foregroundMemoryWarningCount != 0);
(...skipping 29 matching lines...) Expand all
96 // Action. 99 // Action.
97 [GetMemoryHelper() handleMemoryPressure]; 100 [GetMemoryHelper() handleMemoryPressure];
98 101
99 // Tests. 102 // Tests.
100 EXPECT_TRUE([[NSUserDefaults standardUserDefaults] 103 EXPECT_TRUE([[NSUserDefaults standardUserDefaults]
101 boolForKey:kDidSeeMemoryWarningShortlyBeforeTerminating]); 104 boolForKey:kDidSeeMemoryWarningShortlyBeforeTerminating]);
102 EXPECT_FALSE(memoryWarningFlagBeforeAlert); 105 EXPECT_FALSE(memoryWarningFlagBeforeAlert);
103 EXPECT_EQ(foregroundMemoryWarningCountBeforeWarning + 1, 106 EXPECT_EQ(foregroundMemoryWarningCountBeforeWarning + 1,
104 GetMemoryHelper().foregroundMemoryWarningCount); 107 GetMemoryHelper().foregroundMemoryWarningCount);
105 } 108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698