Modified: trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_download_job.cpp (152763 => 152764)
--- trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_download_job.cpp 2013-07-17 07:12:11 UTC (rev 152763)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_download_job.cpp 2013-07-17 07:15:09 UTC (rev 152764)
@@ -41,112 +41,115 @@
static const char serverSuggestedFilename[] = "webkit-downloaded-file";
static const char testFilePath[] = "/test.pdf";
-struct DownloadTestData {
- const char* fileUrl;
- const char* destinationPath;
-};
+class EWK2DownloadJobTest : public EWK2UnitTestBase {
+public:
+ struct DownloadTestData {
+ const char* fileUrl;
+ const char* destinationPath;
+ };
-static inline bool fileExists(const char* path)
-{
- struct stat buf;
- return !stat(path, &buf);
-}
-
-static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, void*)
-{
- if (message->method != SOUP_METHOD_GET) {
- soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
- return;
+ static bool fileExists(const char* path)
+ {
+ struct stat buf;
+ return !stat(path, &buf);
}
- Eina_Strbuf* filePath = eina_strbuf_new();
- eina_strbuf_append(filePath, TEST_RESOURCES_DIR);
- eina_strbuf_append(filePath, path);
+ static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, void*)
+ {
+ if (message->method != SOUP_METHOD_GET) {
+ soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
+ return;
+ }
- Eina_File* f = eina_file_open(eina_strbuf_string_get(filePath), false);
- eina_strbuf_free(filePath);
- if (!f) {
- soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
- soup_message_body_complete(message->response_body);
- return;
- }
+ Eina_Strbuf* filePath = eina_strbuf_new();
+ eina_strbuf_append(filePath, TEST_RESOURCES_DIR);
+ eina_strbuf_append(filePath, path);
- size_t fileSize = eina_file_size_get(f);
+ Eina_File* f = eina_file_open(eina_strbuf_string_get(filePath), false);
+ eina_strbuf_free(filePath);
+ if (!f) {
+ soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
+ soup_message_body_complete(message->response_body);
+ return;
+ }
- void* contents = eina_file_map_all(f, EINA_FILE_POPULATE);
- if (!contents) {
- soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
- soup_message_body_complete(message->response_body);
- return;
- }
+ size_t fileSize = eina_file_size_get(f);
- soup_message_set_status(message, SOUP_STATUS_OK);
+ void* contents = eina_file_map_all(f, EINA_FILE_POPULATE);
+ if (!contents) {
+ soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
+ soup_message_body_complete(message->response_body);
+ return;
+ }
- Eina_Strbuf* contentDisposition = eina_strbuf_new();
- eina_strbuf_append_printf(contentDisposition, "filename=%s", serverSuggestedFilename);
- soup_message_headers_append(message->response_headers, "Content-Disposition", eina_strbuf_string_get(contentDisposition));
- eina_strbuf_free(contentDisposition);
+ soup_message_set_status(message, SOUP_STATUS_OK);
- soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, contents, fileSize);
- soup_message_body_complete(message->response_body);
+ Eina_Strbuf* contentDisposition = eina_strbuf_new();
+ eina_strbuf_append_printf(contentDisposition, "filename=%s", serverSuggestedFilename);
+ soup_message_headers_append(message->response_headers, "Content-Disposition", eina_strbuf_string_get(contentDisposition));
+ eina_strbuf_free(contentDisposition);
- eina_file_map_free(f, contents);
- eina_file_close(f);
-}
+ soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, contents, fileSize);
+ soup_message_body_complete(message->response_body);
-static void on_download_requested(void* userData, Evas_Object* webview, void* eventInfo)
-{
- DownloadTestData* testData = static_cast<DownloadTestData*>(userData);
- Ewk_Download_Job* download = static_cast<Ewk_Download_Job*>(eventInfo);
- ASSERT_EQ(EWK_DOWNLOAD_JOB_STATE_NOT_STARTED, ewk_download_job_state_get(download));
- ASSERT_EQ(0, ewk_download_job_estimated_progress_get(download));
- ASSERT_EQ(0, ewk_download_job_elapsed_time_get(download));
+ eina_file_map_free(f, contents);
+ eina_file_close(f);
+ }
- Ewk_Url_Request* request = ewk_download_job_request_get(download);
- ASSERT_TRUE(request);
- EXPECT_STREQ(testData->fileUrl, ewk_url_request_url_get(request));
+ static void on_download_requested(void* userData, Evas_Object* webview, void* eventInfo)
+ {
+ DownloadTestData* testData = static_cast<DownloadTestData*>(userData);
+ Ewk_Download_Job* download = static_cast<Ewk_Download_Job*>(eventInfo);
+ ASSERT_EQ(EWK_DOWNLOAD_JOB_STATE_NOT_STARTED, ewk_download_job_state_get(download));
+ ASSERT_EQ(0, ewk_download_job_estimated_progress_get(download));
+ ASSERT_EQ(0, ewk_download_job_elapsed_time_get(download));
- Ewk_Url_Response* response = ewk_download_job_response_get(download);
- ASSERT_TRUE(response);
- EXPECT_STREQ("application/pdf", ewk_url_response_mime_type_get(response));
+ Ewk_Url_Request* request = ewk_download_job_request_get(download);
+ ASSERT_TRUE(request);
+ EXPECT_STREQ(testData->fileUrl, ewk_url_request_url_get(request));
- EXPECT_STREQ(serverSuggestedFilename, ewk_download_job_suggested_filename_get(download));
+ Ewk_Url_Response* response = ewk_download_job_response_get(download);
+ ASSERT_TRUE(response);
+ EXPECT_STREQ("application/pdf", ewk_url_response_mime_type_get(response));
- ASSERT_FALSE(fileExists(testData->destinationPath));
- ewk_download_job_destination_set(download, testData->destinationPath);
- EXPECT_STREQ(testData->destinationPath, ewk_download_job_destination_get(download));
-}
+ EXPECT_STREQ(serverSuggestedFilename, ewk_download_job_suggested_filename_get(download));
-static void on_download_cancelled(void* userData, Evas_Object* webview, void* eventInfo)
-{
- fprintf(stderr, "Download was cancelled.\n");
- ecore_main_loop_quit();
- FAIL();
-}
+ ASSERT_FALSE(fileExists(testData->destinationPath));
+ ewk_download_job_destination_set(download, testData->destinationPath);
+ EXPECT_STREQ(testData->destinationPath, ewk_download_job_destination_get(download));
+ }
-static void on_download_failed(void* userData, Evas_Object* webview, void* eventInfo)
-{
- Ewk_Download_Job_Error* downloadError = static_cast<Ewk_Download_Job_Error*>(eventInfo);
- fprintf(stderr, "Download error: %s\n", ewk_error_description_get(downloadError->error));
- ecore_main_loop_quit();
- FAIL();
-}
+ static void on_download_cancelled(void* userData, Evas_Object* webview, void* eventInfo)
+ {
+ fprintf(stderr, "Download was cancelled.\n");
+ ecore_main_loop_quit();
+ FAIL();
+ }
-static void on_download_finished(void* userData, Evas_Object* webview, void* eventInfo)
-{
- DownloadTestData* testData = static_cast<DownloadTestData*>(userData);
- Ewk_Download_Job* download = static_cast<Ewk_Download_Job*>(eventInfo);
+ static void on_download_failed(void* userData, Evas_Object* webview, void* eventInfo)
+ {
+ Ewk_Download_Job_Error* downloadError = static_cast<Ewk_Download_Job_Error*>(eventInfo);
+ fprintf(stderr, "Download error: %s\n", ewk_error_description_get(downloadError->error));
+ ecore_main_loop_quit();
+ FAIL();
+ }
- ASSERT_EQ(1, ewk_download_job_estimated_progress_get(download));
- ASSERT_EQ(EWK_DOWNLOAD_JOB_STATE_FINISHED, ewk_download_job_state_get(download));
- ASSERT_GT(ewk_download_job_elapsed_time_get(download), 0);
+ static void on_download_finished(void* userData, Evas_Object* webview, void* eventInfo)
+ {
+ DownloadTestData* testData = static_cast<DownloadTestData*>(userData);
+ Ewk_Download_Job* download = static_cast<Ewk_Download_Job*>(eventInfo);
- ASSERT_TRUE(fileExists(testData->destinationPath));
+ ASSERT_EQ(1, ewk_download_job_estimated_progress_get(download));
+ ASSERT_EQ(EWK_DOWNLOAD_JOB_STATE_FINISHED, ewk_download_job_state_get(download));
+ ASSERT_GT(ewk_download_job_elapsed_time_get(download), 0);
- ecore_main_loop_quit();
-}
+ ASSERT_TRUE(fileExists(testData->destinationPath));
-TEST_F(EWK2UnitTestBase, ewk_download)
+ ecore_main_loop_quit();
+ }
+};
+
+TEST_F(EWK2DownloadJobTest, ewk_download)
{
OwnPtr<EWK2UnitTestServer> httpServer = adoptPtr(new EWK2UnitTestServer);
httpServer->run(serverCallback);