subresource_filter_browser_test_harness.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 WEBLAYER_TEST_SUBRESOURCE_FILTER_BROWSER_TEST_HARNESS_H_
  5. #define WEBLAYER_TEST_SUBRESOURCE_FILTER_BROWSER_TEST_HARNESS_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/test/scoped_feature_list.h"
  9. #include "build/build_config.h"
  10. #include "components/subresource_filter/core/common/test_ruleset_creator.h"
  11. #include "components/url_pattern_index/proto/rules.pb.h"
  12. #include "weblayer/test/weblayer_browser_test.h"
  13. namespace content {
  14. class WebContents;
  15. }
  16. namespace subresource_filter {
  17. class ContentSubresourceFilterThrottleManager;
  18. }
  19. namespace weblayer {
  20. // A base class for //weblayer browsertests that directly test or rely on
  21. // subresource filter functionality.
  22. class SubresourceFilterBrowserTest : public WebLayerBrowserTest {
  23. public:
  24. SubresourceFilterBrowserTest();
  25. ~SubresourceFilterBrowserTest() override;
  26. SubresourceFilterBrowserTest(const SubresourceFilterBrowserTest&) = delete;
  27. SubresourceFilterBrowserTest& operator=(const SubresourceFilterBrowserTest&) =
  28. delete;
  29. void SetUpOnMainThread() override;
  30. protected:
  31. void SetRulesetToDisallowURLsWithPathSuffix(const std::string& suffix);
  32. void SetRulesetWithRules(
  33. const std::vector<url_pattern_index::proto::UrlRule>& rules);
  34. content::WebContents* web_contents();
  35. // Returns whether a script resource that sets document.scriptExecuted to true
  36. // on load was loaded.
  37. bool WasParsedScriptElementLoaded(content::RenderFrameHost* rfh);
  38. // By default SubresourceFilterBrowsertest starts the embedded test server in
  39. // SetUpOnMainThread(). Tests that wish to control the starting of the
  40. // embedded test server themselves should override this method to return
  41. // false.
  42. virtual bool StartEmbeddedTestServerAutomatically();
  43. // The ContentSubresourceFilterthrottleManager class is per-page, meaning
  44. // each Page object will create its own instance. This method returns the
  45. // throttle manager associated with the currently primary Page in the
  46. // web_contents() (i.e. the one the user is currently seeing and interacting
  47. // with, as opposed to a prerendering or BFCached page).
  48. subresource_filter::ContentSubresourceFilterThrottleManager*
  49. GetPrimaryPageThrottleManager();
  50. private:
  51. subresource_filter::testing::TestRulesetCreator test_ruleset_creator_;
  52. base::test::ScopedFeatureList feature_list_;
  53. };
  54. } // namespace weblayer
  55. #endif // WEBLAYER_TEST_SUBRESOURCE_FILTER_BROWSER_TEST_HARNESS_H_