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

Unified Diff: chrome/test/chromedriver/chrome/event_listener_count.cc

Issue 34773002: Adding an api to get number of event listeners. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding some more files to the patch set. Created 7 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 side-by-side diff with in-line comments
Download patch
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);
+}
+

Powered by Google App Engine
This is Rietveld 408576698