Allow key events to continue propagation for commands without any event listeners.
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / keybinding / continue_propagation / background.js
blob88338a1a0f1cb0e6e3a1be5dc7be24ffcf1e6b68
1 // Copyright 2014 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.
5 // Keeps track of who should be receiving keystrokes sent:
6 // The 'webPage' or the 'backgroundPage'.
7 var expectedListener = 'webPage';
9 function gotCommand(command) {
10   if (expectedListener == 'backgroundPage') {
11     expectedListener = 'webPage';
12     chrome.commands.onCommand.removeListener(gotCommand);
13     chrome.test.notifyPass();
14   } else {
15     chrome.test.notifyFail('Webpage expected keystroke, but sent to extension');
16   }
19 chrome.extension.onConnect.addListener(function(port) {
20   port.onMessage.addListener(function(message) {
21     if (expectedListener == 'webPage') {
22       expectedListener = 'backgroundPage';
23       chrome.commands.onCommand.addListener(gotCommand);
24       chrome.test.notifyPass();
25     } else {
26       chrome.test.notifyFail('Extension expected keystroke, but sent to' +
27           ' webpage');
28     }
29   });
30 });
32 chrome.test.notifyPass();