Commit d1abc70b authored by Trent Begin's avatar Trent Begin Committed by Chromium LUCI CQ

connectivity-diagnostics: add browser test for routine-group element

This change adds the framework for network health cr_component tests and
adds a test for the routine-group element.

Bug: chromium:1142857
Change-Id: I8299749f0ed3c5a77271919db211f46cb4d7d621
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2572996Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Trent Begin <tbegin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833898}
parent 9f0ff082
......@@ -4,11 +4,11 @@
import("//ui/webui/resources/tools/js_modulizer.gni")
group("modulize") {
deps = [
"cellular_setup:modulize",
"network:modulize",
"network_health:modulize",
"//chrome/test/data/webui/chromeos:modulize",
]
}
......@@ -59,6 +59,10 @@ GEN('#include "content/public/test/browser_test.h"');
['NetworkSelect', 'network/network_select_test.js', []],
].forEach(test => registerTest('NetworkComponents', 'network', ...test));
[
['RoutineGroup', 'network_health/routine_group_test.js', []],
].forEach(test => registerTest('NetworkHealth', 'network', ...test));
[
['ActivationCodePage', 'cellular_setup/activation_code_page_test.js',[
'./cellular_setup/fake_media_devices.js',
......
......@@ -30,7 +30,10 @@ GEN('#include "chromeos/constants/chromeos_features.h"');
['NetworkProxy', 'network/network_proxy_test.m.js'],
['NetworkSelect', 'network/network_select_test.m.js'],
['NetworkSiminfo', 'network/network_siminfo_test.m.js'],
].forEach(test => registerTest('NetworkComponents', ...test));
].forEach(test => registerTest('NetworkComponents', 'os-settings', ...test));
[['RoutineGroup', 'network_health/routine_group_test.m.js'],
].forEach(test => registerTest('NetworkHealth', 'connectivity-diagnostics', ...test));
[['ActivationCodePage', 'cellular_setup/activation_code_page_test.m.js'],
['BasePage', 'cellular_setup/base_page_test.m.js'],
......@@ -42,17 +45,18 @@ GEN('#include "chromeos/constants/chromeos_features.h"');
['PsimFlowUi', 'cellular_setup/psim_flow_ui_test.m.js'],
['SetupSelectionFlow', 'cellular_setup/setup_selection_flow_test.m.js'],
['SetupLoadingPage', 'cellular_setup/setup_loading_page_test.m.js'],
].forEach(test => registerTest('CellularSetup', ...test));
].forEach(test => registerTest('CellularSetup', 'os-settings', ...test));
// clang-format on
function registerTest(componentName, testName, module, caseName) {
function registerTest(componentName, webuiHost, testName, module, caseName) {
const className = `${componentName}${testName}TestV3`;
this[className] = class extends PolymerTest {
/** @override */
get browsePreload() {
// TODO(jhawkins): Set up test_loader.html for internet-config-dialog
// and use it here instead of os-settings.
return `chrome://os-settings/test_loader.html?module=cr_components/chromeos/${module}`;
return `chrome://${
webuiHost}/test_loader.html?module=cr_components/chromeos/${module}`;
}
/** @override */
......@@ -67,6 +71,7 @@ function registerTest(componentName, testName, module, caseName) {
get featureList() {
return {
enabled: [
'chromeos::features::kConnectivityDiagnosticsWebUi',
'chromeos::features::kOsSettingsPolymer3',
'chromeos::features::kUpdatedCellularActivationUi',
],
......
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//third_party/closure_compiler/compile_js.gni")
import("//ui/webui/resources/tools/js_modulizer.gni")
js_library("routine_group_test") {
deps = [
"../../..:chai_assert",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
}
js_modulizer("modulize") {
input_files = [ "routine_group_test.js" ]
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// clang-format off
// #import 'chrome://connectivity-diagnostics/strings.m.js';
// #import 'chrome://resources/cr_components/chromeos/network_health/network_diagnostics_mojo.m.js'
// #import {Routine, Icons} from 'chrome://resources/cr_components/chromeos/network_health/network_diagnostics_types.m.js'
// #import 'chrome://resources/cr_components/chromeos/network_health/routine_group.m.js'
// #import {assertTrue, assertFalse, assertEquals} from '../../../chai_assert.js';
// #import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
// clang-format on
/**
* Creates baseline routines.
* @return {!Array<!Routine>}
* @private
*/
function createRoutines() {
return [
{
name: 'NetworkDiagnosticsLanConnectivity',
running: false,
resultMsg: 'Passed',
group: 0,
type: 0,
result: {
verdict: chromeos.networkDiagnostics.mojom.RoutineVerdict.kNoProblem
},
ariaDescription: '',
},
{
name: 'NetworkDiagnosticsSignalStrength',
running: false,
resultMsg: 'Passed',
group: 0,
type: 1,
result: {
verdict: chromeos.networkDiagnostics.mojom.RoutineVerdict.kNoProblem
},
ariaDescription: '',
}
];
}
/**
* Removes any prefixed URL from a icon image path
* @param {string}
* @return {string}
* @private
*/
function getIconFromSrc(src) {
const values = src.split('/');
return values[values.length - 1];
}
/**
* Test suite for the Routine Group element.
*/
suite('RoutineGroupTest', function routineGroupTest() {
/** @type {?RoutineGroupElement} */
let routineGroup = null;
setup(() => {
document.body.innerHTML = '';
routineGroup = /** @type {!RoutineGroupElement} */ (
document.createElement('routine-group'));
routineGroup.name = 'Group';
routineGroup.expanded = false;
document.body.appendChild(routineGroup);
Polymer.dom.flush();
});
teardown(function() {
routineGroup.remove();
routineGroup = null;
});
/**
* Takes the provided routines and passes them to the RoutineGroupElement,
* then flushes the Polymes DOM.
* @param {!Array<!Routine>} routines
*/
function setRoutines(routines) {
routineGroup.routines = routines;
Polymer.dom.flush();
}
/**
* Clicks the routine group container to toggle the expanded state.
* @param {boolean} expanded
*/
function clickRoutineGroup() {
const container = routineGroup.$$('.group-container');
assertTrue(!!container);
container.click();
Polymer.dom.flush();
}
/**
* Check that the spinner is visible and the group icon is not.
*/
function checkRunning() {
const spinner = routineGroup.$$('paper-spinner-lite');
assertTrue(!!spinner);
assertFalse(spinner.hidden);
const icon = routineGroup.$$('.routine-icon');
assertTrue(!!icon);
assertTrue(icon.hidden);
}
/**
* Check that the spinner is hidden and the group icon is visible and set to
* `iconResult`.
* @param {string} iconResult
*/
function checkResult(iconResult) {
const spinner = routineGroup.$$('paper-spinner-lite');
assertFalse(!!spinner);
const icon = routineGroup.$$('.routine-icon');
assertTrue(!!icon);
assertFalse(icon.hidden);
assertEquals(getIconFromSrc(icon.src), iconResult);
}
/**
* Test using one running routine.
*/
test('RunningOne', () => {
let routines = createRoutines();
routines[0].running = true;
routines[0].result = null;
routines[0].resultMsg = '';
setRoutines(routines);
checkRunning();
clickRoutineGroup();
});
/**
* Test when all routines are running.
*/
test('RunningAll', () => {
let routines = createRoutines();
for (let routine of routines) {
routine.running = true;
routine.result = null;
routine.resultMsg = '';
}
setRoutines(routines);
checkRunning();
clickRoutineGroup();
});
/**
* Test when all routines are complete.
*/
test('RunningNone', () => {
routineGroup.routines = createRoutines();
Polymer.dom.flush();
checkResult(Icons.TEST_PASSED);
clickRoutineGroup();
});
/**
* Test when all routines are complete and one has failed.
*/
test('FailedOne', () => {
let routines = createRoutines();
routines[0].resultMsg = 'Failed';
routines[0].result = {
'verdict': chromeos.networkDiagnostics.mojom.RoutineVerdict.kProblem
};
setRoutines(routines);
checkResult(Icons.TEST_FAILED);
clickRoutineGroup();
});
/**
* Test when routines are complete and one did not run.
*/
test('NotRunOne', () => {
let routines = createRoutines();
routines[0].resultMsg = 'Not Run';
routines[0].result = {
'verdict': chromeos.networkDiagnostics.mojom.RoutineVerdict.kNotRun
};
setRoutines(routines);
checkResult(Icons.TEST_NOT_RUN);
clickRoutineGroup();
});
/**
* Test when routines are complete. One routine failed and one did not run.
*/
test('NotRunAndFailed', () => {
let routines = createRoutines();
routines[0].resultMsg = 'Not Run';
routines[0].result = {
'verdict': chromeos.networkDiagnostics.mojom.RoutineVerdict.kNotRun
};
routines[1].resultMsg = 'Failed';
routines[1].result = {
'verdict': chromeos.networkDiagnostics.mojom.RoutineVerdict.kProblem
};
setRoutines(routines);
checkResult(Icons.TEST_FAILED);
clickRoutineGroup();
});
});
......@@ -14,6 +14,7 @@
#include "chromeos/strings/grit/chromeos_strings.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui_data_source.h"
#include "ui/resources/grit/webui_generated_resources.h"
namespace chromeos {
......@@ -37,6 +38,8 @@ void SetUpWebUIDataSource(content::WebUIDataSource* source,
}
source->SetDefaultResource(default_resource);
source->AddResourcePath("test_loader.html", IDR_WEBUI_HTML_TEST_LOADER_HTML);
source->AddResourcePath("test_loader.js", IDR_WEBUI_JS_TEST_LOADER_JS);
}
} // namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment