Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / context_menus / basics / test.js
blob5d28f728883beffc55b7e6bd9c661905e0210625
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;
7 var tests = [
8 function simple() {
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();
16 });
19 function remove() {
20 var id;
21 id = chrome.contextMenus.create({"title":"1"}, function() {
22 assertNoLastError();
23 chrome.contextMenus.remove(id, chrome.test.callbackPass());
24 });
27 function update() {
28 var id;
29 id = chrome.contextMenus.create({"title":"update test"}, function() {
30 assertNoLastError();
31 chrome.contextMenus.update(id, {"title": "test2"},
32 chrome.test.callbackPass());
33 });
35 chrome.contextMenus.create({"id": "test3", "type": "checkbox",
36 "title": "test3"}, function() {
37 assertNoLastError();
38 // Calling update without specifying "type" should not change the menu
39 // item's type to "normal" and therefore setting "checked" should not
40 // fail.
41 chrome.contextMenus.update("test3", {"checked": true},
42 chrome.test.callbackPass());
43 });
46 function removeAll() {
47 chrome.contextMenus.create({"title":"1"}, function() {
48 assertNoLastError();
49 chrome.contextMenus.create({"title":"2"}, function() {
50 assertNoLastError();
51 chrome.contextMenus.removeAll(chrome.test.callbackPass());
52 });
53 });
56 function hasParent() {
57 var id;
58 id = chrome.contextMenus.create({"title":"parent"}, function() {
59 assertNoLastError();
60 chrome.contextMenus.create({"title":"child", "parentId":id},
61 function() {
62 assertNoLastError();
63 chrome.test.succeed();
64 });
65 });
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",
73 "video", "audio"];
74 function makeCreateTest(type, contexts) {
75 var result = function() {
76 var title = type;
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(",") : "");
86 return result;
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);