Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015 The Chromium 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 | |
| 5 /** @const {string} Path to source root. */ | |
| 6 var ROOT_PATH = '../../../../'; | |
| 7 | |
| 8 // Polymer BrowserTest fixture. | |
| 9 GEN_INCLUDE( | |
| 10 [ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js']); | |
| 11 | |
| 12 GEN('#include "chrome/test/data/webui/policy_ui_material.h"'); | |
| 13 | |
| 14 /** @type {Object} * @const */ | |
| 15 var GROUP = { | |
| 16 ADMIN: 'fullAdminAccess', | |
| 17 SECURITY: 'systemSecurity' | |
| 18 }; | |
| 19 | |
| 20 /** @type {!Array<string>} @const */ | |
| 21 var GROUP_NAMES = Object.keys(GROUP).map(key => GROUP[key]); | |
| 22 | |
| 23 /** @type {Object} @const */ | |
| 24 var POLICY = { | |
| 25 SAMPLE_A: { | |
| 26 NAME: 'RandomPolicy', | |
| 27 TAGS: [GROUP.ADMIN, GROUP.SECURITY] | |
| 28 }, | |
| 29 SAMPLE_B: { | |
| 30 NAME: 'AnotherPolicy', | |
| 31 TAGS: [GROUP.ADMIN] | |
| 32 } | |
| 33 }; | |
| 34 | |
| 35 /** | |
| 36 * Test fixture for policy ui WebUI testing. | |
| 37 * @constructor | |
| 38 * @extends {PolymerTest} | |
| 39 */ | |
| 40 function PolicyUiMaterialWebUITest() { | |
|
Dan Beam
2015/11/03 18:22:31
arguable nit: file name should match this class na
fhorschig
2015/11/22 17:55:27
Sounds good. (Will come within the next Patchset)
| |
| 41 } | |
| 42 | |
| 43 PolicyUiMaterialWebUITest.prototype = { | |
| 44 __proto__: PolymerTest.prototype, | |
| 45 | |
| 46 /** @override */ | |
| 47 browsePreload: 'chrome://md-policy', | |
| 48 | |
| 49 /** @override */ | |
| 50 runAccessibilityChecks: true, | |
| 51 | |
| 52 /** @override */ | |
| 53 accessibilityIssuesAreErrors: true, | |
| 54 | |
| 55 /** @override */ | |
| 56 typedefCppFixture: null, | |
| 57 | |
| 58 /** | |
| 59 * Set extra libraries relative to source root. | |
| 60 * @override | |
| 61 */ | |
| 62 extraLibraries: PolymerTest.getLibraries(ROOT_PATH), | |
|
Dan Beam
2015/11/03 18:22:32
does this actually override anything or is the sam
fhorschig
2015/11/22 17:55:27
The test cases cannot be instantiated without sett
| |
| 63 | |
| 64 /** | |
| 65 * Creates object as send by chromium. Can include only a subset of policies. | |
| 66 * @param {Array.Object=} opt_policies Defaults to all policies. | |
| 67 * @return {Object} Name object with policies within 'chromePolicyNames' key. | |
| 68 */ | |
| 69 createPolicyNames: function(opt_policies) { | |
| 70 opt_policies = opt_policies || Object.keys(POLICY).map(key => POLICY[key]); | |
| 71 var data = {chromePolicyNames: {}}; | |
| 72 for (var i = opt_policies.length - 1; i >= 0; i--) | |
| 73 data.chromePolicyNames[opt_policies[i].NAME] = opt_policies[i].TAGS; | |
| 74 return data; | |
| 75 }, | |
| 76 | |
| 77 /** | |
| 78 * Tries to find at least one of the element matching the selector. | |
| 79 * @param {string} selector | |
| 80 * @param {Element=} opt_root Defaults to document | |
| 81 * @return {boolean} Returns true if an object with matching selector exists. | |
| 82 */ | |
| 83 exists: function(selector, opt_root) { | |
| 84 opt_root = opt_root || document; | |
| 85 return opt_root.querySelector(selector) !== undefined; | |
|
Dan Beam
2015/11/03 18:22:32
this is always true (querySelector never returns u
fhorschig
2015/11/22 17:55:27
Function deleted.
| |
| 86 }, | |
| 87 | |
| 88 /** | |
| 89 * Tries to find at least one of the element matching the selector. | |
| 90 * @param {string} selector | |
| 91 * @param {Element=} opt_root Defaults to document | |
| 92 * @return {number} Returns how many objects with the selector were found. | |
| 93 */ | |
| 94 count: function(selector, opt_root) { | |
| 95 opt_root = opt_root || document; | |
| 96 return opt_root.querySelectorAll(selector).length; | |
| 97 }, | |
| 98 | |
| 99 /** | |
| 100 * Tries to find a group by name within the first POLICY-UI tag. | |
| 101 * @param {string} name Name of the group | |
| 102 * @return {?Element} Group with name matching |name|. | |
| 103 */ | |
| 104 group: function(name) { | |
| 105 var ui = document.querySelector('policy-ui'); | |
| 106 return ui.$.groups.querySelector('[risk-tag=' + name + ']'); | |
| 107 }, | |
| 108 | |
| 109 /** | |
| 110 * Returns if there is a group with the given |groupName| whose content | |
| 111 * contains the given |text|. | |
| 112 * @param {string} groupName | |
| 113 * @param {string} text | |
| 114 * @return {boolean} Returns false when there is no group named |groupName| or | |
| 115 * if the group doesn't contain the string. | |
| 116 */ | |
| 117 groupContainsText: function(groupName, text) { | |
| 118 var group = this.group(groupName); | |
| 119 if (!group) | |
| 120 return false; | |
| 121 return group.$.content.textContent.indexOf(text) != -1; | |
| 122 } | |
| 123 }; | |
| 124 | |
| 125 // Test some basic assumptions about the print preview WebUI. | |
| 126 TEST_F('PolicyUiMaterialWebUITest', 'TestPolicyLayout', function() { | |
| 127 var createPolicyNames = this.createPolicyNames.bind(this); | |
| 128 var count = this.count.bind(this); | |
| 129 var exists = this.exists.bind(this); | |
| 130 var groupContainsText = this.groupContainsText.bind(this); | |
| 131 | |
| 132 suite('Layout', function() { | |
| 133 test('has one PolicyUi', function() { | |
| 134 expectTrue(exists('policy-ui')); | |
|
Dan Beam
2015/11/03 18:22:31
if the test is "has one PolictyUi", why not expect
fhorschig
2015/11/22 17:55:27
Good point, exists doesn't exist anymore.
| |
| 135 }); | |
| 136 | |
| 137 test('PolicyUi renders paper-cards', function() { | |
| 138 var policyUi = document.querySelector('policy-ui'); | |
| 139 expectTrue(exists('paper-card', policyUi)); | |
| 140 }); | |
| 141 }); | |
| 142 | |
| 143 suite('Functionality', function() { | |
| 144 setup(function() { | |
| 145 this.policyUi = document.querySelector('policy-ui'); | |
| 146 }); | |
| 147 | |
| 148 test('PolicyUi loads introduction title', function() { | |
| 149 expectTrue(this.policyUi.$.introduction.heading != ''); | |
| 150 }); | |
| 151 | |
| 152 test('PolicyUi loads at least one group', function() { | |
| 153 this.policyUi.setPolicyGroups(GROUP_NAMES); | |
| 154 this.policyUi.setPolicyNames(createPolicyNames([POLICY.SAMPLE_A])); | |
| 155 expectTrue(exists('policy-group', this.policyUi)); | |
|
Dan Beam
2015/11/03 18:22:32
nit: this.policyUi.$$('policy-group')
fhorschig
2015/11/22 17:55:27
Done.
| |
| 156 }); | |
| 157 | |
| 158 test('PolicyUi provides same methods as internal page', function() { | |
| 159 expectTrue(typeof this.policyUi.setPolicyGroups === 'function'); | |
| 160 expectTrue(typeof this.policyUi.setPolicyNames === 'function'); | |
| 161 expectTrue(typeof this.policyUi.setPolicyValues === 'function'); | |
| 162 expectTrue(typeof this.policyUi.setStatus === 'function'); | |
| 163 }); | |
| 164 | |
| 165 // TODO(fhorschig): Move to separate async Test. | |
| 166 test.skip('PolicyUi clears groups when names are loaded', function() { | |
| 167 this.policyUi.setPolicyGroups(GROUP_NAMES); | |
| 168 this.policyUi.setPolicyNames(createPolicyNames()); | |
| 169 | |
| 170 expectTrue(count('policy-group', this.policyUi) == 2); | |
| 171 | |
| 172 this.policyUi.setPolicyGroups([POLICY.SAMPLE_B.TAGS[0]]); | |
| 173 this.policyUi.setPolicyNames(createPolicyNames([POLICY.SAMPLE_B])); | |
| 174 | |
| 175 expectTrue(count('policy-group', this.policyUi) == 1); | |
| 176 }); | |
| 177 | |
| 178 // TODO(fhorschig): Move to separate async Test. | |
| 179 test.skip('policies with multiple tags are in multiple groups', function() { | |
| 180 this.policyUi.setPolicyGroups(GROUP_NAMES); | |
| 181 this.policyUi.setPolicyNames(createPolicyNames()); | |
| 182 | |
| 183 expectTrue(groupContainsText(GROUP.ADMIN, POLICY.SAMPLE_A.NAME)); | |
| 184 expectTrue(groupContainsText(GROUP.SECURITY, POLICY.SAMPLE_A.NAME)); | |
| 185 }); | |
| 186 }); | |
| 187 | |
| 188 mocha.run(); | |
| 189 }); | |
| OLD | NEW |