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

Unified Diff: chrome/test/data/extensions/context_menus/icons/sample.js

Issue 2576833002: Make some updates to extension iconography. (Closed)
Patch Set: add test Created 4 years 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/context_menus/icons/sample.js
diff --git a/chrome/test/data/extensions/context_menus/icons/sample.js b/chrome/test/data/extensions/context_menus/icons/sample.js
new file mode 100644
index 0000000000000000000000000000000000000000..be77af08cc472ae862dfa9458821b98e29214acc
--- /dev/null
+++ b/chrome/test/data/extensions/context_menus/icons/sample.js
@@ -0,0 +1,69 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
Devlin 2016/12/15 17:14:41 not 2010
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
Devlin 2016/12/15 17:14:41 I just realized this whole file was copy-pasted.
+// A generic onclick callback function.
+function genericOnClick(info, tab) {
+ console.log("item " + info.menuItemId + " was clicked");
Devlin 2016/12/15 17:14:41 nit: prefer single quotes in js
+ console.log("info: " + JSON.stringify(info));
+ console.log("tab: " + JSON.stringify(tab));
+}
+
+// Create one test item for each context type.
+var contexts = ["page","selection","link","editable","image","video",
+ "audio"];
+for (var i = 0; i < contexts.length; i++) {
Devlin 2016/12/15 17:14:41 for (let context of contexts)?
+ var context = contexts[i];
+ var title = "Test '" + context + "' menu item";
+ var id = chrome.contextMenus.create({"title": title, "contexts":[context],
Devlin 2016/12/15 17:14:41 nit: no quotes around keys in objects. nit: add a
+ "onclick": genericOnClick});
+ console.log("'" + context + "' item:" + id);
+}
+
+
+// Create a parent item and two children.
+var parent = chrome.contextMenus.create({"title": "Test parent item"});
+var child1 = chrome.contextMenus.create(
+ {"title": "Child 1", "parentId": parent, "onclick": genericOnClick});
+var child2 = chrome.contextMenus.create(
+ {"title": "Child 2", "parentId": parent, "onclick": genericOnClick});
+console.log("parent:" + parent + " child1:" + child1 + " child2:" + child2);
+
+
+// Create some radio items.
+function radioOnClick(info, tab) {
+ console.log("radio item " + info.menuItemId +
+ " was clicked (previous checked state was " +
+ info.wasChecked + ")");
+}
+var radio1 = chrome.contextMenus.create({"title": "Radio 1", "type": "radio",
+ "onclick":radioOnClick});
+var radio2 = chrome.contextMenus.create({"title": "Radio 2", "type": "radio",
+ "onclick":radioOnClick});
+console.log("radio1:" + radio1 + " radio2:" + radio2);
+
+
+// Create some checkbox items.
+function checkboxOnClick(info, tab) {
+ console.log(JSON.stringify(info));
+ console.log("checkbox item " + info.menuItemId +
+ " was clicked, state is now: " + info.checked +
+ "(previous state was " + info.wasChecked + ")");
+
+}
+var checkbox1 = chrome.contextMenus.create(
+ {"title": "Checkbox1", "type": "checkbox", "onclick":checkboxOnClick});
+var checkbox2 = chrome.contextMenus.create(
+ {"title": "Checkbox2", "type": "checkbox", "onclick":checkboxOnClick});
+console.log("checkbox1:" + checkbox1 + " checkbox2:" + checkbox2);
+
+
+// Intentionally create an invalid item, to show off error checking in the
+// create callback.
+console.log("About to try creating an invalid item - an error about " +
+ "item 999 should show up");
+chrome.contextMenus.create({"title": "Oops", "parentId":999}, function() {
+ if (chrome.extension.lastError) {
+ console.log("Got expected error: " + chrome.extension.lastError.message);
+ }
+});

Powered by Google App Engine
This is Rietveld 408576698