X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-WebView.cpp;h=36258d4a1297a553abddcd2132ab4bc9ccfc8b0d;hp=0d254aba2e406ec16b24a854c7255a35dff2e403;hb=420f036b7f7ca779aae2b12b066241e0a12f3144;hpb=f4e0f2637386a36e21c7af1e0dd5e824e1ead1cc diff --git a/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp index 0d254ab..36258d4 100755 --- a/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp @@ -24,7 +24,11 @@ #include #include #include +#include +#include +#include #include +#include #include #include #include @@ -39,10 +43,8 @@ #include #include #include -#include #include #include -#include #include #include @@ -73,14 +75,14 @@ static bool gTouched = false; static bool gHovered = false; static bool gWheelEventHandled = false; static int gFormRepostDecisionCallbackCalled = 0; -static std::shared_ptr gFormRepostDecisionInstance = nullptr; +static std::shared_ptr gFormRepostDecisionInstance = nullptr; static int gFrameRenderedCallbackCalled = 0; static int gRequestInterceptorCallbackCalled = 0; static std::shared_ptr gRequestInterceptorInstance = nullptr; static int gConsoleMessageCallbackCalled = 0; static std::shared_ptr gConsoleMessageInstance = nullptr; -static int gPolicyDecisionCallbackCalled = 0; -static std::shared_ptr gPolicyDecisionInstance = nullptr; +static int gResponsePolicyDecidedCallbackCalled = 0; +static std::shared_ptr gResponsePolicyDecisionInstance = nullptr; static int gCertificateConfirmCallbackCalled = 0; static std::shared_ptr gCertificateConfirmInstance = nullptr; static int gSslCertificateChangedCallbackCalled = 0; @@ -94,6 +96,12 @@ static int gDownloadStartedCallbackCalled = 0; static int gMimeOverriddenCallbackCalled = 0; static std::vector> gSecurityOriginList; static std::vector> gPasswordDataList; +static int gContextMenuShownCallbackCalled = 0; +static std::shared_ptr gContextMenuShownInstance = nullptr; +static int gContextMenuHiddenCallbackCalled = 0; +static std::shared_ptr gContextMenuHiddenInstance = nullptr; +static int gHitTestCreatedCallbackCalled = 0; +static int gCookieManagerChangsWatchCallbackCalled = 0; struct CallbackFunctor { @@ -129,10 +137,10 @@ static void OnScrollEdgeReached( WebView view, Dali::WebEnginePlugin::ScrollEdge gScrollEdgeReachedCallbackCalled++; } -static void OnPolicyDecisionRequest(WebView view, std::shared_ptr decision) +static void OnResponsePolicyDecided(WebView view, std::shared_ptr decision) { - gPolicyDecisionCallbackCalled++; - gPolicyDecisionInstance = std::move(decision); + gResponsePolicyDecidedCallbackCalled++; + gResponsePolicyDecisionInstance = std::move(decision); } static void OnUrlChanged( WebView view, const std::string& url ) @@ -140,6 +148,12 @@ static void OnUrlChanged( WebView view, const std::string& url ) gUrlChangedCallbackCalled++; } +static bool OnHitTestCreated(std::unique_ptr test) +{ + gHitTestCreatedCallbackCalled++; + return true; +} + static void OnPageLoadError(WebView view, std::shared_ptr error) { gPageLoadErrorCallbackCalled++; @@ -191,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; @@ -203,7 +222,7 @@ static bool OnWheelEvent( Actor actor, const Dali::WheelEvent& wheel ) return true; } -static void OnFormRepostDecision(WebView, std::shared_ptr decision) +static void OnFormRepostDecision(WebView, std::shared_ptr decision) { gFormRepostDecisionCallbackCalled++; gFormRepostDecisionInstance = std::move(decision); @@ -274,6 +293,18 @@ static bool OnMimeOverridden(const std::string&, const std::string&, std::string return false; } +static void OnContextMenuShown(WebView view, std::shared_ptr menu) +{ + gContextMenuShownCallbackCalled++; + gContextMenuShownInstance = std::move(menu); +} + +static void OnContextMenuHidden(WebView view, std::shared_ptr menu) +{ + gContextMenuHiddenCallbackCalled++; + gContextMenuHiddenInstance = std::move(menu); +} + } // namespace void web_view_startup(void) @@ -1028,12 +1059,76 @@ int UtcDaliWebViewPropertyTitleFavicon(void) view.GetProperty( WebView::Property::TITLE ).Get( output ); DALI_TEST_EQUALS( output, testValue, TEST_LOCATION ); - // Check default value of favicon - Dali::Toolkit::ImageView* favicon = &view.GetFavicon(); + // Check the case that favicon is not null. + Dali::Toolkit::ImageView favicon = view.GetFavicon(); DALI_TEST_CHECK( favicon ); - Dali::Vector3 iconsize = favicon->GetProperty< Vector3 >( Dali::Actor::Property::SIZE ); + Dali::Vector3 iconsize = favicon.GetProperty< Vector3 >( Dali::Actor::Property::SIZE ); DALI_TEST_CHECK( ( int )iconsize.width == 2 && ( int )iconsize.height == 2 ); + // Check the case that favicon is null. + favicon = view.GetFavicon(); + DALI_TEST_CHECK( !favicon ); + + END_TEST; +} + +int UtcDaliWebViewContextMenuShownAndHidden(void) +{ + ToolkitTestApplication application; + + WebView view = WebView::New(); + DALI_TEST_CHECK( view ); + + // load url. + ConnectionTracker* testTracker = new ConnectionTracker(); + view.ContextMenuShownSignal().Connect( &OnContextMenuShown ); + view.ContextMenuHiddenSignal().Connect( &OnContextMenuHidden ); + bool signal1 = false; + bool signal2 = false; + view.ConnectSignal( testTracker, "contextMenuShown", CallbackFunctor(&signal1) ); + view.ConnectSignal( testTracker, "contextMenuHidden", CallbackFunctor(&signal2) ); + DALI_TEST_EQUALS( gContextMenuShownCallbackCalled, 0, TEST_LOCATION ); + DALI_TEST_EQUALS( gContextMenuHiddenCallbackCalled, 0, TEST_LOCATION ); + DALI_TEST_CHECK(gContextMenuShownInstance == 0); + DALI_TEST_CHECK(gContextMenuHiddenInstance == 0); + + view.LoadUrl( TEST_URL1 ); + Test::EmitGlobalTimerSignal(); + DALI_TEST_EQUALS( gContextMenuShownCallbackCalled, 1, TEST_LOCATION ); + DALI_TEST_EQUALS( gContextMenuHiddenCallbackCalled, 1, TEST_LOCATION ); + DALI_TEST_CHECK( signal1 ); + DALI_TEST_CHECK( signal2 ); + + // check context meun & its items. + DALI_TEST_CHECK(gContextMenuShownInstance != 0); + std::unique_ptr item = gContextMenuShownInstance->GetItemAt(0); + DALI_TEST_CHECK(item.get() != 0); + std::vector> itemList = gContextMenuShownInstance->GetItemList(); + DALI_TEST_CHECK(itemList.size() == 1); + DALI_TEST_CHECK(gContextMenuShownInstance->RemoveItem(*(item.get()))); + DALI_TEST_CHECK(gContextMenuShownInstance->AppendItemAsAction(WebEngineContextMenuItem::ItemTag::NO_ACTION, "", false)); + DALI_TEST_CHECK(gContextMenuShownInstance->AppendItem(WebEngineContextMenuItem::ItemTag::NO_ACTION, "", "", false)); + DALI_TEST_CHECK(gContextMenuShownInstance->SelectItem(*(item.get()))); + DALI_TEST_CHECK(gContextMenuShownInstance->Hide()); + + Dali::WebEngineContextMenuItem::ItemTag testItemTag = Dali::WebEngineContextMenuItem::ItemTag::NO_ACTION; + DALI_TEST_EQUALS(item->GetTag(), testItemTag, TEST_LOCATION); + Dali::WebEngineContextMenuItem::ItemType testItemType = Dali::WebEngineContextMenuItem::ItemType::ACTION; + DALI_TEST_EQUALS(item->GetType(), testItemType, TEST_LOCATION); + DALI_TEST_CHECK(item->IsEnabled()); + std::string testLinkUrl("http://test.html"); + DALI_TEST_EQUALS(item->GetLinkUrl(), testLinkUrl, TEST_LOCATION); + std::string testImageUrl("http://test.jpg"); + DALI_TEST_EQUALS(item->GetImageUrl(), testImageUrl, TEST_LOCATION); + std::string testTitle("title"); + DALI_TEST_EQUALS(item->GetTitle(), testTitle, TEST_LOCATION); + DALI_TEST_CHECK(item->GetParentMenu().get() == 0); + + DALI_TEST_CHECK(gContextMenuHiddenInstance != 0); + + gContextMenuShownInstance = nullptr; + gContextMenuHiddenInstance = nullptr; + END_TEST; } @@ -1208,7 +1303,7 @@ int UtcDaliWebViewHttpRequestInterceptor(void) END_TEST; } -int UtcDaliWebViewPolicyDecisionRequest(void) +int UtcDaliWebViewResponsePolicyDecisionRequest(void) { ToolkitTestApplication application; @@ -1217,42 +1312,86 @@ int UtcDaliWebViewPolicyDecisionRequest(void) // load url. ConnectionTracker* testTracker = new ConnectionTracker(); - view.PolicyDecisionSignal().Connect( &OnPolicyDecisionRequest ); + view.ResponsePolicyDecisionSignal().Connect( &OnResponsePolicyDecided ); bool signal1 = false; - view.ConnectSignal( testTracker, "policyDecision", CallbackFunctor(&signal1) ); - DALI_TEST_EQUALS( gPolicyDecisionCallbackCalled, 0, TEST_LOCATION ); - DALI_TEST_CHECK(gPolicyDecisionInstance == 0); + view.ConnectSignal( testTracker, "responsePolicyDecided", CallbackFunctor(&signal1) ); + DALI_TEST_EQUALS( gResponsePolicyDecidedCallbackCalled, 0, TEST_LOCATION ); + DALI_TEST_CHECK(gResponsePolicyDecisionInstance == 0); view.LoadUrl( TEST_URL1 ); Test::EmitGlobalTimerSignal(); - DALI_TEST_EQUALS( gPolicyDecisionCallbackCalled, 1, TEST_LOCATION ); + DALI_TEST_EQUALS( gResponsePolicyDecidedCallbackCalled, 1, TEST_LOCATION ); DALI_TEST_CHECK( signal1 ); - // check policy decision & its frame. - DALI_TEST_CHECK(gPolicyDecisionInstance != 0); + // check response policy decision & its frame. + DALI_TEST_CHECK(gResponsePolicyDecisionInstance != 0); std::string testUrl("http://test.html"); - DALI_TEST_EQUALS(gPolicyDecisionInstance->GetUrl(), testUrl, TEST_LOCATION); + DALI_TEST_EQUALS(gResponsePolicyDecisionInstance->GetUrl(), testUrl, TEST_LOCATION); std::string testCookie("test:abc"); - DALI_TEST_EQUALS(gPolicyDecisionInstance->GetCookie(), testCookie, TEST_LOCATION); + DALI_TEST_EQUALS(gResponsePolicyDecisionInstance->GetCookie(), testCookie, TEST_LOCATION); Dali::WebEnginePolicyDecision::DecisionType testDecisionType = Dali::WebEnginePolicyDecision::DecisionType::USE; - DALI_TEST_EQUALS(gPolicyDecisionInstance->GetDecisionType(), testDecisionType, TEST_LOCATION); + DALI_TEST_EQUALS(gResponsePolicyDecisionInstance->GetDecisionType(), testDecisionType, TEST_LOCATION); std::string testResponseMime("txt/xml"); - DALI_TEST_EQUALS(gPolicyDecisionInstance->GetResponseMime(), testResponseMime, TEST_LOCATION); + DALI_TEST_EQUALS(gResponsePolicyDecisionInstance->GetResponseMime(), testResponseMime, TEST_LOCATION); int32_t ResponseStatusCode = 500; - DALI_TEST_EQUALS(gPolicyDecisionInstance->GetResponseStatusCode(), ResponseStatusCode, TEST_LOCATION); + DALI_TEST_EQUALS(gResponsePolicyDecisionInstance->GetResponseStatusCode(), ResponseStatusCode, TEST_LOCATION); Dali::WebEnginePolicyDecision::NavigationType testNavigationType = Dali::WebEnginePolicyDecision::NavigationType::LINK_CLICKED; - DALI_TEST_EQUALS(gPolicyDecisionInstance->GetNavigationType(), testNavigationType, TEST_LOCATION); + DALI_TEST_EQUALS(gResponsePolicyDecisionInstance->GetNavigationType(), testNavigationType, TEST_LOCATION); std::string testScheme("test"); - DALI_TEST_EQUALS(gPolicyDecisionInstance->GetScheme(), testScheme, TEST_LOCATION); - DALI_TEST_CHECK(gPolicyDecisionInstance->Use()); - DALI_TEST_CHECK(gPolicyDecisionInstance->Ignore()); - DALI_TEST_CHECK(gPolicyDecisionInstance->Suspend()); + DALI_TEST_EQUALS(gResponsePolicyDecisionInstance->GetScheme(), testScheme, TEST_LOCATION); + DALI_TEST_CHECK(gResponsePolicyDecisionInstance->Use()); + DALI_TEST_CHECK(gResponsePolicyDecisionInstance->Ignore()); + DALI_TEST_CHECK(gResponsePolicyDecisionInstance->Suspend()); - Dali::WebEngineFrame* webFrame = &(gPolicyDecisionInstance->GetFrame()); + Dali::WebEngineFrame* webFrame = &(gResponsePolicyDecisionInstance->GetFrame()); DALI_TEST_CHECK(webFrame); DALI_TEST_CHECK(webFrame->IsMainFrame()); - gPolicyDecisionInstance = nullptr; + gResponsePolicyDecisionInstance = nullptr; + + 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 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; } @@ -1397,9 +1536,15 @@ int UtcDaliWebBackForwardListCheckItem(void) unsigned int itemCount = bfList->GetItemCount(); DALI_TEST_CHECK( itemCount == 1 ) - Dali::Toolkit::WebBackForwardListItem* citem = bfList->GetCurrentItem(); + std::unique_ptr citem = bfList->GetCurrentItem(); DALI_TEST_CHECK( citem != 0 ); + std::unique_ptr citemP = bfList->GetPreviousItem(); + DALI_TEST_CHECK( citemP != 0 ); + + std::unique_ptr 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 ); @@ -1412,9 +1557,15 @@ int UtcDaliWebBackForwardListCheckItem(void) testValue = citem->GetOriginalUrl(); DALI_TEST_EQUALS( testValue, kDefaultOriginalUrl, TEST_LOCATION ); - Dali::Toolkit::WebBackForwardListItem* item = bfList->GetItemAtIndex( 0 ); + std::unique_ptr item = bfList->GetItemAtIndex( 0 ); DALI_TEST_CHECK( item != 0 ); + std::vector> vecBack = bfList->GetBackwardItems(-1); + DALI_TEST_CHECK( vecBack.size() == 1 ); + + std::vector> vecForward = bfList->GetForwardItems(-1); + DALI_TEST_CHECK( vecForward.size() == 1 ); + END_TEST; } @@ -1433,14 +1584,17 @@ int UtcDaliWebContextGetSetCacheModel(void) std::string kDefaultValue; // Reset something - context->SetProxyUri( kDefaultValue ); - context->SetCertificateFilePath( kDefaultValue ); - context->DisableCache( false ); + context->SetAppId( "id" ); + context->SetApplicationType( Dali::WebEngineContext::ApplicationType::OTHER ); + context->SetTimeOffset( 0 ); + context->SetTimeZoneOffset( 0, 0 ); context->SetDefaultProxyAuth( kDefaultValue, kDefaultValue ); context->DeleteAllWebDatabase(); context->DeleteAllWebStorage(); context->DeleteLocalFileSystem(); context->ClearCache(); + context->DeleteAllFormPasswordData(); + context->DeleteAllFormCandidateData(); // Check default value Dali::WebEngineContext::CacheModel value = context->GetCacheModel(); @@ -1451,6 +1605,41 @@ int UtcDaliWebContextGetSetCacheModel(void) value = context->GetCacheModel(); DALI_TEST_CHECK( value == Dali::WebEngineContext::CacheModel::DOCUMENT_BROWSER ); + // Get cache enabled + context->EnableCache( true ); + DALI_TEST_CHECK( context->IsCacheEnabled() ); + + // Get certificate + context->SetCertificateFilePath( "test" ); + std::string str = context->GetCertificateFilePath(); + DALI_TEST_EQUALS( str, "test", TEST_LOCATION ); + + // Set version + DALI_TEST_CHECK( context->SetAppVersion( "test" ) ); + + // Register + std::vector temp; + context->RegisterUrlSchemesAsCorsEnabled( temp ); + context->RegisterJsPluginMimeTypes( temp ); + context->DeleteFormPasswordDataList( temp ); + + // Get zoom factor + context->SetDefaultZoomFactor( 1.0f ); + DALI_TEST_EQUALS( context->GetDefaultZoomFactor(), float( 1.0f ), TEST_LOCATION ); + + // Delete cache and database + DALI_TEST_CHECK( context->DeleteAllApplicationCache() ); + DALI_TEST_CHECK( context->DeleteAllWebIndexedDatabase() ); + + // Get contextProxy + context->SetProxyUri( "test" ); + DALI_TEST_EQUALS( context->GetProxyUri(), "test", TEST_LOCATION ); + context->SetProxyBypassRule("", "test"); + DALI_TEST_EQUALS( context->GetProxyBypassRule(), "test", TEST_LOCATION ); + + //Notify low memory + DALI_TEST_CHECK( context->FreeUnusedMemory() ); + END_TEST; } @@ -1496,7 +1685,7 @@ int UtcDaliWebContextGetWebDatabaseStorageOrigins(void) Test::EmitGlobalTimerSignal(); DALI_TEST_EQUALS( gStorageUsageAcquiredCallbackCalled, 1, TEST_LOCATION ); - result = context->DeleteWebStorageOrigin(*origin); + result = context->DeleteWebStorage(*origin); DALI_TEST_CHECK( result ); result = context->DeleteApplicationCache(*origin); @@ -1554,6 +1743,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) @@ -2065,3 +2271,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; +} +