[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-WebView.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 30693fc..2ede899
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
@@ -29,9 +29,9 @@
 #include <dali.h>
 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-certificate.h>
 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-console-message.h>
-#include <dali/devel-api/adaptor-framework/web-engine/web-engine-context.h>
 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-context-menu-item.h>
 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-context-menu.h>
+#include <dali/devel-api/adaptor-framework/web-engine/web-engine-context.h>
 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-cookie-manager.h>
 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-form-repost-decision.h>
 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-frame.h>
@@ -79,6 +79,7 @@ static int                                                                gConso
 static std::unique_ptr<Dali::WebEngineConsoleMessage>                     gConsoleMessageInstance                = nullptr;
 static int                                                                gResponsePolicyDecidedCallbackCalled   = 0;
 static int                                                                gNavigationPolicyDecidedCallbackCalled = 0;
+static int                                                                gNewWindowCreatedCallbackCalled        = 0;
 static std::unique_ptr<Dali::WebEnginePolicyDecision>                     gResponsePolicyDecisionInstance        = nullptr;
 static int                                                                gCertificateConfirmCallbackCalled      = 0;
 static std::unique_ptr<Dali::WebEngineCertificate>                        gCertificateConfirmInstance            = nullptr;
@@ -148,6 +149,13 @@ static void OnNavigationPolicyDecided(std::unique_ptr<Dali::WebEnginePolicyDecis
   gNavigationPolicyDecidedCallbackCalled++;
 }
 
+static void OnNewWindowCreated(Dali::WebEnginePlugin*& outPlugin)
+{
+  gNewWindowCreatedCallbackCalled++;
+  WebView newView = WebView::New();
+  outPlugin       = newView.GetPlugin();
+}
+
 static void OnUrlChanged(const std::string& url)
 {
   gUrlChangedCallbackCalled++;
@@ -890,7 +898,7 @@ int UtcDaliWebViewGetWebContext(void)
   ToolkitTestApplication application;
 
   Dali::WebEngineContext* context = WebView::GetContext();
-  DALI_TEST_CHECK(context != 0);
+  DALI_TEST_CHECK(context != nullptr);
 
   END_TEST;
 }
@@ -1293,6 +1301,24 @@ int UtcDaliWebViewNavigationPolicyDecisionRequest(void)
   END_TEST;
 }
 
+int UtcDaliWebViewNewWindowCreated(void)
+{
+  ToolkitTestApplication application;
+
+  WebView view = WebView::New();
+  DALI_TEST_CHECK(view);
+
+  // load url.
+  view.RegisterNewWindowCreatedCallback(&OnNewWindowCreated);
+  DALI_TEST_EQUALS(gNewWindowCreatedCallbackCalled, 0, TEST_LOCATION);
+
+  view.LoadUrl(TEST_URL1);
+  Test::EmitGlobalTimerSignal();
+  DALI_TEST_EQUALS(gNewWindowCreatedCallbackCalled, 1, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliWebViewHitTest(void)
 {
   ToolkitTestApplication application;
@@ -1397,7 +1423,7 @@ int UtcDaliWebViewLoadHtmlStringOverrideCurrentEntryAndContents(void)
   application.Render();
   Test::EmitGlobalTimerSignal();
 
-  result = view.LoadContents(html, html.length(), "html/text", "utf-8", basicUri);
+  result = view.LoadContents((const int8_t*)html.c_str(), html.length(), "html/text", "utf-8", basicUri);
   DALI_TEST_CHECK(result);
 
   END_TEST;
@@ -1655,6 +1681,12 @@ int UtcDaliWebContextHttpRequestInterceptor(void)
   Dali::WebEngineContext* context = WebView::GetContext();
   DALI_TEST_CHECK(context != 0)
 
+  WebView view = WebView::New();
+  DALI_TEST_CHECK(view);
+
+  // Check if web view is found or not when plugin is null.
+  DALI_TEST_CHECK(!WebView::FindWebView(nullptr));
+
   // load url.
   context->RegisterRequestInterceptedCallback(&OnRequestIntercepted);
   DALI_TEST_EQUALS(gRequestInterceptedCallbackCalled, 0, TEST_LOCATION);
@@ -1674,6 +1706,11 @@ int UtcDaliWebContextHttpRequestInterceptor(void)
   DALI_TEST_CHECK(gRequestInterceptorInstance->AddResponseBody((const int8_t*)"test", 4));
   DALI_TEST_CHECK(gRequestInterceptorInstance->AddResponse("key:value", (const int8_t*)"test", 4));
   DALI_TEST_CHECK(gRequestInterceptorInstance->WriteResponseChunk((const int8_t*)"test", 4));
+
+  DALI_TEST_CHECK(gRequestInterceptorInstance->GetWebEngine());
+  // Check if web view is found or not when plugin is not null.
+  DALI_TEST_CHECK(WebView::FindWebView(gRequestInterceptorInstance->GetWebEngine()));
+
   std::string testUrl("http://test.html");
   DALI_TEST_EQUALS(gRequestInterceptorInstance->GetUrl(), testUrl, TEST_LOCATION);
   std::string testMethod("GET");
@@ -1681,6 +1718,8 @@ int UtcDaliWebContextHttpRequestInterceptor(void)
   Dali::Property::Map resultHeaders = gRequestInterceptorInstance->GetHeaders();
   DALI_TEST_EQUALS(resultHeaders.Count(), 2, TEST_LOCATION);
 
+  // Destroy web view.
+  view.Reset();
   gRequestInterceptorInstance = nullptr;
 
   END_TEST;
@@ -2328,3 +2367,50 @@ int UtcDaliWebViewGetPlainText(void)
 
   END_TEST;
 }
+
+int UtcDaliWebViewVisibilityChange(void)
+{
+  ToolkitTestApplication application;
+
+  WebView view  = WebView::New();
+  Control dummy = Control::New();
+  DALI_TEST_CHECK(view);
+  DALI_TEST_CHECK(dummy);
+
+  view.LoadUrl(TEST_URL1);
+
+  dummy.Add(view);
+  auto window = application.GetWindow();
+  window.Add(dummy);
+
+  application.SendNotification();
+  application.Render();
+
+  try
+  {
+    // TODO : There is no way to check visiblity setting result from web engine.
+    // Just call API and exception check.
+    view.SetProperty(Actor::Property::VISIBLE, false);
+    view.SetProperty(Actor::Property::VISIBLE, true);
+    dummy.SetProperty(Actor::Property::VISIBLE, false);
+    dummy.SetProperty(Actor::Property::VISIBLE, true);
+    dummy.Unparent();
+    window.Hide();
+    window.Add(dummy);
+    window.Show();
+    window.Hide();
+    window.Show();
+    dummy.SetProperty(Actor::Property::VISIBLE, false);
+    view.SetProperty(Actor::Property::VISIBLE, false);
+    dummy.SetProperty(Actor::Property::VISIBLE, true);
+    view.SetProperty(Actor::Property::VISIBLE, true);
+    tet_result(TET_PASS);
+  }
+  catch(...)
+  {
+    // Should not throw exception
+    tet_result(TET_FAIL);
+  }
+
+  END_TEST;
+}
\ No newline at end of file