protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref CefDictionaryValue extraInfo, ref bool noJavascriptAccess) { if (_browser is not null) { _browser.InvokeAsyncIfPossible(() => _browser.OnBeforePopup(new BeforePopupEventArgs(frame, targetUrl, targetFrameName))); } if (_config is not null) { var isUrlExternal = _config.UrlSchemes?.IsUrlRegisteredExternalBrowserScheme(targetUrl); if (isUrlExternal.HasValue && isUrlExternal.Value) { BrowserLauncher.Open(_config.Platform, targetUrl); return(true); } } // Sample: http://chromely.com/democontroller/showdevtools // Expected to execute controller route action without return value var route = _routeProvider.GetRoute(targetUrl); if (route is not null && !route.HasReturnValue) { _requestHandler.Execute(targetUrl); return(true); } return(false); }
public void GetRouteTest() { foreach (var routePathItem in TodoController.GetRoutePaths) { Assert.NotNull(_routeProvider.GetRoute("http://chromely.com" + routePathItem.Value)); } }
public IChromelyResponse Execute(string requestId, string routePath, IDictionary <string, object>?parameters, object?postData, string?requestData) { if (string.IsNullOrWhiteSpace(routePath)) { return(_chromelyErrorHandler.HandleRouteNotFound(requestId, routePath)); } if (routePath.ToLower().Equals("/info")) { return(_chromelyInfo.GetInfo(requestId)); } var route = _routeProvider.GetRoute(routePath); if (route is null) { throw new Exception($"Route for path = {routePath} is null or invalid."); } return(ExecuteRoute(requestId, routePath, parameters, postData, requestData)); }
/// <inheritdoc/> protected override bool OnBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, bool userGesture, bool isRedirect) { if (_config is not null) { var isUrlExternal = _config.UrlSchemes?.IsUrlRegisteredExternalBrowserScheme(request.Url); if (isUrlExternal.HasValue && isUrlExternal.Value) { BrowserLauncher.Open(_config.Platform, request.Url); return(true); } } // Sample: http://chromely.com/democontroller/showdevtools // Expected to execute controller route action without return value var route = _routeProvider.GetRoute(request.Url); if (route is not null && !route.HasReturnValue) { _requestHandler.Execute(request.Url); return(true); } return(false); }
public void CreateUpdateGetDeleteTest() { var todoItem = TodoItem.FakeTodoItem; // Create dynamic postData = new ExpandoObject(); postData.todoItem = todoItem; var route = _routeProvider.GetRoute(TodoController.GetRoutePaths[TodoControllerRouteKeys.CreateItem]); Assert.NotNull(route); var createRequest = new ChromelyRequest { PostData = JsonSerializer.Serialize(postData) }; var createResponse = route?.Invoke(createRequest) as IChromelyResponse; var createData = createResponse is not null && createResponse.Data is int?(int)createResponse.Data : -1; Assert.NotNull(createResponse); Assert.True(createData > 0); // Update var newItemName = TodoItem.FakeTodoItemName; todoItem.Name = newItemName; postData = new ExpandoObject(); postData.id = todoItem.Id; postData.todoItem = todoItem; route = _routeProvider.GetRoute(TodoController.GetRoutePaths[TodoControllerRouteKeys.UpdateItem]); Assert.NotNull(route); var updateRequest = new ChromelyRequest { PostData = JsonSerializer.Serialize(postData) }; var updateResponse = route?.Invoke(updateRequest) as IChromelyResponse; var updateData = updateResponse is not null && updateResponse.Data is int?(int)updateResponse.Data : -1; Assert.NotNull(updateResponse); Assert.True(updateData > 0); // Get route = _routeProvider.GetRoute(TodoController.GetRoutePaths[TodoControllerRouteKeys.GetItem]); Assert.NotNull(route); var getRequest = new ChromelyRequest { RouteUrl = $"{TodoController.GetRoutePaths[TodoControllerRouteKeys.GetItem]}?id={todoItem.Id}" }; getRequest.Parameters = getRequest.RouteUrl.GetParameters(); var getResponse = route?.Invoke(getRequest) as IChromelyResponse; TodoItem?getData = getResponse?.Data as TodoItem; Assert.NotNull(getResponse); Assert.NotNull(getData); if (getData is not null) { Assert.Equal(todoItem.Id, getData.Id); Assert.Equal(todoItem.Name, getData.Name); Assert.Equal(todoItem.IsComplete, getData.IsComplete); } // Delete route = _routeProvider.GetRoute(TodoController.GetRoutePaths[TodoControllerRouteKeys.DeleteItem]); Assert.NotNull(route); var deleteRequest = new ChromelyRequest { RouteUrl = $"{TodoController.GetRoutePaths[TodoControllerRouteKeys.DeleteItem]}?id={todoItem.Id}", Parameters = getRequest.RouteUrl.GetParameters() }; var deleteResponse = route?.Invoke(deleteRequest) as IChromelyResponse; var deleteData = deleteResponse is not null && deleteResponse.Data is int?(int)deleteResponse.Data : -1; Assert.NotNull(deleteResponse); Assert.True(deleteData > 0); // Get: Ensure delete route = _routeProvider.GetRoute(TodoController.GetRoutePaths[TodoControllerRouteKeys.GetItem]); Assert.NotNull(route); getRequest = new ChromelyRequest { RouteUrl = $"{TodoController.GetRoutePaths[TodoControllerRouteKeys.GetItem]}?id={todoItem.Id}" }; getRequest.Parameters = getRequest.RouteUrl.GetParameters(); getResponse = route?.Invoke(getRequest) as IChromelyResponse; getData = getResponse?.Data as TodoItem; Assert.NotNull(getResponse); Assert.Null(getData); }