Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Side by Side Diff: chrome/test/data/webui/settings/protocol_handlers_tests.js

Issue 2500513003: Make setting's protocol handler use cr-action-menu instead of paper-item. (Closed)
Patch Set: fix return type of boolean function Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 /** @fileoverview Suite of tests for protocol_handlers. */
6 cr.define('protocol_handlers', function() {
7 function registerTests() {
8 suite('ProtocolHandlers', function() {
9 /**
10 * A dummy protocol handler element created before each test.
11 * @type {ProtocolHandlers}
12 */
13 var testElement;
14
15 /**
16 * A list of ProtocolEntry fixtures.
17 * @type {!Array<!ProtocolEntry>}
18 */
19 var protocols = [
20 {
21 default_handler: 0,
22 handlers: [
23 {
24 host: 'www.google.com',
25 protocol: 'mailto',
26 spec: 'http://www.google.com/%s'
27 }
28 ],
29 has_policy_recommendations: false,
30 is_default_handler_set_by_user: true,
31 protocol: 'mailto'
32 }, {
33 default_handler: 0,
34 handlers: [
35 {
36 host: 'www.google1.com',
37 protocol: 'webcal',
38 spec: 'http://www.google1.com/%s'
39 }, {
40 host: 'www.google2.com',
41 protocol: 'webcal',
42 spec: 'http://www.google2.com/%s'
43 }
44 ],
45 has_policy_recommendations: false,
46 is_default_handler_set_by_user: true,
47 protocol: 'webcal'
48 }
49 ];
50
51 /**
52 * The mock proxy object to use during test.
53 * @type {TestSiteSettingsPrefsBrowserProxy}
54 */
55 var browserProxy = null;
56
57 // Import necessary html before running suite.
58 suiteSetup(function() {
59 return PolymerTest.importHtml(
60 'chrome://md-settings/site_settings/protocol_handlers.html');
61 });
62
63 setup(function() {
64 browserProxy = new TestSiteSettingsPrefsBrowserProxy();
65 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy;
66 });
67
68 teardown(function() {
69 testElement.remove();
70 testElement = null;
71 });
72
73 /** @return {!Promise} */
74 function initPage() {
75 browserProxy.reset();
76 PolymerTest.clearBody();
77 testElement = document.createElement('protocol-handlers');
78 document.body.appendChild(testElement);
79 return browserProxy.whenCalled('initializeProtocolHandlerList').
80 then(Polymer.dom.flush.bind(Polymer.dom));
81 }
82
83 test('empty list', function() {
84 return initPage().then(function(){
85 var listFrames = testElement.root.querySelectorAll('.list-frame');
86 assertEquals(0, listFrames.length);
87 });
88 });
89
90 test('non-empty list', function() {
91 browserProxy.setProtocolHandlers(protocols);
92
93 return initPage().then(function(){
94 var listFrames = testElement.root.querySelectorAll('.list-frame');
95 var listItems = testElement.root.querySelectorAll('.list-item');
96 // There are two protocols: ["mailto", "webcal"].
97 assertEquals(2, listFrames.length);
98 // There are three total handlers within the two protocols.
99 assertEquals(3, listItems.length);
100
101 // Check that item hosts are rendered correctly.
102 var hosts = testElement.root.querySelectorAll('.protocol-host');
103 assertEquals('www.google.com', hosts[0].textContent);
104 assertEquals('www.google1.com', hosts[1].textContent);
105 assertEquals('www.google2.com', hosts[2].textContent);
106
107 // Check that item default subtexts are rendered correctly.
108 var defText = testElement.root.querySelectorAll('.protocol-default');
109 assertFalse(defText[0].hidden);
110 assertFalse(defText[1].hidden);
111 assertTrue(defText[2].hidden);
112 });
113 });
114
115 /**
116 * A reusable function to test different action buttons.
117 * @param {!string} button id of the button to test.
118 * @param {!string} handler name of browserProxy handler to react.
119 * @return {!Promise}
120 */
121 function testButtonFlow(button, browserProxyHandler) {
122 var menuButtons, functionButton, dialog;
123
124 return initPage().then(function(){
125 // Initiating the elements
126 menuButtons = testElement.root.
127 querySelectorAll('paper-icon-button');
128 functionButton = testElement.$[button];
129 dialog = testElement.$$('dialog[is=cr-action-menu]');
130 assertEquals(3, menuButtons.length);
131
132 // Test the button for the first protocol handler
133 MockInteractions.tap(menuButtons[0]);
134 assertTrue(dialog.open);
135
136 MockInteractions.tap(functionButton);
137
138 return browserProxy.whenCalled(browserProxyHandler);
139 }).then(function(args) {
140 // BrowserProxy's handler is expected to be called with arguments as
141 // [protocol, url].
142 assertEquals(protocols[0].protocol, args[0]);
143 assertEquals(protocols[0].handlers[0].spec, args[1]);
144
145 var dialog = testElement.$$('dialog[is=cr-action-menu]');
146 assertFalse(dialog.open);
147
148 // Test the button for the second protocol handler
149 browserProxy.reset();
150 MockInteractions.tap(menuButtons[1]);
151 assertTrue(dialog.open);
152 MockInteractions.tap(functionButton);
153
154 return browserProxy.whenCalled(browserProxyHandler);
155 }).then(function(args) {
156 assertEquals(protocols[1].protocol, args[0]);
157 assertEquals(protocols[1].handlers[0].spec, args[1]);
158 });
159 }
160
161 test('remove button works', function() {
162 browserProxy.setProtocolHandlers(protocols);
163 return testButtonFlow('removeButton', 'removeProtocolHandler');
164 });
165
166 test('default button works', function() {
167 browserProxy.setProtocolHandlers(protocols);
168 return testButtonFlow('defaultButton', 'setProtocolDefault');
169 });
170 });
171 }
172
173 return {
174 registerTests: registerTests,
175 };
176 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698