Roll src/third_party/WebKit 9f7fb92:f103b33 (svn 202621:202622)
[chromium-blink-merge.git] / components / drive / event_logger_unittest.cc
blob9d3b1fd399c7f009f493c1d343df3839d5a988b6
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
3 // found in the LICENSE file.
5 #include "components/drive/event_logger.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace drive {
11 TEST(EventLoggerTest, BasicLogging) {
12 EventLogger logger;
13 logger.SetHistorySize(3); // At most 3 events are kept.
14 EXPECT_EQ(0U, logger.GetHistory().size());
16 logger.Log(logging::LOG_INFO, "first");
17 logger.Log(logging::LOG_INFO, "%dnd", 2);
18 logger.Log(logging::LOG_INFO, "third");
20 // Events are recorded in the chronological order with sequential IDs.
21 std::vector<EventLogger::Event> history = logger.GetHistory();
22 ASSERT_EQ(3U, history.size());
23 EXPECT_EQ(0, history[0].id);
24 EXPECT_EQ("first", history[0].what);
25 EXPECT_EQ(1, history[1].id);
26 EXPECT_EQ("2nd", history[1].what);
27 EXPECT_EQ(2, history[2].id);
28 EXPECT_EQ("third", history[2].what);
30 logger.Log(logging::LOG_INFO, "fourth");
31 // It does not log events beyond the specified.
32 history = logger.GetHistory();
33 ASSERT_EQ(3U, history.size());
34 // The oldest events is pushed out.
35 EXPECT_EQ(1, history[0].id);
36 EXPECT_EQ("2nd", history[0].what);
37 EXPECT_EQ(2, history[1].id);
38 EXPECT_EQ("third", history[1].what);
39 EXPECT_EQ(3, history[2].id);
40 EXPECT_EQ("fourth", history[2].what);
43 } // namespace drive