Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Unified Diff: chrome/test/data/extensions/api_test/content_scripts/ntp/background.js

Issue 2978953002: [Extensions] Don't allow content scripts on the New Tab Page (Closed)
Patch Set: Remove logging! Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
+ 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]);
+});

Powered by Google App Engine
This is Rietveld 408576698