Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 'use strict'; | |
| 6 | |
| 5 // Register for events in 4 configurations, then navigate to page2.html, which | 7 // Register for events in 4 configurations, then navigate to page2.html, which |
| 6 // will notify success and succeed the test on the C++ side. The C++ code | 8 // will notify success and succeed the test on the C++ side. The C++ code |
| 7 // asserts that the events have been unregistered. | 9 // asserts that the events have been unregistered. |
| 8 | 10 |
| 11 // | |
| 12 // Unfiltered events. | |
| 13 // | |
| 14 | |
| 9 // A single listener. | 15 // A single listener. |
| 10 chrome.browserAction.onClicked.addListener(function() {}); | 16 chrome.browserAction.onClicked.addListener(function() {}); |
| 11 // Multiple listeners for the same event. | 17 // Multiple listeners for the same event. |
| 12 chrome.runtime.onStartup.addListener(function() {}); | 18 chrome.runtime.onStartup.addListener(function() {}); |
| 13 chrome.runtime.onStartup.addListener(function() {}); | 19 chrome.runtime.onStartup.addListener(function() {}); |
| 14 // A single listener, which previously had multiple listeners. | 20 // A single listener, which previously had multiple listeners. |
| 15 chrome.runtime.onSuspend.addListener(function() {}); | 21 { |
| 16 chrome.runtime.onSuspend.addListener(function() {}); | 22 let singleListener = function() {}; |
| 17 chrome.runtime.onSuspend.removeListener(function() {}); | 23 chrome.runtime.onSuspend.addListener(singleListener); |
| 24 chrome.runtime.onSuspend.addListener(function() {}); | |
|
Devlin
2015/07/10 17:57:30
why some with singleListener and some with functio
not at google - send to devlin
2015/07/10 20:39:17
Listener identity comes from pointer identity. If
| |
| 25 chrome.runtime.onSuspend.removeListener(singleListener); | |
| 26 } | |
| 18 // No listeners, which previously had listeners (all were removed). | 27 // No listeners, which previously had listeners (all were removed). |
| 19 chrome.runtime.onInstalled.addListener(function() {}); | 28 { |
| 20 chrome.runtime.onInstalled.addListener(function() {}); | 29 let listener1 = function() {}; |
| 21 chrome.runtime.onInstalled.removeListener(function() {}); | 30 let listener2 = function() {}; |
| 22 chrome.runtime.onInstalled.removeListener(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); | |
| 35 } | |
| 36 | |
| 37 // | |
| 38 // Filtered events. | |
| 39 // | |
| 40 | |
| 41 function filterPort(portNumber) { | |
| 42 return {url: [{ports: [portNumber]}]}; | |
| 43 } | |
| 44 | |
| 45 // A single listener. | |
| 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. | |
| 56 { | |
| 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); | |
| 67 } | |
| 23 | 68 |
| 24 location.assign('page2.html'); | 69 location.assign('page2.html'); |
| OLD | NEW |