diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-05-20 09:56:07 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-05-20 09:56:07 +0000 |
commit | 41386e9cb918eed93b3f13648cbef387e371e451 (patch) | |
tree | a97f9d7bd1d9d091833286085f72da9d83fd0606 /Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp | |
parent | e15dd966d523731101f70ccf768bba12435a0208 (diff) | |
download | WebKitGtk-tarball-41386e9cb918eed93b3f13648cbef387e371e451.tar.gz |
webkitgtk-2.4.9webkitgtk-2.4.9
Diffstat (limited to 'Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp')
-rw-r--r-- | Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp | 323 |
1 files changed, 9 insertions, 314 deletions
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp b/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp index ae89be18c..d24edc601 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestUIClient.cpp @@ -20,7 +20,7 @@ #include "config.h" #include "WebViewTest.h" #include <wtf/HashSet.h> -#include <wtf/glib/GRefPtr.h> +#include <wtf/gobject/GRefPtr.h> #include <wtf/text/StringHash.h> static const char* kAlertDialogMessage = "WebKitGTK+ alert dialog message"; @@ -117,9 +117,9 @@ public: test->m_windowPropertiesChanged.add(g_param_spec_get_name(paramSpec)); } - static GtkWidget* viewCreateCallback(WebKitWebView* webView, WebKitNavigationAction* navigation, UIClientTest* test) + static GtkWidget* viewCreateCallback(WebKitWebView* webView, UIClientTest* test) { - return test->viewCreate(webView, navigation); + return test->viewCreate(webView); } static void viewReadyToShowCallback(WebKitWebView* webView, UIClientTest* test) @@ -197,12 +197,6 @@ public: g_assert(WEBKIT_IS_PERMISSION_REQUEST(request)); test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(request)); - if (test->m_verifyMediaTypes && WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST(request)) { - WebKitUserMediaPermissionRequest* userMediaRequest = WEBKIT_USER_MEDIA_PERMISSION_REQUEST(request); - g_assert(webkit_user_media_permission_is_for_audio_device(userMediaRequest) == test->m_expectedAudioMedia); - g_assert(webkit_user_media_permission_is_for_video_device(userMediaRequest) == test->m_expectedVideoMedia); - } - if (test->m_allowPermissionRequests) webkit_permission_request_allow(request); else @@ -215,9 +209,6 @@ public: : m_scriptDialogType(WEBKIT_SCRIPT_DIALOG_ALERT) , m_scriptDialogConfirmed(true) , m_allowPermissionRequests(false) - , m_verifyMediaTypes(false) - , m_expectedAudioMedia(false) - , m_expectedVideoMedia(false) , m_mouseTargetModifiers(0) { webkit_settings_set_javascript_can_open_windows_automatically(webkit_web_view_get_settings(m_webView), TRUE); @@ -249,10 +240,9 @@ public: return m_mouseTargetHitTestResult.get(); } - virtual GtkWidget* viewCreate(WebKitWebView* webView, WebKitNavigationAction* navigation) + virtual GtkWidget* viewCreate(WebKitWebView* webView) { g_assert(webView == m_webView); - g_assert(navigation); GtkWidget* newWebView = webkit_web_view_new_with_context(webkit_web_view_get_context(webView)); g_object_ref_sink(newWebView); @@ -297,9 +287,6 @@ public: WebKitScriptDialogType m_scriptDialogType; bool m_scriptDialogConfirmed; bool m_allowPermissionRequests; - gboolean m_verifyMediaTypes; - gboolean m_expectedAudioMedia; - gboolean m_expectedVideoMedia; WindowProperties m_windowProperties; HashSet<WTF::String> m_windowPropertiesChanged; GRefPtr<WebKitHitTestResult> m_mouseTargetHitTestResult; @@ -318,91 +305,6 @@ static void testWebViewCreateReadyClose(UIClientTest* test, gconstpointer) g_assert_cmpint(events[2], ==, UIClientTest::Close); } -class CreateNavigationDataTest: public UIClientTest { -public: - MAKE_GLIB_TEST_FIXTURE(CreateNavigationDataTest); - - CreateNavigationDataTest() - : m_navigation(nullptr) - { - } - - ~CreateNavigationDataTest() - { - clearNavigation(); - } - - void clearNavigation() - { - if (m_navigation) - webkit_navigation_action_free(m_navigation); - m_navigation = nullptr; - } - - GtkWidget* viewCreate(WebKitWebView* webView, WebKitNavigationAction* navigation) - { - g_assert(navigation); - g_assert(!m_navigation); - m_navigation = webkit_navigation_action_copy(navigation); - g_main_loop_quit(m_mainLoop); - return nullptr; - } - - void loadHTML(const char* html) - { - clearNavigation(); - WebViewTest::loadHtml(html, nullptr); - } - - void clickAndWaitUntilMainLoopFinishes(int x, int y) - { - clearNavigation(); - clickMouseButton(x, y, 1); - g_main_loop_run(m_mainLoop); - } - - WebKitNavigationAction* m_navigation; -}; - -static void testWebViewCreateNavigationData(CreateNavigationDataTest* test, gconstpointer) -{ - test->showInWindowAndWaitUntilMapped(); - - test->loadHTML( - "<html><body>" - "<input style=\"position:absolute; left:0; top:0; margin:0; padding:0\" type=\"button\" value=\"click to show a popup\" onclick=\"window.open('data:foo');\"/>" - "<a style=\"position:absolute; left:20; top:20;\" href=\"data:bar\" target=\"_blank\">popup link</a>" - "</body></html>"); - test->waitUntilLoadFinished(); - - // Click on a button. - test->clickAndWaitUntilMainLoopFinishes(5, 5); - g_assert_cmpstr(webkit_uri_request_get_uri(webkit_navigation_action_get_request(test->m_navigation)), ==, "data:foo"); - g_assert_cmpuint(webkit_navigation_action_get_navigation_type(test->m_navigation), ==, WEBKIT_NAVIGATION_TYPE_OTHER); - // FIXME: This should be button 1. - g_assert_cmpuint(webkit_navigation_action_get_mouse_button(test->m_navigation), ==, 0); - g_assert_cmpuint(webkit_navigation_action_get_modifiers(test->m_navigation), ==, 0); - g_assert(webkit_navigation_action_is_user_gesture(test->m_navigation)); - - // Click on a link. - test->clickAndWaitUntilMainLoopFinishes(21, 21); - g_assert_cmpstr(webkit_uri_request_get_uri(webkit_navigation_action_get_request(test->m_navigation)), ==, "data:bar"); - g_assert_cmpuint(webkit_navigation_action_get_navigation_type(test->m_navigation), ==, WEBKIT_NAVIGATION_TYPE_LINK_CLICKED); - g_assert_cmpuint(webkit_navigation_action_get_mouse_button(test->m_navigation), ==, 1); - g_assert_cmpuint(webkit_navigation_action_get_modifiers(test->m_navigation), ==, 0); - g_assert(webkit_navigation_action_is_user_gesture(test->m_navigation)); - - // No user interaction. - test->loadHTML("<html><body onLoad=\"window.open();\"></html>"); - test->waitUntilMainLoopFinishes(); - - g_assert_cmpstr(webkit_uri_request_get_uri(webkit_navigation_action_get_request(test->m_navigation)), ==, ""); - g_assert_cmpuint(webkit_navigation_action_get_navigation_type(test->m_navigation), ==, WEBKIT_NAVIGATION_TYPE_OTHER); - g_assert_cmpuint(webkit_navigation_action_get_mouse_button(test->m_navigation), ==, 0); - g_assert_cmpuint(webkit_navigation_action_get_modifiers(test->m_navigation), ==, 0); - g_assert(!webkit_navigation_action_is_user_gesture(test->m_navigation)); -} - static gboolean checkMimeTypeForFilter(GtkFileFilter* filter, const gchar* mimeType) { GtkFileFilterInfo filterInfo; @@ -421,11 +323,11 @@ public: test->m_webViewEvents.append(RunAsModal); } - GtkWidget* viewCreate(WebKitWebView* webView, WebKitNavigationAction* navigation) + GtkWidget* viewCreate(WebKitWebView* webView) { g_assert(webView == m_webView); - GtkWidget* newWebView = UIClientTest::viewCreate(webView, navigation); + GtkWidget* newWebView = UIClientTest::viewCreate(webView); g_signal_connect(newWebView, "run-as-modal", G_CALLBACK(dialogRunAsModalCallback), this); return newWebView; } @@ -521,23 +423,13 @@ static void testWebViewMouseTarget(UIClientTest* test, gconstpointer) test->showInWindowAndWaitUntilMapped(GTK_WINDOW_TOPLEVEL); const char* linksHoveredHTML = - "<html><head>" - " <script>" - " window.onload = function () {" - " window.getSelection().removeAllRanges();" - " var select_range = document.createRange();" - " select_range.selectNodeContents(document.getElementById('text_to_select'));" - " window.getSelection().addRange(select_range);" - " }" - " </script>" - "</head><body>" + "<html><body>" " <a style='position:absolute; left:1; top:1' href='http://www.webkitgtk.org' title='WebKitGTK+ Title'>WebKitGTK+ Website</a>" " <img style='position:absolute; left:1; top:10' src='0xdeadbeef' width=5 height=5></img>" " <a style='position:absolute; left:1; top:20' href='http://www.webkitgtk.org/logo' title='WebKitGTK+ Logo'><img src='0xdeadbeef' width=5 height=5></img></a>" " <input style='position:absolute; left:1; top:30' size='10'></input>" " <div style='position:absolute; left:1; top:50; width:30; height:30; overflow:scroll'> </div>" " <video style='position:absolute; left:1; top:100' width='300' height='300' controls='controls' preload='none'><source src='movie.ogg' type='video/ogg' /></video>" - " <p style='position:absolute; left:1; top:120' id='text_to_select'>Lorem ipsum.</p>" "</body></html>"; test->loadHtml(linksHoveredHTML, "file:///"); @@ -549,7 +441,6 @@ static void testWebViewMouseTarget(UIClientTest* test, gconstpointer) g_assert(!webkit_hit_test_result_context_is_image(hitTestResult)); g_assert(!webkit_hit_test_result_context_is_media(hitTestResult)); g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult)); g_assert_cmpstr(webkit_hit_test_result_get_link_uri(hitTestResult), ==, "http://www.webkitgtk.org/"); g_assert_cmpstr(webkit_hit_test_result_get_link_title(hitTestResult), ==, "WebKitGTK+ Title"); g_assert_cmpstr(webkit_hit_test_result_get_link_label(hitTestResult), ==, "WebKitGTK+ Website"); @@ -561,7 +452,6 @@ static void testWebViewMouseTarget(UIClientTest* test, gconstpointer) g_assert(!webkit_hit_test_result_context_is_image(hitTestResult)); g_assert(!webkit_hit_test_result_context_is_media(hitTestResult)); g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult)); g_assert(!test->m_mouseTargetModifiers); // Move over image with GDK_CONTROL_MASK. @@ -570,7 +460,6 @@ static void testWebViewMouseTarget(UIClientTest* test, gconstpointer) g_assert(webkit_hit_test_result_context_is_image(hitTestResult)); g_assert(!webkit_hit_test_result_context_is_media(hitTestResult)); g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult)); g_assert(!webkit_hit_test_result_context_is_scrollbar(hitTestResult)); g_assert_cmpstr(webkit_hit_test_result_get_image_uri(hitTestResult), ==, "file:///0xdeadbeef"); g_assert(test->m_mouseTargetModifiers & GDK_CONTROL_MASK); @@ -582,7 +471,6 @@ static void testWebViewMouseTarget(UIClientTest* test, gconstpointer) g_assert(!webkit_hit_test_result_context_is_media(hitTestResult)); g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult)); g_assert(!webkit_hit_test_result_context_is_scrollbar(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult)); g_assert_cmpstr(webkit_hit_test_result_get_link_uri(hitTestResult), ==, "http://www.webkitgtk.org/logo"); g_assert_cmpstr(webkit_hit_test_result_get_image_uri(hitTestResult), ==, "file:///0xdeadbeef"); g_assert_cmpstr(webkit_hit_test_result_get_link_title(hitTestResult), ==, "WebKitGTK+ Logo"); @@ -596,7 +484,6 @@ static void testWebViewMouseTarget(UIClientTest* test, gconstpointer) g_assert(webkit_hit_test_result_context_is_media(hitTestResult)); g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult)); g_assert(!webkit_hit_test_result_context_is_scrollbar(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult)); g_assert_cmpstr(webkit_hit_test_result_get_media_uri(hitTestResult), ==, "file:///movie.ogg"); g_assert(!test->m_mouseTargetModifiers); @@ -607,7 +494,6 @@ static void testWebViewMouseTarget(UIClientTest* test, gconstpointer) g_assert(!webkit_hit_test_result_context_is_media(hitTestResult)); g_assert(!webkit_hit_test_result_context_is_scrollbar(hitTestResult)); g_assert(webkit_hit_test_result_context_is_editable(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult)); g_assert(!test->m_mouseTargetModifiers); // Move over scrollbar. @@ -617,22 +503,10 @@ static void testWebViewMouseTarget(UIClientTest* test, gconstpointer) g_assert(!webkit_hit_test_result_context_is_media(hitTestResult)); g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult)); g_assert(webkit_hit_test_result_context_is_scrollbar(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_selection(hitTestResult)); - g_assert(!test->m_mouseTargetModifiers); - - // Move over selection. - hitTestResult = test->moveMouseAndWaitUntilMouseTargetChanged(2, 145); - g_assert(!webkit_hit_test_result_context_is_link(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_image(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_media(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_scrollbar(hitTestResult)); - g_assert(webkit_hit_test_result_context_is_selection(hitTestResult)); g_assert(!test->m_mouseTargetModifiers); - } -static void testWebViewGeolocationPermissionRequests(UIClientTest* test, gconstpointer) +static void testWebViewPermissionRequests(UIClientTest* test, gconstpointer) { // Some versions of geoclue give a runtime warning because it tries // to register the error quark twice. See https://bugs.webkit.org/show_bug.cgi?id=89858. @@ -673,77 +547,6 @@ static void testWebViewGeolocationPermissionRequests(UIClientTest* test, gconstp test->addLogFatalFlag(G_LOG_LEVEL_WARNING); } -#if ENABLE(MEDIA_STREAM) -static void testWebViewUserMediaPermissionRequests(UIClientTest* test, gconstpointer) -{ - WebKitSettings* settings = webkit_web_view_get_settings(test->m_webView); - gboolean enabled = webkit_settings_get_enable_media_stream(settings); - webkit_settings_set_enable_media_stream(settings, TRUE); - - test->showInWindowAndWaitUntilMapped(); - static const char* userMediaRequestHTML = - "<html>" - " <script>" - " function runTest()" - " {" - " navigator.webkitGetUserMedia({audio: true, video: true}," - " function(s) { document.title = \"OK\" }," - " function(e) { document.title = e.name });" - " }" - " </script>" - " <body onload='runTest();'></body>" - "</html>"; - - test->m_verifyMediaTypes = TRUE; - test->m_expectedAudioMedia = TRUE; - test->m_expectedVideoMedia = TRUE; - - // Test denying a permission request. - test->m_allowPermissionRequests = false; - test->loadHtml(userMediaRequestHTML, nullptr); - test->waitUntilTitleChangedTo("PermissionDeniedError"); - - // Test allowing a permission request. - test->m_allowPermissionRequests = true; - test->loadHtml(userMediaRequestHTML, nullptr); - test->waitUntilTitleChangedTo("OK"); - - webkit_settings_set_enable_media_stream(settings, enabled); -} - -static void testWebViewAudioOnlyUserMediaPermissionRequests(UIClientTest* test, gconstpointer) -{ - WebKitSettings* settings = webkit_web_view_get_settings(test->m_webView); - gboolean enabled = webkit_settings_get_enable_media_stream(settings); - webkit_settings_set_enable_media_stream(settings, TRUE); - - test->showInWindowAndWaitUntilMapped(); - static const char* userMediaRequestHTML = - "<html>" - " <script>" - " function runTest()" - " {" - " navigator.webkitGetUserMedia({audio: true, video: false}," - " function(s) { document.title = \"OK\" }," - " function(e) { document.title = e.name });" - " }" - " </script>" - " <body onload='runTest();'></body>" - "</html>"; - - test->m_verifyMediaTypes = TRUE; - test->m_expectedAudioMedia = TRUE; - test->m_expectedVideoMedia = FALSE; - - // Test denying a permission request. - test->m_allowPermissionRequests = false; - test->loadHtml(userMediaRequestHTML, nullptr); - test->waitUntilTitleChangedTo("PermissionDeniedError"); - - webkit_settings_set_enable_media_stream(settings, enabled); -} -#endif // ENABLE(MEDIA_STREAM) - class FileChooserTest: public UIClientTest { public: MAKE_GLIB_TEST_FIXTURE(FileChooserTest); @@ -859,124 +662,16 @@ static void testWebViewFileChooserRequest(FileChooserTest* test, gconstpointer) webkit_file_chooser_request_cancel(fileChooserRequest); } -class ColorChooserTest: public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(ColorChooserTest); - - static gboolean runColorChooserCallback(WebKitWebView*, WebKitColorChooserRequest* request, ColorChooserTest* test) - { - test->runColorChooser(request); - return TRUE; - } - - static void requestFinishedCallback(WebKitColorChooserRequest* request, ColorChooserTest* test) - { - g_assert(test->m_request.get() == request); - test->m_request = nullptr; - if (g_main_loop_is_running(test->m_mainLoop)) - g_main_loop_quit(test->m_mainLoop); - } - - ColorChooserTest() - { - g_signal_connect(m_webView, "run-color-chooser", G_CALLBACK(runColorChooserCallback), this); - } - - void runColorChooser(WebKitColorChooserRequest* request) - { - g_assert(WEBKIT_IS_COLOR_CHOOSER_REQUEST(request)); - assertObjectIsDeletedWhenTestFinishes(G_OBJECT(request)); - m_request = request; - g_signal_connect(request, "finished", G_CALLBACK(requestFinishedCallback), this); - g_main_loop_quit(m_mainLoop); - } - - void finishRequest() - { - g_assert(m_request.get()); - webkit_color_chooser_request_finish(m_request.get()); - g_assert(!m_request); - } - - void cancelRequest() - { - g_assert(m_request.get()); - webkit_color_chooser_request_cancel(m_request.get()); - g_assert(!m_request); - } - - WebKitColorChooserRequest* clickMouseButtonAndWaitForColorChooserRequest(int x, int y) - { - clickMouseButton(x, y); - g_main_loop_run(m_mainLoop); - g_assert(m_request.get()); - return m_request.get(); - } - -private: - GRefPtr<WebKitColorChooserRequest> m_request; -}; - -static void testWebViewColorChooserRequest(ColorChooserTest* test, gconstpointer) -{ - static const char* colorChooserHTMLFormat = "<html><body><input style='position:absolute;left:1;top:1;margin:0;padding:0;width:45;height:25' type='color' %s/></body></html>"; - test->showInWindowAndWaitUntilMapped(); - - GUniquePtr<char> defaultColorHTML(g_strdup_printf(colorChooserHTMLFormat, "")); - test->loadHtml(defaultColorHTML.get(), nullptr); - test->waitUntilLoadFinished(); - WebKitColorChooserRequest* request = test->clickMouseButtonAndWaitForColorChooserRequest(5, 5); - - // Default color is black (#000000). - GdkRGBA rgba1; - GdkRGBA rgba2 = { 0., 0., 0., 1. }; - webkit_color_chooser_request_get_rgba(request, &rgba1); - g_assert(gdk_rgba_equal(&rgba1, &rgba2)); - - // Set a different color. - rgba2.green = 1; - webkit_color_chooser_request_set_rgba(request, &rgba2); - webkit_color_chooser_request_get_rgba(request, &rgba1); - g_assert(gdk_rgba_equal(&rgba1, &rgba2)); - - GdkRectangle rect; - webkit_color_chooser_request_get_element_rectangle(request, &rect); - g_assert_cmpint(rect.x, == , 1); - g_assert_cmpint(rect.y, == , 1); - g_assert_cmpint(rect.width, == , 45); - g_assert_cmpint(rect.height, == , 25); - - test->finishRequest(); - - // Use an initial color. - GUniquePtr<char> initialColorHTML(g_strdup_printf(colorChooserHTMLFormat, "value='#FF00FF'")); - test->loadHtml(initialColorHTML.get(), nullptr); - test->waitUntilLoadFinished(); - request = test->clickMouseButtonAndWaitForColorChooserRequest(5, 5); - - webkit_color_chooser_request_get_rgba(request, &rgba1); - GdkRGBA rgba3 = { 1., 0., 1., 1. }; - g_assert(gdk_rgba_equal(&rgba1, &rgba3)); - - test->cancelRequest(); -} - void beforeAll() { UIClientTest::add("WebKitWebView", "create-ready-close", testWebViewCreateReadyClose); - CreateNavigationDataTest::add("WebKitWebView", "create-navigation-data", testWebViewCreateNavigationData); ModalDialogsTest::add("WebKitWebView", "allow-modal-dialogs", testWebViewAllowModalDialogs); ModalDialogsTest::add("WebKitWebView", "disallow-modal-dialogs", testWebViewDisallowModalDialogs); UIClientTest::add("WebKitWebView", "javascript-dialogs", testWebViewJavaScriptDialogs); UIClientTest::add("WebKitWebView", "window-properties", testWebViewWindowProperties); UIClientTest::add("WebKitWebView", "mouse-target", testWebViewMouseTarget); - UIClientTest::add("WebKitWebView", "geolocation-permission-requests", testWebViewGeolocationPermissionRequests); -#if ENABLE(MEDIA_STREAM) - UIClientTest::add("WebKitWebView", "usermedia-permission-requests", testWebViewUserMediaPermissionRequests); - UIClientTest::add("WebKitWebView", "audio-usermedia-permission-request", testWebViewAudioOnlyUserMediaPermissionRequests); -#endif + UIClientTest::add("WebKitWebView", "permission-requests", testWebViewPermissionRequests); FileChooserTest::add("WebKitWebView", "file-chooser-request", testWebViewFileChooserRequest); - ColorChooserTest::add("WebKitWebView", "color-chooser-request", testWebViewColorChooserRequest); } void afterAll() |