[Autotest] Adding a poll in get_extension() within chrome.py

Sometimes an extension will be in the _extensions_to_load, but not
be fully loaded, and will error when trying to fetch from
self.browser.extensions. Happens most common when ARC is enabled.
This will add a wait/retry.

BUG=chromium:1033107
TEST=policy_ArcDisableScreenshots (which was previously flakey due to
this)

Change-Id: Ibc2e35aa3188d4c7ae751e05caa66489748b69ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/1959399
Tested-by: Derek Beckett <dbeckett@chromium.org>
Commit-Queue: Derek Beckett <dbeckett@chromium.org>
Reviewed-by: Achuith Bhandarkar <achuith@chromium.org>
diff --git a/client/common_lib/cros/chrome.py b/client/common_lib/cros/chrome.py
index c5efd2b..30101b6 100644
--- a/client/common_lib/cros/chrome.py
+++ b/client/common_lib/cros/chrome.py
@@ -281,10 +281,29 @@
         """Returns a telemetry browser instance."""
         return self._browser
 
-    def get_extension(self, extension_path):
+    def get_extension(self, extension_path, retry=5):
         """Fetches a telemetry extension instance given the extension path."""
+        def _has_ext(ext):
+            """
+            Return True if the extension is fully loaded.
+
+            Sometimes an extension will be in the _extensions_to_load, but not
+            be fully loaded, and will error when trying to fetch from
+            self.browser.extensions. Happens most common when ARC is enabled.
+            This will add a wait/retry.
+
+            @param ext: the extension to look for
+            @returns True if found, False if not.
+            """
+            try:
+                return bool(self.browser.extensions[ext])
+            except KeyError:
+                return False
+
         for ext in self._extensions_to_load:
             if extension_path == ext.path:
+                utils.poll_for_condition(lambda: _has_ext(ext),
+                                         timeout=retry)
                 return self.browser.extensions[ext]
         return None