/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "dali-toolkit-test-utils/toolkit-timer.h"
#include <dali.h>
+#include <dali/devel-api/adaptor-framework/web-engine-request-interceptor.h>
+#include <dali/integration-api/events/hover-event-integ.h>
#include <dali/integration-api/events/key-event-integ.h>
#include <dali/integration-api/events/touch-event-integ.h>
+#include <dali/integration-api/events/wheel-event-integ.h>
#include <dali/public-api/images/pixel-data.h>
#include <dali-toolkit/public-api/controls/image-view/image-view.h>
#include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
#include <dali-toolkit/devel-api/controls/web-view/web-back-forward-list-item.h>
#include <dali-toolkit/devel-api/controls/web-view/web-context.h>
#include <dali-toolkit/devel-api/controls/web-view/web-cookie-manager.h>
+#include <dali-toolkit/devel-api/controls/web-view/web-form-repost-decision.h>
#include <dali-toolkit/devel-api/controls/web-view/web-settings.h>
#include <dali-toolkit/devel-api/controls/web-view/web-view.h>
static int gJavaScriptAlertCallbackCalled = 0;
static int gJavaScriptConfirmCallbackCalled = 0;
static int gJavaScriptPromptCallbackCalled = 0;
+static int gScreenshotCapturedCallbackCalled = 0;
+static int gVideoPlayingCallbackCalled = 0;
+static int gGeolocationPermissionCallbackCalled = 0;
static bool gTouched = false;
+static bool gHovered = false;
+static bool gWheelEventHandled = false;
+static int gFormRepostDecisionCallbackCalled = 0;
+static std::shared_ptr<Dali::Toolkit::WebFormRepostDecision> gFormRepostDecisionInstance;
+static int gFrameRenderedCallbackCalled = 0;
+static int gRequestInterceptorCallbackCalled = 0;
+static std::shared_ptr<Dali::WebEngineRequestInterceptor> gRequestInterceptorInstance = nullptr;
struct CallbackFunctor
{
return true;
}
+static void OnScreenshotCaptured(Dali::Toolkit::ImageView)
+{
+ gScreenshotCapturedCallbackCalled++;\r
+}
+
+static void OnVideoPlaying(bool isPlaying)
+{
+ gVideoPlayingCallbackCalled++;
+}
+
+static bool OnGeolocationPermission(const std::string&, const std::string&)
+{
+ gGeolocationPermissionCallbackCalled++;
+ return true;
+}
+
static bool OnTouched( Actor actor, const Dali::TouchEvent& touch )
{
gTouched = true;
return true;
}
+static bool OnHovered( Actor actor, const Dali::HoverEvent& hover )
+{
+ gHovered = true;
+ return true;
+}
+
+static bool OnWheelEvent( Actor actor, const Dali::WheelEvent& wheel )
+{
+ gWheelEventHandled = true;
+ return true;
+}
+
+static void OnFormRepostDecision(WebView, std::shared_ptr<Dali::Toolkit::WebFormRepostDecision> decision)
+{
+ gFormRepostDecisionCallbackCalled++;
+ gFormRepostDecisionInstance = decision;
+}
+
+static void OnFrameRendered(WebView)
+{
+ gFrameRenderedCallbackCalled++;
+}
+
+static void OnRequestInterceptor(WebView view, std::shared_ptr<Dali::WebEngineRequestInterceptor> interceptor)
+{
+ gRequestInterceptorCallbackCalled++;
+ gRequestInterceptorInstance = std::move(interceptor);
+}
+
} // namespace
void web_view_startup(void)
END_TEST;
}
+int UtcDaliWebViewPropertyPageZoomFactor(void)
+{
+ ToolkitTestApplication application;
+
+ WebView view = WebView::New();
+ DALI_TEST_CHECK( view );
+
+ view.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+ view.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+ view.SetProperty( Actor::Property::POSITION, Vector2( 0, 0 ));
+ view.SetProperty( Actor::Property::SIZE, Vector2( 800, 600 ) );
+
+ application.GetScene().Add( view );
+ application.SendNotification();
+ application.Render();
+
+ view.SetProperty( WebView::Property::PAGE_ZOOM_FACTOR, 1.5f);
+ float zoomFactor = view.GetProperty<float>( WebView::Property::PAGE_ZOOM_FACTOR );
+ DALI_TEST_EQUALS( zoomFactor, 1.5f, TEST_LOCATION );
+
+ view.SetProperty( WebView::Property::PAGE_ZOOM_FACTOR, 1.0f);
+ zoomFactor = view.GetProperty<float>( WebView::Property::PAGE_ZOOM_FACTOR );
+ DALI_TEST_EQUALS( zoomFactor, 1.0f, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliWebViewPropertyTextZoomFactor(void)
+{
+ ToolkitTestApplication application;
+
+ WebView view = WebView::New();
+ DALI_TEST_CHECK( view );
+
+ view.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+ view.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+ view.SetProperty( Actor::Property::POSITION, Vector2( 0, 0 ));
+ view.SetProperty( Actor::Property::SIZE, Vector2( 800, 600 ) );
+
+ application.GetScene().Add( view );
+ application.SendNotification();
+ application.Render();
+
+ view.SetProperty( WebView::Property::TEXT_ZOOM_FACTOR, 1.5f);
+ float zoomFactor = view.GetProperty<float>( WebView::Property::TEXT_ZOOM_FACTOR );
+ DALI_TEST_EQUALS( zoomFactor, 1.5f, TEST_LOCATION );
+
+ view.SetProperty( WebView::Property::TEXT_ZOOM_FACTOR, 1.0f);
+ zoomFactor = view.GetProperty<float>( WebView::Property::TEXT_ZOOM_FACTOR );
+ DALI_TEST_EQUALS( zoomFactor, 1.0f, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliWebViewPropertyLoadProgressPercentage(void)
+{
+ ToolkitTestApplication application;
+
+ WebView view = WebView::New();
+ DALI_TEST_CHECK( view );
+
+ view.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+ view.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+ view.SetProperty( Actor::Property::POSITION, Vector2( 0, 0 ));
+ view.SetProperty( Actor::Property::SIZE, Vector2( 800, 600 ) );
+
+ application.GetScene().Add( view );
+ application.SendNotification();
+ application.Render();
+
+ float percentage = view.GetProperty<float>( WebView::Property::LOAD_PROGRESS_PERCENTAGE );
+ DALI_TEST_EQUALS( percentage, 0.5f, TEST_LOCATION );
+
+ END_TEST;
+}
+
int UtcDaliWebViewMove(void)
{
ToolkitTestApplication application;
END_TEST;
}
-int UtcDaliWebViewPropertyVideoHole(void)
+int UtcDaliWebViewPropertyVideoHoleEnabled(void)
{
ToolkitTestApplication application;
END_TEST;
}
+int UtcDaliWebViewPropertyMouseEventsEnabled(void)
+{
+ ToolkitTestApplication application;
+
+ WebView view = WebView::New();
+ DALI_TEST_CHECK( view );
+
+ const bool kDefaultValue = true;
+ const bool kTestValue = false;
+
+ // Check default value
+ bool output;
+ Property::Value value = view.GetProperty( WebView::Property::MOUSE_EVENTS_ENABLED );
+ DALI_TEST_CHECK( value.Get( output ) );
+ DALI_TEST_EQUALS( output, kDefaultValue, TEST_LOCATION );
+
+ // Check Set/GetProperty
+ view.SetProperty( WebView::Property::MOUSE_EVENTS_ENABLED, kTestValue );
+ value = view.GetProperty( WebView::Property::MOUSE_EVENTS_ENABLED );
+ DALI_TEST_CHECK( value.Get( output ) );
+ DALI_TEST_EQUALS( output, kTestValue, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliWebViewPropertyKeyEventsEnabled(void)
+{
+ ToolkitTestApplication application;
+
+ WebView view = WebView::New();
+ DALI_TEST_CHECK( view );
+
+ const bool kDefaultValue = true;
+ const bool kTestValue = false;
+
+ // Check default value
+ bool output;
+ Property::Value value = view.GetProperty( WebView::Property::KEY_EVENTS_ENABLED );
+ DALI_TEST_CHECK( value.Get( output ) );
+ DALI_TEST_EQUALS( output, kDefaultValue, TEST_LOCATION );
+
+ // Check Set/GetProperty
+ view.SetProperty( WebView::Property::KEY_EVENTS_ENABLED, kTestValue );
+ value = view.GetProperty( WebView::Property::KEY_EVENTS_ENABLED );
+ DALI_TEST_CHECK( value.Get( output ) );
+ DALI_TEST_EQUALS( output, kTestValue, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliWebViewHoverAndWheel(void)
+{
+ ToolkitTestApplication application;
+
+ WebView view = WebView::New();
+ DALI_TEST_CHECK( view );
+ view.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+ view.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+ view.SetProperty( Actor::Property::POSITION, Vector2( 0, 0 ));
+ view.SetProperty( Actor::Property::SIZE, Vector2( 800, 600 ) );
+
+ application.GetScene().Add( view );
+ application.SendNotification();
+ application.Render();
+
+ view.GetNaturalSize();
+ view.HoveredSignal().Connect( &OnHovered );
+ view.WheelEventSignal().Connect( &OnWheelEvent );
+
+ // Hover event
+ Dali::Integration::HoverEvent event = Dali::Integration::HoverEvent();
+ Dali::Integration::Point pointDown;
+ pointDown.SetState( PointState::DOWN );
+ pointDown.SetScreenPosition( Vector2( 10, 10 ) );
+ event.AddPoint( pointDown );
+ application.ProcessEvent( event );
+
+ event = Dali::Integration::HoverEvent();
+ Dali::Integration::Point pointUp;
+ pointUp.SetState( PointState::UP );
+ pointUp.SetScreenPosition( Vector2( 10, 10 ) );
+ event.AddPoint( pointUp );
+ application.ProcessEvent( event );
+
+ event = Dali::Integration::HoverEvent();
+ Dali::Integration::Point pointMotion;
+ pointUp.SetState( PointState::MOTION );
+ pointUp.SetScreenPosition( Vector2( 10, 10 ) );
+ event.AddPoint( pointMotion );
+ application.ProcessEvent( event );
+
+ // Wheel event
+ Dali::Integration::WheelEvent wheelEvent;
+ wheelEvent.type = Dali::Integration::WheelEvent::Type::MOUSE_WHEEL;
+ wheelEvent.direction = 0;
+ wheelEvent.point = Vector2( 20, 20 );
+ wheelEvent.delta = 10;
+ application.ProcessEvent( wheelEvent );
+ application.SendNotification();
+
+ DALI_TEST_CHECK( gHovered );
+ DALI_TEST_CHECK( gWheelEventHandled );
+
+ END_TEST;
+}
+
+int UtcDaliWebViewFormRepostDecisionFrameRendering(void)
+{
+ ToolkitTestApplication application;
+
+ WebView view = WebView::New();
+ view.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+ view.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+ view.SetProperty( Actor::Property::POSITION, Vector2( 0, 0 ));
+ view.SetProperty( Actor::Property::SIZE, Vector2( 800, 600 ) );
+ application.GetScene().Add( view );
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_CHECK( view );
+
+ ConnectionTracker* testTracker = new ConnectionTracker();
+ view.FormRepostDecisionSignal().Connect(&OnFormRepostDecision);
+ view.FrameRenderedSignal().Connect(&OnFrameRendered);
+ bool signal1 = false;
+ bool signal2 = false;
+ view.ConnectSignal( testTracker, "formRepostDecision", CallbackFunctor(&signal1) );
+ view.ConnectSignal( testTracker, "frameRendered", CallbackFunctor(&signal2) );
+ DALI_TEST_EQUALS( gFormRepostDecisionCallbackCalled, 0, TEST_LOCATION );
+ DALI_TEST_EQUALS( gFrameRenderedCallbackCalled, 0, TEST_LOCATION );
+
+ view.LoadUrl( TEST_URL1 );
+ Test::EmitGlobalTimerSignal();
+ DALI_TEST_EQUALS( gFormRepostDecisionCallbackCalled, 1, TEST_LOCATION );
+ DALI_TEST_EQUALS( gFrameRenderedCallbackCalled, 1, TEST_LOCATION );
+ DALI_TEST_CHECK( signal1 & signal2);
+
+ // form repost decision.
+ DALI_TEST_CHECK(gFormRepostDecisionInstance);
+ gFormRepostDecisionInstance->Reply(true);
+
+ // reset
+ gFormRepostDecisionInstance = nullptr;
+
+ END_TEST;
+}
+
int UtcDaliWebViewGetWebBackForwardList(void)
{
ToolkitTestApplication application;
END_TEST;
}
+int UtcDaliWebViewPropertyBackgroundColorSelectedTextEtc(void)
+{
+ ToolkitTestApplication application;
+
+ WebView view = WebView::New();
+ DALI_TEST_CHECK( view );
+
+ Dali::Vector4 testValue = Dali::Vector4(0.0f, 0.0f, 0.0f, 0.0f);
+ view.SetProperty(WebView::Property::DOCUMENT_BACKGROUND_COLOR, testValue);
+ view.SetProperty(WebView::Property::TILES_CLEARED_WHEN_HIDDEN, true);
+ view.SetProperty(WebView::Property::TILE_COVER_AREA_MULTIPLIER, 1.0f);
+ view.SetProperty(WebView::Property::CURSOR_ENABLED_BY_CLIENT, true);
+
+ // Check default value
+ std::string testText("test");
+ std::string output;
+ view.GetProperty(WebView::Property::SELECTED_TEXT).Get(output);
+ DALI_TEST_EQUALS(output, testText, TEST_LOCATION);
+
+ END_TEST;
+}
+
int UtcDaliWebViewPropertyTitleFavicon(void)
{
- // SCROLL_POSITION
ToolkitTestApplication application;
char argv[] = "--test";
DALI_TEST_EQUALS( gScrollEdgeReachedCallbackCalled, 1, TEST_LOCATION );
DALI_TEST_CHECK( signal1 );
+ // scroll by and trigger scrollEdgeReached event.
+ bool result = view.ScrollEdgeBy( 50, 50 );
+ DALI_TEST_CHECK( result );
+ Test::EmitGlobalTimerSignal();
+
+ view.GetProperty( WebView::Property::SCROLL_POSITION ).Get( output );
+ DALI_TEST_CHECK( output.x == 200 && output.y == 200 );
+ DALI_TEST_EQUALS( gScrollEdgeReachedCallbackCalled, 2, TEST_LOCATION );
+ DALI_TEST_CHECK( signal1 );
+
+ END_TEST;
+}
+
+int UtcDaliWebViewSetGetScaleFactorActivateAccessibility(void)
+{
+ ToolkitTestApplication application;
+
+ WebView view = WebView::New();
+ DALI_TEST_CHECK( view );
+
+ view.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+ view.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+ view.SetProperty( Actor::Property::POSITION, Vector2( 0, 0 ));
+ view.SetProperty( Actor::Property::SIZE, Vector2( 800, 600 ) );
+
+ application.GetScene().Add( view );
+ application.SendNotification();
+ application.Render();
+
+ view.ActivateAccessibility(true);
+ view.AddDynamicCertificatePath("host", "test/to/path");
+ bool found = view.HighlightText("test", Dali::WebEnginePlugin::FindOption::CASE_INSENSITIVE, 2);
+ DALI_TEST_CHECK( found );
+
+ view.SetScaleFactor(1.5f, Dali::Vector2(0.0f, 0.0f));
+ float result = view.GetScaleFactor();
+ DALI_TEST_EQUALS( result, 1.5f, TEST_LOCATION );
+
+ view.SetScaleFactor(1.0f, Dali::Vector2(0.0f, 0.0f));
+ result = view.GetScaleFactor();
+ DALI_TEST_EQUALS( result, 1.0f, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliWebViewGetScreenshotSyncAndAsync(void)
+{
+ // SCROLL_POSITION
+ ToolkitTestApplication application;
+
+ char argv[] = "--test";
+ WebView view = WebView::New( 1, (char**)&argv );
+ DALI_TEST_CHECK( view );
+
+ // Check GetScreenshot
+ Dali::Rect<int> viewArea;
+ viewArea.x = 100;
+ viewArea.y = 100;
+ viewArea.width = 10;
+ viewArea.height = 10;
+ Dali::Toolkit::ImageView screenshot = view.GetScreenshot(viewArea, 1.0f);
+ DALI_TEST_CHECK( screenshot );
+ Dali::Vector3 shotsize = screenshot.GetProperty< Vector3 >( Dali::Actor::Property::SIZE );
+ DALI_TEST_CHECK( ( int )shotsize.width == viewArea.width && ( int )shotsize.height == viewArea.height );
+
+ // Check GetScreenshotAsynchronously
+ viewArea.x = 100;
+ viewArea.y = 100;
+ viewArea.width = 100;
+ viewArea.height = 100;
+ bool result = view.GetScreenshotAsynchronously(viewArea, 1.0f, &OnScreenshotCaptured);
+ DALI_TEST_CHECK( result );
+
+ Test::EmitGlobalTimerSignal();
+
+ Test::EmitGlobalTimerSignal();
+ DALI_TEST_EQUALS( gScreenshotCapturedCallbackCalled, 1, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliWebViewVideoPlayingGeolocationPermission(void)
+{
+ // SCROLL_POSITION
+ ToolkitTestApplication application;
+
+ char argv[] = "--test";
+ WebView view = WebView::New( 1, (char**)&argv );
+ DALI_TEST_CHECK( view );
+
+ // Check CheckVideoPlayingAsynchronously
+ bool result = view.CheckVideoPlayingAsynchronously(&OnVideoPlaying);
+ DALI_TEST_CHECK( result );
+ Test::EmitGlobalTimerSignal();
+ DALI_TEST_EQUALS( gVideoPlayingCallbackCalled, 1, TEST_LOCATION );
+
+ // Check RegisterGeolocationPermissionCallback
+ view.RegisterGeolocationPermissionCallback(&OnGeolocationPermission);
+ Test::EmitGlobalTimerSignal();
+ DALI_TEST_EQUALS( gGeolocationPermissionCallbackCalled, 1, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliWebViewHttpRequestInterceptor(void)
+{
+ ToolkitTestApplication application;
+
+ WebView view = WebView::New();
+ DALI_TEST_CHECK( view );
+
+ // load url.
+ ConnectionTracker* testTracker = new ConnectionTracker();
+ view.RequestInterceptorSignal().Connect( &OnRequestInterceptor );
+ bool signal1 = false;
+ view.ConnectSignal( testTracker, "requestInterceptor", CallbackFunctor(&signal1) );
+ DALI_TEST_EQUALS( gRequestInterceptorCallbackCalled, 0, TEST_LOCATION );
+ DALI_TEST_CHECK(gRequestInterceptorInstance == 0);
+
+ view.LoadUrl( TEST_URL1 );
+ Test::EmitGlobalTimerSignal();
+ DALI_TEST_EQUALS( gRequestInterceptorCallbackCalled, 1, TEST_LOCATION );
+ DALI_TEST_CHECK( signal1 );
+
+ // check request interceptor.
+ DALI_TEST_CHECK(gRequestInterceptorInstance != 0);
+ DALI_TEST_CHECK(gRequestInterceptorInstance->Ignore());
+ DALI_TEST_CHECK(gRequestInterceptorInstance->SetResponseStatus(400, "error"));
+ DALI_TEST_CHECK(gRequestInterceptorInstance->AddResponseHeader("key", "value"));
+ DALI_TEST_CHECK(gRequestInterceptorInstance->AddResponseBody("test", 4));
+ std::string testUrl("http://test.html");
+ DALI_TEST_EQUALS(gRequestInterceptorInstance->GetUrl(), testUrl, TEST_LOCATION);
+
+ gRequestInterceptorInstance = nullptr;
+
END_TEST;
}
END_TEST;
}
+int UtcDaliWebViewLoadHtmlStringOverrideCurrentEntryAndContents(void)
+{
+ ToolkitTestApplication application;
+
+ WebView view = WebView::New( "ko-KR", "Asia/Seoul" );
+ DALI_TEST_CHECK( view );
+
+ std::string html("<body>Hello World!</body>");
+ std::string basicUri("http://basicurl");
+ std::string unreachableUrl("http://unreachableurl");
+ bool result = view.LoadHtmlStringOverrideCurrentEntry( html, basicUri, unreachableUrl );
+ DALI_TEST_CHECK( result );
+
+ application.SendNotification();
+ application.Render();
+ Test::EmitGlobalTimerSignal();
+
+ result = view.LoadContents( html, html.length(), "html/text", "utf-8", basicUri );
+ DALI_TEST_CHECK( result );
+
+ END_TEST;
+}
+
+int UtcDaliWebViewReloadSuspendResumeNetworkLoadingCustomHeader(void)
+{
+ ToolkitTestApplication application;
+
+ WebView view = WebView::New();
+ view.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+ view.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+ view.SetProperty( Actor::Property::POSITION, Vector2( 0, 0 ));
+ view.SetProperty( Actor::Property::SIZE, Vector2( 800, 600 ) );
+
+ application.GetScene().Add( view );
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_CHECK( view );
+
+ view.LoadUrl( "http://test.html" );
+ bool result = view.AddCustomHeader("key", "value");
+ DALI_TEST_CHECK( result );
+
+ result = view.ReloadWithoutCache();
+ DALI_TEST_CHECK( result );
+
+ uint32_t portNumber = view.StartInspectorServer(5000);
+ DALI_TEST_EQUALS( portNumber, 5000, TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render();
+ Test::EmitGlobalTimerSignal();
+
+ result = view.StopInspectorServer();
+ DALI_TEST_CHECK( result );
+
+ view.SuspendNetworkLoading();
+
+ result = view.RemoveCustomHeader("key");
+ DALI_TEST_CHECK( result );
+
+ view.ResumeNetworkLoading();
+
+ END_TEST;
+}
+
int UtcDaliWebViewMethodsForCoverage(void)
{
ToolkitTestApplication application;