OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "chrome/browser/ui/global_error/global_error_service.h" | 5 #include "chrome/browser/ui/global_error/global_error_service.h" |
6 | 6 |
| 7 #include <memory> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "chrome/browser/ui/global_error/global_error.h" | 11 #include "chrome/browser/ui/global_error/global_error.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 // Error base class that keeps track of the number of errors that exist. | 16 // Error base class that keeps track of the number of errors that exist. |
16 class BaseError : public GlobalError { | 17 class BaseError : public GlobalError { |
17 public: | 18 public: |
18 BaseError() { ++count_; } | 19 BaseError() { ++count_; } |
19 ~BaseError() override { --count_; } | 20 ~BaseError() override { --count_; } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 int command_id_; | 65 int command_id_; |
65 Severity severity_; | 66 Severity severity_; |
66 | 67 |
67 DISALLOW_COPY_AND_ASSIGN(MenuError); | 68 DISALLOW_COPY_AND_ASSIGN(MenuError); |
68 }; | 69 }; |
69 | 70 |
70 } // namespace | 71 } // namespace |
71 | 72 |
72 // Test adding errors to the global error service. | 73 // Test adding errors to the global error service. |
73 TEST(GlobalErrorServiceTest, AddError) { | 74 TEST(GlobalErrorServiceTest, AddError) { |
74 scoped_ptr<GlobalErrorService> service(new GlobalErrorService(NULL)); | 75 std::unique_ptr<GlobalErrorService> service(new GlobalErrorService(NULL)); |
75 EXPECT_EQ(0u, service->errors().size()); | 76 EXPECT_EQ(0u, service->errors().size()); |
76 | 77 |
77 BaseError* error1 = new BaseError; | 78 BaseError* error1 = new BaseError; |
78 service->AddGlobalError(error1); | 79 service->AddGlobalError(error1); |
79 EXPECT_EQ(1u, service->errors().size()); | 80 EXPECT_EQ(1u, service->errors().size()); |
80 EXPECT_EQ(error1, service->errors()[0]); | 81 EXPECT_EQ(error1, service->errors()[0]); |
81 | 82 |
82 BaseError* error2 = new BaseError; | 83 BaseError* error2 = new BaseError; |
83 service->AddGlobalError(error2); | 84 service->AddGlobalError(error2); |
84 EXPECT_EQ(2u, service->errors().size()); | 85 EXPECT_EQ(2u, service->errors().size()); |
85 EXPECT_EQ(error1, service->errors()[0]); | 86 EXPECT_EQ(error1, service->errors()[0]); |
86 EXPECT_EQ(error2, service->errors()[1]); | 87 EXPECT_EQ(error2, service->errors()[1]); |
87 | 88 |
88 // Ensure that deleting the service deletes the error objects. | 89 // Ensure that deleting the service deletes the error objects. |
89 EXPECT_EQ(2, BaseError::count()); | 90 EXPECT_EQ(2, BaseError::count()); |
90 service.reset(); | 91 service.reset(); |
91 EXPECT_EQ(0, BaseError::count()); | 92 EXPECT_EQ(0, BaseError::count()); |
92 } | 93 } |
93 | 94 |
94 // Test removing errors from the global error service. | 95 // Test removing errors from the global error service. |
95 TEST(GlobalErrorServiceTest, RemoveError) { | 96 TEST(GlobalErrorServiceTest, RemoveError) { |
96 scoped_ptr<GlobalErrorService> service(new GlobalErrorService(NULL)); | 97 std::unique_ptr<GlobalErrorService> service(new GlobalErrorService(NULL)); |
97 BaseError error1; | 98 BaseError error1; |
98 service->AddGlobalError(&error1); | 99 service->AddGlobalError(&error1); |
99 BaseError error2; | 100 BaseError error2; |
100 service->AddGlobalError(&error2); | 101 service->AddGlobalError(&error2); |
101 | 102 |
102 EXPECT_EQ(2u, service->errors().size()); | 103 EXPECT_EQ(2u, service->errors().size()); |
103 service->RemoveGlobalError(&error1); | 104 service->RemoveGlobalError(&error1); |
104 EXPECT_EQ(1u, service->errors().size()); | 105 EXPECT_EQ(1u, service->errors().size()); |
105 EXPECT_EQ(&error2, service->errors()[0]); | 106 EXPECT_EQ(&error2, service->errors()[0]); |
106 service->RemoveGlobalError(&error2); | 107 service->RemoveGlobalError(&error2); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 service.AddGlobalError(error3); | 147 service.AddGlobalError(error3); |
147 EXPECT_EQ(error3, service.GetHighestSeverityGlobalErrorWithAppMenuItem()); | 148 EXPECT_EQ(error3, service.GetHighestSeverityGlobalErrorWithAppMenuItem()); |
148 | 149 |
149 // Remove the highest-severity error. | 150 // Remove the highest-severity error. |
150 service.RemoveGlobalError(error3); | 151 service.RemoveGlobalError(error3); |
151 delete error3; | 152 delete error3; |
152 | 153 |
153 // Now error2 should be the next highest severity error. | 154 // Now error2 should be the next highest severity error. |
154 EXPECT_EQ(error2, service.GetHighestSeverityGlobalErrorWithAppMenuItem()); | 155 EXPECT_EQ(error2, service.GetHighestSeverityGlobalErrorWithAppMenuItem()); |
155 } | 156 } |
OLD | NEW |