1 // Copyright (c) 2010 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.
5 var assertNoLastError = chrome.test.assertNoLastError;
9 chrome.contextMenus.create({"title":"1"}, chrome.test.callbackPass());
12 function no_properties() {
13 chrome.contextMenus.create({}, function(id) {
14 chrome.test.assertTrue(chrome.runtime.lastError != null);
15 chrome.test.succeed();
21 id = chrome.contextMenus.create({"title":"1"}, function() {
23 chrome.contextMenus.remove(id, chrome.test.callbackPass());
29 id = chrome.contextMenus.create({"title":"update test"}, function() {
31 chrome.contextMenus.update(id, {"title": "test2"},
32 chrome.test.callbackPass());
35 chrome.contextMenus.create({"id": "test3", "type": "checkbox",
36 "title": "test3"}, function() {
38 // Calling update without specifying "type" should not change the menu
39 // item's type to "normal" and therefore setting "checked" should not
41 chrome.contextMenus.update("test3", {"checked": true},
42 chrome.test.callbackPass());
46 function removeAll() {
47 chrome.contextMenus.create({"title":"1"}, function() {
49 chrome.contextMenus.create({"title":"2"}, function() {
51 chrome.contextMenus.removeAll(chrome.test.callbackPass());
56 function hasParent() {
58 id = chrome.contextMenus.create({"title":"parent"}, function() {
60 chrome.contextMenus.create({"title":"child", "parentId":id},
63 chrome.test.succeed();
70 // Add tests for creating menu item with various types and contexts.
71 var types = ["checkbox", "radio", "separator"];
72 var contexts = ["all", "page", "selection", "link", "editable", "image",
74 function makeCreateTest(type, contexts) {
75 var result = function() {
77 if (contexts && contexts.length > 0) {
78 title += " " + contexts.join(",");
80 var properties = {"title": title, "type": type};
82 chrome.contextMenus.create(properties, chrome.test.callbackPass());
84 result.generatedName = "create_" + type +
85 (contexts ? "-" + contexts.join(",") : "");
89 for (var i in types) {
90 tests.push(makeCreateTest(types[i]));
92 for (var i in contexts) {
93 tests.push(makeCreateTest("normal", [ contexts[i] ]));
96 chrome.test.runTests(tests);