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

Side by Side Diff: ios/chrome/browser/crash_report/crash_restore_helper_unittest.mm

Issue 2688163002: [ObjC ARC] Converts ios/chrome/browser/crash_report:unit_tests to ARC. (Closed)
Patch Set: 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
« no previous file with comments | « ios/chrome/browser/crash_report/breakpad_helper_unittest.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 <Foundation/Foundation.h> 5 #import <Foundation/Foundation.h>
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/scoped_nsobject.h"
11 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
12 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 11 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
13 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" 12 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
14 #include "ios/chrome/browser/crash_report/crash_restore_helper.h" 13 #include "ios/chrome/browser/crash_report/crash_restore_helper.h"
15 #import "ios/chrome/browser/sessions/session_service.h" 14 #import "ios/chrome/browser/sessions/session_service.h"
16 #include "ios/web/public/test/test_web_thread_bundle.h" 15 #include "ios/web/public/test/test_web_thread_bundle.h"
17 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 #include "testing/platform_test.h" 18 #include "testing/platform_test.h"
20 #import "third_party/ocmock/OCMock/OCMock.h" 19 #import "third_party/ocmock/OCMock/OCMock.h"
21 #include "third_party/ocmock/gtest_support.h" 20 #include "third_party/ocmock/gtest_support.h"
22 21
22 #if !defined(__has_feature) || !__has_feature(objc_arc)
23 #error "This file requires ARC support."
24 #endif
25
23 using testing::Return; 26 using testing::Return;
24 27
25 @interface CrashRestoreHelper (Test) 28 @interface CrashRestoreHelper (Test)
26 - (NSString*)sessionBackupPath; 29 - (NSString*)sessionBackupPath;
27 @end 30 @end
28 31
29 namespace { 32 namespace {
30 33
31 class CrashRestoreHelperTest : public PlatformTest { 34 class CrashRestoreHelperTest : public PlatformTest {
32 public: 35 public:
33 void SetUp() override { 36 void SetUp() override {
34 TestChromeBrowserState::Builder test_cbs_builder; 37 TestChromeBrowserState::Builder test_cbs_builder;
35 chrome_browser_state_ = test_cbs_builder.Build(); 38 chrome_browser_state_ = test_cbs_builder.Build();
36 otr_chrome_browser_state_ = 39 otr_chrome_browser_state_ =
37 chrome_browser_state_->GetOffTheRecordChromeBrowserState(); 40 chrome_browser_state_->GetOffTheRecordChromeBrowserState();
38 helper_.reset([[CrashRestoreHelper alloc] 41 helper_ = [[CrashRestoreHelper alloc]
39 initWithBrowserState:chrome_browser_state_.get()]); 42 initWithBrowserState:chrome_browser_state_.get()];
40 } 43 }
41 44
42 protected: 45 protected:
43 web::TestWebThreadBundle thread_bundle_; 46 web::TestWebThreadBundle thread_bundle_;
44 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; 47 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
45 ios::ChromeBrowserState* otr_chrome_browser_state_; 48 ios::ChromeBrowserState* otr_chrome_browser_state_;
46 base::scoped_nsobject<CrashRestoreHelper> helper_; 49 CrashRestoreHelper* helper_;
47 }; 50 };
48 51
49 TEST_F(CrashRestoreHelperTest, MoveAsideTest) { 52 TEST_F(CrashRestoreHelperTest, MoveAsideTest) {
50 NSString* backupPath = [helper_ sessionBackupPath]; 53 NSString* backupPath = [helper_ sessionBackupPath];
51 NSFileManager* fileManager = [NSFileManager defaultManager]; 54 NSFileManager* fileManager = [NSFileManager defaultManager];
52 [fileManager removeItemAtPath:backupPath error:NULL]; 55 [fileManager removeItemAtPath:backupPath error:NULL];
53 56
54 NSData* data = [NSData dataWithBytes:"hello" length:5]; 57 NSData* data = [NSData dataWithBytes:"hello" length:5];
55 SessionServiceIOS* sessionService = [SessionServiceIOS sharedService]; 58 SessionServiceIOS* sessionService = [SessionServiceIOS sharedService];
56 NSString* profileStashPath = 59 NSString* profileStashPath =
57 base::SysUTF8ToNSString(chrome_browser_state_->GetStatePath().value()); 60 base::SysUTF8ToNSString(chrome_browser_state_->GetStatePath().value());
58 NSString* sessionPath = 61 NSString* sessionPath =
59 [sessionService sessionFilePathForDirectory:profileStashPath]; 62 [sessionService sessionFilePathForDirectory:profileStashPath];
60 [fileManager createFileAtPath:sessionPath contents:data attributes:nil]; 63 [fileManager createFileAtPath:sessionPath contents:data attributes:nil];
61 NSString* otrProfileStashPath = base::SysUTF8ToNSString( 64 NSString* otrProfileStashPath = base::SysUTF8ToNSString(
62 otr_chrome_browser_state_->GetStatePath().value()); 65 otr_chrome_browser_state_->GetStatePath().value());
63 NSString* otrSessionPath = 66 NSString* otrSessionPath =
64 [sessionService sessionFilePathForDirectory:otrProfileStashPath]; 67 [sessionService sessionFilePathForDirectory:otrProfileStashPath];
65 [fileManager createFileAtPath:otrSessionPath contents:data attributes:nil]; 68 [fileManager createFileAtPath:otrSessionPath contents:data attributes:nil];
66 69
67 [helper_ moveAsideSessionInformation]; 70 [helper_ moveAsideSessionInformation];
68 71
69 EXPECT_EQ(NO, [fileManager fileExistsAtPath:sessionPath]); 72 EXPECT_EQ(NO, [fileManager fileExistsAtPath:sessionPath]);
70 EXPECT_EQ(NO, [fileManager fileExistsAtPath:otrSessionPath]); 73 EXPECT_EQ(NO, [fileManager fileExistsAtPath:otrSessionPath]);
71 EXPECT_EQ(YES, [fileManager fileExistsAtPath:backupPath]); 74 EXPECT_EQ(YES, [fileManager fileExistsAtPath:backupPath]);
72 [fileManager removeItemAtPath:backupPath error:NULL]; 75 [fileManager removeItemAtPath:backupPath error:NULL];
73 } 76 }
74 77
75 } // namespace 78 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/crash_report/breakpad_helper_unittest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698