From 31c67d0dca30535ed803e431522f1e1b4d2ffbf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDan=20Dober=C5=A1ek?= Date: Wed, 24 Jan 2018 10:01:21 +0000 Subject: [PATCH] Merge r226716 - WebDriver: deserializeTimeouts() shouldn't reject double timeout values https://bugs.webkit.org/show_bug.cgi?id=181473 Reviewed by Carlos Garcia Campos. With these changes, the following tests are fixed: imported/selenium/py/test/selenium/webdriver/common/executing_async_javascript_tests.py::testShouldTimeoutIfScriptDoesNotInvokeCallbackWithLongTimeout imported/selenium/py/test/selenium/webdriver/common/executing_async_javascript_tests.py::testShouldDetectPageLoadsWhileWaitingOnAnAsyncScriptAndReturnAnError imported/selenium/py/test/selenium/webdriver/common/executing_async_javascript_tests.py::testShouldBeAbleToExecuteAsynchronousScripts imported/selenium/py/test/selenium/webdriver/common/implicit_waits_tests.py::testShouldImplicitlyWaitForASingleElement imported/selenium/py/test/selenium/webdriver/common/implicit_waits_tests.py::testShouldStillFailToFindAnElementWhenImplicitWaitsAreEnabled imported/selenium/py/test/selenium/webdriver/common/implicit_waits_tests.py::testShouldReturnAfterFirstAttemptToFindOneAfterDisablingImplicitWaits imported/selenium/py/test/selenium/webdriver/common/implicit_waits_tests.py::testShouldImplicitlyWaitUntilAtLeastOneElementIsFoundWhenSearchingForMany imported/selenium/py/test/selenium/webdriver/common/implicit_waits_tests.py::testShouldStillFailToFindAnElemenstWhenImplicitWaitsAreEnabled imported/selenium/py/test/selenium/webdriver/common/implicit_waits_tests.py::testShouldReturnAfterFirstAttemptToFindManyAfterDisablingImplicitWaits imported/selenium/py/test/selenium/webdriver/common/page_load_timeout_tests.py::testShouldTimeoutOnPageLoadTakingTooLong imported/selenium/py/test/selenium/webdriver/common/page_load_timeout_tests.py::testShouldTimeoutOnPageLoadTakingTooLong imported/selenium/py/test/selenium/webdriver/common/webdriverwait_tests.py::testShouldWaitOnlyAsLongAsTimeoutSpecifiedWhenImplicitWaitsAreSet The following two tests regress, and will be looked into separately: imported/w3c/webdriver/tests/sessions/new_session/merge.py::test_merge_invalid imported/w3c/webdriver/tests/sessions/new_session/merge.py::test_merge_invalid * WebDriverService.cpp: (WebDriver::integerValue): Helper function that retrieves an integer value from a given JSON::Value object, if possible. (WebDriver::deserializeTimeouts): Timeout JSON value has to be converted to an integer, which is allowed if the value is of either Integer or Double type. Helper integerValue() function retrieves the integer value, in addition to ensuring that possible double value that we convert to an integer is already in integer form to begin with. --- Source/WebDriver/ChangeLog | 34 +++++++++++++++++++++++++++ Source/WebDriver/WebDriverService.cpp | 18 +++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Source/WebDriver/ChangeLog b/Source/WebDriver/ChangeLog index 5781f5516fb3..07a449b8e478 100644 --- a/Source/WebDriver/ChangeLog +++ b/Source/WebDriver/ChangeLog @@ -1,3 +1,37 @@ +2018-01-10 Zan Dobersek + + WebDriver: deserializeTimeouts() shouldn't reject double timeout values + https://bugs.webkit.org/show_bug.cgi?id=181473 + + Reviewed by Carlos Garcia Campos. + + With these changes, the following tests are fixed: + imported/selenium/py/test/selenium/webdriver/common/executing_async_javascript_tests.py::testShouldTimeoutIfScriptDoesNotInvokeCallbackWithLongTimeout + imported/selenium/py/test/selenium/webdriver/common/executing_async_javascript_tests.py::testShouldDetectPageLoadsWhileWaitingOnAnAsyncScriptAndReturnAnError + imported/selenium/py/test/selenium/webdriver/common/executing_async_javascript_tests.py::testShouldBeAbleToExecuteAsynchronousScripts + imported/selenium/py/test/selenium/webdriver/common/implicit_waits_tests.py::testShouldImplicitlyWaitForASingleElement + imported/selenium/py/test/selenium/webdriver/common/implicit_waits_tests.py::testShouldStillFailToFindAnElementWhenImplicitWaitsAreEnabled + imported/selenium/py/test/selenium/webdriver/common/implicit_waits_tests.py::testShouldReturnAfterFirstAttemptToFindOneAfterDisablingImplicitWaits + imported/selenium/py/test/selenium/webdriver/common/implicit_waits_tests.py::testShouldImplicitlyWaitUntilAtLeastOneElementIsFoundWhenSearchingForMany + imported/selenium/py/test/selenium/webdriver/common/implicit_waits_tests.py::testShouldStillFailToFindAnElemenstWhenImplicitWaitsAreEnabled + imported/selenium/py/test/selenium/webdriver/common/implicit_waits_tests.py::testShouldReturnAfterFirstAttemptToFindManyAfterDisablingImplicitWaits + imported/selenium/py/test/selenium/webdriver/common/page_load_timeout_tests.py::testShouldTimeoutOnPageLoadTakingTooLong + imported/selenium/py/test/selenium/webdriver/common/page_load_timeout_tests.py::testShouldTimeoutOnPageLoadTakingTooLong + imported/selenium/py/test/selenium/webdriver/common/webdriverwait_tests.py::testShouldWaitOnlyAsLongAsTimeoutSpecifiedWhenImplicitWaitsAreSet + + The following two tests regress, and will be looked into separately: + imported/w3c/webdriver/tests/sessions/new_session/merge.py::test_merge_invalid + imported/w3c/webdriver/tests/sessions/new_session/merge.py::test_merge_invalid + + * WebDriverService.cpp: + (WebDriver::integerValue): Helper function that retrieves an integer value + from a given JSON::Value object, if possible. + (WebDriver::deserializeTimeouts): Timeout JSON value has to be converted to + an integer, which is allowed if the value is of either Integer or Double type. + Helper integerValue() function retrieves the integer value, in addition to + ensuring that possible double value that we convert to an integer is already + in integer form to begin with. + 2017-12-15 Carlos Garcia Campos WebDriver: add support for accept/dismiss and notify unhandled prompt behavior diff --git a/Source/WebDriver/WebDriverService.cpp b/Source/WebDriver/WebDriverService.cpp index 63118cb12e72..dc411bf42ad5 100644 --- a/Source/WebDriver/WebDriverService.cpp +++ b/Source/WebDriver/WebDriverService.cpp @@ -270,6 +270,22 @@ void WebDriverService::sendResponse(FunctiontoJSONString().utf8(), ASCIILiteral("application/json; charset=utf-8") }); } +static bool integerValue(JSON::Value& value, int& output) +{ + // Bail if an integer value cannot be retrieved. + if (!value.asInteger(output)) + return false; + + // If the contained value is a double, bail in case it doesn't match the integer + // value, i.e. if the double value was not originally in integer form. + // https://w3c.github.io/webdriver/webdriver-spec.html#dfn-integer + double doubleValue; + if (value.asDouble(doubleValue) && doubleValue != output) + return false; + + return true; +} + static std::optional deserializeTimeouts(JSON::Object& timeoutsObject) { // ยง8.5 Set Timeouts. @@ -281,7 +297,7 @@ static std::optional deserializeTimeouts(JSON::Object& timeoutsObject) continue; int timeoutMS; - if (it->value->type() != JSON::Value::Type::Integer || !it->value->asInteger(timeoutMS) || timeoutMS < 0 || timeoutMS > INT_MAX) + if (!integerValue(*it->value, timeoutMS) || timeoutMS < 0 || timeoutMS > INT_MAX) return std::nullopt; if (it->key == "script")