Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: net/log/net_log_unittest.cc

Issue 1893083002: Change scoped_ptr to std::unique_ptr in //net. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptr-net-all: iwyu Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/log/net_log.cc ('k') | net/log/net_log_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
12 #include "base/threading/simple_thread.h" 13 #include "base/threading/simple_thread.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
15 #include "net/log/test_net_log.h" 16 #include "net/log/test_net_log.h"
16 #include "net/log/test_net_log_entry.h" 17 #include "net/log/test_net_log_entry.h"
17 #include "net/log/test_net_log_util.h" 18 #include "net/log/test_net_log_util.h"
18 19
19 namespace net { 20 namespace net {
20 21
(...skipping 10 matching lines...) Expand all
31 return 0; 32 return 0;
32 if (capture_mode == NetLogCaptureMode::IncludeCookiesAndCredentials()) 33 if (capture_mode == NetLogCaptureMode::IncludeCookiesAndCredentials())
33 return 1; 34 return 1;
34 if (capture_mode == NetLogCaptureMode::IncludeSocketBytes()) 35 if (capture_mode == NetLogCaptureMode::IncludeSocketBytes())
35 return 2; 36 return 2;
36 37
37 ADD_FAILURE() << "Unknown capture mode"; 38 ADD_FAILURE() << "Unknown capture mode";
38 return -1; 39 return -1;
39 } 40 }
40 41
41 scoped_ptr<base::Value> CaptureModeToValue(NetLogCaptureMode capture_mode) { 42 std::unique_ptr<base::Value> CaptureModeToValue(
42 return make_scoped_ptr( 43 NetLogCaptureMode capture_mode) {
44 return base::WrapUnique(
43 new base::FundamentalValue(CaptureModeToInt(capture_mode))); 45 new base::FundamentalValue(CaptureModeToInt(capture_mode)));
44 } 46 }
45 47
46 scoped_ptr<base::Value> NetCaptureModeCallback(NetLogCaptureMode capture_mode) { 48 std::unique_ptr<base::Value> NetCaptureModeCallback(
47 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 49 NetLogCaptureMode capture_mode) {
50 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
48 dict->Set("capture_mode", CaptureModeToValue(capture_mode)); 51 dict->Set("capture_mode", CaptureModeToValue(capture_mode));
49 return std::move(dict); 52 return std::move(dict);
50 } 53 }
51 54
52 TEST(NetLogTest, Basic) { 55 TEST(NetLogTest, Basic) {
53 TestNetLog net_log; 56 TestNetLog net_log;
54 TestNetLogEntry::List entries; 57 TestNetLogEntry::List entries;
55 net_log.GetEntries(&entries); 58 net_log.GetEntries(&entries);
56 EXPECT_EQ(0u, entries.size()); 59 EXPECT_EQ(0u, entries.size());
57 60
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 class LoggingObserver : public NetLog::ThreadSafeObserver { 126 class LoggingObserver : public NetLog::ThreadSafeObserver {
124 public: 127 public:
125 LoggingObserver() {} 128 LoggingObserver() {}
126 129
127 ~LoggingObserver() override { 130 ~LoggingObserver() override {
128 if (net_log()) 131 if (net_log())
129 net_log()->DeprecatedRemoveObserver(this); 132 net_log()->DeprecatedRemoveObserver(this);
130 } 133 }
131 134
132 void OnAddEntry(const NetLog::Entry& entry) override { 135 void OnAddEntry(const NetLog::Entry& entry) override {
133 scoped_ptr<base::DictionaryValue> dict = 136 std::unique_ptr<base::DictionaryValue> dict =
134 base::DictionaryValue::From(make_scoped_ptr(entry.ToValue())); 137 base::DictionaryValue::From(base::WrapUnique(entry.ToValue()));
135 ASSERT_TRUE(dict); 138 ASSERT_TRUE(dict);
136 values_.push_back(std::move(dict)); 139 values_.push_back(std::move(dict));
137 } 140 }
138 141
139 size_t GetNumValues() const { return values_.size(); } 142 size_t GetNumValues() const { return values_.size(); }
140 base::DictionaryValue* GetValue(size_t index) const { 143 base::DictionaryValue* GetValue(size_t index) const {
141 return values_[index].get(); 144 return values_[index].get();
142 } 145 }
143 146
144 private: 147 private:
145 std::vector<scoped_ptr<base::DictionaryValue>> values_; 148 std::vector<std::unique_ptr<base::DictionaryValue>> values_;
146 }; 149 };
147 150
148 void AddEvent(NetLog* net_log) { 151 void AddEvent(NetLog* net_log) {
149 net_log->AddGlobalEntry(NetLog::TYPE_CANCELLED, 152 net_log->AddGlobalEntry(NetLog::TYPE_CANCELLED,
150 base::Bind(CaptureModeToValue)); 153 base::Bind(CaptureModeToValue));
151 } 154 }
152 155
153 // A thread that waits until an event has been signalled before calling 156 // A thread that waits until an event has been signalled before calling
154 // RunTestThread. 157 // RunTestThread.
155 class NetLogTestThread : public base::SimpleThread { 158 class NetLogTestThread : public base::SimpleThread {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 NetLog net_log; 394 NetLog net_log;
392 395
393 // Run a bunch of threads to completion, each of which will repeatedly add 396 // Run a bunch of threads to completion, each of which will repeatedly add
394 // and remove an observer, and set its logging level. 397 // and remove an observer, and set its logging level.
395 RunTestThreads<AddRemoveObserverTestThread>(&net_log); 398 RunTestThreads<AddRemoveObserverTestThread>(&net_log);
396 } 399 }
397 400
398 } // namespace 401 } // namespace
399 402
400 } // namespace net 403 } // namespace net
OLDNEW
« no previous file with comments | « net/log/net_log.cc ('k') | net/log/net_log_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698