Chromium Code Reviews| Index: chrome/test/chromedriver/chrome/event_listener_count.cc |
| diff --git a/chrome/test/chromedriver/chrome/event_listener_count.cc b/chrome/test/chromedriver/chrome/event_listener_count.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b25c3f170708e78baf017c3a89dec949f87f913f |
| --- /dev/null |
| +++ b/chrome/test/chromedriver/chrome/event_listener_count.cc |
| @@ -0,0 +1,66 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/test/chromedriver/chrome/event_listener_count.h" |
| + |
| +#include "base/json/json_reader.h" |
| +#include "base/logging.h" |
| +#include "base/values.h" |
| +#include "chrome/test/chromedriver/chrome/devtools_client.h" |
| +#include "chrome/test/chromedriver/chrome/status.h" |
| + |
| + |
| +EventListenerCount::EventListenerCount(DevToolsClient* client) |
| + : client_(client) { |
| + client_->AddListener(this); |
| +} |
| + |
| +EventListenerCount::~EventListenerCount() {} |
| + |
| +Status EventListenerCount::GetEventListenersCount(int *count) { |
| + if (count == NULL) |
| + return Status(kForbidden); |
| + |
| + scoped_ptr<base::DictionaryValue>* result; |
| + Status status1 = GetEventListenersCountInternal(result); |
| + if (status1.IsError()) |
| + return status1; |
| + |
| + bool isEventListenerValueSet = (*result)->GetIntegerWithoutPathExpansion( |
| + "jsEventListeners", count); |
| + if (!isEventListenerValueSet) |
| + return Status(kUnknownError); |
| + |
| + base::DictionaryValue params; |
| + Status status2 = client_->SendCommand("Debugger.disable", params); |
| + if (status2.IsError()) |
| + return status2; |
| + |
| + return Status(kOk); |
| +} |
| + |
| +Status EventListenerCount::GetEventListenersCountInternal( |
| + scoped_ptr<base::DictionaryValue>* result) { |
| + |
| + base::DictionaryValue params; |
| + const char* kMethods[] = { |
| + "Debugger.enable", |
| + "HeapProfiler.collectGarbage", |
| + "Memory.getDOMCounters" |
|
chrisgao (Use stgao instead)
2013/10/26 00:54:01
It seems no need to enable the debugger.
And I th
|
| + }; |
| + for (size_t i = 0; i < arraysize(kMethods); ++i) { |
| + Status status = client_->SendCommand(kMethods[i], params); |
| + if (status.IsError()) |
| + return status; |
| + } |
| + |
| + base::DictionaryValue uid_params; |
| + uid_params.SetInteger("uid", -1); |
| + Status status = client_->SendCommandAndGetResult( |
| + "Memory.getDOMCounters", uid_params, result); |
| + if (status.IsError()) |
| + return status; |
| + return Status(kOk); |
| +} |
| + |