summaryrefslogtreecommitdiffstats
path: root/WebKit/gtk/tests/testdomdocument.c
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/gtk/tests/testdomdocument.c')
-rw-r--r--WebKit/gtk/tests/testdomdocument.c147
1 files changed, 145 insertions, 2 deletions
diff --git a/WebKit/gtk/tests/testdomdocument.c b/WebKit/gtk/tests/testdomdocument.c
index ec2f579..56e233f 100644
--- a/WebKit/gtk/tests/testdomdocument.c
+++ b/WebKit/gtk/tests/testdomdocument.c
@@ -30,7 +30,8 @@
#define HTML_DOCUMENT_ELEMENTS "<html><body><ul><li>1</li><li>2</li><li>3</li></ul></body></html>"
#define HTML_DOCUMENT_ELEMENTS_CLASS "<html><body><div class=\"test\"></div><div class=\"strange\"></div><div class=\"test\"></div></body></html>"
#define HTML_DOCUMENT_ELEMENTS_ID "<html><body><div id=\"testok\"></div><div id=\"testbad\">first</div><div id=\"testbad\">second</div></body></html>"
-#define HTML_DOCUMENT_LINKS "<html><body><a href=\"about:blank\">blank</a><a href=\"http://www.google.com\">google</a><a href=\"http://www.webkit.org\">webkit</a></body></html>"
+#define HTML_DOCUMENT_LINKS "<html><head><title>Title</title></head><body><a href=\"about:blank\">blank</a><a href=\"http://www.google.com\">google</a><a href=\"http://www.webkit.org\">webkit</a></body></html>"
+#define HTML_DOCUMENT_IFRAME "<html><head><title>IFrame</title></head><body><iframe id='iframe'></iframe><div id='test'></div></body></html>"
typedef struct {
GtkWidget* webView;
@@ -60,7 +61,8 @@ static void dom_document_fixture_setup(DomDocumentFixture* fixture, gconstpointe
static void dom_document_fixture_teardown(DomDocumentFixture* fixture, gconstpointer data)
{
- g_object_unref(fixture->webView);
+ if (fixture->webView)
+ g_object_unref(fixture->webView);
g_main_loop_unref(fixture->loop);
}
@@ -107,6 +109,8 @@ static void test_dom_document_get_elements_by_tag_name(DomDocumentFixture* fixtu
g_assert_cmpstr(webkit_dom_html_element_get_inner_text(htmlElement), ==, n);
g_free(n);
}
+
+ g_object_unref(list);
}
static void test_dom_document_get_elements_by_class_name(DomDocumentFixture* fixture, gconstpointer data)
@@ -130,6 +134,8 @@ static void test_dom_document_get_elements_by_class_name(DomDocumentFixture* fix
g_assert(element);
g_assert_cmpstr(webkit_dom_element_get_tag_name(element), ==, "DIV");
}
+
+ g_object_unref(list);
}
static void test_dom_document_get_element_by_id(DomDocumentFixture* fixture, gconstpointer data)
@@ -178,6 +184,137 @@ static void test_dom_document_get_links(DomDocumentFixture* fixture, gconstpoint
WebKitDOMHTMLAnchorElement *anchor = (WebKitDOMHTMLAnchorElement*)element;
g_assert_cmpstr(webkit_dom_html_anchor_element_get_href(anchor), ==, uris[i]);
}
+ g_object_unref(collection);
+}
+
+static void weak_notify(gpointer data, GObject* zombie)
+{
+ guint* count = (guint*)data;
+ (*count)++;
+}
+
+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);
}
int main(int argc, char** argv)
@@ -219,6 +356,12 @@ int main(int argc, char** argv)
test_dom_document_get_links,
dom_document_fixture_teardown);
+ g_test_add("/webkit/domdocument/test_garbage_collection",
+ DomDocumentFixture, HTML_DOCUMENT_LINKS,
+ dom_document_fixture_setup,
+ test_dom_document_garbage_collection,
+ dom_document_fixture_teardown);
+
return g_test_run();
}