| 1 | /* |
| 2 | * Copyright (C) 2018 Igalia S.L. |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Library General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Library General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Library General Public License |
| 15 | * along with this library; see the file COPYING.LIB. If not, write to |
| 16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | #include "config.h" |
| 21 | |
| 22 | #include "WebProcessTest.h" |
| 23 | #include <gio/gio.h> |
| 24 | #include <wtf/glib/GUniquePtr.h> |
| 25 | |
| 26 | class DOMElementTest : public WebProcessTest { |
| 27 | public: |
| 28 | static std::unique_ptr<WebProcessTest> create() { return std::unique_ptr<WebProcessTest>(new DOMElementTest()); } |
| 29 | |
| 30 | private: |
| 31 | bool testAutoFill(WebKitWebPage* page) |
| 32 | { |
| 33 | WebKitFrame* frame = webkit_web_page_get_main_frame(page); |
| 34 | g_assert_true(WEBKIT_IS_FRAME(frame)); |
| 35 | |
| 36 | GRefPtr<JSCContext> jsContext = adoptGRef(webkit_frame_get_js_context(frame)); |
| 37 | g_assert_true(JSC_IS_CONTEXT(jsContext.get())); |
| 38 | assertObjectIsDeletedWhenTestFinishes(G_OBJECT(jsContext.get())); |
| 39 | |
| 40 | GRefPtr<JSCValue> jsInputElement = adoptGRef(jsc_context_evaluate(jsContext.get(), "document.getElementById('auto-fill')" , -1)); |
| 41 | g_assert_true(JSC_IS_VALUE(jsInputElement.get())); |
| 42 | assertObjectIsDeletedWhenTestFinishes(G_OBJECT(jsInputElement.get())); |
| 43 | g_assert_true(jsc_value_is_object(jsInputElement.get())); |
| 44 | g_assert_true(jsc_value_object_is_instance_of(jsInputElement.get(), "HTMLInputElement" )); |
| 45 | |
| 46 | auto* node = webkit_dom_node_for_js_value(jsInputElement.get()); |
| 47 | g_assert_true(WEBKIT_DOM_IS_NODE(node)); |
| 48 | assertObjectIsDeletedWhenTestFinishes(G_OBJECT(node)); |
| 49 | |
| 50 | auto* element = WEBKIT_DOM_ELEMENT(node); |
| 51 | g_assert_false(webkit_dom_element_html_input_element_get_auto_filled(element)); |
| 52 | GRefPtr<JSCValue> value = adoptGRef(jsc_value_object_get_property(jsInputElement.get(), "value" )); |
| 53 | g_assert_true(JSC_IS_VALUE(value.get())); |
| 54 | g_assert_true(jsc_value_is_string(value.get())); |
| 55 | GUniquePtr<char> valueString(jsc_value_to_string(value.get())); |
| 56 | g_assert_cmpstr(valueString.get(), ==, "" ); |
| 57 | |
| 58 | webkit_dom_element_html_input_element_set_editing_value(element, "auto filled value" ); |
| 59 | webkit_dom_element_html_input_element_set_auto_filled(element, TRUE); |
| 60 | value = adoptGRef(jsc_value_object_get_property(jsInputElement.get(), "value" )); |
| 61 | g_assert_true(JSC_IS_VALUE(value.get())); |
| 62 | g_assert_true(jsc_value_is_string(value.get())); |
| 63 | valueString.reset(jsc_value_to_string(value.get())); |
| 64 | g_assert_cmpstr(valueString.get(), ==, "auto filled value" ); |
| 65 | g_assert_true(webkit_dom_element_html_input_element_get_auto_filled(element)); |
| 66 | |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | bool runTest(const char* testName, WebKitWebPage* page) override |
| 71 | { |
| 72 | if (!strcmp(testName, "auto-fill" )) |
| 73 | return testAutoFill(page); |
| 74 | |
| 75 | g_assert_not_reached(); |
| 76 | return false; |
| 77 | } |
| 78 | }; |
| 79 | |
| 80 | static void __attribute__((constructor)) registerTests() |
| 81 | { |
| 82 | REGISTER_TEST(DOMElementTest, "WebKitDOMElement/auto-fill" ); |
| 83 | } |
| 84 | |