@Test void rebuildsApisJSCacheWhenApisChanged() { Supplier<Map<String, Object>> supplier = () -> new HashMap<>(); Function<Map<String, Object>, JsApiCache> jsCacheBuilder = mock(Function.class); MessageRouterHandler handler = new MessageRouterHandler(supplier, jsCacheBuilder); handler.onQuery(null,null,0,"request",false, mock(CefQueryCallback.class)); handler.onQuery(null,null,0,"request",false, mock(CefQueryCallback.class)); verify(jsCacheBuilder, times(2)).apply(any()); }
@Override public boolean onQuery(CefBrowser browser, CefFrame frame, long query_id, String request, boolean persistent, CefQueryCallback callback) { Map<String, Object> apis = apisSupplier.get(); if(jsApiCache == null || apis != lastApis) { jsApiCache = jsCacheBuilder.apply(apisSupplier.get()); lastApis = apis; } if("--getApis".equals(request)) { callback.success(jsApiCache.getApiDescription()); return true; } if(request.startsWith("--call:")) { Gson gson = new Gson(); FunctionCall functionCall = gson.fromJson(request.substring("--call:".length()), FunctionCall.class); ObjectDescription objectDescription = jsApiCache.call(functionCall); callback.success(objectDescription.describe()); return true; } return false; }
MessageRouterHandler extends CefMessageRouterHandlerAdapter { @Override public boolean onQuery(CefBrowser browser, CefFrame frame, long query_id, String request, boolean persistent, CefQueryCallback callback) { Map<String, Object> apis = apisSupplier.get(); if(jsApiCache == null || apis != lastApis) { jsApiCache = jsCacheBuilder.apply(apisSupplier.get()); lastApis = apis; } if("--getApis".equals(request)) { callback.success(jsApiCache.getApiDescription()); return true; } if(request.startsWith("--call:")) { Gson gson = new Gson(); FunctionCall functionCall = gson.fromJson(request.substring("--call:".length()), FunctionCall.class); ObjectDescription objectDescription = jsApiCache.call(functionCall); callback.success(objectDescription.describe()); return true; } return false; } }
MessageRouterHandler extends CefMessageRouterHandlerAdapter { @Override public boolean onQuery(CefBrowser browser, CefFrame frame, long query_id, String request, boolean persistent, CefQueryCallback callback) { Map<String, Object> apis = apisSupplier.get(); if(jsApiCache == null || apis != lastApis) { jsApiCache = jsCacheBuilder.apply(apisSupplier.get()); lastApis = apis; } if("--getApis".equals(request)) { callback.success(jsApiCache.getApiDescription()); return true; } if(request.startsWith("--call:")) { Gson gson = new Gson(); FunctionCall functionCall = gson.fromJson(request.substring("--call:".length()), FunctionCall.class); ObjectDescription objectDescription = jsApiCache.call(functionCall); callback.success(objectDescription.describe()); return true; } return false; } MessageRouterHandler(Supplier<Map<String, Object>> apisSupplier, Function<Map<String, Object>, JsApiCache> jsCacheBuilder); }
MessageRouterHandler extends CefMessageRouterHandlerAdapter { @Override public boolean onQuery(CefBrowser browser, CefFrame frame, long query_id, String request, boolean persistent, CefQueryCallback callback) { Map<String, Object> apis = apisSupplier.get(); if(jsApiCache == null || apis != lastApis) { jsApiCache = jsCacheBuilder.apply(apisSupplier.get()); lastApis = apis; } if("--getApis".equals(request)) { callback.success(jsApiCache.getApiDescription()); return true; } if(request.startsWith("--call:")) { Gson gson = new Gson(); FunctionCall functionCall = gson.fromJson(request.substring("--call:".length()), FunctionCall.class); ObjectDescription objectDescription = jsApiCache.call(functionCall); callback.success(objectDescription.describe()); return true; } return false; } MessageRouterHandler(Supplier<Map<String, Object>> apisSupplier, Function<Map<String, Object>, JsApiCache> jsCacheBuilder); @Override boolean onQuery(CefBrowser browser, CefFrame frame, long query_id, String request,
						   boolean persistent, CefQueryCallback callback); }
MessageRouterHandler extends CefMessageRouterHandlerAdapter { @Override public boolean onQuery(CefBrowser browser, CefFrame frame, long query_id, String request, boolean persistent, CefQueryCallback callback) { Map<String, Object> apis = apisSupplier.get(); if(jsApiCache == null || apis != lastApis) { jsApiCache = jsCacheBuilder.apply(apisSupplier.get()); lastApis = apis; } if("--getApis".equals(request)) { callback.success(jsApiCache.getApiDescription()); return true; } if(request.startsWith("--call:")) { Gson gson = new Gson(); FunctionCall functionCall = gson.fromJson(request.substring("--call:".length()), FunctionCall.class); ObjectDescription objectDescription = jsApiCache.call(functionCall); callback.success(objectDescription.describe()); return true; } return false; } MessageRouterHandler(Supplier<Map<String, Object>> apisSupplier, Function<Map<String, Object>, JsApiCache> jsCacheBuilder); @Override boolean onQuery(CefBrowser browser, CefFrame frame, long query_id, String request,
						   boolean persistent, CefQueryCallback callback);  }