| 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" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/threading/simple_thread.h" | 13 #include "base/threading/simple_thread.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 16 #include "net/log/net_log_event_type.h" |
| 17 #include "net/log/net_log_source_type.h" |
| 16 #include "net/log/test_net_log.h" | 18 #include "net/log/test_net_log.h" |
| 17 #include "net/log/test_net_log_entry.h" | 19 #include "net/log/test_net_log_entry.h" |
| 18 #include "net/log/test_net_log_util.h" | 20 #include "net/log/test_net_log_util.h" |
| 19 | 21 |
| 20 namespace net { | 22 namespace net { |
| 21 | 23 |
| 22 namespace { | 24 namespace { |
| 23 | 25 |
| 24 const int kThreads = 10; | 26 const int kThreads = 10; |
| 25 const int kEvents = 100; | 27 const int kEvents = 100; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 51 dict->Set("capture_mode", CaptureModeToValue(capture_mode)); | 53 dict->Set("capture_mode", CaptureModeToValue(capture_mode)); |
| 52 return std::move(dict); | 54 return std::move(dict); |
| 53 } | 55 } |
| 54 | 56 |
| 55 TEST(NetLogTest, Basic) { | 57 TEST(NetLogTest, Basic) { |
| 56 TestNetLog net_log; | 58 TestNetLog net_log; |
| 57 TestNetLogEntry::List entries; | 59 TestNetLogEntry::List entries; |
| 58 net_log.GetEntries(&entries); | 60 net_log.GetEntries(&entries); |
| 59 EXPECT_EQ(0u, entries.size()); | 61 EXPECT_EQ(0u, entries.size()); |
| 60 | 62 |
| 61 net_log.AddGlobalEntry(NetLog::TYPE_CANCELLED); | 63 net_log.AddGlobalEntry(NetLogEventType::CANCELLED); |
| 62 | 64 |
| 63 net_log.GetEntries(&entries); | 65 net_log.GetEntries(&entries); |
| 64 ASSERT_EQ(1u, entries.size()); | 66 ASSERT_EQ(1u, entries.size()); |
| 65 EXPECT_EQ(NetLog::TYPE_CANCELLED, entries[0].type); | 67 EXPECT_EQ(NetLogEventType::CANCELLED, entries[0].type); |
| 66 EXPECT_EQ(NetLog::SOURCE_NONE, entries[0].source.type); | 68 EXPECT_EQ(NetLogSourceType::NONE, entries[0].source.type); |
| 67 EXPECT_NE(NetLog::Source::kInvalidId, entries[0].source.id); | 69 EXPECT_NE(NetLog::Source::kInvalidId, entries[0].source.id); |
| 68 EXPECT_EQ(NetLog::PHASE_NONE, entries[0].phase); | 70 EXPECT_EQ(NetLogEventPhase::NONE, entries[0].phase); |
| 69 EXPECT_GE(base::TimeTicks::Now(), entries[0].time); | 71 EXPECT_GE(base::TimeTicks::Now(), entries[0].time); |
| 70 EXPECT_FALSE(entries[0].params); | 72 EXPECT_FALSE(entries[0].params); |
| 71 } | 73 } |
| 72 | 74 |
| 73 // Check that the correct CaptureMode is sent to NetLog Value callbacks. | 75 // Check that the correct CaptureMode is sent to NetLog Value callbacks. |
| 74 TEST(NetLogTest, CaptureModes) { | 76 TEST(NetLogTest, CaptureModes) { |
| 75 NetLogCaptureMode kModes[] = { | 77 NetLogCaptureMode kModes[] = { |
| 76 NetLogCaptureMode::Default(), | 78 NetLogCaptureMode::Default(), |
| 77 NetLogCaptureMode::IncludeCookiesAndCredentials(), | 79 NetLogCaptureMode::IncludeCookiesAndCredentials(), |
| 78 NetLogCaptureMode::IncludeSocketBytes(), | 80 NetLogCaptureMode::IncludeSocketBytes(), |
| 79 }; | 81 }; |
| 80 | 82 |
| 81 TestNetLog net_log; | 83 TestNetLog net_log; |
| 82 | 84 |
| 83 for (NetLogCaptureMode mode : kModes) { | 85 for (NetLogCaptureMode mode : kModes) { |
| 84 net_log.SetCaptureMode(mode); | 86 net_log.SetCaptureMode(mode); |
| 85 EXPECT_EQ(mode, net_log.GetObserver()->capture_mode()); | 87 EXPECT_EQ(mode, net_log.GetObserver()->capture_mode()); |
| 86 | 88 |
| 87 net_log.AddGlobalEntry(NetLog::TYPE_SOCKET_ALIVE, | 89 net_log.AddGlobalEntry(NetLogEventType::SOCKET_ALIVE, |
| 88 base::Bind(NetCaptureModeCallback)); | 90 base::Bind(NetCaptureModeCallback)); |
| 89 | 91 |
| 90 TestNetLogEntry::List entries; | 92 TestNetLogEntry::List entries; |
| 91 net_log.GetEntries(&entries); | 93 net_log.GetEntries(&entries); |
| 92 | 94 |
| 93 ASSERT_EQ(1u, entries.size()); | 95 ASSERT_EQ(1u, entries.size()); |
| 94 EXPECT_EQ(NetLog::TYPE_SOCKET_ALIVE, entries[0].type); | 96 EXPECT_EQ(NetLogEventType::SOCKET_ALIVE, entries[0].type); |
| 95 EXPECT_EQ(NetLog::SOURCE_NONE, entries[0].source.type); | 97 EXPECT_EQ(NetLogSourceType::NONE, entries[0].source.type); |
| 96 EXPECT_NE(NetLog::Source::kInvalidId, entries[0].source.id); | 98 EXPECT_NE(NetLog::Source::kInvalidId, entries[0].source.id); |
| 97 EXPECT_EQ(NetLog::PHASE_NONE, entries[0].phase); | 99 EXPECT_EQ(NetLogEventPhase::NONE, entries[0].phase); |
| 98 EXPECT_GE(base::TimeTicks::Now(), entries[0].time); | 100 EXPECT_GE(base::TimeTicks::Now(), entries[0].time); |
| 99 | 101 |
| 100 int logged_capture_mode; | 102 int logged_capture_mode; |
| 101 ASSERT_TRUE( | 103 ASSERT_TRUE( |
| 102 entries[0].GetIntegerValue("capture_mode", &logged_capture_mode)); | 104 entries[0].GetIntegerValue("capture_mode", &logged_capture_mode)); |
| 103 EXPECT_EQ(CaptureModeToInt(mode), logged_capture_mode); | 105 EXPECT_EQ(CaptureModeToInt(mode), logged_capture_mode); |
| 104 | 106 |
| 105 net_log.Clear(); | 107 net_log.Clear(); |
| 106 } | 108 } |
| 107 } | 109 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 size_t GetNumValues() const { return values_.size(); } | 144 size_t GetNumValues() const { return values_.size(); } |
| 143 base::DictionaryValue* GetValue(size_t index) const { | 145 base::DictionaryValue* GetValue(size_t index) const { |
| 144 return values_[index].get(); | 146 return values_[index].get(); |
| 145 } | 147 } |
| 146 | 148 |
| 147 private: | 149 private: |
| 148 std::vector<std::unique_ptr<base::DictionaryValue>> values_; | 150 std::vector<std::unique_ptr<base::DictionaryValue>> values_; |
| 149 }; | 151 }; |
| 150 | 152 |
| 151 void AddEvent(NetLog* net_log) { | 153 void AddEvent(NetLog* net_log) { |
| 152 net_log->AddGlobalEntry(NetLog::TYPE_CANCELLED, | 154 net_log->AddGlobalEntry(NetLogEventType::CANCELLED, |
| 153 base::Bind(CaptureModeToValue)); | 155 base::Bind(CaptureModeToValue)); |
| 154 } | 156 } |
| 155 | 157 |
| 156 // A thread that waits until an event has been signalled before calling | 158 // A thread that waits until an event has been signalled before calling |
| 157 // RunTestThread. | 159 // RunTestThread. |
| 158 class NetLogTestThread : public base::SimpleThread { | 160 class NetLogTestThread : public base::SimpleThread { |
| 159 public: | 161 public: |
| 160 NetLogTestThread() | 162 NetLogTestThread() |
| 161 : base::SimpleThread("NetLogTest"), net_log_(NULL), start_event_(NULL) {} | 163 : base::SimpleThread("NetLogTest"), net_log_(NULL), start_event_(NULL) {} |
| 162 | 164 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 NetLog net_log; | 398 NetLog net_log; |
| 397 | 399 |
| 398 // 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 |
| 399 // and remove an observer, and set its logging level. | 401 // and remove an observer, and set its logging level. |
| 400 RunTestThreads<AddRemoveObserverTestThread>(&net_log); | 402 RunTestThreads<AddRemoveObserverTestThread>(&net_log); |
| 401 } | 403 } |
| 402 | 404 |
| 403 } // namespace | 405 } // namespace |
| 404 | 406 |
| 405 } // namespace net | 407 } // namespace net |
| OLD | NEW |