Reland "[Enrollment] Mock EnrollmentLauncher with a factory."

This is a reland of commit 0090223f92fb1a29f3b3ccf2638c382836b69ab3

The problem with original commit was that MockEnrollmentLauncher has to
outlive its tested consumers.

The reland adds better lifetime handling of EnrollmentScreen,
DemoSetupController and MockEnrollmentLauncher in unittests. Browsertest
already have satisfying lifetime.

Now in unit tests, lifetime of mock and tested consumer are managed via
construction order:
1. In EnrollmentScreenUnitTest, mocks are regular non-pointer members
   initialized before enrollment screen. Except for MockErrorScreen which
   has to be reset in TearDown() before network portal shutdown.
   Enrollment screen is also destroyed in TearDown() as it requires
   browser process shutdown.
2. In DemoSetupControllerTest, mocks are regular non-pointer members
   initialized before tested DemoSetupController.
3. In DemoSetupControllerTest, task environment moved to be the first
   member so that all other members (specifically
   DemoSetupControllerTestHelper) use it.
4. All mocks are wrapped with NiceMock to prevent unused warnings.

Original change's description:
> [Enrollment] Mock EnrollmentLauncher with a factory.
>
> In tests, enrollment launcher was mocked via global mock holder. Tests
> used to set a mock before it is yanked by
> EnrollmentLauncher::Create function called by a launcher's consumer
> (e.g. enrollment screen). It was one time set after which tests needed
> to set another mock, and had to know when to do so.
>
> Now, tests have full control and access to the launcher's mock and can
> easily set and reset expectations. Tests have no care about when
> fake enrollment launchers, connected to the mock, are created and used.
> Tests can inject fake enrollment launchers via factory override.
>
> Bug: b:233859530
> Test: None
> Change-Id: Ica1aac291bcaafbc3648a9745c3a4c66e0b9699a
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4567496
> Commit-Queue: Artem Sumaneev <asumaneev@google.com>
> Reviewed-by: Jackson Tadie <jacksontadie@google.com>
> Reviewed-by: Roman Sorokin <rsorokin@google.com>
> Reviewed-by: Renato Silva <rrsilva@google.com>
> Cr-Commit-Position: refs/heads/main@{#1152426}

Bug: b:233859530
Test: unit_tests --gtest_filter="EnrollmentScreenUnitTest.*"
Test: unit_tests --gtest_filter="*AutomaticEnrollmentScreenUnitTest.*"
Test: unit_tests --gtest_filter="DemoSetupControllerTest.*"
Test: unit_tests --gtest_filter="*RetailerNameCanonicalizationTestCase.*"
Change-Id: Ice8787429450d90963a4887e7489c21a9465f3c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4584249
Reviewed-by: Jackson Tadie <jacksontadie@google.com>
Commit-Queue: Artem Sumaneev <asumaneev@google.com>
Reviewed-by: Renato Silva <rrsilva@google.com>
Cr-Commit-Position: refs/heads/main@{#1156109}
11 files changed
tree: 7e3286877d2f1389af183d44c6fb237e24b7ca4d
  1. android_webview/
  2. apps/
  3. ash/
  4. base/
  5. build/
  6. build_overrides/
  7. buildtools/
  8. cc/
  9. chrome/
  10. chromecast/
  11. chromeos/
  12. codelabs/
  13. components/
  14. content/
  15. courgette/
  16. crypto/
  17. dbus/
  18. device/
  19. docs/
  20. extensions/
  21. fuchsia_web/
  22. gin/
  23. google_apis/
  24. google_update/
  25. gpu/
  26. headless/
  27. infra/
  28. ios/
  29. ipc/
  30. media/
  31. mojo/
  32. native_client_sdk/
  33. net/
  34. pdf/
  35. ppapi/
  36. printing/
  37. remoting/
  38. rlz/
  39. sandbox/
  40. services/
  41. skia/
  42. sql/
  43. storage/
  44. styleguide/
  45. testing/
  46. third_party/
  47. tools/
  48. ui/
  49. url/
  50. weblayer/
  51. .clang-format
  52. .clang-tidy
  53. .eslintrc.js
  54. .git-blame-ignore-revs
  55. .gitattributes
  56. .gitignore
  57. .gn
  58. .mailmap
  59. .rustfmt.toml
  60. .vpython3
  61. .yapfignore
  62. ATL_OWNERS
  63. AUTHORS
  64. BUILD.gn
  65. CODE_OF_CONDUCT.md
  66. codereview.settings
  67. DEPS
  68. DIR_METADATA
  69. LICENSE
  70. LICENSE.chromium_os
  71. OWNERS
  72. PRESUBMIT.py
  73. PRESUBMIT_test.py
  74. PRESUBMIT_test_mocks.py
  75. README.md
  76. WATCHLISTS
README.md

Logo Chromium

Chromium is an open-source browser project that aims to build a safer, faster, and more stable way for all users to experience the web.

The project's web site is https://www.chromium.org.

To check out the source code locally, don't use git clone! Instead, follow the instructions on how to get the code.

Documentation in the source is rooted in docs/README.md.

Learn how to Get Around the Chromium Source Code Directory Structure .

For historical reasons, there are some small top level directories. Now the guidance is that new top level directories are for product (e.g. Chrome, Android WebView, Ash). Even if these products have multiple executables, the code should be in subdirectories of the product.

If you found a bug, please file it at https://crbug.com/new.