OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // NOTE: Some of the test code was put in the global scope on purpose! | 5 // NOTE: Some of the test code was put in the global scope on purpose! |
6 | 6 |
7 function useToolbarGetter() { | 7 var resultFromToolbarGetterAtStart = window.toolbar; |
8 var result; | |
9 try { | |
10 // The following will invoke the window.toolbar getter, and this may or may | |
11 // not throw an exception. | |
12 result = {object: window.toolbar}; | |
13 } catch (e) { | |
14 result = {exception: e}; | |
15 } | |
16 return result; | |
17 } | |
18 | |
19 var resultFromToolbarGetterAtStart = useToolbarGetter(); | |
20 | 8 |
21 // The following statement implicitly invokes the window.toolbar setter. This | 9 // The following statement implicitly invokes the window.toolbar setter. This |
22 // should delete the "disabler" getter and setter that were set up in | 10 // should delete the "disabler" getter and setter that were set up in |
23 // chrome/renderer/resources/extensions/platform_app.js, and restore normal | 11 // chrome/renderer/resources/extensions/platform_app.js, and restore normal |
24 // getter/setter behaviors from here on. | 12 // getter/setter behaviors from here on. |
25 var toolbar = {blah: 'glarf'}; | 13 var toolbar = {blah: 'glarf'}; |
26 | 14 |
27 var resultFromToolbarGetterAfterRedefinition = useToolbarGetter(); | 15 var resultFromToolbarGetterAfterRedefinition = window.toolbar; |
28 var toolbarIsWindowToolbarAfterRedefinition = (toolbar === window.toolbar); | 16 var toolbarIsWindowToolbarAfterRedefinition = (toolbar === window.toolbar); |
29 | 17 |
30 toolbar.blah = 'baz'; | 18 toolbar.blah = 'baz'; |
31 | 19 |
32 chrome.app.runtime.onLaunched.addListener(function() { | 20 chrome.app.runtime.onLaunched.addListener(function() { |
33 chrome.test.assertTrue( | 21 chrome.test.assertEq('undefined', typeof(resultFromToolbarGetterAtStart)); |
34 resultFromToolbarGetterAtStart.hasOwnProperty('exception')); | 22 chrome.test.assertEq('object', |
35 | 23 typeof(resultFromToolbarGetterAfterRedefinition)); |
36 chrome.test.assertTrue( | |
37 resultFromToolbarGetterAfterRedefinition.hasOwnProperty('object')); | |
38 chrome.test.assertTrue(toolbarIsWindowToolbarAfterRedefinition); | 24 chrome.test.assertTrue(toolbarIsWindowToolbarAfterRedefinition); |
39 | 25 |
40 chrome.test.assertEq('baz', toolbar.blah); | 26 chrome.test.assertEq('baz', toolbar.blah); |
41 | 27 |
42 chrome.test.notifyPass(); | 28 chrome.test.notifyPass(); |
43 }); | 29 }); |
OLD | NEW |