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

Side by Side Diff: chrome/test/chromedriver/performance_logger_unittest.cc

Issue 653773004: Standardize usage of virtual/override/final in chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/test/chromedriver/performance_logger.h" 5 #include "chrome/test/chromedriver/performance_logger.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 17 matching lines...) Expand all
28 ~DevToolsCommand() {} 28 ~DevToolsCommand() {}
29 29
30 std::string method; 30 std::string method;
31 scoped_ptr<base::DictionaryValue> params; 31 scoped_ptr<base::DictionaryValue> params;
32 }; 32 };
33 33
34 class FakeDevToolsClient : public StubDevToolsClient { 34 class FakeDevToolsClient : public StubDevToolsClient {
35 public: 35 public:
36 explicit FakeDevToolsClient(const std::string& id) 36 explicit FakeDevToolsClient(const std::string& id)
37 : id_(id), listener_(NULL), command_index_(0) {} 37 : id_(id), listener_(NULL), command_index_(0) {}
38 virtual ~FakeDevToolsClient() {} 38 ~FakeDevToolsClient() override {}
39 39
40 bool PopSentCommand(DevToolsCommand** out_command) { 40 bool PopSentCommand(DevToolsCommand** out_command) {
41 if (sent_commands_.size() > command_index_) { 41 if (sent_commands_.size() > command_index_) {
42 *out_command = sent_commands_.get().at(command_index_++); 42 *out_command = sent_commands_.get().at(command_index_++);
43 return true; 43 return true;
44 } 44 }
45 return false; 45 return false;
46 } 46 }
47 47
48 Status TriggerEvent(const std::string& method) { 48 Status TriggerEvent(const std::string& method) {
49 base::DictionaryValue empty_params; 49 base::DictionaryValue empty_params;
50 return listener_->OnEvent(this, method, empty_params); 50 return listener_->OnEvent(this, method, empty_params);
51 } 51 }
52 52
53 Status TriggerEvent(const std::string& method, 53 Status TriggerEvent(const std::string& method,
54 const base::DictionaryValue& params) { 54 const base::DictionaryValue& params) {
55 return listener_->OnEvent(this, method, params); 55 return listener_->OnEvent(this, method, params);
56 } 56 }
57 57
58 // Overridden from DevToolsClient: 58 // Overridden from DevToolsClient:
59 virtual Status ConnectIfNecessary() override { 59 Status ConnectIfNecessary() override { return listener_->OnConnected(this); }
60 return listener_->OnConnected(this);
61 }
62 60
63 virtual Status SendCommandAndGetResult( 61 Status SendCommandAndGetResult(
64 const std::string& method, 62 const std::string& method,
65 const base::DictionaryValue& params, 63 const base::DictionaryValue& params,
66 scoped_ptr<base::DictionaryValue>* result) override { 64 scoped_ptr<base::DictionaryValue>* result) override {
67 sent_commands_.push_back(new DevToolsCommand(method, 65 sent_commands_.push_back(new DevToolsCommand(method,
68 params.DeepCopy())); 66 params.DeepCopy()));
69 return Status(kOk); 67 return Status(kOk);
70 } 68 }
71 69
72 virtual void AddListener(DevToolsEventListener* listener) override { 70 void AddListener(DevToolsEventListener* listener) override {
73 CHECK(!listener_); 71 CHECK(!listener_);
74 listener_ = listener; 72 listener_ = listener;
75 } 73 }
76 74
77 virtual const std::string& GetId() override { 75 const std::string& GetId() override { return id_; }
78 return id_;
79 }
80 76
81 private: 77 private:
82 const std::string id_; // WebView id. 78 const std::string id_; // WebView id.
83 ScopedVector<DevToolsCommand> sent_commands_; // Commands that were sent. 79 ScopedVector<DevToolsCommand> sent_commands_; // Commands that were sent.
84 DevToolsEventListener* listener_; // The fake allows only one event listener. 80 DevToolsEventListener* listener_; // The fake allows only one event listener.
85 size_t command_index_; 81 size_t command_index_;
86 }; 82 };
87 83
88 struct LogEntry { 84 struct LogEntry {
89 const base::Time timestamp; 85 const base::Time timestamp;
90 const Log::Level level; 86 const Log::Level level;
91 const std::string source; 87 const std::string source;
92 const std::string message; 88 const std::string message;
93 89
94 LogEntry(const base::Time& timestamp, 90 LogEntry(const base::Time& timestamp,
95 Log::Level level, 91 Log::Level level,
96 const std::string& source, 92 const std::string& source,
97 const std::string& message) 93 const std::string& message)
98 : timestamp(timestamp), level(level), source(source), message(message) {} 94 : timestamp(timestamp), level(level), source(source), message(message) {}
99 }; 95 };
100 96
101 class FakeLog : public Log { 97 class FakeLog : public Log {
102 public: 98 public:
103 virtual void AddEntryTimestamped(const base::Time& timestamp, 99 void AddEntryTimestamped(const base::Time& timestamp,
104 Level level, 100 Level level,
105 const std::string& source, 101 const std::string& source,
106 const std::string& message) override; 102 const std::string& message) override;
107 103
108 const ScopedVector<LogEntry>& GetEntries() { 104 const ScopedVector<LogEntry>& GetEntries() {
109 return entries_; 105 return entries_;
110 } 106 }
111 107
112 private: 108 private:
113 ScopedVector<LogEntry> entries_; 109 ScopedVector<LogEntry> entries_;
114 }; 110 };
115 111
116 void FakeLog::AddEntryTimestamped(const base::Time& timestamp, 112 void FakeLog::AddEntryTimestamped(const base::Time& timestamp,
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 ASSERT_FALSE(client.PopSentCommand(&cmd)); 242 ASSERT_FALSE(client.PopSentCommand(&cmd));
247 } 243 }
248 244
249 namespace { 245 namespace {
250 246
251 class FakeBrowserwideClient : public FakeDevToolsClient { 247 class FakeBrowserwideClient : public FakeDevToolsClient {
252 public: 248 public:
253 FakeBrowserwideClient() 249 FakeBrowserwideClient()
254 : FakeDevToolsClient(DevToolsClientImpl::kBrowserwideDevToolsClientId), 250 : FakeDevToolsClient(DevToolsClientImpl::kBrowserwideDevToolsClientId),
255 events_handled_(false) {} 251 events_handled_(false) {}
256 virtual ~FakeBrowserwideClient() {} 252 ~FakeBrowserwideClient() override {}
257 253
258 bool events_handled() const { 254 bool events_handled() const {
259 return events_handled_; 255 return events_handled_;
260 } 256 }
261 257
262 // Overridden from DevToolsClient: 258 // Overridden from DevToolsClient:
263 virtual Status HandleEventsUntil( 259 Status HandleEventsUntil(const ConditionalFunc& conditional_func,
264 const ConditionalFunc& conditional_func, 260 const base::TimeDelta& timeout) override {
265 const base::TimeDelta& timeout) override {
266 TriggerEvent("Tracing.tracingComplete"); 261 TriggerEvent("Tracing.tracingComplete");
267 events_handled_ = true; 262 events_handled_ = true;
268 return Status(kOk); 263 return Status(kOk);
269 } 264 }
270 265
271 private: 266 private:
272 bool events_handled_; 267 bool events_handled_;
273 }; 268 };
274 269
275 } // namespace 270 } // namespace
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 std::string webview; 373 std::string webview;
379 EXPECT_TRUE(message->GetString("webview", &webview)); 374 EXPECT_TRUE(message->GetString("webview", &webview));
380 EXPECT_EQ(DevToolsClientImpl::kBrowserwideDevToolsClientId, webview); 375 EXPECT_EQ(DevToolsClientImpl::kBrowserwideDevToolsClientId, webview);
381 std::string method; 376 std::string method;
382 EXPECT_TRUE(message->GetString("message.method", &method)); 377 EXPECT_TRUE(message->GetString("message.method", &method));
383 EXPECT_EQ("Tracing.bufferUsage", method); 378 EXPECT_EQ("Tracing.bufferUsage", method);
384 base::DictionaryValue* actual_params; 379 base::DictionaryValue* actual_params;
385 EXPECT_TRUE(message->GetDictionary("message.params", &actual_params)); 380 EXPECT_TRUE(message->GetDictionary("message.params", &actual_params));
386 EXPECT_TRUE(actual_params->HasKey("error")); 381 EXPECT_TRUE(actual_params->HasKey("error"));
387 } 382 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/performance_logger.h ('k') | chrome/test/chromedriver/server/chromedriver_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698