Diff
Modified: trunk/Source/WebKit2/ChangeLog (125973 => 125974)
--- trunk/Source/WebKit2/ChangeLog 2012-08-19 12:02:38 UTC (rev 125973)
+++ trunk/Source/WebKit2/ChangeLog 2012-08-19 12:29:18 UTC (rev 125974)
@@ -1,3 +1,27 @@
+2012-08-19 Christophe Dumez <[email protected]>
+
+ [EFL][WK2] Add API unit tests for Web Intents
+ https://bugs.webkit.org/show_bug.cgi?id=90454
+
+ Reviewed by Kenneth Rohde Christiansen.
+
+ Add unit testing for Web intent requests,
+ including the "intent,request,new" signal on
+ the Ewk_View and the Ewk_Intent API.
+
+ * UIProcess/API/efl/ewk_view.h: Fix documentation for argument type of "intent,request,new" signal.
+ * UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp:
+ (EWK2UnitTest::EWK2UnitTestBase::mouseClick): Add utility method to simulate a click at given
+ coordinates. This is needed for testing functionality that requires a user gesture.
+ (EWK2UnitTest):
+ * UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h:
+ (EWK2UnitTestBase):
+ * UIProcess/API/efl/tests/resources/intent-request.html: Added.
+ * UIProcess/API/efl/tests/test_ewk2_intents.cpp:
+ (stringSortCb):
+ (onIntentReceived):
+ (TEST_F):
+
2012-08-18 Carlos Garcia Campos <[email protected]>
[GTK] Add API to set preferred languages to WebKit2 GTK+
Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.h (125973 => 125974)
--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.h 2012-08-19 12:02:38 UTC (rev 125973)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.h 2012-08-19 12:29:18 UTC (rev 125974)
@@ -42,7 +42,7 @@
* when done to continue with the form submission. If the last reference is removed on a
* #Ewk_Form_Submission_Request and the form has not been submitted yet,
* ewk_form_submission_request_submit() will be called automatically.
- * - "intent,request,new", Ewk_Intent_Request*: reports new Web intent request.
+ * - "intent,request,new", Ewk_Intent*: reports new Web intent request.
* - "intent,service,register", Ewk_Intent_Service*: reports new Web intent service registration.
* - "load,error", const Ewk_Web_Error*: reports main frame load failed.
* - "load,finished", void: reports load finished.
Modified: trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp (125973 => 125974)
--- trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp 2012-08-19 12:02:38 UTC (rev 125973)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp 2012-08-19 12:29:18 UTC (rev 125974)
@@ -112,4 +112,12 @@
evas_object_smart_callback_del(m_webView, "title,changed", onTitleChanged);
}
+void EWK2UnitTestBase::mouseClick(int x, int y)
+{
+ Evas* evas = evas_object_evas_get(m_webView);
+ evas_event_feed_mouse_move(evas, x, y, 0, 0);
+ evas_event_feed_mouse_down(evas, /* Left */ 1, EVAS_BUTTON_NONE, 0, 0);
+ evas_event_feed_mouse_up(evas, /* Left */ 1, EVAS_BUTTON_NONE, 0, 0);
+}
+
} // namespace EWK2UnitTest
Modified: trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h (125973 => 125974)
--- trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h 2012-08-19 12:02:38 UTC (rev 125973)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h 2012-08-19 12:29:18 UTC (rev 125974)
@@ -38,6 +38,7 @@
void loadUrlSync(const char* url);
void waitUntilTitleChangedTo(const char* expectedTitle);
+ void mouseClick(int x, int y);
private:
Evas_Object* m_webView;
Added: trunk/Source/WebKit2/UIProcess/API/efl/tests/resources/intent-request.html (0 => 125974)
--- trunk/Source/WebKit2/UIProcess/API/efl/tests/resources/intent-request.html (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/resources/intent-request.html 2012-08-19 12:29:18 UTC (rev 125974)
@@ -0,0 +1,29 @@
+<html>
+<head>
+<title>Web intent request test</title>
+<script type="text/_javascript_">
+var clickCount = 0;
+
+function buttonClicked() {
+ if (clickCount == 0) {
+ var testIntent = new WebKitIntent(
+ {"action": "action1",
+ "type": "mime/type1",
+ "service": "http://service1.com/",
+ "extras": {"key1": "value1", "key2": "value2"}});
+ navigator.webkitStartActivity(testIntent);
+ } else if (clickCount == 1) {
+ var testIntent = new WebKitIntent(
+ {"action": "action2",
+ "type": "mime/type2",
+ "suggestions": ["http://service1.com/", "http://service2.com/"]});
+ navigator.webkitStartActivity(testIntent);
+ }
+ clickCount++;
+}
+</script>
+</head>
+<body>
+<input type="button" id="button" value="Start Web Intent" _onmouseup_="buttonClicked()" style="position: absolute; top: 0px; left: 0px;"/>
+</body>
+</html>
Modified: trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_intents.cpp (125973 => 125974)
--- trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_intents.cpp 2012-08-19 12:02:38 UTC (rev 125973)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_intents.cpp 2012-08-19 12:29:18 UTC (rev 125974)
@@ -29,6 +29,7 @@
#include "UnitTestUtils/EWK2UnitTestEnvironment.h"
#include "UnitTestUtils/EWK2UnitTestServer.h"
#include <EWebKit2.h>
+#include <Ecore.h>
using namespace EWK2UnitTest;
@@ -57,3 +58,59 @@
evas_object_smart_callback_del(webView(), "intent,service,register", onIntentServiceRegistration);
ASSERT_TRUE(intentRegistered);
}
+
+int stringSortCb(const void* d1, const void* d2)
+{
+ return strcmp(static_cast<const char*>(d1), static_cast<const char*>(d2));
+}
+
+static void onIntentReceived(void* userData, Evas_Object*, void* eventInfo)
+{
+ unsigned* intentReceivedCount = static_cast<unsigned*>(userData);
+ ASSERT_GE(*intentReceivedCount, 0);
+ ASSERT_LE(*intentReceivedCount, 1);
+ ++(*intentReceivedCount);
+
+ Ewk_Intent* intent = static_cast<Ewk_Intent*>(eventInfo);
+ ASSERT_TRUE(intent);
+
+ if (*intentReceivedCount == 1) {
+ // First intent.
+ EXPECT_STREQ(ewk_intent_action_get(intent), "action1");
+ EXPECT_STREQ(ewk_intent_type_get(intent), "mime/type1");
+ EXPECT_STREQ(ewk_intent_service_get(intent), "http://service1.com/");
+ EXPECT_STREQ(ewk_intent_extra_get(intent, "key1"), "value1");
+ EXPECT_STREQ(ewk_intent_extra_get(intent, "key2"), "value2");
+ } else {
+ // Second intent.
+ EXPECT_STREQ(ewk_intent_action_get(intent), "action2");
+ EXPECT_STREQ(ewk_intent_type_get(intent), "mime/type2");
+ Eina_List* suggestions = ewk_intent_suggestions_get(intent);
+ ASSERT_TRUE(suggestions);
+ ASSERT_EQ(eina_list_count(suggestions), 2);
+ // We need to sort the suggestions since Intent is using a HashSet internally.
+ suggestions = eina_list_sort(suggestions, 2, stringSortCb);
+ EXPECT_STREQ(static_cast<const char*>(eina_list_nth(suggestions, 0)), "http://service1.com/");
+ EXPECT_STREQ(static_cast<const char*>(eina_list_nth(suggestions, 1)), "http://service2.com/");
+ }
+}
+
+TEST_F(EWK2UnitTestBase, ewk_intent_request)
+{
+ unsigned intentReceivedCount = 0;
+ evas_object_smart_callback_add(webView(), "intent,request,new", onIntentReceived, &intentReceivedCount);
+ loadUrlSync(environment->urlForResource("intent-request.html").data());
+
+ // A user gesture is required for the intent to start.
+ mouseClick(5, 5);
+ while (intentReceivedCount != 1)
+ ecore_main_loop_iterate();
+ ASSERT_EQ(intentReceivedCount, 1);
+
+ // Generate a second intent request.
+ mouseClick(5, 5);
+ while (intentReceivedCount != 2)
+ ecore_main_loop_iterate();
+ ASSERT_EQ(intentReceivedCount, 2);
+ evas_object_smart_callback_del(webView(), "intent,request,new", onIntentReceived);
+}