summaryrefslogtreecommitdiffstats
path: root/android_webview/tools
diff options
context:
space:
mode:
authortimvolodine <timvolodine@chromium.org>2015-10-16 05:25:30 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-16 12:26:04 +0000
commitbeebf8aac8acd93bd045d94a5835e12b4992176e (patch)
treec7e7eedf584d4089d46a15de243d0a117becf290 /android_webview/tools
parent69f2a3d887fa576b7d1f17b75ed9772d42eee338 (diff)
downloadchromium_src-beebf8aac8acd93bd045d94a5835e12b4992176e.zip
chromium_src-beebf8aac8acd93bd045d94a5835e12b4992176e.tar.gz
chromium_src-beebf8aac8acd93bd045d94a5835e12b4992176e.tar.bz2
[WebViewLayoutTest] Fix potential rounding error in testBatteryApi() layout test.
The battery.level precision test isInteger(battery.level * 100) can occasionally fail due to rounding error, e.g. (0.58 * 100) % 1 = 0.9999999999999929. This patch uses toPrecision and toString methods instead to correct this issue. BUG= Review URL: https://codereview.chromium.org/1394303007 Cr-Commit-Position: refs/heads/master@{#354498}
Diffstat (limited to 'android_webview/tools')
-rw-r--r--android_webview/tools/WebViewShell/test/blink-apis/battery-status/battery-callback-expected.txt4
-rw-r--r--android_webview/tools/WebViewShell/test/blink-apis/battery-status/battery-callback.html11
2 files changed, 4 insertions, 11 deletions
diff --git a/android_webview/tools/WebViewShell/test/blink-apis/battery-status/battery-callback-expected.txt b/android_webview/tools/WebViewShell/test/blink-apis/battery-status/battery-callback-expected.txt
index 64e31f5..ca967ee 100644
--- a/android_webview/tools/WebViewShell/test/blink-apis/battery-status/battery-callback-expected.txt
+++ b/android_webview/tools/WebViewShell/test/blink-apis/battery-status/battery-callback-expected.txt
@@ -2,7 +2,7 @@ Test Battery Status API callback in WebView
batteryStatusSuccess invoked
PASS: battery.level is >= 0
PASS: battery.level is <= 1
-PASS: isInteger(battery.level * 100) is true
+PASS: battery.level.toPrecision(2) === battery.level.toString() is true
PASS: !battery.charging || battery.dischargingTime === Infinity is true
PASS: battery.charging || battery.chargingTime === Infinity is true
-TEST FINISHED \ No newline at end of file
+TEST FINISHED
diff --git a/android_webview/tools/WebViewShell/test/blink-apis/battery-status/battery-callback.html b/android_webview/tools/WebViewShell/test/blink-apis/battery-status/battery-callback.html
index 42f2ec3..a85a3e4 100644
--- a/android_webview/tools/WebViewShell/test/blink-apis/battery-status/battery-callback.html
+++ b/android_webview/tools/WebViewShell/test/blink-apis/battery-status/battery-callback.html
@@ -6,13 +6,6 @@
description("Test Battery Status API callback in WebView");
window.jsTestIsAsync = true;
- function isInteger(value) {
- if ((undefined === value) || (null === value)) {
- return false;
- }
- return value % 1 == 0;
- }
-
var battery;
function batteryStatusSuccess(batteryManager) {
debug('batteryStatusSuccess invoked');
@@ -22,7 +15,7 @@
shouldBeGreaterThanOrEqual('battery.level', '0');
shouldBeLessThanOrEqual('battery.level', '1');
// Check that level has at most 2 significant digits
- shouldBeTrue('isInteger(battery.level * 100)');
+ shouldBeTrue('battery.level.toPrecision(2) === battery.level.toString()');
shouldBeTrue('!battery.charging || battery.dischargingTime === Infinity');
shouldBeTrue('battery.charging || battery.chargingTime === Infinity');
finishJSTest();
@@ -36,4 +29,4 @@
navigator.getBattery().then(batteryStatusSuccess, batteryStatusFailure);
</script>
</body>
-</html> \ No newline at end of file
+</html>