Chromium Code Reviews| Index: chrome/test/data/extensions/api_test/content_scripts/ntp/background.js | 
| diff --git a/chrome/test/data/extensions/api_test/content_scripts/ntp/background.js b/chrome/test/data/extensions/api_test/content_scripts/ntp/background.js | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..b1f8ea29b758710a20f234a28966cacb8392b29d | 
| --- /dev/null | 
| +++ b/chrome/test/data/extensions/api_test/content_scripts/ntp/background.js | 
| @@ -0,0 +1,26 @@ | 
| +// Copyright 2017 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +function testExecuteScriptInNewTab() { | 
| + // Create a new tab to chrome://newtab and wait for the loading to complete. | 
| + // Then, try to inject a script into that tab. The injection should fail. | 
| + chrome.tabs.onUpdated.addListener(function listener(tabId, changeInfo, tab) { | 
| + if (tab.url != 'chrome://newtab/' || changeInfo.status != 'complete') | 
| + return; | 
| + chrome.tabs.onUpdated.removeListener(listener); | 
| + chrome.tabs.executeScript(tab.id, {file: 'script.js'}, function() { | 
| + chrome.test.assertTrue(!!chrome.runtime.lastError); | 
| 
 
karandeepb
2017/07/18 19:27:00
I am not up to speed with how different JS types b
 
Devlin
2017/07/18 20:53:46
!!x checks that x is not "false-y".  This has trad
 
karandeepb
2017/07/18 21:06:25
Acknowledged.
 
 | 
| + chrome.test.assertTrue( | 
| + chrome.runtime.lastError.message.indexOf( | 
| + 'Cannot access contents of') != -1, | 
| + chrome.runtime.lastError.message); | 
| + chrome.test.succeed(); | 
| + }); | 
| + }); | 
| + chrome.tabs.create({url: 'chrome://newtab'}); | 
| +} | 
| + | 
| +chrome.test.sendMessage('ready', function() { | 
| + chrome.test.runTests([testExecuteScriptInNewTab]); | 
| +}); |