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() { |
| 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), |
| 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 {number} Returns how many objects with the selector were found. |
| 82 */ |
| 83 count: function(selector, opt_root) { |
| 84 opt_root = opt_root || document; |
| 85 return opt_root.querySelectorAll(selector).length; |
| 86 }, |
| 87 |
| 88 /** |
| 89 * Tries to find a group by name within the first POLICY-UI tag. |
| 90 * @param {string} name Name of the group |
| 91 * @return {?Element} Group with name matching |name|. |
| 92 */ |
| 93 group: function(name) { |
| 94 var ui = document.querySelector('policy-ui'); |
| 95 return ui.$.groups.querySelector('[risk-tag=' + name + ']'); |
| 96 }, |
| 97 |
| 98 /** |
| 99 * Returns if there is a group with the given |groupName| whose content |
| 100 * contains the given |text|. |
| 101 * @param {string} groupName |
| 102 * @param {string} text |
| 103 * @return {boolean} Returns false when there is no group named |groupName| or |
| 104 * if the group doesn't contain the string. |
| 105 */ |
| 106 groupContainsText: function(groupName, text) { |
| 107 var group = this.group(groupName); |
| 108 if (!group) |
| 109 return false; |
| 110 return group.$.content.textContent.indexOf(text) != -1; |
| 111 } |
| 112 }; |
| 113 |
| 114 // Test some basic assumptions about the print preview WebUI. |
| 115 TEST_F('PolicyUiMaterialWebUITest', 'TestPolicyLayout', function() { |
| 116 var createPolicyNames = this.createPolicyNames.bind(this); |
| 117 var count = this.count.bind(this); |
| 118 var groupContainsText = this.groupContainsText.bind(this); |
| 119 |
| 120 suite('Layout', function() { |
| 121 test('has one PolicyUi', function() { |
| 122 expectEquals(count('policy-ui'), 1); |
| 123 }); |
| 124 |
| 125 test('PolicyUi renders paper-cards', function() { |
| 126 var policyUi = document.querySelector('policy-ui'); |
| 127 expectTrue(policyUi.$$('paper-card') != null); |
| 128 }); |
| 129 }); |
| 130 |
| 131 suite('Functionality', function() { |
| 132 setup(function() { |
| 133 this.policyUi = document.querySelector('policy-ui'); |
| 134 }); |
| 135 |
| 136 test('PolicyUi loads introduction title', function() { |
| 137 expectTrue(this.policyUi.$.introduction.heading != ''); |
| 138 }); |
| 139 |
| 140 test('PolicyUi loads at least one group', function() { |
| 141 this.policyUi.setPolicyGroups(GROUP_NAMES); |
| 142 this.policyUi.setPolicyNames(createPolicyNames([POLICY.SAMPLE_A])); |
| 143 expectTrue(this.policyUi.$$('policy-group') != null); |
| 144 }); |
| 145 |
| 146 test('PolicyUi provides same methods as internal page', function() { |
| 147 expectTrue(typeof this.policyUi.setPolicyGroups === 'function'); |
| 148 expectTrue(typeof this.policyUi.setPolicyNames === 'function'); |
| 149 expectTrue(typeof this.policyUi.setPolicyValues === 'function'); |
| 150 expectTrue(typeof this.policyUi.setStatus === 'function'); |
| 151 }); |
| 152 |
| 153 // TODO(fhorschig): Move to separate async Test. |
| 154 test.skip('PolicyUi clears groups when names are loaded', function() { |
| 155 this.policyUi.setPolicyGroups(GROUP_NAMES); |
| 156 this.policyUi.setPolicyNames(createPolicyNames()); |
| 157 |
| 158 expectEquals(count('policy-group', this.policyUi), 2); |
| 159 |
| 160 this.policyUi.setPolicyGroups([POLICY.SAMPLE_B.TAGS[0]]); |
| 161 this.policyUi.setPolicyNames(createPolicyNames([POLICY.SAMPLE_B])); |
| 162 |
| 163 expectEquals(count('policy-group', this.policyUi), 1); |
| 164 }); |
| 165 |
| 166 // TODO(fhorschig): Move to separate async Test. |
| 167 test.skip('policies with multiple tags are in multiple groups', function() { |
| 168 this.policyUi.setPolicyGroups(GROUP_NAMES); |
| 169 this.policyUi.setPolicyNames(createPolicyNames()); |
| 170 |
| 171 expectTrue(groupContainsText(GROUP.ADMIN, POLICY.SAMPLE_A.NAME)); |
| 172 expectTrue(groupContainsText(GROUP.SECURITY, POLICY.SAMPLE_A.NAME)); |
| 173 }); |
| 174 }); |
| 175 |
| 176 mocha.run(); |
| 177 }); |
OLD | NEW |