| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "net/log/net_log.h" | 5 #include "net/log/net_log.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 TestNetLogEntry::List entries; | 59 TestNetLogEntry::List entries; |
| 60 net_log.GetEntries(&entries); | 60 net_log.GetEntries(&entries); |
| 61 EXPECT_EQ(0u, entries.size()); | 61 EXPECT_EQ(0u, entries.size()); |
| 62 | 62 |
| 63 net_log.AddGlobalEntry(NetLogEventType::CANCELLED); | 63 net_log.AddGlobalEntry(NetLogEventType::CANCELLED); |
| 64 | 64 |
| 65 net_log.GetEntries(&entries); | 65 net_log.GetEntries(&entries); |
| 66 ASSERT_EQ(1u, entries.size()); | 66 ASSERT_EQ(1u, entries.size()); |
| 67 EXPECT_EQ(NetLogEventType::CANCELLED, entries[0].type); | 67 EXPECT_EQ(NetLogEventType::CANCELLED, entries[0].type); |
| 68 EXPECT_EQ(NetLogSourceType::NONE, entries[0].source.type); | 68 EXPECT_EQ(NetLogSourceType::NONE, entries[0].source.type); |
| 69 EXPECT_NE(NetLog::Source::kInvalidId, entries[0].source.id); | 69 EXPECT_NE(NetLogSource::kInvalidId, entries[0].source.id); |
| 70 EXPECT_EQ(NetLogEventPhase::NONE, entries[0].phase); | 70 EXPECT_EQ(NetLogEventPhase::NONE, entries[0].phase); |
| 71 EXPECT_GE(base::TimeTicks::Now(), entries[0].time); | 71 EXPECT_GE(base::TimeTicks::Now(), entries[0].time); |
| 72 EXPECT_FALSE(entries[0].params); | 72 EXPECT_FALSE(entries[0].params); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Check that the correct CaptureMode is sent to NetLog Value callbacks. | 75 // Check that the correct CaptureMode is sent to NetLog Value callbacks. |
| 76 TEST(NetLogTest, CaptureModes) { | 76 TEST(NetLogTest, CaptureModes) { |
| 77 NetLogCaptureMode kModes[] = { | 77 NetLogCaptureMode kModes[] = { |
| 78 NetLogCaptureMode::Default(), | 78 NetLogCaptureMode::Default(), |
| 79 NetLogCaptureMode::IncludeCookiesAndCredentials(), | 79 NetLogCaptureMode::IncludeCookiesAndCredentials(), |
| 80 NetLogCaptureMode::IncludeSocketBytes(), | 80 NetLogCaptureMode::IncludeSocketBytes(), |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 TestNetLog net_log; | 83 TestNetLog net_log; |
| 84 | 84 |
| 85 for (NetLogCaptureMode mode : kModes) { | 85 for (NetLogCaptureMode mode : kModes) { |
| 86 net_log.SetCaptureMode(mode); | 86 net_log.SetCaptureMode(mode); |
| 87 EXPECT_EQ(mode, net_log.GetObserver()->capture_mode()); | 87 EXPECT_EQ(mode, net_log.GetObserver()->capture_mode()); |
| 88 | 88 |
| 89 net_log.AddGlobalEntry(NetLogEventType::SOCKET_ALIVE, | 89 net_log.AddGlobalEntry(NetLogEventType::SOCKET_ALIVE, |
| 90 base::Bind(NetCaptureModeCallback)); | 90 base::Bind(NetCaptureModeCallback)); |
| 91 | 91 |
| 92 TestNetLogEntry::List entries; | 92 TestNetLogEntry::List entries; |
| 93 net_log.GetEntries(&entries); | 93 net_log.GetEntries(&entries); |
| 94 | 94 |
| 95 ASSERT_EQ(1u, entries.size()); | 95 ASSERT_EQ(1u, entries.size()); |
| 96 EXPECT_EQ(NetLogEventType::SOCKET_ALIVE, entries[0].type); | 96 EXPECT_EQ(NetLogEventType::SOCKET_ALIVE, entries[0].type); |
| 97 EXPECT_EQ(NetLogSourceType::NONE, entries[0].source.type); | 97 EXPECT_EQ(NetLogSourceType::NONE, entries[0].source.type); |
| 98 EXPECT_NE(NetLog::Source::kInvalidId, entries[0].source.id); | 98 EXPECT_NE(NetLogSource::kInvalidId, entries[0].source.id); |
| 99 EXPECT_EQ(NetLogEventPhase::NONE, entries[0].phase); | 99 EXPECT_EQ(NetLogEventPhase::NONE, entries[0].phase); |
| 100 EXPECT_GE(base::TimeTicks::Now(), entries[0].time); | 100 EXPECT_GE(base::TimeTicks::Now(), entries[0].time); |
| 101 | 101 |
| 102 int logged_capture_mode; | 102 int logged_capture_mode; |
| 103 ASSERT_TRUE( | 103 ASSERT_TRUE( |
| 104 entries[0].GetIntegerValue("capture_mode", &logged_capture_mode)); | 104 entries[0].GetIntegerValue("capture_mode", &logged_capture_mode)); |
| 105 EXPECT_EQ(CaptureModeToInt(mode), logged_capture_mode); | 105 EXPECT_EQ(CaptureModeToInt(mode), logged_capture_mode); |
| 106 | 106 |
| 107 net_log.Clear(); | 107 net_log.Clear(); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 | 110 |
| 111 class CountingObserver : public NetLog::ThreadSafeObserver { | 111 class CountingObserver : public NetLog::ThreadSafeObserver { |
| 112 public: | 112 public: |
| 113 CountingObserver() : count_(0) {} | 113 CountingObserver() : count_(0) {} |
| 114 | 114 |
| 115 ~CountingObserver() override { | 115 ~CountingObserver() override { |
| 116 if (net_log()) | 116 if (net_log()) |
| 117 net_log()->DeprecatedRemoveObserver(this); | 117 net_log()->DeprecatedRemoveObserver(this); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void OnAddEntry(const NetLog::Entry& entry) override { ++count_; } | 120 void OnAddEntry(const NetLogEntry& entry) override { ++count_; } |
| 121 | 121 |
| 122 int count() const { return count_; } | 122 int count() const { return count_; } |
| 123 | 123 |
| 124 private: | 124 private: |
| 125 int count_; | 125 int count_; |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 class LoggingObserver : public NetLog::ThreadSafeObserver { | 128 class LoggingObserver : public NetLog::ThreadSafeObserver { |
| 129 public: | 129 public: |
| 130 LoggingObserver() {} | 130 LoggingObserver() {} |
| 131 | 131 |
| 132 ~LoggingObserver() override { | 132 ~LoggingObserver() override { |
| 133 if (net_log()) | 133 if (net_log()) |
| 134 net_log()->DeprecatedRemoveObserver(this); | 134 net_log()->DeprecatedRemoveObserver(this); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void OnAddEntry(const NetLog::Entry& entry) override { | 137 void OnAddEntry(const NetLogEntry& entry) override { |
| 138 std::unique_ptr<base::DictionaryValue> dict = | 138 std::unique_ptr<base::DictionaryValue> dict = |
| 139 base::DictionaryValue::From(entry.ToValue()); | 139 base::DictionaryValue::From(entry.ToValue()); |
| 140 ASSERT_TRUE(dict); | 140 ASSERT_TRUE(dict); |
| 141 values_.push_back(std::move(dict)); | 141 values_.push_back(std::move(dict)); |
| 142 } | 142 } |
| 143 | 143 |
| 144 size_t GetNumValues() const { return values_.size(); } | 144 size_t GetNumValues() const { return values_.size(); } |
| 145 base::DictionaryValue* GetValue(size_t index) const { | 145 base::DictionaryValue* GetValue(size_t index) const { |
| 146 return values_[index].get(); | 146 return values_[index].get(); |
| 147 } | 147 } |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 NetLog net_log; | 398 NetLog net_log; |
| 399 | 399 |
| 400 // Run a bunch of threads to completion, each of which will repeatedly add | 400 // Run a bunch of threads to completion, each of which will repeatedly add |
| 401 // and remove an observer, and set its logging level. | 401 // and remove an observer, and set its logging level. |
| 402 RunTestThreads<AddRemoveObserverTestThread>(&net_log); | 402 RunTestThreads<AddRemoveObserverTestThread>(&net_log); |
| 403 } | 403 } |
| 404 | 404 |
| 405 } // namespace | 405 } // namespace |
| 406 | 406 |
| 407 } // namespace net | 407 } // namespace net |
| OLD | NEW |