X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Fdali-toolkit-test-utils%2Ftoolkit-web-engine.cpp;h=f400f7530587e5b22bf019b8227595b62b2d525d;hp=01b5ae5a3d6bc309a043d91e1cdddf9b96ccb0c4;hb=03d087167ceac9acf09a9cb7eb86bc06c0a5d4e7;hpb=f1876c34a8f667f79182fa8a772ee889e27290c1 diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-web-engine.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-web-engine.cpp index 01b5ae5..f400f75 100755 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-web-engine.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-web-engine.cpp @@ -20,13 +20,19 @@ #include #include #include +#include #include #include +#include +#include +#include #include #include #include #include #include +#include +#include #include namespace Dali @@ -56,6 +62,9 @@ bool OnJavaScriptAlert(); bool OnJavaScriptConfirm(); bool OnJavaScriptPrompt(); bool OnScrollEdge(); +bool OnScreenshotCaptured(); +bool OnVideoPlaying(); +bool OnGeolocationPermission(); bool OnClearHistory(); static void ConnectToGlobalSignal( bool ( *func )() ) @@ -189,7 +198,7 @@ private: class MockWebEngineBackForwardList : public Dali::WebEngineBackForwardList { public: - MockWebEngineBackForwardList( ) + MockWebEngineBackForwardList() : mockItem(), pMockItem( &mockItem ) { @@ -215,6 +224,109 @@ private: WebEngineBackForwardListItem* pMockItem; }; +class MockWebEngineFormRepostDecision : public WebEngineFormRepostDecision +{ +public: + MockWebEngineFormRepostDecision() + { + } + + void Reply(bool allowed) override {} +}; + +class MockWebEngineRequestInterceptor : public WebEngineRequestInterceptor +{ +public: + MockWebEngineRequestInterceptor() + { + } + + std::string GetUrl() const override + { + return "http://test.html"; + } + + bool Ignore() override + { + return true; + } + + bool SetResponseStatus(int statusCode, const std::string &customedStatusText) override + { + return true; + } + + bool AddResponseHeader(const std::string &fieldName, const std::string &fieldValue) override + { + return true; + } + + bool AddResponseBody(const std::string &body, uint32_t length) override + { + return true; + } +}; + +class MockWebEngineConsoleMessage : public Dali::WebEngineConsoleMessage +{ +public: + MockWebEngineConsoleMessage() + { + } + + std::string GetSource() const override + { + return "source"; + } + + uint32_t GetLine() const override + { + return 10; + } + + SeverityLevel GetSeverityLevel() const override + { + return SeverityLevel::EMPTY; + } + + std::string GetText() const override + { + return "This is a text."; + } +}; + +class MockWebEngineLoadError : public Dali::WebEngineLoadError +{ +public: + MockWebEngineLoadError(const std::string& url) + : mockUrl(url) + { + } + + std::string GetUrl() const override + { + return mockUrl; + } + + ErrorCode GetCode() const override + { + return ErrorCode::UNKNOWN; + } + + std::string GetDescription() const override + { + return "This is an error."; + } + + ErrorType GetType() const override + { + return ErrorType::NONE; + } + +private: + std::string mockUrl; +}; + class MockWebEngineSettings : public WebEngineSettings { public: @@ -454,9 +566,6 @@ class WebEngine: public Dali::BaseObject public: using JavaScriptEvaluatedResultCallback = std::function; - using JavaScriptAlertCallback = std::function; - using JavaScriptConfirmCallback = std::function; - using JavaScriptPromptCallback = std::function; WebEngine() : mUrl() @@ -638,6 +747,16 @@ public: } } + bool ScrollEdgeBy( int dx, int dy ) + { + mScrollPosition += Dali::Vector2( dx, dy ); + if ( mScrollPosition.y + mScrollSize.height > mContentSize.height ) + { + ConnectToGlobalSignal( &OnScrollEdge ); + } + return true; + } + void SetScrollPosition( int x, int y ) { mScrollPosition.x = x; @@ -656,7 +775,81 @@ public: Dali::Vector2 GetContentSize() const { - return mContentSize; + return mContentSize; + } + + void SetPageZoomFactor(float zoomFactor) + { + mPageZoomFactor = zoomFactor; + } + + float GetPageZoomFactor() const + { + return mPageZoomFactor; + } + + void SetTextZoomFactor(float zoomFactor) + { + mTextZoomFactor = zoomFactor; + } + + float GetTextZoomFactor() const + { + return mTextZoomFactor; + } + + float GetLoadProgressPercentage() const + { + return 0.5f; + } + + void SetScaleFactor(float scaleFactor, Dali::Vector2 point) + { + mScaleFactor = scaleFactor; + } + + float GetScaleFactor() const + { + return mScaleFactor; + } + + Dali::PixelData GetScreenshot(Dali::Rect viewArea, float scaleFactor) + { + uint32_t bufferSize = viewArea.width * viewArea.height * 4 ; + uint8_t* pixel = new uint8_t[ bufferSize ]; + memset(pixel, 0xff, bufferSize); + return Dali::PixelData::New( pixel, bufferSize, viewArea.width, viewArea.height, + Dali::Pixel::Format::RGBA8888, + Dali::PixelData::ReleaseFunction::DELETE_ARRAY ); + } + + bool GetScreenshotAsynchronously(Dali::Rect viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback) + { + if ( callback ) + { + ConnectToGlobalSignal( &OnScreenshotCaptured ); + mScreenshotCapturedCallback = callback; + } + return true; + } + + bool CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback) + { + if ( callback ) + { + ConnectToGlobalSignal( &OnVideoPlaying ); + mVideoPlayingCallback = callback; + } + return true; + } + + void RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback) + { + if ( callback ) + { + ConnectToGlobalSignal( &OnGeolocationPermission ); + mGeolocationPermissionCallback = callback; + } } Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal() @@ -689,30 +882,62 @@ public: return mUrlChangedSignal; } - std::string mUrl; - std::vector< std::string > mHistory; - size_t mCurrentPlusOnePos; - std::string mUserAgent; - Dali::WebEnginePlugin::WebEnginePageLoadSignalType mPageLoadStartedSignal; - Dali::WebEnginePlugin::WebEnginePageLoadSignalType mPageLoadInProgressSignal; - Dali::WebEnginePlugin::WebEnginePageLoadSignalType mPageLoadFinishedSignal; - Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType mPageLoadErrorSignal; - std::vector mResultCallbacks; - bool mEvaluating; - - Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType mScrollEdgeReachedSignal; - Dali::Vector2 mScrollPosition; - Dali::Vector2 mScrollSize; - Dali::Vector2 mContentSize; - WebEngineBackForwardList* mockWebEngineBackForwardList; - WebEngineContext* mockWebEngineContext; - WebEngineCookieManager* mockWebEngineCookieManager; - WebEngineSettings* mockWebEngineSettings; - Dali::WebEnginePlugin::WebEngineUrlChangedSignalType mUrlChangedSignal; - - JavaScriptAlertCallback mJavaScriptAlertCallback; - JavaScriptConfirmCallback mJavaScriptConfirmCallback; - JavaScriptPromptCallback mJavaScriptPromptCallback; + Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType& FormRepostDecisionSignal() + { + return mFormRepostDecisionSignal; + } + + Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& FrameRenderedSignal() + { + return mFrameRenderedSignal; + } + + Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& RequestInterceptorSignal() + { + return mRequestInterceptorSignal; + } + + Dali::WebEnginePlugin::WebEngineConsoleMessageSignalType& ConsoleMessageSignal() + { + return mConsoleMessageSignal; + } + + std::string mUrl; + std::vector mHistory; + size_t mCurrentPlusOnePos; + std::string mUserAgent; + + Dali::WebEnginePlugin::WebEnginePageLoadSignalType mPageLoadStartedSignal; + Dali::WebEnginePlugin::WebEnginePageLoadSignalType mPageLoadInProgressSignal; + Dali::WebEnginePlugin::WebEnginePageLoadSignalType mPageLoadFinishedSignal; + Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType mPageLoadErrorSignal; + Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType mScrollEdgeReachedSignal; + Dali::WebEnginePlugin::WebEngineUrlChangedSignalType mUrlChangedSignal; + Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType mFormRepostDecisionSignal; + Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType mFrameRenderedSignal; + Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType mRequestInterceptorSignal; + Dali::WebEnginePlugin::WebEngineConsoleMessageSignalType mConsoleMessageSignal; + + bool mEvaluating; + float mPageZoomFactor; + float mTextZoomFactor; + float mScaleFactor; + + Dali::Vector2 mScrollPosition; + Dali::Vector2 mScrollSize; + Dali::Vector2 mContentSize; + WebEngineBackForwardList* mockWebEngineBackForwardList; + WebEngineContext* mockWebEngineContext; + WebEngineCookieManager* mockWebEngineCookieManager; + WebEngineSettings* mockWebEngineSettings; + + std::vector mResultCallbacks; + Dali::WebEnginePlugin::JavaScriptAlertCallback mJavaScriptAlertCallback; + Dali::WebEnginePlugin::JavaScriptConfirmCallback mJavaScriptConfirmCallback; + Dali::WebEnginePlugin::JavaScriptPromptCallback mJavaScriptPromptCallback; + Dali::WebEnginePlugin::ScreenshotCapturedCallback mScreenshotCapturedCallback; + Dali::WebEnginePlugin::VideoPlayingCallback mVideoPlayingCallback; + Dali::WebEnginePlugin::GeolocationPermissionCallback mGeolocationPermissionCallback; }; @@ -757,6 +982,17 @@ bool OnLoadUrl() gInstance->mPageLoadInProgressSignal.Emit( gInstance->mUrl ); gInstance->mPageLoadFinishedSignal.Emit( gInstance->mUrl ); gInstance->mUrlChangedSignal.Emit( "http://new-test" ); + + std::shared_ptr decision(new MockWebEngineFormRepostDecision()); + gInstance->mFormRepostDecisionSignal.Emit(std::move(decision)); + gInstance->mFrameRenderedSignal.Emit(); + std::shared_ptr interceptor(new MockWebEngineRequestInterceptor()); + gInstance->mRequestInterceptorSignal.Emit(std::move(interceptor)); + + std::shared_ptr error(new MockWebEngineLoadError(gInstance->mUrl)); + gInstance->mPageLoadErrorSignal.Emit(std::move(error)); + std::shared_ptr message(new MockWebEngineConsoleMessage()); + gInstance->mConsoleMessageSignal.Emit(std::move(message)); } return false; } @@ -818,6 +1054,41 @@ bool OnJavaScriptPrompt() return false; } +bool OnScreenshotCaptured() +{ + DisconnectFromGlobalSignal( &OnScreenshotCaptured ); + if ( gInstance ) + { + uint8_t* pixel = new uint8_t[ 2 * 2 * 4 ]; + memset(pixel, 0xff, 2 * 2 * 4); + Dali::PixelData data = Dali::PixelData::New( pixel, 2 * 2 * 4, 2, 2, + Dali::Pixel::Format::RGBA8888, + Dali::PixelData::ReleaseFunction::DELETE_ARRAY ); + gInstance->mScreenshotCapturedCallback( data ); + } + return false; +} + +bool OnVideoPlaying() +{ + DisconnectFromGlobalSignal( &OnVideoPlaying ); + if ( gInstance ) + { + gInstance->mVideoPlayingCallback( true ); + } + return false; +} + +bool OnGeolocationPermission() +{ + DisconnectFromGlobalSignal( &OnGeolocationPermission ); + if ( gInstance ) + { + gInstance->mGeolocationPermissionCallback( "", "" ); + } + return false; +} + bool OnClearHistory() { DisconnectFromGlobalSignal( &OnClearHistory ); @@ -952,10 +1223,25 @@ void WebEngine::LoadHtmlString( const std::string& htmlString ) { } +bool WebEngine::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl) +{ + return true; +} + +bool WebEngine::LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri) +{ + return true; +} + void WebEngine::Reload() { } +bool WebEngine::ReloadWithoutCache() +{ + return true; +} + void WebEngine::StopLoading() { } @@ -968,6 +1254,34 @@ void WebEngine::Resume() { } +void WebEngine::SuspendNetworkLoading() +{ +} + +void WebEngine::ResumeNetworkLoading() +{ +} + +bool WebEngine::AddCustomHeader(const std::string& name, const std::string& value) +{ + return true; +} + +bool WebEngine::RemoveCustomHeader(const std::string& name) +{ + return true; +} + +uint32_t WebEngine::StartInspectorServer(uint32_t port) +{ + return port; +} + +bool WebEngine::StopInspectorServer() +{ + return true; +} + bool WebEngine::CanGoForward() { return Internal::Adaptor::GetImplementation( *this ).CanGoForward(); @@ -1033,6 +1347,49 @@ void WebEngine::ClearHistory() Internal::Adaptor::GetImplementation( *this ).ClearHistory(); } +void WebEngine::SetScaleFactor(float scaleFactor, Dali::Vector2 point) +{ + Internal::Adaptor::GetImplementation( *this ).SetScaleFactor(scaleFactor, point); +} + +float WebEngine::GetScaleFactor() const +{ + return Internal::Adaptor::GetImplementation( *this ).GetScaleFactor(); +} + +void WebEngine::ActivateAccessibility(bool activated) +{ +} + +bool WebEngine::HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount) +{ + return true; +} + +void WebEngine::AddDynamicCertificatePath(const std::string& host, const std::string& certPath) +{ +} + +Dali::PixelData WebEngine::GetScreenshot(Dali::Rect viewArea, float scaleFactor) +{ + return Internal::Adaptor::GetImplementation( *this ).GetScreenshot(viewArea, scaleFactor); +} + +bool WebEngine::GetScreenshotAsynchronously(Dali::Rect viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback) +{ + return Internal::Adaptor::GetImplementation( *this ).GetScreenshotAsynchronously(viewArea, scaleFactor, callback); +} + +bool WebEngine::CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback) +{ + return Internal::Adaptor::GetImplementation( *this ).CheckVideoPlayingAsynchronously(callback); +} + +void WebEngine::RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback) +{ + Internal::Adaptor::GetImplementation( *this ).RegisterGeolocationPermissionCallback(callback); +} + const std::string& WebEngine::GetUserAgent() const { return Internal::Adaptor::GetImplementation( *this ).GetUserAgent(); @@ -1048,6 +1405,11 @@ void WebEngine::ScrollBy( int dx, int dy ) Internal::Adaptor::GetImplementation( *this ).ScrollBy( dx, dy ); } +bool WebEngine::ScrollEdgeBy( int dx, int dy ) +{ + return Internal::Adaptor::GetImplementation( *this ).ScrollEdgeBy( dx, dy ); +} + void WebEngine::SetScrollPosition( int x, int y ) { Internal::Adaptor::GetImplementation( *this ).SetScrollPosition( x, y ); @@ -1072,6 +1434,27 @@ void WebEngine::SetSize( int width, int height ) { } +void WebEngine::SetDocumentBackgroundColor(Dali::Vector4 color) +{ +} + +void WebEngine::ClearTilesWhenHidden(bool cleared) +{ +} + +void WebEngine::SetTileCoverAreaMultiplier(float multiplier) +{ +} + +void WebEngine::EnableCursorByClient(bool enabled) +{ +} + +std::string WebEngine::GetSelectedText() const +{ + return "test"; +} + bool WebEngine::SendTouchEvent( const TouchEvent& touch ) { return true; @@ -1082,10 +1465,45 @@ bool WebEngine::SendKeyEvent( const KeyEvent& event ) return true; } +bool WebEngine::SendHoverEvent( const HoverEvent& event ) +{ + return true; +} + +bool WebEngine::SendWheelEvent( const WheelEvent& event ) +{ + return true; +} + void WebEngine::SetFocus( bool focused ) { } +void WebEngine::SetPageZoomFactor(float zoomFactor) +{ + Internal::Adaptor::GetImplementation( *this ).SetPageZoomFactor(zoomFactor); +} + +float WebEngine::GetPageZoomFactor() const +{ + return Internal::Adaptor::GetImplementation( *this ).GetPageZoomFactor(); +} + +void WebEngine::SetTextZoomFactor(float zoomFactor) +{ + Internal::Adaptor::GetImplementation( *this ).SetTextZoomFactor(zoomFactor); +} + +float WebEngine::GetTextZoomFactor() const +{ + return Internal::Adaptor::GetImplementation( *this ).GetTextZoomFactor(); +} + +float WebEngine::GetLoadProgressPercentage() const +{ + return Internal::Adaptor::GetImplementation( *this ).GetLoadProgressPercentage(); +} + void WebEngine::UpdateDisplayArea( Dali::Rect< int > displayArea ) { } @@ -1094,6 +1512,14 @@ void WebEngine::EnableVideoHole( bool enabled ) { } +void WebEngine::EnableMouseEvents( bool enabled ) +{ +} + +void WebEngine::EnableKeyEvents( bool enabled ) +{ +} + Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadStartedSignal() { return Internal::Adaptor::GetImplementation( *this ).PageLoadStartedSignal(); @@ -1124,5 +1550,25 @@ Dali::WebEnginePlugin::WebEngineUrlChangedSignalType& WebEngine::UrlChangedSigna return Internal::Adaptor::GetImplementation( *this ).UrlChangedSignal(); } +Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType& WebEngine::FormRepostDecisionSignal() +{ + return Internal::Adaptor::GetImplementation( *this ).FormRepostDecisionSignal(); +} + +Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& WebEngine::FrameRenderedSignal() +{ + return Internal::Adaptor::GetImplementation(*this).FrameRenderedSignal(); +} + +Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& WebEngine::RequestInterceptorSignal() +{ + return Internal::Adaptor::GetImplementation(*this).RequestInterceptorSignal(); +} + +Dali::WebEnginePlugin::WebEngineConsoleMessageSignalType& WebEngine::ConsoleMessageSignal() +{ + return Internal::Adaptor::GetImplementation(*this).ConsoleMessageSignal(); +} + } // namespace Dali;