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

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: Rebase onto HEAD and consolidate changes into one commit 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
« no previous file with comments | « chrome/test/data/extensions/api_test/mdns/api-packaged-apps/manifest.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..4b22bc93038e37bcf9b3853143feb1446e367585
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/mdns/api-packaged-apps/register_too_many_listeners.js
@@ -0,0 +1,45 @@
+// Copyright 2015 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.
+
+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) {
+ chrome.test.assertEq('Too many listeners for mdns.onServiceList',
+ x.message);
+ failedToAddLast = true;
+ }
+ 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();
+ }
+ ]);
+});
« no previous file with comments | « chrome/test/data/extensions/api_test/mdns/api-packaged-apps/manifest.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698