| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/error_map.h" | 5 #include "extensions/browser/error_map.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> |
| 9 #include <utility> | 10 #include <utility> |
| 10 | 11 |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "components/crx_file/id_util.h" | 14 #include "components/crx_file/id_util.h" |
| 15 #include "extensions/browser/extension_error.h" | 15 #include "extensions/browser/extension_error.h" |
| 16 #include "extensions/browser/extension_error_test_util.h" | 16 #include "extensions/browser/extension_error_test_util.h" |
| 17 #include "extensions/common/constants.h" | 17 #include "extensions/common/constants.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 | 21 |
| 22 using error_test_util::CreateNewRuntimeError; | 22 using error_test_util::CreateNewRuntimeError; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 const size_t kNumErrors = 3u; | 144 const size_t kNumErrors = 3u; |
| 145 | 145 |
| 146 // Report three errors. | 146 // Report three errors. |
| 147 for (size_t i = 0; i < kNumErrors; ++i) { | 147 for (size_t i = 0; i < kNumErrors; ++i) { |
| 148 ASSERT_TRUE( | 148 ASSERT_TRUE( |
| 149 errors_.AddError(CreateNewRuntimeError(kId, base::SizeTToString(i)))); | 149 errors_.AddError(CreateNewRuntimeError(kId, base::SizeTToString(i)))); |
| 150 } | 150 } |
| 151 | 151 |
| 152 // Create an error identical to the second error reported, save its | 152 // Create an error identical to the second error reported, save its |
| 153 // location, and add it to the error map. | 153 // location, and add it to the error map. |
| 154 scoped_ptr<ExtensionError> runtime_error2 = | 154 std::unique_ptr<ExtensionError> runtime_error2 = |
| 155 CreateNewRuntimeError(kId, base::UintToString(1u)); | 155 CreateNewRuntimeError(kId, base::UintToString(1u)); |
| 156 const ExtensionError* weak_error = runtime_error2.get(); | 156 const ExtensionError* weak_error = runtime_error2.get(); |
| 157 ASSERT_TRUE(errors_.AddError(std::move(runtime_error2))); | 157 ASSERT_TRUE(errors_.AddError(std::move(runtime_error2))); |
| 158 | 158 |
| 159 // We should only have three errors stored, since two of the four reported | 159 // We should only have three errors stored, since two of the four reported |
| 160 // were identical, and the older should have been replaced. | 160 // were identical, and the older should have been replaced. |
| 161 ASSERT_EQ(1u, errors_.size()); | 161 ASSERT_EQ(1u, errors_.size()); |
| 162 const ErrorList& list = errors_.GetErrorsForExtension(kId); | 162 const ErrorList& list = errors_.GetErrorsForExtension(kId); |
| 163 ASSERT_EQ(kNumErrors, list.size()); | 163 ASSERT_EQ(kNumErrors, list.size()); |
| 164 | 164 |
| 165 // The duplicate error should be the last reported (pointer comparison)... | 165 // The duplicate error should be the last reported (pointer comparison)... |
| 166 ASSERT_EQ(weak_error, list.back()); | 166 ASSERT_EQ(weak_error, list.back()); |
| 167 // ... and should have two reported occurrences. | 167 // ... and should have two reported occurrences. |
| 168 ASSERT_EQ(2u, list.back()->occurrences()); | 168 ASSERT_EQ(2u, list.back()->occurrences()); |
| 169 } | 169 } |
| 170 | 170 |
| 171 } // namespace extensions | 171 } // namespace extensions |
| OLD | NEW |