Index: chrome/test/data/webui/policy_ui_material.js |
diff --git a/chrome/test/data/webui/policy_ui_material.js b/chrome/test/data/webui/policy_ui_material.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..855b501a2e5d2957b136dd866cb883a06562c3b9 |
--- /dev/null |
+++ b/chrome/test/data/webui/policy_ui_material.js |
@@ -0,0 +1,189 @@ |
+// Copyright (c) 2015 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. |
+ |
+/** @const {string} Path to source root. */ |
+var ROOT_PATH = '../../../../'; |
+ |
+// Polymer BrowserTest fixture. |
+GEN_INCLUDE( |
+ [ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js']); |
+ |
+GEN('#include "chrome/test/data/webui/policy_ui_material.h"'); |
+ |
+/** @type {Object} * @const */ |
+var GROUP = { |
+ ADMIN: 'fullAdminAccess', |
+ SECURITY: 'systemSecurity' |
+}; |
+ |
+/** @type {!Array<string>} @const */ |
+var GROUP_NAMES = Object.keys(GROUP).map(key => GROUP[key]); |
+ |
+/** @type {Object} @const */ |
+var POLICY = { |
+ SAMPLE_A: { |
+ NAME: 'RandomPolicy', |
+ TAGS: [GROUP.ADMIN, GROUP.SECURITY] |
+ }, |
+ SAMPLE_B: { |
+ NAME: 'AnotherPolicy', |
+ TAGS: [GROUP.ADMIN] |
+ } |
+}; |
+ |
+/** |
+ * Test fixture for policy ui WebUI testing. |
+ * @constructor |
+ * @extends {PolymerTest} |
+ */ |
+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)
|
+} |
+ |
+PolicyUiMaterialWebUITest.prototype = { |
+ __proto__: PolymerTest.prototype, |
+ |
+ /** @override */ |
+ browsePreload: 'chrome://md-policy', |
+ |
+ /** @override */ |
+ runAccessibilityChecks: true, |
+ |
+ /** @override */ |
+ accessibilityIssuesAreErrors: true, |
+ |
+ /** @override */ |
+ typedefCppFixture: null, |
+ |
+ /** |
+ * Set extra libraries relative to source root. |
+ * @override |
+ */ |
+ 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
|
+ |
+ /** |
+ * Creates object as send by chromium. Can include only a subset of policies. |
+ * @param {Array.Object=} opt_policies Defaults to all policies. |
+ * @return {Object} Name object with policies within 'chromePolicyNames' key. |
+ */ |
+ createPolicyNames: function(opt_policies) { |
+ opt_policies = opt_policies || Object.keys(POLICY).map(key => POLICY[key]); |
+ var data = {chromePolicyNames: {}}; |
+ for (var i = opt_policies.length - 1; i >= 0; i--) |
+ data.chromePolicyNames[opt_policies[i].NAME] = opt_policies[i].TAGS; |
+ return data; |
+ }, |
+ |
+ /** |
+ * Tries to find at least one of the element matching the selector. |
+ * @param {string} selector |
+ * @param {Element=} opt_root Defaults to document |
+ * @return {boolean} Returns true if an object with matching selector exists. |
+ */ |
+ exists: function(selector, opt_root) { |
+ opt_root = opt_root || document; |
+ 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.
|
+ }, |
+ |
+ /** |
+ * Tries to find at least one of the element matching the selector. |
+ * @param {string} selector |
+ * @param {Element=} opt_root Defaults to document |
+ * @return {number} Returns how many objects with the selector were found. |
+ */ |
+ count: function(selector, opt_root) { |
+ opt_root = opt_root || document; |
+ return opt_root.querySelectorAll(selector).length; |
+ }, |
+ |
+ /** |
+ * Tries to find a group by name within the first POLICY-UI tag. |
+ * @param {string} name Name of the group |
+ * @return {?Element} Group with name matching |name|. |
+ */ |
+ group: function(name) { |
+ var ui = document.querySelector('policy-ui'); |
+ return ui.$.groups.querySelector('[risk-tag=' + name + ']'); |
+ }, |
+ |
+ /** |
+ * Returns if there is a group with the given |groupName| whose content |
+ * contains the given |text|. |
+ * @param {string} groupName |
+ * @param {string} text |
+ * @return {boolean} Returns false when there is no group named |groupName| or |
+ * if the group doesn't contain the string. |
+ */ |
+ groupContainsText: function(groupName, text) { |
+ var group = this.group(groupName); |
+ if (!group) |
+ return false; |
+ return group.$.content.textContent.indexOf(text) != -1; |
+ } |
+}; |
+ |
+// Test some basic assumptions about the print preview WebUI. |
+TEST_F('PolicyUiMaterialWebUITest', 'TestPolicyLayout', function() { |
+ var createPolicyNames = this.createPolicyNames.bind(this); |
+ var count = this.count.bind(this); |
+ var exists = this.exists.bind(this); |
+ var groupContainsText = this.groupContainsText.bind(this); |
+ |
+ suite('Layout', function() { |
+ test('has one PolicyUi', function() { |
+ 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.
|
+ }); |
+ |
+ test('PolicyUi renders paper-cards', function() { |
+ var policyUi = document.querySelector('policy-ui'); |
+ expectTrue(exists('paper-card', policyUi)); |
+ }); |
+ }); |
+ |
+ suite('Functionality', function() { |
+ setup(function() { |
+ this.policyUi = document.querySelector('policy-ui'); |
+ }); |
+ |
+ test('PolicyUi loads introduction title', function() { |
+ expectTrue(this.policyUi.$.introduction.heading != ''); |
+ }); |
+ |
+ test('PolicyUi loads at least one group', function() { |
+ this.policyUi.setPolicyGroups(GROUP_NAMES); |
+ this.policyUi.setPolicyNames(createPolicyNames([POLICY.SAMPLE_A])); |
+ 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.
|
+ }); |
+ |
+ test('PolicyUi provides same methods as internal page', function() { |
+ expectTrue(typeof this.policyUi.setPolicyGroups === 'function'); |
+ expectTrue(typeof this.policyUi.setPolicyNames === 'function'); |
+ expectTrue(typeof this.policyUi.setPolicyValues === 'function'); |
+ expectTrue(typeof this.policyUi.setStatus === 'function'); |
+ }); |
+ |
+ // TODO(fhorschig): Move to separate async Test. |
+ test.skip('PolicyUi clears groups when names are loaded', function() { |
+ this.policyUi.setPolicyGroups(GROUP_NAMES); |
+ this.policyUi.setPolicyNames(createPolicyNames()); |
+ |
+ expectTrue(count('policy-group', this.policyUi) == 2); |
+ |
+ this.policyUi.setPolicyGroups([POLICY.SAMPLE_B.TAGS[0]]); |
+ this.policyUi.setPolicyNames(createPolicyNames([POLICY.SAMPLE_B])); |
+ |
+ expectTrue(count('policy-group', this.policyUi) == 1); |
+ }); |
+ |
+ // TODO(fhorschig): Move to separate async Test. |
+ test.skip('policies with multiple tags are in multiple groups', function() { |
+ this.policyUi.setPolicyGroups(GROUP_NAMES); |
+ this.policyUi.setPolicyNames(createPolicyNames()); |
+ |
+ expectTrue(groupContainsText(GROUP.ADMIN, POLICY.SAMPLE_A.NAME)); |
+ expectTrue(groupContainsText(GROUP.SECURITY, POLICY.SAMPLE_A.NAME)); |
+ }); |
+ }); |
+ |
+ mocha.run(); |
+}); |