webui_test_prod_util.h 1.6 KB

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_WEBUI_WEB_APPLICATIONS_WEBUI_TEST_PROD_UTIL_H_
  5. #define ASH_WEBUI_WEB_APPLICATIONS_WEBUI_TEST_PROD_UTIL_H_
  6. #include "content/public/browser/web_ui_data_source.h"
  7. // If the current process is running for tests, configures |host_source| for
  8. // testing by installing a request filter that can be satisfied by tests wanting
  9. // to provide custom resources. Note that if these resources are scripts,
  10. // further CSP changes (e.g. trusted-types) may be required in order for them to
  11. // load. If `real_[should_]handle_request_callback` arguments are provided, the
  12. // test request filter will be configured to handle these as well.
  13. // If not running for tests, `real_[should_]handle_request_callback` arguments
  14. // are passed directly to host_source->SetRequestFilter().
  15. // Returns true if the testing request filter was installed.
  16. bool MaybeConfigureTestableDataSource(
  17. content::WebUIDataSource* host_source,
  18. const content::WebUIDataSource::ShouldHandleRequestCallback&
  19. real_should_handle_request_callback = {},
  20. const content::WebUIDataSource::HandleRequestCallback&
  21. real_handle_request_callback = {});
  22. // Configures the data source request filter used for testing. Only testing code
  23. // should call this.
  24. void SetTestableDataSourceRequestHandlerForTesting(
  25. content::WebUIDataSource::ShouldHandleRequestCallback should_handle,
  26. content::WebUIDataSource::HandleRequestCallback handler);
  27. #endif // ASH_WEBUI_WEB_APPLICATIONS_WEBUI_TEST_PROD_UTIL_H_