Merge "Fix opacity issue when we use corner radius" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-WebView.cpp
index f12353a..0ca47b6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -39,6 +39,7 @@ const char* const TEST_URL2( "http://www.somewhere.valid2.com" );
 
 static int gPageLoadStartedCallbackCalled = 0;
 static int gPageLoadFinishedCallbackCalled = 0;
+static int gScrollEdgeReachedCallbackCalled = 0;
 static int gEvaluateJavaScriptCallbackCalled = 0;
 static bool gTouched = false;
 
@@ -66,6 +67,11 @@ static void OnPageLoadFinished( WebView view, const std::string& url )
   gPageLoadFinishedCallbackCalled++;
 }
 
+static void OnScrollEdgeReached( WebView view, Dali::WebEnginePlugin::ScrollEdge edge )
+{
+  gScrollEdgeReachedCallbackCalled++;
+}
+
 static void OnPageLoadError( WebView view, const std::string& url, WebView::LoadErrorCode errorCode )
 {
 }
@@ -75,7 +81,7 @@ static void OnEvaluateJavaScript( const std::string& result )
   gEvaluateJavaScriptCallbackCalled++;
 }
 
-static bool OnTouched( Actor actor, const Dali::TouchData& touch )
+static bool OnTouched( Actor actor, const Dali::TouchEvent& touch )
 {
   gTouched = true;
   return true;
@@ -146,9 +152,9 @@ int UtcDaliWebViewPageNavigation(void)
   WebView view = WebView::New();
   view.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
   view.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
-  view.SetPosition( 0, 0 );
-  view.SetSize( 800, 600 );
-  Stage::GetCurrent().Add( view );
+  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 );
@@ -178,7 +184,7 @@ int UtcDaliWebViewPageNavigation(void)
 
   view.LoadUrl( TEST_URL2 );
   view.Suspend();
-  view.SetSize( 400, 300 );
+  view.SetProperty( Actor::Property::SIZE, Vector2( 400, 300 ) );
   application.SendNotification();
   application.Render();
   Test::EmitGlobalTimerSignal();
@@ -217,15 +223,15 @@ int UtcDaliWebViewTouchAndKeys(void)
   WebView view = WebView::New();
   view.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
   view.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
-  view.SetPosition( 0, 0 );
-  view.SetSize( 800, 600 );
+  view.SetProperty( Actor::Property::POSITION, Vector2( 0, 0 ));
+  view.SetProperty( Actor::Property::SIZE, Vector2( 800, 600 ) );
 
-  Stage::GetCurrent().Add( view );
+  application.GetScene().Add( view );
   application.SendNotification();
   application.Render();
 
   view.GetNaturalSize();
-  view.TouchSignal().Connect( &OnTouched );
+  view.TouchedSignal().Connect( &OnTouched );
 
   // Touch event
   Dali::Integration::TouchEvent event;
@@ -245,7 +251,7 @@ int UtcDaliWebViewTouchAndKeys(void)
 
   // Key event
   Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor( view );
-  application.ProcessEvent( Integration::KeyEvent( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Down, "", "", Device::Class::NONE, Device::Subclass::NONE ) );
+  application.ProcessEvent( Integration::KeyEvent( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::DOWN, "", "", Device::Class::NONE, Device::Subclass::NONE ) );
   application.SendNotification();
 
   DALI_TEST_CHECK( gTouched );
@@ -254,6 +260,32 @@ int UtcDaliWebViewTouchAndKeys(void)
   END_TEST;
 }
 
+int UtcDaliWebViewFocusGainedAndLost(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.SetKeyInputFocus();
+  DALI_TEST_CHECK( view.HasKeyInputFocus() );
+
+  // reset
+  view.ClearKeyInputFocus();
+  DALI_TEST_CHECK( !view.HasKeyInputFocus() );
+
+  END_TEST;
+}
+
 int UtcDaliWebViewProperty1(void)
 {
   // URL
@@ -465,6 +497,72 @@ int UtcDaliWebViewProperty8(void)
   END_TEST;
 }
 
+int UtcDaliWebViewProperty9(void)
+{
+  // SCROLL_POSITION
+  ToolkitTestApplication application;
+
+  WebView view = WebView::New();
+  DALI_TEST_CHECK( view );
+
+  // Check default value
+  Dali::Vector2 output = Dali::Vector2::ONE;
+  view.GetProperty( WebView::Property::SCROLL_POSITION ).Get( output );
+  DALI_TEST_CHECK( output.x == 0 && output.y == 0 );
+
+  // Check Set/GetProperty
+  Dali::Vector2 testValue = Dali::Vector2( 100, 100 );
+  view.SetProperty( WebView::Property::SCROLL_POSITION, testValue );
+  view.GetProperty( WebView::Property::SCROLL_POSITION ).Get( output );
+  DALI_TEST_EQUALS( output, testValue, TEST_LOCATION );
+
+  // Check default value of scroll size
+  output = Dali::Vector2::ONE;
+  view.GetProperty( WebView::Property::SCROLL_SIZE ).Get( output );
+  DALI_TEST_CHECK( output.x == 500 && output.y == 500 );
+
+  // Check default value of content size
+  output = Dali::Vector2::ONE;
+  view.GetProperty( WebView::Property::CONTENT_SIZE ).Get( output );
+  DALI_TEST_CHECK( output.x == 500 && output.y == 500 );
+
+  END_TEST;
+}
+
+int UtcDaliWebViewScrollBy(void)
+{
+  ToolkitTestApplication application;
+
+  WebView view = WebView::New();
+  DALI_TEST_CHECK( view );
+
+  // load url.
+  ConnectionTracker* testTracker = new ConnectionTracker();
+  view.ScrollEdgeReachedSignal().Connect( &OnScrollEdgeReached );
+  bool signal1 = false;
+  view.ConnectSignal( testTracker, "scrollEdgeReached", CallbackFunctor(&signal1) );
+  DALI_TEST_EQUALS( gScrollEdgeReachedCallbackCalled, 0, TEST_LOCATION );
+
+  view.LoadUrl( TEST_URL1 );
+  Test::EmitGlobalTimerSignal();
+
+  // set scroll position.
+  Dali::Vector2 output = Dali::Vector2::ONE;
+  Dali::Vector2 testValue = Dali::Vector2( 100, 100 );
+  view.SetProperty( WebView::Property::SCROLL_POSITION, testValue );
+  view.GetProperty( WebView::Property::SCROLL_POSITION ).Get( output );
+  DALI_TEST_EQUALS( output, testValue, TEST_LOCATION );
+
+  // scroll by and trigger scrollEdgeReached event.
+  view.ScrollBy( 50, 50 );
+  view.GetProperty( WebView::Property::SCROLL_POSITION ).Get( output );
+  DALI_TEST_CHECK( output.x == 150 && output.y == 150 );
+  DALI_TEST_EQUALS( gScrollEdgeReachedCallbackCalled, 1, TEST_LOCATION );
+  DALI_TEST_CHECK( signal1 );
+
+  END_TEST;
+}
+
 int UtcDaliWebViewEvaluteJavaScript(void)
 {
   ToolkitTestApplication application;