summaryrefslogtreecommitdiffstats
path: root/android_webview
diff options
context:
space:
mode:
authortimvolodine <timvolodine@chromium.org>2015-10-16 10:09:32 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-16 17:10:41 +0000
commit863fd741f32361a9154a61482e29944befe767ca (patch)
treeece5e7738f1e53d190471f8d85518173723eddea /android_webview
parentd315c171ac0594a730185b37b804cf0d34fb44e2 (diff)
downloadchromium_src-863fd741f32361a9154a61482e29944befe767ca.zip
chromium_src-863fd741f32361a9154a61482e29944befe767ca.tar.gz
chromium_src-863fd741f32361a9154a61482e29944befe767ca.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= Committed: https://crrev.com/beebf8aac8acd93bd045d94a5835e12b4992176e Cr-Commit-Position: refs/heads/master@{#354498} Review URL: https://codereview.chromium.org/1394303007 Cr-Commit-Position: refs/heads/master@{#354533}
Diffstat (limited to 'android_webview')
-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..2d7be9a 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 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..fd9a2e1 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');
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>