Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 chrome.test.runTests([ | |
| 6 // Tests if the <extensionoptions> guest view is successfully created. This | |
| 7 // test expects that the guest options page will add a {'pass': true} property | |
| 8 // to every Window and fire the runtime.onMessage event with a short message. | |
| 9 function canCreateExtensionOptionsGuest() { | |
| 10 var done = chrome.test.listenForever(chrome.runtime.onMessage, | |
| 11 function(message, sender, sendResponse) { | |
| 12 if (message == 'ready') { | |
| 13 sendResponse('canCreateExtensionOptionsGuest'); | |
| 14 | |
|
not at google - send to devlin
2014/07/21 16:30:43
nit: no blank line here
ericzeng
2014/07/21 17:52:39
Done.
| |
| 15 } else if (message == 'hi') { | |
| 16 var views = chrome.extension.getViews(); | |
| 17 chrome.test.assertEq(2, views.length); | |
| 18 views.forEach(function(view) { | |
| 19 chrome.test.assertTrue(view.pass); | |
| 20 }); | |
| 21 chrome.test.assertEq(chrome.runtime.id, sender.id); | |
| 22 document.body.removeChild(extensionoptions); | |
| 23 done(); | |
| 24 } | |
| 25 }); | |
| 26 | |
| 27 var extensionoptions = document.createElement('extensionoptions'); | |
| 28 extensionoptions.setAttribute('extension', chrome.runtime.id); | |
| 29 document.body.appendChild(extensionoptions); | |
| 30 }, | |
| 31 | |
| 32 // Tests if the <extensionoptions> guest view can access the chrome.storage | |
| 33 // API, a privileged extension API. | |
| 34 function guestCanAccessStorage() { | |
| 35 var onStorage = false; | |
| 36 var onSetCallback = false; | |
| 37 | |
| 38 chrome.test.listenOnce(chrome.storage.onChanged, function(change) { | |
| 39 chrome.test.assertEq(42, change.test.newValue); | |
| 40 }); | |
| 41 | |
| 42 // Listens for messages from the options page. | |
| 43 var done = chrome.test.listenForever(chrome.runtime.onMessage, | |
| 44 function(message, sender, sendResponse) { | |
| 45 // Options page is waiting for a command | |
| 46 if (message == 'ready') | |
|
not at google - send to devlin
2014/07/21 16:30:43
nits:
- if one block needs braces, they all do.
-
ericzeng
2014/07/21 17:52:39
Done.
| |
| 47 sendResponse('guestCanAccessStorage'); | |
| 48 // Messages from the options page containing test data | |
| 49 else if (message.hasOwnProperty('description')) { | |
| 50 if (message.description == 'onStorage') { | |
|
not at google - send to devlin
2014/07/21 16:30:43
that said I don't think the outer message.hasOwnPr
ericzeng
2014/07/21 17:52:39
Done.
| |
| 51 chrome.test.assertEq(message.expected, message.actual); | |
| 52 onStorage = true; | |
| 53 } | |
| 54 if (message.description == 'onSetCallback') { | |
| 55 chrome.test.assertEq(message.expected, message.actual); | |
| 56 onSetCallback = true; | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 if (onStorage && onSetCallback) { | |
| 61 document.body.removeChild(extensionoptions); | |
| 62 done(); | |
| 63 } | |
| 64 }); | |
| 65 | |
| 66 var extensionoptions = document.createElement('extensionoptions'); | |
| 67 extensionoptions.setAttribute('extension', chrome.runtime.id); | |
| 68 document.body.appendChild(extensionoptions); | |
| 69 } | |
| 70 ]); | |
| OLD | NEW |