Delay the CPU idle check after login

New APNG login pictures increase the CPU consumption so the idle check
has to be done later (right before the actual test is started).

BUG=chromium:753292
TEST=video_PlaybackPerf and video_WebRtcPerf

Change-Id: I5ea10b9ef9c26198869ffd7bdba240248622ba22
Reviewed-on: https://chromium-review.googlesource.com/638230
Commit-Ready: Ben Cheng <bccheng@chromium.org>
Tested-by: Ben Cheng <bccheng@chromium.org>
Reviewed-by: Ben Cheng <bccheng@chromium.org>
(cherry picked from commit 549bc4732f2eacec3fda4af315ceeaf1265da2cc)
Reviewed-on: https://chromium-review.googlesource.com/650066
Commit-Queue: Ben Cheng <bccheng@chromium.org>
Trybot-Ready: Ben Cheng <bccheng@chromium.org>
diff --git a/client/site_tests/video_PlaybackPerf/video_PlaybackPerf.py b/client/site_tests/video_PlaybackPerf/video_PlaybackPerf.py
index 48e29b6..03d2c78 100644
--- a/client/site_tests/video_PlaybackPerf/video_PlaybackPerf.py
+++ b/client/site_tests/video_PlaybackPerf/video_PlaybackPerf.py
@@ -171,11 +171,12 @@
             cpu_usage_end = utils.get_cpu_usage()
             return utils.compute_active_cpu_time(cpu_usage_start,
                                                       cpu_usage_end) * 100
-        if not utils.wait_for_idle_cpu(WAIT_FOR_IDLE_CPU_TIMEOUT,
-                                       CPU_IDLE_USAGE):
-            raise error.TestError('Could not get idle CPU.')
-        if not utils.wait_for_cool_machine():
-            raise error.TestError('Could not get cold machine.')
+
+        # crbug/753292 - APNG login pictures increase CPU usage. Move the more
+        # strict idle checks after the login phase.
+        utils.wait_for_idle_cpu(WAIT_FOR_IDLE_CPU_TIMEOUT, CPU_IDLE_USAGE)
+        utils.wait_for_cool_machine()
+
         # Stop the thermal service that may change the cpu frequency.
         self._service_stopper = service_stopper.ServiceStopper(THERMAL_SERVICES)
         self._service_stopper.stop_services()
@@ -245,6 +246,14 @@
                 extra_browser_args=helper_logger.chrome_vmodule_flag(),
                 arc_mode=self.arc_mode,
                 init_network_controller=True) as cr:
+
+            # crbug/753292 - enforce the idle checks after login
+            if not utils.wait_for_idle_cpu(WAIT_FOR_IDLE_CPU_TIMEOUT,
+                                           CPU_IDLE_USAGE):
+                raise error.TestError('Could not get idle CPU post login.')
+            if not utils.wait_for_cool_machine():
+                raise error.TestError('Could not get cold machine post login.')
+
             # Open the video playback page and start playing.
             self.start_playback(cr, local_path)
             result = gather_result(cr)
diff --git a/client/site_tests/video_WebRtcPerf/video_WebRtcPerf.py b/client/site_tests/video_WebRtcPerf/video_WebRtcPerf.py
index d308122..7630f61 100644
--- a/client/site_tests/video_WebRtcPerf/video_WebRtcPerf.py
+++ b/client/site_tests/video_WebRtcPerf/video_WebRtcPerf.py
@@ -226,6 +226,14 @@
                 DISABLE_ACCELERATED_VIDEO_DECODE_BROWSER_ARGS +
                 EXTRA_BROWSER_ARGS, arc_mode=self.arc_mode,
                 init_network_controller=True) as cr:
+
+            # crbug/753292 - enforce the idle checks after login
+            if not utils.wait_for_idle_cpu(WAIT_FOR_IDLE_CPU_TIMEOUT,
+                                           CPU_IDLE_USAGE):
+                raise error.TestError('Could not get idle CPU post login.')
+            if not utils.wait_for_cool_machine():
+                raise error.TestError('Could not get cold machine post login.')
+
             if utils.get_board() == 'daisy':
               logging.warning('Delay 30s for issue 588579 on daisy')
               time.sleep(30)
@@ -259,11 +267,12 @@
             cpu_usage_end = utils.get_cpu_usage()
             return utils.compute_active_cpu_time(cpu_usage_start,
                                                       cpu_usage_end) * 100
-        if not utils.wait_for_idle_cpu(WAIT_FOR_IDLE_CPU_TIMEOUT,
-                                       CPU_IDLE_USAGE):
-            raise error.TestError('Could not get idle CPU.')
-        if not utils.wait_for_cool_machine():
-            raise error.TestError('Could not get cool machine.')
+
+        # crbug/753292 - APNG login pictures increase CPU usage. Move the more
+        # strict idle checks after the login phase.
+        utils.wait_for_idle_cpu(WAIT_FOR_IDLE_CPU_TIMEOUT, CPU_IDLE_USAGE)
+        utils.wait_for_cool_machine()
+
         # Stop the thermal service that may change the cpu frequency.
         self._service_stopper = service_stopper.ServiceStopper(THERMAL_SERVICES)
         self._service_stopper.stop_services()