Skip to content

Commit

Permalink
Added Badging API Web Platform Tests.
Browse files Browse the repository at this point in the history
The [Badging API](https://wicg.github.io/badging/) is a new API
allowing the setting of application/document badges. This change
converts the Badging API web tests into Web Platform Tests.

This change adds a no-op MockBadgeService to the content_shell.
This is necessary because the RenderProcessHostImpl will terminate
the render process if unknown Mojo messages are received.

Bug: 1051684
Change-Id: I61e29b8f197a754fea489ebb2d0dcd41484f6cf4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2088297
Reviewed-by: Scott Violet <[email protected]>
Reviewed-by: Mike West <[email protected]>
Reviewed-by: Matt Giuca <[email protected]>
Commit-Queue: Chris Mumford <[email protected]>
Cr-Commit-Position: refs/heads/master@{#754676}
  • Loading branch information
cmumford authored and chromium-wpt-export-bot committed Mar 30, 2020
1 parent 79a262e commit 051ca83
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
36 changes: 36 additions & 0 deletions badging/badge-error.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<title>Badging: Unsupported values</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>

promise_test(t => {
return promise_rejects_js(t, TypeError, navigator.setAppBadge(-1));
}, "Negative value not allowed");

promise_test(t => {
return promise_rejects_js(t, TypeError, navigator.setAppBadge(
Number.MAX_SAFE_INTEGER + 1));
}, "Value too large (2^53)");

promise_test(t => {
return promise_rejects_js(t, TypeError, navigator.setAppBadge(Infinity));
}, "Positive infinity");

promise_test(t => {
return promise_rejects_js(t, TypeError, navigator.setAppBadge(-Infinity));
}, "Negative infinity");

promise_test(t => {
return promise_rejects_js(t, TypeError, navigator.setAppBadge(NaN));
}, "NaN");

promise_test(t => {
return promise_rejects_js(t, TypeError, navigator.setAppBadge("Foo"));
}, 'Cannot convert to long: "Foo"');

promise_test(t => {
return promise_rejects_js(t, TypeError, navigator.setAppBadge({}));
}, "Cannot convert to long: object");

</script>
62 changes: 62 additions & 0 deletions badging/badge-success.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<title>Badging: Supported values</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>

promise_test(async t => {
const result = await navigator.setAppBadge();
assert_equals(result, undefined);
}, "No parameter should show a flag with no numeric value.");

promise_test(async t => {
const result = await navigator.setAppBadge(undefined);
assert_equals(result, undefined);
}, "undefined should show a flag with no numeric value.");

promise_test(async t => {
const result = await navigator.setAppBadge(1);
assert_equals(result, undefined);
}, "An integer value of 3 should show the badge vale 3.");

promise_test(async t => {
const result = await navigator.setAppBadge(10.6);
assert_equals(result, undefined);
}, "Non-whole number should round down to nearest integer (10).");

promise_test(async t => {
const result = await navigator.setAppBadge(Number.MAX_SAFE_INTEGER);
assert_equals(result, undefined);
}, "Maximum allowed value (2^53 - 1) should display saturated value: '99+'.");

promise_test(async t => {
const result = await navigator.setAppBadge(0);
assert_equals(result, undefined);
}, "Set to zero should clear the badge.");

promise_test(async t => {
const result = await navigator.clearAppBadge();
assert_equals(result, undefined);
}, "Should clear the badge.");

promise_test(async t => {
const result = await navigator.setAppBadge(null);
assert_equals(result, undefined);
}, "Setting to null should clear the badge.");

promise_test(async t => {
const result = await navigator.setAppBadge(false);
assert_equals(result, undefined);
}, "Setting to false should clear the badge.");

promise_test(async t => {
const result = await navigator.setAppBadge(true);
assert_equals(result, undefined);
}, "Setting to true should display a value of 1.");

promise_test(async t => {
const result = await navigator.setAppBadge("3");
assert_equals(result, undefined);
}, "Setting to the string '3' should display a value of 3.");

</script>

0 comments on commit 051ca83

Please sign in to comment.