Commit a46aab2f authored by dschuyler's avatar dschuyler Committed by Commit bot

[MD settings] split protocol handler tests from site tests

This CL separates the site settings protocol handler tests from the
site settings test. This is a step toward a code health todo in the
code.

(code health)
BUG=None

Review-Url: https://codereview.chromium.org/2855943004
Cr-Commit-Position: refs/heads/master@{#469039}
parent 5753d991
...@@ -805,7 +805,6 @@ CrSettingsSiteSettingsTest.prototype = { ...@@ -805,7 +805,6 @@ CrSettingsSiteSettingsTest.prototype = {
'test_site_settings_prefs_browser_proxy.js', 'test_site_settings_prefs_browser_proxy.js',
'zoom_levels_tests.js', 'zoom_levels_tests.js',
'usb_devices_tests.js', 'usb_devices_tests.js',
'protocol_handlers_tests.js',
'site_data_details_subpage_tests.js', 'site_data_details_subpage_tests.js',
]), ]),
}; };
...@@ -818,11 +817,34 @@ TEST_F('CrSettingsSiteSettingsTest', 'SiteSettings', function() { ...@@ -818,11 +817,34 @@ TEST_F('CrSettingsSiteSettingsTest', 'SiteSettings', function() {
site_list.registerTests(); site_list.registerTests();
zoom_levels.registerTests(); zoom_levels.registerTests();
usb_devices.registerTests(); usb_devices.registerTests();
protocol_handlers.registerTests();
mocha.run(); mocha.run();
}); });
/**
* @constructor
* @extends {CrSettingsBrowserTest}
*/
function CrSettingsProtocolHandlersTest() {}
CrSettingsProtocolHandlersTest.prototype = {
__proto__: CrSettingsBrowserTest.prototype,
/** @override */
browsePreload: 'chrome://md-settings/privacy_page/privacy_page.html',
/** @override */
extraLibraries: CrSettingsBrowserTest.prototype.extraLibraries.concat([
'test_browser_proxy.js',
'test_site_settings_prefs_browser_proxy.js',
'protocol_handlers_tests.js',
]),
};
TEST_F('CrSettingsProtocolHandlersTest', 'ProtocolHandlers', function() {
mocha.run();
});
/** /**
* @constructor * @constructor
* @extends {CrSettingsBrowserTest} * @extends {CrSettingsBrowserTest}
......
...@@ -3,122 +3,120 @@ ...@@ -3,122 +3,120 @@
// found in the LICENSE file. // found in the LICENSE file.
/** @fileoverview Suite of tests for protocol_handlers. */ /** @fileoverview Suite of tests for protocol_handlers. */
cr.define('protocol_handlers', function() { suite('ProtocolHandlers', function() {
function registerTests() { /**
suite('ProtocolHandlers', function() { * A dummy protocol handler element created before each test.
/** * @type {ProtocolHandlers}
* A dummy protocol handler element created before each test. */
* @type {ProtocolHandlers} var testElement;
*/
var testElement; /**
* A list of ProtocolEntry fixtures.
/** * @type {!Array<!ProtocolEntry>}
* A list of ProtocolEntry fixtures. */
* @type {!Array<!ProtocolEntry>} var protocols = [
*/ {
var protocols = [ default_handler: 0,
handlers: [{
host: 'www.google.com',
protocol: 'mailto',
spec: 'http://www.google.com/%s'
}],
has_policy_recommendations: false,
is_default_handler_set_by_user: true,
protocol: 'mailto'
},
{
default_handler: 0,
handlers: [
{ {
default_handler: 0, host: 'www.google1.com',
handlers: [ protocol: 'webcal',
{ spec: 'http://www.google1.com/%s'
host: 'www.google.com', },
protocol: 'mailto', {
spec: 'http://www.google.com/%s' host: 'www.google2.com',
} protocol: 'webcal',
], spec: 'http://www.google2.com/%s'
has_policy_recommendations: false,
is_default_handler_set_by_user: true,
protocol: 'mailto'
}, {
default_handler: 0,
handlers: [
{
host: 'www.google1.com',
protocol: 'webcal',
spec: 'http://www.google1.com/%s'
}, {
host: 'www.google2.com',
protocol: 'webcal',
spec: 'http://www.google2.com/%s'
}
],
has_policy_recommendations: false,
is_default_handler_set_by_user: true,
protocol: 'webcal'
} }
]; ],
has_policy_recommendations: false,
/** is_default_handler_set_by_user: true,
* The mock proxy object to use during test. protocol: 'webcal'
* @type {TestSiteSettingsPrefsBrowserProxy} }
*/ ];
var browserProxy = null;
/**
setup(function() { * The mock proxy object to use during test.
browserProxy = new TestSiteSettingsPrefsBrowserProxy(); * @type {TestSiteSettingsPrefsBrowserProxy}
settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; */
}); var browserProxy = null;
teardown(function() { setup(function() {
testElement.remove(); browserProxy = new TestSiteSettingsPrefsBrowserProxy();
testElement = null; settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy;
}); });
/** @return {!Promise} */ teardown(function() {
function initPage() { testElement.remove();
browserProxy.reset(); testElement = null;
PolymerTest.clearBody(); });
testElement = document.createElement('protocol-handlers');
document.body.appendChild(testElement); /** @return {!Promise} */
return browserProxy.whenCalled('observeProtocolHandlers'). function initPage() {
then(Polymer.dom.flush.bind(Polymer.dom)); browserProxy.reset();
} PolymerTest.clearBody();
testElement = document.createElement('protocol-handlers');
test('empty list', function() { document.body.appendChild(testElement);
return initPage().then(function(){ return browserProxy.whenCalled('observeProtocolHandlers')
var listFrames = testElement.root.querySelectorAll('.list-frame'); .then(Polymer.dom.flush.bind(Polymer.dom));
assertEquals(0, listFrames.length); }
});
}); test('empty list', function() {
return initPage().then(function() {
test('non-empty list', function() { var listFrames = testElement.root.querySelectorAll('.list-frame');
browserProxy.setProtocolHandlers(protocols); assertEquals(0, listFrames.length);
});
return initPage().then(function(){ });
var listFrames = testElement.root.querySelectorAll('.list-frame');
var listItems = testElement.root.querySelectorAll('.list-item'); test('non-empty list', function() {
// There are two protocols: ["mailto", "webcal"]. browserProxy.setProtocolHandlers(protocols);
assertEquals(2, listFrames.length);
// There are three total handlers within the two protocols. return initPage().then(function() {
assertEquals(3, listItems.length); var listFrames = testElement.root.querySelectorAll('.list-frame');
var listItems = testElement.root.querySelectorAll('.list-item');
// Check that item hosts are rendered correctly. // There are two protocols: ["mailto", "webcal"].
var hosts = testElement.root.querySelectorAll('.protocol-host'); assertEquals(2, listFrames.length);
assertEquals('www.google.com', hosts[0].textContent); // There are three total handlers within the two protocols.
assertEquals('www.google1.com', hosts[1].textContent); assertEquals(3, listItems.length);
assertEquals('www.google2.com', hosts[2].textContent);
// Check that item hosts are rendered correctly.
// Check that item default subtexts are rendered correctly. var hosts = testElement.root.querySelectorAll('.protocol-host');
var defText = testElement.root.querySelectorAll('.protocol-default'); assertEquals('www.google.com', hosts[0].textContent);
assertFalse(defText[0].hidden); assertEquals('www.google1.com', hosts[1].textContent);
assertFalse(defText[1].hidden); assertEquals('www.google2.com', hosts[2].textContent);
assertTrue(defText[2].hidden);
}); // Check that item default subtexts are rendered correctly.
}); var defText = testElement.root.querySelectorAll('.protocol-default');
assertFalse(defText[0].hidden);
/** assertFalse(defText[1].hidden);
* A reusable function to test different action buttons. assertTrue(defText[2].hidden);
* @param {string} button id of the button to test. });
* @param {string} handler name of browserProxy handler to react. });
* @return {!Promise}
*/ /**
function testButtonFlow(button, browserProxyHandler) { * A reusable function to test different action buttons.
var menuButtons, functionButton, dialog; * @param {string} button id of the button to test.
* @param {string} handler name of browserProxy handler to react.
return initPage().then(function(){ * @return {!Promise}
*/
function testButtonFlow(button, browserProxyHandler) {
var menuButtons, functionButton, dialog;
return initPage()
.then(function() {
// Initiating the elements // Initiating the elements
menuButtons = testElement.root. menuButtons = testElement.root.querySelectorAll('paper-icon-button');
querySelectorAll('paper-icon-button');
functionButton = testElement.$[button]; functionButton = testElement.$[button];
dialog = testElement.$$('dialog[is=cr-action-menu]'); dialog = testElement.$$('dialog[is=cr-action-menu]');
assertEquals(3, menuButtons.length); assertEquals(3, menuButtons.length);
...@@ -130,7 +128,8 @@ cr.define('protocol_handlers', function() { ...@@ -130,7 +128,8 @@ cr.define('protocol_handlers', function() {
MockInteractions.tap(functionButton); MockInteractions.tap(functionButton);
return browserProxy.whenCalled(browserProxyHandler); return browserProxy.whenCalled(browserProxyHandler);
}).then(function(args) { })
.then(function(args) {
// BrowserProxy's handler is expected to be called with arguments as // BrowserProxy's handler is expected to be called with arguments as
// [protocol, url]. // [protocol, url].
assertEquals(protocols[0].protocol, args[0]); assertEquals(protocols[0].protocol, args[0]);
...@@ -146,25 +145,20 @@ cr.define('protocol_handlers', function() { ...@@ -146,25 +145,20 @@ cr.define('protocol_handlers', function() {
MockInteractions.tap(functionButton); MockInteractions.tap(functionButton);
return browserProxy.whenCalled(browserProxyHandler); return browserProxy.whenCalled(browserProxyHandler);
}).then(function(args) { })
.then(function(args) {
assertEquals(protocols[1].protocol, args[0]); assertEquals(protocols[1].protocol, args[0]);
assertEquals(protocols[1].handlers[0].spec, args[1]); assertEquals(protocols[1].handlers[0].spec, args[1]);
}); });
}
test('remove button works', function() {
browserProxy.setProtocolHandlers(protocols);
return testButtonFlow('removeButton', 'removeProtocolHandler');
});
test('default button works', function() {
browserProxy.setProtocolHandlers(protocols);
return testButtonFlow('defaultButton', 'setProtocolDefault');
});
});
} }
return { test('remove button works', function() {
registerTests: registerTests, browserProxy.setProtocolHandlers(protocols);
}; return testButtonFlow('removeButton', 'removeProtocolHandler');
});
test('default button works', function() {
browserProxy.setProtocolHandlers(protocols);
return testButtonFlow('defaultButton', 'setProtocolDefault');
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment