static void test_dom_document_get_links(DomDocumentFixture* fixture, gconstpointer data) { g_assert(fixture); WebKitWebView* view = (WebKitWebView*)fixture->webView; g_assert(view); WebKitDOMDocument* document = webkit_web_view_get_dom_document(view); g_assert(document); WebKitDOMHTMLCollection *collection = webkit_dom_document_get_links(document); g_assert(collection); gulong length = webkit_dom_html_collection_get_length(collection); g_assert_cmpint(length, ==, 3); guint i; for (i = 0; i < length; i++) { static const char* names[] = { "blank", "google", "webkit" }; static const char* uris[] = { "about:blank", "http://www.google.com/", "http://www.webkit.org/" }; WebKitDOMNode *node = webkit_dom_html_collection_item(collection, i); g_assert(node); WebKitDOMElement* element = (WebKitDOMElement*)node; g_assert_cmpstr(webkit_dom_element_get_tag_name(element), ==, "A"); WebKitDOMHTMLElement *htmlElement = (WebKitDOMHTMLElement*)element; g_assert_cmpstr(webkit_dom_html_element_get_inner_text(htmlElement), ==, names[i]); WebKitDOMHTMLAnchorElement *anchor = (WebKitDOMHTMLAnchorElement*)element; g_assert_cmpstr(webkit_dom_html_anchor_element_get_href(anchor), ==, uris[i]); } g_object_unref(collection); }
static void mark_links(GtkButton *button, WebKitWebView *view) { WebKitDOMDocument* document = webkit_web_view_get_dom_document(view); WebKitDOMHTMLCollection *collection = webkit_dom_document_get_links(document); gulong length = webkit_dom_html_collection_get_length(collection); guint i; for (i = 0; i < length; i++) { WebKitDOMNode *node = webkit_dom_html_collection_item(collection, i); WebKitDOMElement* element = (WebKitDOMElement*)node; WebKitDOMCSSStyleDeclaration *style = webkit_dom_element_get_style(element); webkit_dom_css_style_declaration_set_property(style, "-webkit-transition", "top 1s ease-in", "", NULL); webkit_dom_css_style_declaration_set_property(style, "top", "25px", "", NULL); webkit_dom_css_style_declaration_set_property(style, "position", "relative", "", NULL); g_timeout_add(1000, (GSourceFunc)bounce_back, style); } }
static void test_dom_document_garbage_collection(DomDocumentFixture* fixture, gconstpointer data) { guint count = 0; g_assert(fixture); WebKitWebView* view = (WebKitWebView*)fixture->webView; g_assert(view); WebKitDOMDocument* document = webkit_web_view_get_dom_document(view); g_assert(document); g_object_weak_ref(G_OBJECT(document), (GWeakNotify)weak_notify, &count); WebKitDOMHTMLHeadElement* head = webkit_dom_document_get_head(document); g_assert(head); g_object_weak_ref(G_OBJECT(head), (GWeakNotify)weak_notify, &count); WebKitDOMHTMLElement* body = webkit_dom_document_get_body(document); g_assert(body); g_object_weak_ref(G_OBJECT(body), (GWeakNotify)weak_notify, &count); WebKitDOMHTMLCollection *collection = webkit_dom_document_get_links(document); g_assert(collection); g_object_weak_ref(G_OBJECT(collection), (GWeakNotify)weak_notify, &count); webkit_web_view_load_string(WEBKIT_WEB_VIEW(view), HTML_DOCUMENT_LINKS, NULL, NULL, NULL); while (g_main_context_pending(NULL)) g_main_context_iteration(NULL, FALSE); g_assert_cmpuint(count, ==, 3); g_object_unref(collection); g_assert_cmpuint(count, ==, 4); count = 0; document = webkit_web_view_get_dom_document(view); g_assert(document); g_object_weak_ref(G_OBJECT(document), (GWeakNotify)weak_notify, &count); head = webkit_dom_document_get_head(document); g_assert(head); g_object_weak_ref(G_OBJECT(head), (GWeakNotify)weak_notify, &count); body = webkit_dom_document_get_body(document); g_assert(body); g_object_weak_ref(G_OBJECT(body), (GWeakNotify)weak_notify, &count); collection = webkit_dom_document_get_links(document); g_assert(collection); g_object_weak_ref(G_OBJECT(collection), (GWeakNotify)weak_notify, &count); /* Ask twice for the same object */ WebKitDOMHTMLCollection* collection2 = webkit_dom_document_get_links(document); g_assert(collection2); g_object_weak_ref(G_OBJECT(collection2), (GWeakNotify)weak_notify, &count); g_object_unref(document); g_object_unref(head); g_object_unref(body); g_object_unref(collection); g_object_unref(collection2); g_assert_cmpuint(count, ==, 5); webkit_web_view_load_string(WEBKIT_WEB_VIEW(view), HTML_DOCUMENT_IFRAME, NULL, NULL, NULL); while (g_main_context_pending(NULL)) g_main_context_iteration(NULL, FALSE); count = 0; document = webkit_web_view_get_dom_document(view); WebKitDOMElement* div = webkit_dom_document_get_element_by_id(document, "test"); g_assert(div); g_object_weak_ref(G_OBJECT(div), (GWeakNotify)weak_notify, &count); WebKitDOMElement* iframe = webkit_dom_document_get_element_by_id(document, "iframe"); g_assert(iframe); webkit_dom_element_set_attribute(iframe, "src", "data:<html><head></head></html>", NULL); while (g_main_context_pending(NULL)) g_main_context_iteration(NULL, FALSE); WebKitDOMDocument* iframeDocument = webkit_dom_html_iframe_element_get_content_document(WEBKIT_DOM_HTML_IFRAME_ELEMENT(iframe)); g_assert(iframeDocument); head = webkit_dom_document_get_head(iframeDocument); g_assert(head); g_object_weak_ref(G_OBJECT(head), (GWeakNotify)weak_notify, &count); webkit_dom_element_set_attribute(iframe, "src", "about:blank", NULL); while (g_main_context_pending(NULL)) g_main_context_iteration(NULL, FALSE); g_assert_cmpuint(count, ==, 1); webkit_web_view_load_string(WEBKIT_WEB_VIEW(view), HTML_DOCUMENT_LINKS, NULL, NULL, NULL); while (g_main_context_pending(NULL)) g_main_context_iteration(NULL, FALSE); g_assert_cmpuint(count, ==, 2); count = 0; document = webkit_web_view_get_dom_document(view); g_assert(document); g_object_weak_ref(G_OBJECT(document), (GWeakNotify)weak_notify, &count); /* Ask twice for the Document */ WebKitDOMDocument* document2 = webkit_web_view_get_dom_document(view); g_assert(document2); g_object_weak_ref(G_OBJECT(document2), (GWeakNotify)weak_notify, &count); head = webkit_dom_document_get_head(document); g_assert(head); g_object_weak_ref(G_OBJECT(head), (GWeakNotify)weak_notify, &count); body = webkit_dom_document_get_body(document); g_assert(body); g_object_weak_ref(G_OBJECT(body), (GWeakNotify)weak_notify, &count); collection = webkit_dom_document_get_links(document); g_assert(collection); g_object_weak_ref(G_OBJECT(collection), (GWeakNotify)weak_notify, &count); gtk_widget_destroy(fixture->webView); fixture->webView = NULL; g_assert_cmpuint(count, ==, 4); g_object_unref(collection); g_assert_cmpuint(count, ==, 5); }