Commit 91f96019 authored by Scott Chen's avatar Scott Chen Committed by Commit Bot

MD Extension: Refactor browser tests.

- Removes unnecessary registerTests()
- Breaks down CrExtensionBrowserTest to smaller sub-classes so test files are included as needed, instead of loading all test files in each TEST_F. (This reduced the generated .cc file from 25XX lines to 16XX lines).
- Allow (in the future) each sub-classes to specify a more specific browserPreload url instead of always loading the entire page.

Bug: 750842
Change-Id: I9e178728724f41c63e59b4edc81589b4366c9df9
Reviewed-on: https://chromium-review.googlesource.com/595188
Commit-Queue: Scott Chen <scottchen@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491847}
parent e83863fb
......@@ -9,7 +9,6 @@ cr.define('extension_code_section_tests', function() {
Layout: 'layout',
};
function registerTests() {
suite('ExtensionCodeSectionTest', function() {
/** @type {chrome.developerPrivate.RequestFileSourceResponse} */
var code = {
......@@ -39,8 +38,7 @@ cr.define('extension_code_section_tests', function() {
test(assert(TestNames.Layout), function() {
Polymer.dom.flush();
var testIsVisible =
extension_test_util.isVisible.bind(null, codeSection);
var testIsVisible = extension_test_util.isVisible.bind(null, codeSection);
expectFalse(!!codeSection.code);
expectTrue(codeSection.isEmpty());
expectTrue(codeSection.$$('#main').hidden);
......@@ -59,14 +57,12 @@ cr.define('extension_code_section_tests', function() {
var highlightSpan = codeSection.$$('.highlight');
expectEquals(code.highlight, highlightSpan.textContent);
expectEquals(code.message, highlightSpan.title);
expectEquals('1\n2\n3\n4',
codeSection.$['line-numbers'].textContent.trim());
expectEquals(
'1\n2\n3\n4', codeSection.$['line-numbers'].textContent.trim());
});
});
}
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -10,7 +10,6 @@ cr.define('extension_detail_view_tests', function() {
ClickableElements: 'clickable elements',
};
function registerTests() {
suite('ExtensionItemTest', function() {
/**
* Extension item created before each test.
......@@ -87,23 +86,22 @@ cr.define('extension_detail_view_tests', function() {
}
expectFalse(testIsVisible('#dependent-extensions-list'));
item.set('data.dependentExtensions',
[{id: 'aaa', name: 'Dependent1'},
{id: 'bbb', name: 'Dependent2'}]);
item.set(
'data.dependentExtensions',
[{id: 'aaa', name: 'Dependent1'}, {id: 'bbb', name: 'Dependent2'}]);
Polymer.dom.flush();
expectTrue(testIsVisible('#dependent-extensions-list'));
expectEquals(2,
item.$$('#dependent-extensions-list').querySelectorAll(
'li').length);
expectEquals(
2,
item.$$('#dependent-extensions-list').querySelectorAll('li').length);
expectFalse(testIsVisible('#permissions-list'));
expectTrue(testIsVisible('#no-permissions'));
item.set('data.permissions', ['Permission 1', 'Permission 2']);
Polymer.dom.flush();
expectTrue(testIsVisible('#permissions-list'));
expectEquals(2,
item.$$('#permissions-list').querySelectorAll('li').
length);
expectEquals(
2, item.$$('#permissions-list').querySelectorAll('li').length);
expectFalse(testIsVisible('#no-permissions'));
var optionsUrl =
......@@ -144,14 +142,11 @@ cr.define('extension_detail_view_tests', function() {
item.$$('#extensions-options'), 'showItemOptionsPage',
[extensionData.id]);
mockDelegate.testClickingCalls(
item.$$('#remove-extension'), 'deleteItem',
[extensionData.id]);
item.$$('#remove-extension'), 'deleteItem', [extensionData.id]);
});
});
}
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -32,7 +32,6 @@ cr.define('extension_error_page_tests', function() {
},
};
function registerTests() {
suite('ExtensionErrorPageTest', function() {
/** @type {chrome.developerPrivate.ExtensionInfo} */
var extensionData;
......@@ -66,12 +65,14 @@ cr.define('extension_error_page_tests', function() {
// Initialize an extension item before each test.
setup(function() {
PolymerTest.clearBody();
var runtimeError = Object.assign({
var runtimeError = Object.assign(
{
source: 'chrome-extension://' + extensionId + '/source.html',
message: 'message',
id: 1,
severity: chrome.developerPrivate.ErrorLevel.ERROR,
}, runtimeErrorBase);
},
runtimeErrorBase);
extensionData = extension_test_util.createExtensionInfo({
runtimeErrors: [runtimeError],
manifestErrors: [],
......@@ -97,17 +98,18 @@ cr.define('extension_error_page_tests', function() {
expectEquals(1, errorElements.length);
var error = errorElements[0];
expectEquals(
'message',
error.querySelector('.error-message').textContent.trim());
expectTrue(error.querySelector('img').classList.contains(
'icon-severity-fatal'));
'message', error.querySelector('.error-message').textContent.trim());
expectTrue(
error.querySelector('img').classList.contains('icon-severity-fatal'));
var manifestError = Object.assign({
var manifestError = Object.assign(
{
source: 'manifest.json',
message: 'invalid key',
id: 2,
manifestKey: 'permissions',
}, manifestErrorBase);
},
manifestErrorBase);
errorPage.set('data.manifestErrors', [manifestError]);
Polymer.dom.flush();
errorElements = errorPage.querySelectorAll('* /deep/ .error-item');
......@@ -149,12 +151,14 @@ cr.define('extension_error_page_tests', function() {
});
test(assert(TestNames.ErrorSelection), function() {
var nextRuntimeError = Object.assign({
var nextRuntimeError = Object.assign(
{
source: 'chrome-extension://' + extensionId + '/other_source.html',
message: 'Other error',
id: 2,
severity: chrome.developerPrivate.ErrorLevel.ERROR,
}, runtimeErrorBase);
},
runtimeErrorBase);
// Add a new runtime error to the end.
errorPage.push('data.runtimeErrors', nextRuntimeError);
Polymer.dom.flush();
......@@ -182,10 +186,8 @@ cr.define('extension_error_page_tests', function() {
expectEquals('other_source.html', args.pathSuffix);
});
});
}
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -11,7 +11,6 @@ cr.define('extension_item_list_tests', function() {
ItemListNoSearchResultsMsg: 'empty item list filtering results',
};
function registerTests() {
suite('ExtensionItemListTest', function() {
/** @type {extensions.ItemList} */
var itemList;
......@@ -28,10 +27,11 @@ cr.define('extension_item_list_tests', function() {
testVisible = extension_test_util.testVisible.bind(null, itemList);
var createExt = extension_test_util.createExtensionInfo;
var items =
[createExt({name: 'Alpha', id: 'a'.repeat(32)}),
var items = [
createExt({name: 'Alpha', id: 'a'.repeat(32)}),
createExt({name: 'Bravo', id: 'b'.repeat(32)}),
createExt({name: 'Charlie', id: 'c'.repeat(32)})];
createExt({name: 'Charlie', id: 'c'.repeat(32)})
];
itemList.items = items;
itemList.filter = '';
document.body.appendChild(itemList);
......@@ -84,10 +84,8 @@ cr.define('extension_item_list_tests', function() {
testVisible('#no-search-results', true);
});
});
}
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -75,7 +75,6 @@ cr.define('extension_item_tests', function() {
RemoveButton: 'remove button hidden when necessary',
};
function registerTests() {
suite('ExtensionItemTest', function() {
/**
* Extension item created before each test.
......@@ -130,18 +129,18 @@ cr.define('extension_item_tests', function() {
mockDelegate.testClickingCalls(
item.$['enable-toggle'], 'setItemEnabled', [item.data.id, false]);
mockDelegate.testClickingCalls(
item.$$('#inspect-views a[is="action-link"]'),
'inspectItemView', [item.data.id, item.data.views[0]]);
item.$$('#inspect-views a[is="action-link"]'), 'inspectItemView',
[item.data.id, item.data.views[0]]);
var listener1 = new extension_test_util.ListenerMock();
listener1.addListener(item, 'extension-item-show-details',
{data: item.data});
listener1.addListener(
item, 'extension-item-show-details', {data: item.data});
MockInteractions.tap(item.$$('#details-button'));
listener1.verify();
var listener2 = new extension_test_util.ListenerMock();
listener2.addListener(item, 'extension-item-show-details',
{data: item.data});
listener2.addListener(
item, 'extension-item-show-details', {data: item.data});
MockInteractions.tap(
item.$$('#inspect-views a[is="action-link"]:nth-of-type(2)'));
listener2.verify();
......@@ -251,10 +250,8 @@ cr.define('extension_item_tests', function() {
expectTrue(item.$['remove-button'].hidden);
});
});
}
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -12,7 +12,6 @@ cr.define('extension_keyboard_shortcut_tests', function() {
ShortcutUtil: 'ExtensionShortcutUtilTest',
};
function registerTests() {
suite('ExtensionKeyboardShortcutTest', function() {
/** @type {extensions.KeyboardShortcuts} */
var keyboardShortcuts;
......@@ -42,21 +41,24 @@ cr.define('extension_keyboard_shortcut_tests', function() {
});
twoCommands = createInfo({
id: 'c'.repeat(32),
commands: [{
commands: [
{
description: 'Another Description',
keybinding: 'Alt+F4',
name: 'cCommand',
isActive: true,
scope: 'GLOBAL',
isExtensionAction: false,
}, {
},
{
description: 'Yet Another Description',
keybinding: '',
name: 'cCommand2',
isActive: false,
scope: 'CHROME',
isExtensionAction: false,
}]
}
]
});
keyboardShortcuts.set('items', [noCommands, oneCommand, twoCommands]);
......@@ -77,8 +79,8 @@ cr.define('extension_keyboard_shortcut_tests', function() {
assertEquals(2, cards.length);
var card1 = cards[0];
expectEquals(oneCommand.name,
card1.querySelector('.card-title span').textContent);
expectEquals(
oneCommand.name, card1.querySelector('.card-title span').textContent);
var commands = card1.querySelectorAll('.command-entry');
assertEquals(1, commands.length);
expectTrue(isVisibleOnCard(commands[0], '.command-name'));
......@@ -89,6 +91,7 @@ cr.define('extension_keyboard_shortcut_tests', function() {
assertEquals(2, commands.length);
});
});
suite(assert(TestNames.ShortcutUtil), function() {
test('isValidKeyCode test', function() {
expectTrue(extensions.isValidKeyCode('A'.charCodeAt(0)));
......@@ -117,10 +120,8 @@ cr.define('extension_keyboard_shortcut_tests', function() {
expectEquals('Ctrl+Shift+A', extensions.keystrokeToString(e));
});
});
}
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -24,7 +24,6 @@ cr.define('extension_load_error_tests', function() {
retryLoadUnpacked: function() {},
};
function registerTests() {
suite('ExtensionLoadErrorTests', function() {
/** @type {extensions.LoadError} */
var loadError;
......@@ -85,10 +84,8 @@ cr.define('extension_load_error_tests', function() {
expectFalse(loadError.$.code.isEmpty());
});
});
}
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -18,7 +18,6 @@ cr.define('extension_manager_tests', function() {
return assert(list.find(function(el) { return el.name == name; }));
}
function registerTests() {
suite('ExtensionManagerTest', function() {
/** @type {extensions.Manager} */
var manager;
......@@ -198,10 +197,8 @@ cr.define('extension_manager_tests', function() {
});
});
}
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -24,7 +24,6 @@ cr.define('extension_navigation_helper_tests', function() {
});
}
function registerTests() {
suite('ExtensionNavigationHelperTest', function() {
setup(function() {
PolymerTest.clearBody();
......@@ -39,8 +38,7 @@ cr.define('extension_navigation_helper_tests', function() {
};
var navigationHelper = new extensions.NavigationHelper(changePage);
expectEquals('chrome://extensions/navigation_helper.html',
location.href);
expectEquals('chrome://extensions/navigation_helper.html', location.href);
expectDeepEquals({page: Page.LIST}, navigationHelper.getCurrentPage());
var currentLength = history.length;
......@@ -53,14 +51,16 @@ cr.define('extension_navigation_helper_tests', function() {
mock.addExpectation({page: Page.DETAILS, extensionId: id});
var waitForPop = getOnPopState();
history.back();
return waitForPop.then(() => {
return waitForPop
.then(() => {
mock.verifyMock();
mock.addExpectation({page: Page.LIST});
var waitForNextPop = getOnPopState();
history.back();
return waitForNextPop;
}).then(() => {
})
.then(() => {
mock.verifyMock();
});
});
......@@ -151,10 +151,8 @@ cr.define('extension_navigation_helper_tests', function() {
expectEquals(++expectedLength, history.length);
});
});
}
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -15,7 +15,6 @@ cr.define('extension_options_dialog_tests', function() {
var MIN_HEIGHT = '300px';
var MIN_WIDTH = '300px';
function registerTests() {
suite('ExtensionOptionsDialogTests', function() {
/** @type {extensions.OptionsDialog} */
var optionsDialog;
......@@ -43,8 +42,8 @@ cr.define('extension_options_dialog_tests', function() {
expectTrue(isDialogVisible());
expectEquals(
data.name,
assert(optionsDialog.$$('#icon-and-name-wrapper span')).
textContent.trim());
assert(optionsDialog.$$('#icon-and-name-wrapper span'))
.textContent.trim());
var optionEle = optionsDialog.$$('extensionoptions');
......@@ -76,16 +75,15 @@ cr.define('extension_options_dialog_tests', function() {
expectFalse(isDialogVisible());
// Try showing a second extension with a longer name.
var secondExtension = extension_test_util.createExtensionInfo({
name: 'Super long named extension for the win'
});
var secondExtension = extension_test_util.createExtensionInfo(
{name: 'Super long named extension for the win'});
optionsDialog.show(secondExtension);
expectTrue(isDialogVisible());
expectEquals(secondExtension.id, mockOptions.extension);
expectEquals(
secondExtension.name,
assert(optionsDialog.$$('#icon-and-name-wrapper span')).
textContent.trim());
assert(optionsDialog.$$('#icon-and-name-wrapper span'))
.textContent.trim());
// The width of the dialog should be set to match the width of the
// header, which is greater than the default min width.
expectTrue(optionsDialog.$.dialog.style.width > MIN_WIDTH);
......@@ -99,10 +97,8 @@ cr.define('extension_options_dialog_tests', function() {
expectEquals(MIN_WIDTH, optionEle.style.width);
});
});
}
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -52,7 +52,6 @@ cr.define('extension_pack_dialog_tests', function() {
return rect.width * rect.height > 0;
};
function registerTests() {
suite('ExtensionPackDialogTests', function() {
/** @type {extensions.PackDialog} */
var packDialog;
......@@ -216,10 +215,8 @@ cr.define('extension_pack_dialog_tests', function() {
});
});
});
}
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -66,7 +66,6 @@ cr.define('extension_service_tests', function() {
ProfileSettings: 'profile settings',
};
function registerTests() {
suite('ExtensionServiceTest', function() {
/** @const{string} */
var kExtensionId = 'ldnnhddmnhbkjipkidpdiheffobcpfmf';
......@@ -84,9 +83,10 @@ cr.define('extension_service_tests', function() {
var manager;
var getItemData = function(id) {
var elMatches = function(el) { return el.id == id; };
return manager.extensions.find(elMatches) ||
manager.apps.find(elMatches);
var elMatches = function(el) {
return el.id == id;
};
return manager.extensions.find(elMatches) || manager.apps.find(elMatches);
};
suiteSetup(function() {
......@@ -109,9 +109,10 @@ cr.define('extension_service_tests', function() {
var disabledListener =
new ItemChangedListener(kExtensionId, EventType.UNLOADED);
service.setItemEnabled(kExtensionId, false);
disabledListener.onUpdate.then(function() {
// Note: we need to re-get the item since the object in the manager's
// collection was replaced, rather than updated.
disabledListener.onUpdate
.then(function() {
// Note: we need to re-get the item since the object in the
// manager's collection was replaced, rather than updated.
var item = getItemData(kExtensionId);
assertTrue(!!item);
expectEquals(ExtensionState.DISABLED, item.state);
......@@ -120,7 +121,8 @@ cr.define('extension_service_tests', function() {
new ItemChangedListener(kExtensionId, EventType.LOADED);
service.setItemEnabled(kExtensionId, true);
return enabledListener.onUpdate;
}).then(function() {
})
.then(function() {
var item = getItemData(kExtensionId);
assertTrue(!!item);
expectEquals(ExtensionState.ENABLED, item.state);
......@@ -139,7 +141,8 @@ cr.define('extension_service_tests', function() {
chrome.test.runWithUserGesture(function() {
service.setItemAllowedIncognito(kExtensionId, true);
});
incognitoListener.onUpdate.then(function() {
incognitoListener.onUpdate
.then(function() {
var item = getItemData(kExtensionId);
assertTrue(!!item);
expectTrue(item.incognitoAccess.isActive);
......@@ -150,7 +153,8 @@ cr.define('extension_service_tests', function() {
service.setItemAllowedIncognito(kExtensionId, false);
});
return disabledIncognitoListener.onUpdate;
}).then(function() {
})
.then(function() {
var item = getItemData(kExtensionId);
assertTrue(!!item);
expectFalse(item.incognitoAccess.isActive);
......@@ -178,23 +182,23 @@ cr.define('extension_service_tests', function() {
var profileListener = new ProfileChangedListener();
service.setProfileInDevMode(true);
profileListener.onUpdate.then(function() {
profileListener.onUpdate
.then(function() {
expectTrue(manager.inDevMode);
var noDevModeProfileListener = new ProfileChangedListener();
service.setProfileInDevMode(false);
return noDevModeProfileListener.onUpdate;
}).then(function() {
})
.then(function() {
expectFalse(manager.inDevMode);
done();
});
});
});
}
return {
ChangeListener: ChangeListener,
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -9,7 +9,6 @@ cr.define('extension_shortcut_input_tests', function() {
Basic: 'basic',
};
function registerTests() {
suite('ExtensionShortcutInputTest', function() {
/** @type {extensions.ShortcutInput} */
var input;
......@@ -24,10 +23,12 @@ cr.define('extension_shortcut_input_tests', function() {
test(assert(TestNames.Basic), function() {
var field = input.$['input'];
var fieldText = function() { return field.value; };
var fieldText = function() {
return field.value;
};
expectEquals('', fieldText());
var isClearVisible = extension_test_util.isVisible.bind(
null, input, '#clear', false);
var isClearVisible =
extension_test_util.isVisible.bind(null, input, '#clear', false);
expectFalse(isClearVisible());
// Click the input. Capture should start.
......@@ -64,10 +65,9 @@ cr.define('extension_shortcut_input_tests', function() {
// Add 'A'. Once a valid shortcut is typed (like Ctrl+A), it is
// committed.
let updatedListener = new extension_test_util.ListenerMock();
updatedListener.addListener(input, 'shortcut-updated',
{keybinding: 'Ctrl+A',
item: 'itemid',
commandName: 'Command'});
updatedListener.addListener(
input, 'shortcut-updated',
{keybinding: 'Ctrl+A', item: 'itemid', commandName: 'Command'});
updatedListener.addListener(input, 'shortcut-capture-ended');
MockInteractions.keyDownOn(field, 65, ['ctrl']);
updatedListener.verify();
......@@ -80,10 +80,9 @@ cr.define('extension_shortcut_input_tests', function() {
{
// Test clearing the shortcut.
let updatedListener = new extension_test_util.ListenerMock();
updatedListener.addListener(input, 'shortcut-updated',
{keybinding: '',
item: 'itemid',
commandName: 'Command'});
updatedListener.addListener(
input, 'shortcut-updated',
{keybinding: '', item: 'itemid', commandName: 'Command'});
MockInteractions.tap(input.$['clear']);
updatedListener.verify();
}
......@@ -102,10 +101,8 @@ cr.define('extension_shortcut_input_tests', function() {
}
});
});
}
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -27,7 +27,6 @@ cr.define('extension_sidebar_tests', function() {
LayoutAndClickHandlers: 'layout and click handlers',
};
function registerTests() {
suite('ExtensionSidebarTest', function() {
/** @type {MockDelegate} */
var mockDelegate;
......@@ -67,10 +66,8 @@ cr.define('extension_sidebar_tests', function() {
sidebar.$$('#sections-shortcuts'), 'showKeyboardShortcuts', []);
});
});
}
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -31,7 +31,6 @@ cr.define('extension_toolbar_tests', function() {
ClickHandlers: 'click handlers',
};
function registerTests() {
suite('ExtensionToolbarTest', function() {
/** @type {MockDelegate} */
var mockDelegate;
......@@ -68,11 +67,9 @@ cr.define('extension_toolbar_tests', function() {
Polymer.dom.flush();
mockDelegate.testClickingCalls(
toolbar.$['dev-mode'], 'setProfileInDevMode',
[false]);
toolbar.$['dev-mode'], 'setProfileInDevMode', [false]);
mockDelegate.testClickingCalls(
toolbar.$['dev-mode'], 'setProfileInDevMode',
[true]);
toolbar.$['dev-mode'], 'setProfileInDevMode', [true]);
mockDelegate.testClickingCalls(
toolbar.$$('#load-unpacked'), 'loadUnpacked', []);
mockDelegate.testClickingCalls(
......@@ -84,10 +81,8 @@ cr.define('extension_toolbar_tests', function() {
listener.verify();
});
});
}
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
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