Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 "components/browser_watcher/system_session_analyzer_win.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/time/time.h" | |
| 11 #include "testing/gmock/include/gmock/gmock.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 namespace browser_watcher { | |
| 15 | |
| 16 // Ensure the fetcher retrieves events. Assumes the test host has at least 1 | |
| 17 // prior session. | |
| 18 TEST(SystemSessionEventFetcherTest, TestRetrieval) { | |
|
Sigurður Ásgeirsson
2017/03/01 15:09:27
mmm - will this fail on every new test bot until i
manzagop (departed)
2017/03/01 21:07:45
Yeah, this will happen and will be annoying. I've
| |
| 19 SystemSessionEventFetcher fetcher(1); | |
| 20 | |
| 21 std::vector<SystemSessionEventFetcher::EventInfo> events; | |
| 22 ASSERT_TRUE(fetcher.FetchEvents(&events)); | |
| 23 EXPECT_EQ(3U, events.size()); | |
| 24 } | |
| 25 | |
| 26 // Ensure the fetcher's retrieved events conform to our expectations. This | |
| 27 // conformance is validated using the SystemSessionAnalyzer. Note that the | |
| 28 // ability of SystemSessionAnalyzer to validate the conformance is tested below. | |
| 29 TEST(SystemSessionEventFetcherTest, NoEvent) { | |
| 30 std::unique_ptr<SystemSessionEventFetcher> fetcher( | |
| 31 new SystemSessionEventFetcher(1)); | |
| 32 SystemSessionAnalyzer analyzer(std::move(fetcher)); | |
| 33 EXPECT_EQ(SystemSessionAnalyzer::CLEAN, | |
| 34 analyzer.IsSessionUnclean(base::Time::Now())); | |
| 35 } | |
| 36 | |
|
Sigurður Ásgeirsson
2017/03/01 15:09:27
In Syzygy we use "Mock"XXX - is there a tradition
manzagop (departed)
2017/03/01 21:07:45
Actually, this is a stub. Mocks validate interacti
| |
| 37 class FakeSystemSessionEventFetcher : public SystemSessionEventFetcher { | |
| 38 public: | |
| 39 FakeSystemSessionEventFetcher() : SystemSessionEventFetcher(10U) {} | |
| 40 | |
| 41 bool FetchEvents(std::vector<EventInfo>* event_infos) const override { | |
| 42 DCHECK(event_infos); | |
| 43 *event_infos = events_; | |
| 44 return true; | |
| 45 } | |
| 46 | |
| 47 void AddEvent(const EventInfo& info) { events_.push_back(info); } | |
| 48 | |
| 49 private: | |
| 50 std::vector<EventInfo> events_; | |
| 51 }; | |
| 52 | |
| 53 TEST(SystemSessionAnalyzerTest, StandardCase) { | |
| 54 std::unique_ptr<FakeSystemSessionEventFetcher> fetcher( | |
| 55 new FakeSystemSessionEventFetcher()); | |
| 56 | |
| 57 base::Time time = base::Time::Now(); | |
| 58 fetcher->AddEvent({6005U, time}); | |
|
Sigurður Ásgeirsson
2017/03/01 15:09:27
nit: can we have declarative constants for the mag
manzagop (departed)
2017/03/01 21:07:45
Done.
| |
| 59 fetcher->AddEvent({6008U, time - base::TimeDelta::FromSeconds(10)}); | |
| 60 fetcher->AddEvent({6005U, time - base::TimeDelta::FromSeconds(20)}); | |
| 61 fetcher->AddEvent({6006U, time - base::TimeDelta::FromSeconds(22)}); | |
| 62 fetcher->AddEvent({6005U, time - base::TimeDelta::FromSeconds(28)}); | |
| 63 | |
| 64 SystemSessionAnalyzer analyzer(std::move(fetcher)); | |
| 65 | |
| 66 EXPECT_EQ(SystemSessionAnalyzer::OUTSIDE_RANGE, | |
| 67 analyzer.IsSessionUnclean(time - base::TimeDelta::FromSeconds(30))); | |
| 68 EXPECT_EQ(SystemSessionAnalyzer::CLEAN, | |
| 69 analyzer.IsSessionUnclean(time - base::TimeDelta::FromSeconds(25))); | |
| 70 EXPECT_EQ(SystemSessionAnalyzer::UNCLEAN, | |
| 71 analyzer.IsSessionUnclean(time - base::TimeDelta::FromSeconds(20))); | |
| 72 EXPECT_EQ(SystemSessionAnalyzer::UNCLEAN, | |
| 73 analyzer.IsSessionUnclean(time - base::TimeDelta::FromSeconds(15))); | |
| 74 EXPECT_EQ(SystemSessionAnalyzer::UNCLEAN, | |
| 75 analyzer.IsSessionUnclean(time - base::TimeDelta::FromSeconds(10))); | |
| 76 EXPECT_EQ(SystemSessionAnalyzer::CLEAN, | |
| 77 analyzer.IsSessionUnclean(time - base::TimeDelta::FromSeconds(5))); | |
| 78 EXPECT_EQ(SystemSessionAnalyzer::CLEAN, | |
| 79 analyzer.IsSessionUnclean(time + base::TimeDelta::FromSeconds(5))); | |
| 80 } | |
| 81 | |
| 82 TEST(SystemSessionAnalyzerTest, NoEvent) { | |
| 83 std::unique_ptr<SystemSessionEventFetcher> fetcher( | |
| 84 new FakeSystemSessionEventFetcher()); | |
| 85 SystemSessionAnalyzer analyzer(std::move(fetcher)); | |
| 86 EXPECT_EQ(SystemSessionAnalyzer::FAILED, | |
| 87 analyzer.IsSessionUnclean(base::Time::Now())); | |
| 88 } | |
| 89 | |
| 90 TEST(SystemSessionAnalyzerTest, TimeInversion) { | |
| 91 std::unique_ptr<FakeSystemSessionEventFetcher> fetcher( | |
| 92 new FakeSystemSessionEventFetcher()); | |
| 93 | |
| 94 base::Time time = base::Time::Now(); | |
| 95 fetcher->AddEvent({6005U, time}); | |
| 96 fetcher->AddEvent({6006U, time + base::TimeDelta::FromSeconds(1)}); | |
| 97 fetcher->AddEvent({6005U, time - base::TimeDelta::FromSeconds(1)}); | |
| 98 | |
| 99 SystemSessionAnalyzer analyzer(std::move(fetcher)); | |
| 100 EXPECT_EQ(SystemSessionAnalyzer::FAILED, | |
| 101 analyzer.IsSessionUnclean(base::Time::Now())); | |
| 102 } | |
| 103 | |
| 104 TEST(SystemSessionAnalyzerTest, IdInversion) { | |
| 105 std::unique_ptr<FakeSystemSessionEventFetcher> fetcher( | |
| 106 new FakeSystemSessionEventFetcher()); | |
| 107 | |
| 108 base::Time time = base::Time::Now(); | |
| 109 fetcher->AddEvent({6005U, time}); | |
| 110 fetcher->AddEvent({6005U, time - base::TimeDelta::FromSeconds(1)}); | |
| 111 fetcher->AddEvent({6006U, time - base::TimeDelta::FromSeconds(2)}); | |
| 112 | |
| 113 SystemSessionAnalyzer analyzer(std::move(fetcher)); | |
| 114 EXPECT_EQ(SystemSessionAnalyzer::FAILED, | |
| 115 analyzer.IsSessionUnclean(base::Time::Now())); | |
| 116 } | |
| 117 | |
| 118 } // namespace browser_watcher | |
| OLD | NEW |