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

Unified Diff: components/proximity_auth/logging/logging_unittest.cc

Issue 2034393004: Allow multiple logging::LogMessage{Handler,Listener}s Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/crash/content/app/crashpad.cc ('k') | content/browser/frame_host/render_frame_host_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/proximity_auth/logging/logging_unittest.cc
diff --git a/components/proximity_auth/logging/logging_unittest.cc b/components/proximity_auth/logging/logging_unittest.cc
index 9efc5d7f7a5530fb2217d93d3e003b54dbaecf06..d06c550cd195055e7c439a55f8ac6666290ea97c 100644
--- a/components/proximity_auth/logging/logging_unittest.cc
+++ b/components/proximity_auth/logging/logging_unittest.cc
@@ -7,6 +7,7 @@
#include <stddef.h>
#include "base/lazy_instance.h"
+#include "base/memory/ptr_util.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "components/proximity_auth/logging/log_buffer.h"
@@ -21,36 +22,34 @@ const char kLog2[] = "Construction grade cedar";
const char kLog3[] = "Pine infested by hungry beetles";
// Called for every log message added to the standard logging system. The new
-// log is saved in |g_standard_logs| and consumed so it does not flood stdout.
+// log is saved in |g_standard_logs|.
base::LazyInstance<std::vector<std::string>> g_standard_logs =
LAZY_INSTANCE_INITIALIZER;
-bool HandleStandardLogMessage(int severity,
- const char* file,
- int line,
- size_t message_start,
- const std::string& str) {
- g_standard_logs.Get().push_back(str);
- return true;
-}
+class StandardLogMessageListener : logging::LogMessageListener {
+ void OnMessage(int severity,
+ const char* file,
+ int line,
+ size_t message_start,
+ const std::string& str) override {
+ g_standard_logs.Get().push_back(str);
+ }
+};
} // namespace
class ProximityAuthLoggingTest : public testing::Test {
public:
- ProximityAuthLoggingTest() : previous_handler_(NULL) {}
-
void SetUp() override {
LogBuffer::GetInstance()->Clear();
g_standard_logs.Get().clear();
- previous_handler_ = logging::GetLogMessageHandler();
- logging::SetLogMessageHandler(&HandleStandardLogMessage);
+ log_listener_ = base::MakeUnique<StandardLogMessageListener>();
}
- void TearDown() override { logging::SetLogMessageHandler(previous_handler_); }
+ void TearDown() override { log_listener_.reset(); }
private:
- logging::LogMessageHandlerFunction previous_handler_;
+ std::unique_ptr<StandardLogMessageListener> log_listener_;
};
TEST_F(ProximityAuthLoggingTest, LogsSavedToBuffer) {
« no previous file with comments | « components/crash/content/app/crashpad.cc ('k') | content/browser/frame_host/render_frame_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698