1# Copyright 2014 The Chromium OS 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
5from autotest_lib.client.bin import test, utils
6from autotest_lib.client.common_lib import error
7from autotest_lib.client.common_lib.cros import chrome
8
9
10class desktopui_ConnectivityDiagnostics(test.test):
11    """Basic sanity check of connectivity diagnostics in Chrome."""
12    version = 1
13
14
15    EXT_CODE = """
16var complete = false;
17var success = false;
18var error = false;
19// Send a message to the connectivity diagnostics app asking it to run tests.
20chrome.runtime.sendMessage(
21    "kodldpbjkkmmnilagfdheibampofhao",
22    {
23      command: "test"
24    }, function(result) {
25      complete = true;
26      if (result instanceof Object) {
27        success = result.success;
28        error = result.error;
29      } else {
30        success = result;
31        if (!success) {
32          error = "Tests threw an exception";
33        }
34      }
35      console.log(result);
36    });
37"""
38
39
40    def run_once(self):
41        with chrome.Chrome(disable_default_apps=False, autotest_ext=True) as cr:
42            extension = cr.autotest_ext
43            extension.EvaluateJavaScript(self.EXT_CODE)
44
45            utils.poll_for_condition(
46                    lambda: extension.EvaluateJavaScript('complete;'),
47                    exception = error.TestError('Tests failed to complete'))
48
49            if not extension.EvaluateJavaScript('success;'):
50                raise error.TestFail(extension.EvaluateJavaScript('error;'))
51