Dan Field 0a6301d5ca Listen for display refresh changes and report them correctly (flutter/engine#29800)
This makes sure the frame timings recorder and vsync waiter implementations get
the correct refresh rate if or when it adjusts at runtime. This should be OK
because we'll only query the refresh rate when the display metrics actually
change, which is much less frequent than every frame. I experimented with an NDK
implementation in the previous patch, but that vastly restricts the API levels
we can support, and currently on API 30 and 31 it just calls Java methods
through JNI anyway.

I've refactored the way Display updates are reported so that AndroidDisplay can
just dynamically get the refresh rate correctly. These values are used by a
service protocol extension and by some Stopwatches on the CompositorContext.

See also #29765

Fixes flutter/flutter#93688
Fixes flutter/flutter#93698
2021-11-18 13:09:26 -08:00
..

Unit testing Java code

All Java code in the engine should now be able to be tested with Robolectric 4.6.1 and JUnit 4. The test suite has been added after the bulk of the Java code was first written, so most of these classes do not have existing tests. Ideally code after this point should be tested, either with unit tests here or with integration tests in other repos.

Adding a new test

  1. Create a file under test/ matching the path and name of the class under test. For example, shell/platform/android/io/flutter/util/Preconditions.java -> shell/platform/android/**test**/io/flutter/util/Preconditions**Test**.java.
  2. Add your file to the sources of the robolectric_tests build target in /shell/platform/android/BUILD.gn. This compiles the test class into the test jar.
  3. Import your test class and add it to the @SuiteClasses annotation in FlutterTestSuite.java. This makes sure the test is actually executed at run time.
  4. Write your test.
  5. Build and run with testing/run_tests.py [--type=java] [--java-filter=<test_class_name>].

Q&A

My new test won't run. There's a "ClassNotFoundException".

See Updating Embedding Dependencies.

My new test won't compile. It can't find one of my imports.

See Updating Embedding Dependencies.