Chromium Code Reviews| 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(); |
| + } |
| + ]); |
| +}); |