diff options
Diffstat (limited to 'chrome/test')
5 files changed, 52 insertions, 0 deletions
diff --git a/chrome/test/data/extensions/context_menus/background.html b/chrome/test/data/extensions/context_menus/background.html new file mode 100644 index 0000000..46f4d74 --- /dev/null +++ b/chrome/test/data/extensions/context_menus/background.html @@ -0,0 +1 @@ +<script src="test.js"></script> diff --git a/chrome/test/data/extensions/context_menus/manifest.json b/chrome/test/data/extensions/context_menus/manifest.json new file mode 100644 index 0000000..5efbbfe --- /dev/null +++ b/chrome/test/data/extensions/context_menus/manifest.json @@ -0,0 +1,6 @@ +{ + "name" : "Context Menus Test Extension", + "version" : "0.1", + "permissions": [ "experimental", "tabs" ], + "background_page": "background.html" +} diff --git a/chrome/test/data/extensions/context_menus/test.html b/chrome/test/data/extensions/context_menus/test.html new file mode 100644 index 0000000..8267927 --- /dev/null +++ b/chrome/test/data/extensions/context_menus/test.html @@ -0,0 +1,5 @@ +<html> +<body> +This is test page 1 +</body> +</html> diff --git a/chrome/test/data/extensions/context_menus/test.js b/chrome/test/data/extensions/context_menus/test.js new file mode 100644 index 0000000..c6a1049 --- /dev/null +++ b/chrome/test/data/extensions/context_menus/test.js @@ -0,0 +1,34 @@ +// Copyright (c) 2010 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. + +// Checks that there is only one window and one tab, and calls back |callback| +// with its id (or -1 if there is more than 1 window or more than 1 tab). +function getCurrentSingleTabId(callback) { + chrome.windows.getAll({"populate":true}, function(windows) { + if (windows.length != 1 || windows[0].tabs.length != 1) { + callback(-1); + } else { + callback(windows[0].tabs[0].id); + } + }); +} + +function navigateCurrentTab(url) { + getCurrentSingleTabId(function(tabid) { + chrome.tabs.update(tabid, {"url": url}); + }); +} + +function onclick(info) { + navigateCurrentTab(chrome.extension.getURL("test2.html")); +} + +window.onload = function() { + chrome.experimental.contextMenu.create({"title":"Extension Item 1", + "onclick": onclick}, function(id) { + if (!chrome.extension.lastError) { + navigateCurrentTab(chrome.extension.getURL("test.html")); + } + }); +}; diff --git a/chrome/test/data/extensions/context_menus/test2.html b/chrome/test/data/extensions/context_menus/test2.html new file mode 100644 index 0000000..7a82e48 --- /dev/null +++ b/chrome/test/data/extensions/context_menus/test2.html @@ -0,0 +1,6 @@ +<html> +<head><title>test2</title></head> +<body> +test2 +</body> +</html> |