Home | History | Annotate | Download | only in sync_file_system
      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 "chrome/browser/sync_file_system/logger.h"
      6 #include "testing/gtest/include/gtest/gtest.h"
      7 
      8 using drive::EventLogger;
      9 
     10 namespace sync_file_system {
     11 
     12 namespace {
     13 
     14 // Logs one event at each supported LogSeverity level.
     15 void LogSampleEvents() {
     16   util::Log(logging::LOG_INFO, FROM_HERE, "Info test message");
     17   util::Log(logging::LOG_WARNING, FROM_HERE, "Warning test message");
     18   util::Log(logging::LOG_ERROR, FROM_HERE, "Error test message");
     19 }
     20 
     21 bool ContainsString(std::string contains_string, EventLogger::Event event) {
     22   return event.what.find(contains_string) != std::string::npos;
     23 }
     24 
     25 }  // namespace
     26 
     27 class LoggerTest : public testing::Test {
     28  public:
     29   LoggerTest() {}
     30 
     31   virtual void SetUp() OVERRIDE {
     32     logging::SetMinLogLevel(logging::LOG_INFO);
     33     util::ClearLog();
     34   }
     35 
     36  private:
     37   DISALLOW_COPY_AND_ASSIGN(LoggerTest);
     38 };
     39 
     40 TEST_F(LoggerTest, GetLogHistory) {
     41   LogSampleEvents();
     42 
     43   const std::vector<EventLogger::Event> log = util::GetLogHistory();
     44   ASSERT_EQ(3u, log.size());
     45   EXPECT_TRUE(ContainsString("Info test message", log[0]));
     46   EXPECT_TRUE(ContainsString("Warning test message", log[1]));
     47   EXPECT_TRUE(ContainsString("Error test message", log[2]));
     48 }
     49 
     50 TEST_F(LoggerTest, ClearLog) {
     51   LogSampleEvents();
     52   EXPECT_EQ(3u, util::GetLogHistory().size());
     53 
     54   util::ClearLog();
     55   EXPECT_EQ(0u, util::GetLogHistory().size());
     56 }
     57 
     58 
     59 }  // namespace sync_file_system
     60