Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 {ProtocolEntry} | |
|
dpapad
2016/11/14 18:26:20
Shouldn't this be !Array<!ProtocolEntry> ?
scottchen
2016/11/14 21:38:36
It should. Any idea why the closure_compiler didn'
dpapad
2016/11/14 21:54:09
Because none of our tests are compiled.
| |
| 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'). | |
|
dpapad
2016/11/14 18:26:20
Would that also work?
return browserProxy.whenCa
scottchen
2016/11/14 21:38:36
this worked:
browserProxy.whenCalled('initializePr
| |
| 80 then(function(){ Polymer.dom.flush();}); | |
| 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. | |
|
dpapad
2016/11/14 18:26:21
"!" is implied for string,number,boolean, since th
scottchen
2016/11/14 21:38:36
Done.
| |
| 118 * @param {!string} handler name of browserProxy handler to react. | |
| 119 * @return {!Promise} | |
| 120 */ | |
| 121 function testButtonFlow(button, handler) { | |
|
dpapad
2016/11/14 18:26:21
Given that that this file is testing "protocol han
scottchen
2016/11/14 21:38:36
Acknowledged.
| |
| 122 var menuButtons, functionButton, dialog; | |
| 123 | |
| 124 return initPage().then(function(){ | |
| 125 // Initiating the elements | |
| 126 menuButtons = testElement.root | |
| 127 .querySelectorAll('paper-icon-button'); | |
|
dpapad
2016/11/14 18:26:20
Nit: Dot operator on previous line.
scottchen
2016/11/14 21:38:36
Done.
| |
| 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 handler | |
| 133 MockInteractions.tap(menuButtons[0]); | |
| 134 assertTrue(dialog.open); | |
| 135 | |
| 136 MockInteractions.tap(functionButton); | |
| 137 | |
| 138 return browserProxy.whenCalled(handler) | |
|
dpapad
2016/11/14 18:26:20
Semicolon missing.
scottchen
2016/11/14 21:38:37
Done.
| |
| 139 }).then(function(args){ | |
|
dpapad
2016/11/14 18:26:21
Space missing after "(args)"
scottchen
2016/11/14 21:38:36
Done.
| |
| 140 /** | |
| 141 * handler is expected to be called with arguments | |
|
dpapad
2016/11/14 18:26:21
"/**" is used when adding JSDoc comments (@param,
scottchen
2016/11/14 21:38:36
Done.
| |
| 142 * as [protocol, url]. | |
| 143 */ | |
| 144 assertEquals(protocols[0].protocol, args[0]); | |
| 145 assertEquals(protocols[0].handlers[0].spec, args[1]); | |
| 146 | |
| 147 var dialog = testElement.$$('dialog[is=cr-action-menu]'); | |
| 148 assertFalse(dialog.open); | |
| 149 | |
| 150 // Test the button for the second handler | |
| 151 browserProxy.reset(); | |
| 152 MockInteractions.tap(menuButtons[1]); | |
| 153 assertTrue(dialog.open); | |
| 154 MockInteractions.tap(functionButton); | |
| 155 | |
| 156 return browserProxy.whenCalled(handler); | |
| 157 }).then(function(args) { | |
| 158 assertEquals(protocols[1].protocol, args[0]); | |
| 159 assertEquals(protocols[1].handlers[0].spec, args[1]); | |
| 160 }); | |
| 161 } | |
| 162 | |
| 163 test('remove button works', function() { | |
| 164 browserProxy.setProtocolHandlers(protocols); | |
| 165 return testButtonFlow('removeButton', 'removeProtocolHandler'); | |
| 166 }); | |
| 167 | |
| 168 test('default button works', function() { | |
| 169 browserProxy.setProtocolHandlers(protocols); | |
| 170 return testButtonFlow('defaultButton', 'setProtocolDefault'); | |
| 171 }); | |
| 172 }); | |
| 173 } | |
| 174 | |
| 175 return { | |
| 176 registerTests: registerTests, | |
| 177 }; | |
| 178 }); | |
| OLD | NEW |