OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "base/mac/scoped_nsobject.h" |
| 6 #import "breakpad/src/client/ios/BreakpadController.h" |
| 7 #import "ios/chrome/app/safe_mode/safe_mode_view_controller.h" |
| 8 #import "ios/chrome/browser/crash_report/breakpad_helper.h" |
| 9 #import "ios/chrome/test/base/scoped_block_swizzler.h" |
| 10 #import "ios/chrome/test/ocmock/OCMockObject+BreakpadControllerTesting.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "testing/platform_test.h" |
| 13 #import "third_party/ocmock/OCMock/OCMock.h" |
| 14 #include "third_party/ocmock/gtest_support.h" |
| 15 |
| 16 namespace { |
| 17 |
| 18 const int kCrashReportCount = 2; |
| 19 |
| 20 class SafeModeViewControllerTest : public PlatformTest { |
| 21 public: |
| 22 void SetUp() override { |
| 23 PlatformTest::SetUp(); |
| 24 |
| 25 mock_breakpad_controller_.reset( |
| 26 [[OCMockObject mockForClass:[BreakpadController class]] retain]); |
| 27 |
| 28 // Swizzle +[BreakpadController sharedInstance] to return |
| 29 // |mock_breakpad_controller_| instead of the normal singleton instance. |
| 30 id implementation_block = ^BreakpadController*(id self) { |
| 31 return mock_breakpad_controller_.get(); |
| 32 }; |
| 33 breakpad_controller_shared_instance_swizzler_.reset(new ScopedBlockSwizzler( |
| 34 [BreakpadController class], @selector(sharedInstance), |
| 35 implementation_block)); |
| 36 } |
| 37 |
| 38 void TearDown() override { |
| 39 [[mock_breakpad_controller_ stub] stop]; |
| 40 breakpad_helper::SetEnabled(false); |
| 41 |
| 42 PlatformTest::TearDown(); |
| 43 } |
| 44 |
| 45 protected: |
| 46 base::scoped_nsobject<id> mock_breakpad_controller_; |
| 47 std::unique_ptr<ScopedBlockSwizzler> |
| 48 breakpad_controller_shared_instance_swizzler_; |
| 49 }; |
| 50 |
| 51 // Verify that +[SafeModeViewController hasSuggestions] returns YES if and only |
| 52 // if crash reporter and crash report uploading are enabled and there are |
| 53 // multiple crash reports to upload. |
| 54 TEST_F(SafeModeViewControllerTest, HasSuggestions) { |
| 55 // Test when crash reporter is disabled. |
| 56 breakpad_helper::SetEnabled(false); |
| 57 EXPECT_OCMOCK_VERIFY(mock_breakpad_controller_.get()); |
| 58 EXPECT_FALSE([SafeModeViewController hasSuggestions]); |
| 59 |
| 60 breakpad_helper::SetUploadingEnabled(false); |
| 61 EXPECT_OCMOCK_VERIFY(mock_breakpad_controller_.get()); |
| 62 EXPECT_FALSE([SafeModeViewController hasSuggestions]); |
| 63 |
| 64 breakpad_helper::SetUploadingEnabled(true); |
| 65 EXPECT_OCMOCK_VERIFY(mock_breakpad_controller_.get()); |
| 66 EXPECT_FALSE([SafeModeViewController hasSuggestions]); |
| 67 |
| 68 // Test when crash reporter is enabled. |
| 69 [[mock_breakpad_controller_ expect] start:NO]; |
| 70 breakpad_helper::SetEnabled(true); |
| 71 EXPECT_OCMOCK_VERIFY(mock_breakpad_controller_.get()); |
| 72 EXPECT_FALSE([SafeModeViewController hasSuggestions]); |
| 73 |
| 74 [[mock_breakpad_controller_ expect] setUploadingEnabled:NO]; |
| 75 breakpad_helper::SetUploadingEnabled(false); |
| 76 EXPECT_OCMOCK_VERIFY(mock_breakpad_controller_.get()); |
| 77 EXPECT_FALSE([SafeModeViewController hasSuggestions]); |
| 78 |
| 79 // Test when crash reporter and crash report uploading are enabled. |
| 80 [[mock_breakpad_controller_ expect] setUploadingEnabled:YES]; |
| 81 breakpad_helper::SetUploadingEnabled(true); |
| 82 EXPECT_OCMOCK_VERIFY(mock_breakpad_controller_.get()); |
| 83 |
| 84 [mock_breakpad_controller_ cr_expectGetCrashReportCount:0]; |
| 85 EXPECT_FALSE([SafeModeViewController hasSuggestions]); |
| 86 EXPECT_OCMOCK_VERIFY(mock_breakpad_controller_.get()); |
| 87 |
| 88 [mock_breakpad_controller_ cr_expectGetCrashReportCount:kCrashReportCount]; |
| 89 EXPECT_TRUE([SafeModeViewController hasSuggestions]); |
| 90 EXPECT_OCMOCK_VERIFY(mock_breakpad_controller_.get()); |
| 91 } |
| 92 |
| 93 } // namespace |
OLD | NEW |