Add changesWatch for webview cookie
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-WebView.cpp
index bc0c261..a4ae7e1 100755 (executable)
@@ -26,7 +26,9 @@
 #include <dali/devel-api/adaptor-framework/web-engine-console-message.h>
 #include <dali/devel-api/adaptor-framework/web-engine-context-menu.h>
 #include <dali/devel-api/adaptor-framework/web-engine-context-menu-item.h>
+#include <dali/devel-api/adaptor-framework/web-engine-form-repost-decision.h>
 #include <dali/devel-api/adaptor-framework/web-engine-frame.h>
+#include <dali/devel-api/adaptor-framework/web-engine-hit-test.h>
 #include <dali/devel-api/adaptor-framework/web-engine-http-auth-handler.h>
 #include <dali/devel-api/adaptor-framework/web-engine-load-error.h>
 #include <dali/devel-api/adaptor-framework/web-engine-policy-decision.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.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>
 
@@ -75,7 +75,7 @@ static bool gTouched = false;
 static bool gHovered = false;
 static bool gWheelEventHandled = false;
 static int gFormRepostDecisionCallbackCalled = 0;
-static std::shared_ptr<Dali::Toolkit::WebFormRepostDecision> gFormRepostDecisionInstance = nullptr;
+static std::shared_ptr<Dali::WebEngineFormRepostDecision> gFormRepostDecisionInstance = nullptr;
 static int gFrameRenderedCallbackCalled = 0;
 static int gRequestInterceptorCallbackCalled = 0;
 static std::shared_ptr<Dali::WebEngineRequestInterceptor> gRequestInterceptorInstance = nullptr;
@@ -97,9 +97,11 @@ static int gMimeOverriddenCallbackCalled = 0;
 static std::vector<std::unique_ptr<Dali::WebEngineSecurityOrigin>> gSecurityOriginList;
 static std::vector<std::unique_ptr<Dali::WebEngineContext::PasswordData>> gPasswordDataList;
 static int gContextMenuCustomizedCallbackCalled = 0;
-static std::shared_ptr<Dali::WebEngineContextMenu> gContextMenuInstance = 0;
+static std::shared_ptr<Dali::WebEngineContextMenu> gContextMenuInstance = nullptr;
 static int gContextMenuItemSelectedCallbackCalled = 0;
-static std::shared_ptr<Dali::WebEngineContextMenuItem> gContextMenuItemInstance = 0;
+static std::shared_ptr<Dali::WebEngineContextMenuItem> gContextMenuItemInstance = nullptr;
+static int gHitTestCreatedCallbackCalled = 0;
+static int gCookieManagerChangsWatchCallbackCalled = 0;
 
 struct CallbackFunctor
 {
@@ -146,6 +148,12 @@ static void OnUrlChanged( WebView view, const std::string& url )
   gUrlChangedCallbackCalled++;
 }
 
+static bool OnHitTestCreated(std::unique_ptr<Dali::WebEngineHitTest> test)
+{
+  gHitTestCreatedCallbackCalled++;
+  return true;
+}
+
 static void OnPageLoadError(WebView view, std::shared_ptr<Dali::WebEngineLoadError> error)
 {
   gPageLoadErrorCallbackCalled++;
@@ -197,6 +205,11 @@ static bool OnTouched( Actor actor, const Dali::TouchEvent& touch )
   return true;
 }
 
+static void OnChangesWatch()
+{
+  gCookieManagerChangsWatchCallbackCalled++;
+}
+
 static bool OnHovered( Actor actor, const Dali::HoverEvent& hover )
 {
   gHovered = true;
@@ -209,7 +222,7 @@ static bool OnWheelEvent( Actor actor, const Dali::WheelEvent& wheel )
   return true;
 }
 
-static void OnFormRepostDecision(WebView, std::shared_ptr<Dali::Toolkit::WebFormRepostDecision> decision)
+static void OnFormRepostDecision(WebView, std::shared_ptr<Dali::WebEngineFormRepostDecision> decision)
 {
   gFormRepostDecisionCallbackCalled++;
   gFormRepostDecisionInstance = std::move(decision);
@@ -1336,6 +1349,50 @@ int UtcDaliWebViewPolicyDecisionRequest(void)
   END_TEST;
 }
 
+int UtcDaliWebViewHitTest(void)
+{
+  ToolkitTestApplication application;
+
+  WebView view = WebView::New();
+  DALI_TEST_CHECK( view );
+
+  // load url.
+  view.LoadUrl( TEST_URL1 );
+
+  // sync hit test.
+  std::unique_ptr<Dali::WebEngineHitTest> hitTest = view.CreateHitTest(100, 100, Dali::WebEngineHitTest::HitTestMode::DEFAULT);
+  DALI_TEST_CHECK(hitTest != 0);
+  DALI_TEST_EQUALS(hitTest->GetResultContext(), Dali::WebEngineHitTest::ResultContext::DOCUMENT, TEST_LOCATION);
+  std::string testLinkUri("http://test.html");
+  DALI_TEST_EQUALS(hitTest->GetLinkUri(), testLinkUri, TEST_LOCATION);
+  std::string testLinkTitle("test");
+  DALI_TEST_EQUALS(hitTest->GetLinkTitle(), testLinkTitle, TEST_LOCATION);
+  std::string testLinkLabel("label");
+  DALI_TEST_EQUALS(hitTest->GetLinkLabel(), testLinkLabel, TEST_LOCATION);
+  std::string testImageUri("http://test.jpg");
+  DALI_TEST_EQUALS(hitTest->GetImageUri(), testImageUri, TEST_LOCATION);
+  std::string testMediaUri("http://test.mp4");
+  DALI_TEST_EQUALS(hitTest->GetMediaUri(), testMediaUri, TEST_LOCATION);
+  std::string testTagName("img");
+  DALI_TEST_EQUALS(hitTest->GetTagName(), testTagName, TEST_LOCATION);
+  std::string testNodeValue("test");
+  DALI_TEST_EQUALS(hitTest->GetNodeValue(), testNodeValue, TEST_LOCATION);
+  Dali::Property::Map* testMap = &hitTest->GetAttributes();
+  DALI_TEST_CHECK(testMap);
+  std::string testImageFileNameExtension("jpg");
+  DALI_TEST_EQUALS(hitTest->GetImageFileNameExtension(), testImageFileNameExtension, TEST_LOCATION);
+  Dali::PixelData testImageBuffer = hitTest->GetImageBuffer();
+  DALI_TEST_CHECK((int)testImageBuffer.GetWidth() == 2 && (int)testImageBuffer.GetHeight() == 2);
+
+  // async...
+  bool result = view.CreateHitTestAsynchronously(100, 100, Dali::WebEngineHitTest::HitTestMode::DEFAULT, &OnHitTestCreated);
+  DALI_TEST_CHECK(result);
+  Test::EmitGlobalTimerSignal();
+  DALI_TEST_EQUALS( gHitTestCreatedCallbackCalled, 1, TEST_LOCATION );
+
+  END_TEST;
+}
+
 int UtcDaliWebViewEvaluteJavaScript(void)
 {
   ToolkitTestApplication application;
@@ -1476,9 +1533,15 @@ int UtcDaliWebBackForwardListCheckItem(void)
   unsigned int itemCount = bfList->GetItemCount();
   DALI_TEST_CHECK( itemCount == 1 )
 
-  Dali::Toolkit::WebBackForwardListItem* citem = bfList->GetCurrentItem();
+  std::unique_ptr<Dali::WebEngineBackForwardListItem> citem = bfList->GetCurrentItem();
   DALI_TEST_CHECK( citem != 0 );
 
+  std::unique_ptr<Dali::WebEngineBackForwardListItem> citemP = bfList->GetPreviousItem();
+  DALI_TEST_CHECK( citemP != 0 );
+
+  std::unique_ptr<Dali::WebEngineBackForwardListItem> citemN = bfList->GetNextItem();
+  DALI_TEST_CHECK( citemN != 0 );
+
   const std::string kDefaultUrl( "http://url" );
   std::string testValue = citem->GetUrl();
   DALI_TEST_EQUALS( testValue, kDefaultUrl, TEST_LOCATION );
@@ -1491,9 +1554,15 @@ int UtcDaliWebBackForwardListCheckItem(void)
   testValue = citem->GetOriginalUrl();
   DALI_TEST_EQUALS( testValue, kDefaultOriginalUrl, TEST_LOCATION );
 
-  Dali::Toolkit::WebBackForwardListItem* item = bfList->GetItemAtIndex( 0 );
+  std::unique_ptr<Dali::WebEngineBackForwardListItem> item = bfList->GetItemAtIndex( 0 );
   DALI_TEST_CHECK( item != 0 );
 
+  std::vector<std::unique_ptr<Dali::WebEngineBackForwardListItem>> vecBack = bfList->GetBackwardItems(-1);
+  DALI_TEST_CHECK( vecBack.size() == 1 );
+
+  std::vector<std::unique_ptr<Dali::WebEngineBackForwardListItem>> vecForward = bfList->GetForwardItems(-1);
+  DALI_TEST_CHECK( vecForward.size() == 1 );
+
   END_TEST;
 }
 
@@ -1633,6 +1702,23 @@ int UtcDaliWebCookieManagerGetSetCookieAcceptPolicy(void)
   END_TEST;
 }
 
+int UtcDaliWebCookieManagerChangesWatch(void)
+{
+  ToolkitTestApplication application;
+
+  WebView view = WebView::New();
+  DALI_TEST_CHECK( view );
+
+  Dali::Toolkit::WebCookieManager* cookieManager = view.GetCookieManager();
+  DALI_TEST_CHECK( cookieManager != 0 )
+
+  cookieManager->ChangesWatch(&OnChangesWatch);
+  Test::EmitGlobalTimerSignal();
+  DALI_TEST_EQUALS( gCookieManagerChangsWatchCallbackCalled, 1, TEST_LOCATION );
+
+  END_TEST;
+}
+
 // test cases for web settings.
 
 int UtcDaliWebSettingsGetSetDefaultFontSize(void)
@@ -2144,3 +2230,78 @@ int UtcDaliWebSettingsGetSetDefaultTextEncodingName(void)
   END_TEST;
 }
 
+int UtcDaliWebSettingsSetViewportMetaTag(void)
+{
+  ToolkitTestApplication application;
+
+  WebView view = WebView::New();
+  DALI_TEST_CHECK( view );
+
+  Dali::Toolkit::WebSettings* settings = view.GetSettings();
+  DALI_TEST_CHECK( settings != 0 )
+
+  // Check the value is true or not
+  bool value = settings->SetViewportMetaTag(true);
+  DALI_TEST_CHECK( value );
+
+  END_TEST;
+}
+
+int UtcDaliWebSettingsSetForceZoom(void)
+{
+  ToolkitTestApplication application;
+
+  WebView view = WebView::New();
+  DALI_TEST_CHECK( view );
+
+  Dali::Toolkit::WebSettings* settings = view.GetSettings();
+  DALI_TEST_CHECK( settings != 0 )
+
+  // Check the value is true or not
+  bool value = settings->SetForceZoom(true);
+  DALI_TEST_CHECK( value );
+
+  value = settings->IsZoomForced();
+  DALI_TEST_CHECK( value );
+
+  END_TEST;
+}
+
+int UtcDaliWebSettingsSetTextZoomEnabled(void)
+{
+  ToolkitTestApplication application;
+
+  WebView view = WebView::New();
+  DALI_TEST_CHECK( view );
+
+  Dali::Toolkit::WebSettings* settings = view.GetSettings();
+  DALI_TEST_CHECK( settings != 0 )
+
+  // Check the value is true or not
+  bool value = settings->SetTextZoomEnabled(true);
+  DALI_TEST_CHECK( value );
+
+  value = settings->IsTextZoomEnabled();
+  DALI_TEST_CHECK( value );
+
+  END_TEST;
+}
+
+int UtcDaliWebSettingsSetExtraFeature(void)
+{
+  ToolkitTestApplication application;
+
+  WebView view = WebView::New();
+  DALI_TEST_CHECK( view );
+
+  Dali::Toolkit::WebSettings* settings = view.GetSettings();
+  DALI_TEST_CHECK( settings != 0 )
+
+  // Check the value is true or not
+  settings->SetExtraFeature("test", true);
+  bool value = settings->IsExtraFeatureEnabled("test");
+  DALI_TEST_CHECK( value );
+
+  END_TEST;
+}
+