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

Unified Diff: chrome/test/data/extensions/api_test/mdns/api-packaged-apps/register_too_many_listeners.js

Issue 1005903005: Cap chrome.mdns.onServiceList listeners per extension at 10 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add maxListeners limit in mdns.idl and corresponding browser test Created 5 years, 9 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/data/extensions/api_test/mdns/api-packaged-apps/register_too_many_listeners.js
diff --git a/chrome/test/data/extensions/api_test/mdns/api-packaged-apps/register_too_many_listeners.js b/chrome/test/data/extensions/api_test/mdns/api-packaged-apps/register_too_many_listeners.js
new file mode 100644
index 0000000000000000000000000000000000000000..ce110639dc710ccbcb5ebb0f09b82cff61c31e3a
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/mdns/api-packaged-apps/register_too_many_listeners.js
@@ -0,0 +1,43 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
mark a. foltz 2015/03/30 17:44:57 Update copyright
Red Daly 2015/03/30 20:28:34 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+chrome.app.runtime.onLaunched.addListener(function() {
+ chrome.test.runTests([
+ function registerListeners() {
+ // Add the maximum number of listeners.
+ var listeners = [];
+ var MAX_LISTENERS = 10;
+ for (var i = 0; i < MAX_LISTENERS; i++) {
+ listeners.push({
+ 'callback': function() {},
+ 'filter': {'serviceType': '_' + i + '._tcp.local'}
+ });
+ }
+ listeners.forEach(function(x) {
+ chrome.mdns.onServiceList.addListener(x.callback, x.filter);
+ });
+
+ var removeAllListeners = function() {
+ };
+
+ // Now try adding one more. This should exceed the limit.
+ var failedToAddLast = false;
+ try {
+ chrome.mdns.onServiceList.addListener(
+ function() {},
+ {'serviceType': '_one_too_many._tcp.local'});
+ } catch (x) {
+ failedToAddLast = true;
mark a. foltz 2015/03/30 17:44:57 Assert that the exception is actually for too many
Red Daly 2015/03/30 20:28:34 Done. (This depends on string matching the error
+ }
+ chrome.test.assertBool(
+ true, failedToAddLast,
+ "there should be an error when adding the 11th listener");
+
+ listeners.forEach(function(x) {
+ chrome.mdns.onServiceList.removeListener(x.callback, x.filter);
+ });
+ chrome.test.notifyPass();
+ }
+ ]);
+});

Powered by Google App Engine
This is Rietveld 408576698