| OLD | NEW |
| 1 <script> | 1 <!-- |
| 2 chrome.test.runTests([ | 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this |
| 3 // Tests that attaching and detaching to an event for which we don't have | 3 * source code is governed by a BSD-style license that can be found in the |
| 4 // permission acts as expected (e.g. we don't DCHECK!). | 4 * LICENSE file. |
| 5 function attachAndDetachNoPermisssions() { | 5 --> |
| 6 function dummy() {}; | 6 <script src="background.js"></script> |
| 7 try { | |
| 8 chrome.tabs.onUpdated.addListener(dummy); | |
| 9 chrome.test.fail(); | |
| 10 } catch (e) { | |
| 11 chrome.test.assertTrue( | |
| 12 e.message.search("You do not have permission") >= 0, | |
| 13 e.message); | |
| 14 } | |
| 15 chrome.test.assertFalse(chrome.tabs.onUpdated.hasListeners()); | |
| 16 chrome.tabs.onUpdated.removeListener(dummy); // browser should not DCHECK | |
| 17 chrome.test.succeed(); | |
| 18 }, | |
| 19 | |
| 20 // Tests that attaching a named event twice will fail. | |
| 21 function doubleAttach() { | |
| 22 function dummy() {}; | |
| 23 var onClicked = new chrome.Event("browserAction.onClicked"); | |
| 24 var onClicked2 = new chrome.Event("browserAction.onClicked"); | |
| 25 onClicked.addListener(dummy); | |
| 26 chrome.test.assertTrue(onClicked.hasListeners()); | |
| 27 try { | |
| 28 onClicked2.addListener(dummy); | |
| 29 chrome.test.fail(); | |
| 30 } catch (e) { | |
| 31 chrome.test.assertTrue( | |
| 32 e.message.search("already attached") >= 0, | |
| 33 e.message); | |
| 34 } | |
| 35 chrome.test.assertFalse(onClicked2.hasListeners()); | |
| 36 onClicked2.removeListener(dummy); | |
| 37 | |
| 38 onClicked.removeListener(dummy); | |
| 39 chrome.test.assertFalse(onClicked.hasListeners()); | |
| 40 chrome.test.succeed(); | |
| 41 }, | |
| 42 | |
| 43 // Tests that 2 pages attaching to the same event does not trigger a DCHECK. | |
| 44 function twoPageAttach() { | |
| 45 // Test harness should already have opened tab.html, which registers this | |
| 46 // listener. | |
| 47 chrome.browserAction.onClicked.addListener(function() {}); | |
| 48 | |
| 49 // Test continues in twoPageAttach.html. | |
| 50 window.open("twoPageAttach.html"); | |
| 51 }, | |
| 52 ]); | |
| 53 </script> | |
| OLD | NEW |