summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/test/schemas
diff options
context:
space:
mode:
Diffstat (limited to 'browser/components/newtab/test/schemas')
-rw-r--r--browser/components/newtab/test/schemas/asrouter_event_ping.schema.json36
-rw-r--r--browser/components/newtab/test/schemas/base_ping.schema.json29
-rw-r--r--browser/components/newtab/test/schemas/pings.js181
-rw-r--r--browser/components/newtab/test/schemas/session_ping.schema.json122
-rw-r--r--browser/components/newtab/test/schemas/user_event_ping.schema.json75
5 files changed, 443 insertions, 0 deletions
diff --git a/browser/components/newtab/test/schemas/asrouter_event_ping.schema.json b/browser/components/newtab/test/schemas/asrouter_event_ping.schema.json
new file mode 100644
index 0000000000..6ad4f86541
--- /dev/null
+++ b/browser/components/newtab/test/schemas/asrouter_event_ping.schema.json
@@ -0,0 +1,36 @@
+{
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "$id": "browser/components/newtab/test/schemas/asrouter_event_ping.schema.json",
+ "title": "ASRouter event PingCentre ping",
+ "type": "object",
+ "properties": {
+ "addon_version": {
+ "type": "string"
+ },
+ "locale": {
+ "type": "string"
+ },
+ "message_id": {
+ "type": "string"
+ },
+ "event": {
+ "type": "string"
+ },
+ "client_id": {
+ "type": "string"
+ },
+ "impression_id": {
+ "type": "string"
+ }
+ },
+ "required": ["addon_version", "locale", "message_id", "event"],
+ "additionalProperties": false,
+ "anyOf": [
+ {
+ "required": ["client_id"]
+ },
+ {
+ "required": ["impression_id"]
+ }
+ ]
+}
diff --git a/browser/components/newtab/test/schemas/base_ping.schema.json b/browser/components/newtab/test/schemas/base_ping.schema.json
new file mode 100644
index 0000000000..bf355b0c16
--- /dev/null
+++ b/browser/components/newtab/test/schemas/base_ping.schema.json
@@ -0,0 +1,29 @@
+{
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "$id": "browser/components/newtab/test/schemas/base_ping.schema.json",
+ "title": "Base PingCentre ping",
+ "type": "object",
+ "properties": {
+ "client_id": {
+ "type": "string"
+ },
+ "addon_version": {
+ "type": "string"
+ },
+ "locale": {
+ "type": "string"
+ },
+ "session_id": {
+ "type": "string"
+ },
+ "page": {
+ "type": ["array", "boolean", "number", "object", "string", "null"],
+ "enum": ["about:home", "about:newtab", "about:welcome", "both", "unknown"]
+ },
+ "user_prefs": {
+ "type": "integer"
+ }
+ },
+ "required": ["addon_version", "locale", "user_prefs"],
+ "additionalProperties": true
+}
diff --git a/browser/components/newtab/test/schemas/pings.js b/browser/components/newtab/test/schemas/pings.js
new file mode 100644
index 0000000000..825083066e
--- /dev/null
+++ b/browser/components/newtab/test/schemas/pings.js
@@ -0,0 +1,181 @@
+import {
+ CONTENT_MESSAGE_TYPE,
+ MAIN_MESSAGE_TYPE,
+} from "common/Actions.sys.mjs";
+import Joi from "joi-browser";
+
+export const baseKeys = {
+ client_id: Joi.string().optional(),
+ addon_version: Joi.string().required(),
+ locale: Joi.string().required(),
+ session_id: Joi.string(),
+ page: Joi.valid([
+ "about:home",
+ "about:newtab",
+ "about:welcome",
+ "both",
+ "unknown",
+ ]),
+ user_prefs: Joi.number().integer().required(),
+};
+
+export const eventsTelemetryExtraKeys = Joi.object()
+ .keys({
+ session_id: baseKeys.session_id.required(),
+ page: baseKeys.page.required(),
+ addon_version: baseKeys.addon_version.required(),
+ user_prefs: baseKeys.user_prefs.required(),
+ action_position: Joi.string().optional(),
+ })
+ .options({ allowUnknown: false });
+
+export const UTUserEventPing = Joi.array().items(
+ Joi.string().required().valid("activity_stream"),
+ Joi.string().required().valid("event"),
+ Joi.string()
+ .required()
+ .valid([
+ "CLICK",
+ "SEARCH",
+ "BLOCK",
+ "DELETE",
+ "DELETE_CONFIRM",
+ "DIALOG_CANCEL",
+ "DIALOG_OPEN",
+ "OPEN_NEW_WINDOW",
+ "OPEN_PRIVATE_WINDOW",
+ "OPEN_NEWTAB_PREFS",
+ "CLOSE_NEWTAB_PREFS",
+ "BOOKMARK_DELETE",
+ "BOOKMARK_ADD",
+ "PIN",
+ "UNPIN",
+ "SAVE_TO_POCKET",
+ ]),
+ Joi.string().required(),
+ eventsTelemetryExtraKeys
+);
+
+// Use this to validate actions generated from Redux
+export const UserEventAction = Joi.object().keys({
+ type: Joi.string().required(),
+ data: Joi.object()
+ .keys({
+ event: Joi.valid([
+ "CLICK",
+ "SEARCH",
+ "SEARCH_HANDOFF",
+ "BLOCK",
+ "DELETE",
+ "DELETE_CONFIRM",
+ "DIALOG_CANCEL",
+ "DIALOG_OPEN",
+ "OPEN_NEW_WINDOW",
+ "OPEN_PRIVATE_WINDOW",
+ "OPEN_NEWTAB_PREFS",
+ "CLOSE_NEWTAB_PREFS",
+ "BOOKMARK_DELETE",
+ "BOOKMARK_ADD",
+ "PIN",
+ "PREVIEW_REQUEST",
+ "UNPIN",
+ "SAVE_TO_POCKET",
+ "MENU_MOVE_UP",
+ "MENU_MOVE_DOWN",
+ "SCREENSHOT_REQUEST",
+ "MENU_REMOVE",
+ "MENU_COLLAPSE",
+ "MENU_EXPAND",
+ "MENU_MANAGE",
+ "MENU_ADD_TOPSITE",
+ "MENU_PRIVACY_NOTICE",
+ "DELETE_FROM_POCKET",
+ "ARCHIVE_FROM_POCKET",
+ "SKIPPED_SIGNIN",
+ "SUBMIT_EMAIL",
+ "SUBMIT_SIGNIN",
+ "SHOW_PRIVACY_INFO",
+ "CLICK_PRIVACY_INFO",
+ ]).required(),
+ source: Joi.valid(["TOP_SITES", "TOP_STORIES", "HIGHLIGHTS"]),
+ action_position: Joi.number().integer(),
+ value: Joi.object().keys({
+ icon_type: Joi.valid([
+ "tippytop",
+ "rich_icon",
+ "screenshot_with_icon",
+ "screenshot",
+ "no_image",
+ "custom_screenshot",
+ ]),
+ card_type: Joi.valid([
+ "bookmark",
+ "trending",
+ "pinned",
+ "pocket",
+ "search",
+ "spoc",
+ "organic",
+ ]),
+ search_vendor: Joi.valid(["google", "amazon"]),
+ has_flow_params: Joi.bool(),
+ }),
+ })
+ .required(),
+ meta: Joi.object()
+ .keys({
+ to: Joi.valid(MAIN_MESSAGE_TYPE).required(),
+ from: Joi.valid(CONTENT_MESSAGE_TYPE).required(),
+ })
+ .required(),
+});
+
+export const TileSchema = Joi.object().keys({
+ id: Joi.number().integer().required(),
+ pos: Joi.number().integer(),
+});
+
+export const UTSessionPing = Joi.array().items(
+ Joi.string().required().valid("activity_stream"),
+ Joi.string().required().valid("end"),
+ Joi.string().required().valid("session"),
+ Joi.string().required(),
+ eventsTelemetryExtraKeys
+);
+
+export function chaiAssertions(_chai, utils) {
+ const { Assertion } = _chai;
+
+ Assertion.addMethod("validate", function (schema, schemaName) {
+ const { error } = Joi.validate(this._obj, schema, { allowUnknown: false });
+ this.assert(
+ !error,
+ `Expected to be ${
+ schemaName ? `a valid ${schemaName}` : "valid"
+ } but there were errors: ${error}`
+ );
+ });
+
+ const assertions = {
+ /**
+ * assert.validate - Validates an item given a Joi schema
+ *
+ * @param {any} actual The item to validate
+ * @param {obj} schema A Joi schema
+ */
+ validate(actual, schema, schemaName) {
+ new Assertion(actual).validate(schema, schemaName);
+ },
+
+ /**
+ * isUserEventAction - Passes if the item is a valid UserEvent action
+ *
+ * @param {any} actual The item to validate
+ */
+ isUserEventAction(actual) {
+ new Assertion(actual).validate(UserEventAction, "UserEventAction");
+ },
+ };
+
+ Object.assign(_chai.assert, assertions);
+}
diff --git a/browser/components/newtab/test/schemas/session_ping.schema.json b/browser/components/newtab/test/schemas/session_ping.schema.json
new file mode 100644
index 0000000000..23e418fff7
--- /dev/null
+++ b/browser/components/newtab/test/schemas/session_ping.schema.json
@@ -0,0 +1,122 @@
+{
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "$id": "browser/components/newtab/test/schemas/session_ping.schema.json",
+ "title": "Session PingCentre ping",
+ "type": "object",
+ "properties": {
+ "client_id": {
+ "type": "string"
+ },
+ "addon_version": {
+ "type": "string"
+ },
+ "locale": {
+ "type": "string"
+ },
+ "session_id": {
+ "type": "string"
+ },
+ "page": {
+ "type": "string",
+ "enum": ["about:home", "about:newtab", "about:welcome", "both", "unknown"]
+ },
+ "user_prefs": {
+ "type": "integer"
+ },
+ "session_duration": {
+ "type": "integer"
+ },
+ "action": {
+ "type": "string",
+ "enum": ["activity_stream_session"]
+ },
+ "profile_creation_date": {
+ "type": "integer"
+ },
+ "perf": {
+ "type": "object",
+ "properties": {
+ "highlights_data_late_by_ms": {
+ "type": "number",
+ "exclusiveMinimum": 0,
+ "description": "How long it took in ms for data to be ready for display."
+ },
+ "load_trigger_ts": {
+ "type": "integer",
+ "description": "Timestamp of the action perceived by the user to trigger the load of this page. Not required at least for the error cases where the observer event doesn't fire."
+ },
+ "load_trigger_type": {
+ "type": "string",
+ "enum": [
+ "first_window_opened",
+ "menu_plus_or_keyboard",
+ "unexpected"
+ ],
+ "description": "What was the perceived trigger of the load action? Not required at least for the error cases where the observer event doesn't fire."
+ },
+ "topsites_data_late_by_ms": {
+ "type": "number",
+ "exclusiveMinimum": 0,
+ "description": "How long it took in ms for data to be ready for display."
+ },
+ "topsites_first_painted_ts": {
+ "type": "integer",
+ "description": "When did the topsites element finish painting? Note that, at least for the first tab to be loaded, and maybe some others, this will be before topsites has yet to receive screenshots updates from the add-on code, and is therefore just showing placeholder screenshots."
+ },
+ "topsites_icon_stats": {
+ "type": "object",
+ "properties": {
+ "custom_screenshot": {
+ "type": "number"
+ },
+ "rich_icon": {
+ "type": "number"
+ },
+ "screenshot": {
+ "type": "number"
+ },
+ "screenshot_with_icon": {
+ "type": "number"
+ },
+ "tippytop": {
+ "type": "number"
+ },
+ "no_image": {
+ "type": "number"
+ }
+ },
+ "additionalProperties": false,
+ "description": "Information about the quality of TopSites images and icons."
+ },
+ "topsites_pinned": {
+ "type": "number",
+ "description": "The count of pinned Top Sites."
+ },
+ "topsites_search_shortcuts": {
+ "type": "number",
+ "description": "The count of search shortcut Top Sites."
+ },
+ "visibility_event_rcvd_ts": {
+ "type": "integer",
+ "description": "When the page itself receives an event that document.visibilityState == visible. Not required at least for the (error?) case where the visibility_event doesn't fire. (It's not clear whether this can happen in practice, but if it does, we'd like to know about it)."
+ },
+ "is_preloaded": {
+ "type": "boolean",
+ "description": "The boolean to signify whether the page is preloaded or not."
+ }
+ },
+ "required": ["load_trigger_type", "is_preloaded"],
+ "additionalProperties": false
+ }
+ },
+ "required": [
+ "addon_version",
+ "locale",
+ "session_id",
+ "page",
+ "user_prefs",
+ "action",
+ "perf"
+ ],
+ "additionalProperties": false
+}
diff --git a/browser/components/newtab/test/schemas/user_event_ping.schema.json b/browser/components/newtab/test/schemas/user_event_ping.schema.json
new file mode 100644
index 0000000000..5b39006b85
--- /dev/null
+++ b/browser/components/newtab/test/schemas/user_event_ping.schema.json
@@ -0,0 +1,75 @@
+{
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "$id": "browser/components/newtab/test/schemas/user_event_ping.schema.json",
+ "title": "User event PingCentre ping",
+ "type": "object",
+ "properties": {
+ "client_id": {
+ "type": "string"
+ },
+ "addon_version": {
+ "type": "string"
+ },
+ "locale": {
+ "type": "string"
+ },
+ "session_id": {
+ "type": "string"
+ },
+ "page": {
+ "type": "string",
+ "enum": ["about:home", "about:newtab", "about:welcome", "both", "unknown"]
+ },
+ "user_prefs": {
+ "type": "integer"
+ },
+ "source": {
+ "type": "string"
+ },
+ "event": {
+ "type": "string"
+ },
+ "action": {
+ "type": "string",
+ "enum": ["activity_stream_user_event"]
+ },
+ "metadata_source": {
+ "type": "string"
+ },
+ "highlight_type": {
+ "type": "string",
+ "enum": ["bookmarks", "recommendation", "history"]
+ },
+ "recommender_type": {
+ "type": "string"
+ },
+ "value": {
+ "type": "object",
+ "properties": {
+ "newtab_url_category": {
+ "type": "string"
+ },
+ "newtab_extension_id": {
+ "type": "string"
+ },
+ "home_url_category": {
+ "type": "string"
+ },
+ "home_extension_id": {
+ "type": "string"
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "required": [
+ "addon_version",
+ "locale",
+ "session_id",
+ "page",
+ "user_prefs",
+ "event",
+ "action"
+ ],
+ "additionalProperties": false
+}