1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 // Register for events in 4 configurations, then navigate to page2.html, which
8 // will notify success and succeed the test on the C++ side. The C++ code
9 // asserts that the events have been unregistered.
16 chrome.browserAction.onClicked.addListener(function() {});
17 // Multiple listeners for the same event.
18 chrome.runtime.onStartup.addListener(function() {});
19 chrome.runtime.onStartup.addListener(function() {});
20 // A single listener, which previously had multiple listeners.
22 let singleListener = function() {};
23 chrome.runtime.onSuspend.addListener(singleListener);
24 chrome.runtime.onSuspend.addListener(function() {});
25 chrome.runtime.onSuspend.removeListener(singleListener);
27 // No listeners, which previously had listeners (all were removed).
29 let listener1 = function() {};
30 let listener2 = function() {};
31 chrome.runtime.onInstalled.addListener(listener1);
32 chrome.runtime.onInstalled.addListener(listener2);
33 chrome.runtime.onInstalled.removeListener(listener1);
34 chrome.runtime.onInstalled.removeListener(listener2);
41 function filterPort(portNumber) {
42 return {url: [{ports: [portNumber]}]};
46 chrome.webNavigation.onBeforeNavigate.addListener(function() {});
47 // Multiple, different listeners.
48 chrome.webNavigation.onCommitted.addListener(function() {});
49 chrome.webNavigation.onCommitted.addListener(function() {});
50 // Different listeners with the same filter.
51 chrome.webNavigation.onDOMContentLoaded.addListener(
52 function() {}, filterPort(80));
53 chrome.webNavigation.onDOMContentLoaded.addListener(
54 function() {}, filterPort(80));
55 // Different listeners with different filters, same event added twice.
57 let singleListener = function() {};
58 chrome.webNavigation.onCompleted.addListener(
59 function() {}, filterPort(80));
60 chrome.webNavigation.onCompleted.addListener(
61 function() {}, filterPort(81));
62 chrome.webNavigation.onCompleted.addListener(
63 function() {}, filterPort(81));
64 chrome.webNavigation.onCompleted.addListener(
65 singleListener, filterPort(82));
66 chrome.webNavigation.onCompleted.removeListener(singleListener);
69 location.assign('page2.html');