diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/old-tests/webdriver/javascript | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/old-tests/webdriver/javascript')
6 files changed, 139 insertions, 0 deletions
diff --git a/testing/web-platform/tests/old-tests/webdriver/javascript/__init__.py b/testing/web-platform/tests/old-tests/webdriver/javascript/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/testing/web-platform/tests/old-tests/webdriver/javascript/__init__.py diff --git a/testing/web-platform/tests/old-tests/webdriver/javascript/execute_script_test.py b/testing/web-platform/tests/old-tests/webdriver/javascript/execute_script_test.py new file mode 100644 index 000000000..dd7cfca94 --- /dev/null +++ b/testing/web-platform/tests/old-tests/webdriver/javascript/execute_script_test.py @@ -0,0 +1,129 @@ +import os +import sys +import unittest + +sys.path.insert(1, os.path.abspath(os.path.join(__file__, "../.."))) +import base_test +from selenium.webdriver.remote.webelement import WebElement + + +class ExecuteScriptTest(base_test.WebDriverBaseTest): + def test_ecmascript_translates_null_return_to_none(self): + self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html")) + result = self.driver.execute_script("return null;") + self.assertIsNone(result) + + def test_ecmascript_translates_undefined_return_to_none(self): + self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html")) + result = self.driver.execute_script("var undef; return undef;") + self.assertIsNone(result) + + def test_can_return_numbers_from_scripts(self): + self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html")) + self.assertEquals(1, self.driver.execute_script("return 1;")) + self.assertEquals(3.14, self.driver.execute_script("return 3.14;")) + + def test_can_return_strings_from_scripts(self): + self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html")) + self.assertEquals("hello, world!", + self.driver.execute_script("return 'hello, world!'")) + + def test_can_return_booleans_from_scripts(self): + self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html")) + self.assertTrue(self.driver.execute_script("return true;")) + self.assertFalse(self.driver.execute_script("return false;")) + + def test_can_return_an_array_of_primitives(self): + self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html")) + + result = self.driver.execute_script("return [1, false, null, 3.14]") + self.assertListEqual([1, False, None, 3.14], result) + + def test_can_return_nested_arrays(self): + self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html")) + result = self.driver.execute_script("return [[1, 2, [3]]]") + + self.assertIsInstance(result, list) + self.assertEquals(1, len(result)) + + result = result[0] + self.assertListEqual([1, 2], result[:2]) + self.assertListEqual([3], result[2]) + + def test_can_return_object_literals(self): + self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html")) + + result = self.driver.execute_script("return {}") + self.assertDictEqual({}, result) + + result = self.driver.execute_script("return {a: 1, b: false, c: null}") + self.assertDictEqual({ + "a": 1, + "b": False, + "c": None + }, result) + + def test_can_return_complex_object_literals(self): + self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html")) + result = self.driver.execute_script("return {a:{b: 'hello'}}") + self.assertIsInstance(result, dict) + self.assertIsInstance(result['a'], dict) + self.assertDictEqual({"b": "hello"}, result["a"]) + + def test_dom_element_return_value_is_translated_to_a_web_element(self): + self.driver.get(self.webserver.where_is( + "javascript/res/return_document_body.html")) + + result = self.driver.execute_script("return document.body") + self.assertEquals(result.text, "Hello, world!") + + def test_return_an_array_of_dom_elements(self): + self.driver.get(self.webserver.where_is( + "javascript/res/return_array_of_dom_elements.html")) + + result = self.driver.execute_script( + "var nodes = document.getElementsByTagName('div');" + "return [nodes[0], nodes[1]]") + + self.assertIsInstance(result, list) + self.assertEquals(2, len(result)) + self.assertEquals("a", result[0].text) + self.assertEquals("b", result[1].text) + + def test_node_list_return_value_is_translated_to_list_of_web_elements(self): + self.driver.get(self.webserver.where_is( + "javascript/res/return_array_of_dom_elements.html")) + + result = self.driver.execute_script( + "return document.getElementsByTagName('div');") + + self.assertIsInstance(result, list) + self.assertEquals(2, len(result)) + self.assertEquals("a", result[0].text) + self.assertEquals("b", result[1].text) + + def test_return_object_literal_with_dom_element_property(self): + self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html")) + result = self.driver.execute_script("return {a: document.body}") + self.assertIsInstance(result, dict) + self.assertEquals("body", result["a"].tag_name) + + def test_scripts_execute_in_anonymous_function_and_do_not_pollute_global_scope(self): + self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html")) + self.driver.execute_script("var x = 1;") + self.assertEquals("undefined", self.driver.execute_script("return typeof x;")); + + def test_scripts_can_modify_context_window_object(self): + self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html")) + self.driver.execute_script("window.x = 1;") + self.assertEquals("number", self.driver.execute_script("return typeof x;")); + self.assertEquals(1, self.driver.execute_script("return x;")); + + def test_that_ecmascript_returns_document_title(self): + self.driver.get(self.webserver.where_is("javascript/res/execute_script_test.html")) + result = self.driver.execute_script("return document.title;") + self.assertEquals("executeScript test", result) + + +if __name__ == "__main__": + unittest.main() diff --git a/testing/web-platform/tests/old-tests/webdriver/javascript/res/execute_script_test.html b/testing/web-platform/tests/old-tests/webdriver/javascript/res/execute_script_test.html new file mode 100644 index 000000000..9491b441a --- /dev/null +++ b/testing/web-platform/tests/old-tests/webdriver/javascript/res/execute_script_test.html @@ -0,0 +1,2 @@ +<!DOCTYPE html> +<title>executeScript test</title>
\ No newline at end of file diff --git a/testing/web-platform/tests/old-tests/webdriver/javascript/res/return_array_of_dom_elements.html b/testing/web-platform/tests/old-tests/webdriver/javascript/res/return_array_of_dom_elements.html new file mode 100644 index 000000000..32827f950 --- /dev/null +++ b/testing/web-platform/tests/old-tests/webdriver/javascript/res/return_array_of_dom_elements.html @@ -0,0 +1,3 @@ +<!DOCTYPE html> +<div id="one">a</div> +<div id="two">b</div> diff --git a/testing/web-platform/tests/old-tests/webdriver/javascript/res/return_document_body.html b/testing/web-platform/tests/old-tests/webdriver/javascript/res/return_document_body.html new file mode 100644 index 000000000..ba1eab446 --- /dev/null +++ b/testing/web-platform/tests/old-tests/webdriver/javascript/res/return_document_body.html @@ -0,0 +1,2 @@ +<!DOCTYPE html> +<div>Hello, world!</div> diff --git a/testing/web-platform/tests/old-tests/webdriver/javascript/res/return_node_list.html b/testing/web-platform/tests/old-tests/webdriver/javascript/res/return_node_list.html new file mode 100644 index 000000000..32827f950 --- /dev/null +++ b/testing/web-platform/tests/old-tests/webdriver/javascript/res/return_node_list.html @@ -0,0 +1,3 @@ +<!DOCTYPE html> +<div id="one">a</div> +<div id="two">b</div> |