- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / events / background.js
1 // Copyright (c) 2011 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.
4
5 chrome.test.runTests([
6   // Tests that attaching a named event twice will fail.
7   function doubleAttach() {
8     function dummy() {};
9     var onClicked = new chrome.Event("browserAction.onClicked");
10     var onClicked2 = new chrome.Event("browserAction.onClicked");
11     onClicked.addListener(dummy);
12     chrome.test.assertTrue(onClicked.hasListeners());
13     try {
14       onClicked2.addListener(dummy);
15       chrome.test.fail();
16     } catch (e) {
17       chrome.test.assertTrue(
18           e.message.search("already attached") >= 0,
19           e.message);
20     }
21     chrome.test.assertFalse(onClicked2.hasListeners());
22     onClicked2.removeListener(dummy);
23
24     onClicked.removeListener(dummy);
25     chrome.test.assertFalse(onClicked.hasListeners());
26     chrome.test.succeed();
27   },
28
29   // Tests that 2 pages attaching to the same event does not trigger a DCHECK.
30   function twoPageAttach() {
31     // Test harness should already have opened tab.html, which registers this
32     // listener.
33     chrome.browserAction.onClicked.addListener(function() {});
34
35     // Test continues in twoPageAttach.html.
36     window.open("twoPageAttach.html");
37   },
38 ]);