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,64 +9,60 @@ cr.define('extension_code_section_tests', function() {
Layout: 'layout',
};
function registerTests() {
suite('ExtensionCodeSectionTest', function() {
/** @type {chrome.developerPrivate.RequestFileSourceResponse} */
var code = {
beforeHighlight: 'this part before the highlight\nAnd this too\n',
highlight: 'highlight this part\n',
afterHighlight: 'this part after the highlight\n',
message: 'Highlight message',
};
suite('ExtensionCodeSectionTest', function() {
/** @type {chrome.developerPrivate.RequestFileSourceResponse} */
var code = {
beforeHighlight: 'this part before the highlight\nAnd this too\n',
highlight: 'highlight this part\n',
afterHighlight: 'this part after the highlight\n',
message: 'Highlight message',
};
/** @type {extensions.CodeSection} */
var codeSection;
/** @type {extensions.CodeSection} */
var codeSection;
var couldNotDisplayCode = 'No code here';
var couldNotDisplayCode = 'No code here';
suiteSetup(function() {
return PolymerTest.importHtml('chrome://extensions/code_section.html');
});
suiteSetup(function() {
return PolymerTest.importHtml('chrome://extensions/code_section.html');
});
// Initialize an extension item before each test.
setup(function() {
PolymerTest.clearBody();
codeSection = new extensions.CodeSection();
codeSection.couldNotDisplayCode = couldNotDisplayCode;
document.body.appendChild(codeSection);
});
// Initialize an extension item before each test.
setup(function() {
PolymerTest.clearBody();
codeSection = new extensions.CodeSection();
codeSection.couldNotDisplayCode = couldNotDisplayCode;
document.body.appendChild(codeSection);
});
test(assert(TestNames.Layout), function() {
Polymer.dom.flush();
test(assert(TestNames.Layout), function() {
Polymer.dom.flush();
var testIsVisible =
extension_test_util.isVisible.bind(null, codeSection);
expectFalse(!!codeSection.code);
expectTrue(codeSection.isEmpty());
expectTrue(codeSection.$$('#main').hidden);
expectFalse(testIsVisible('#main'));
expectTrue(testIsVisible('#no-code'));
expectEquals('', codeSection.$['line-numbers'].textContent.trim());
var testIsVisible = extension_test_util.isVisible.bind(null, codeSection);
expectFalse(!!codeSection.code);
expectTrue(codeSection.isEmpty());
expectTrue(codeSection.$$('#main').hidden);
expectFalse(testIsVisible('#main'));
expectTrue(testIsVisible('#no-code'));
expectEquals('', codeSection.$['line-numbers'].textContent.trim());
codeSection.code = code;
expectTrue(testIsVisible('#main'));
expectFalse(testIsVisible('#no-code'));
codeSection.code = code;
expectTrue(testIsVisible('#main'));
expectFalse(testIsVisible('#no-code'));
var fullSpan = codeSection.$$('#source span');
expectEquals(
code.beforeHighlight + code.highlight + code.afterHighlight,
fullSpan.textContent);
var highlightSpan = codeSection.$$('.highlight');
expectEquals(code.highlight, highlightSpan.textContent);
expectEquals(code.message, highlightSpan.title);
expectEquals('1\n2\n3\n4',
codeSection.$['line-numbers'].textContent.trim());
});
var fullSpan = codeSection.$$('#source span');
expectEquals(
code.beforeHighlight + code.highlight + code.afterHighlight,
fullSpan.textContent);
var highlightSpan = codeSection.$$('.highlight');
expectEquals(code.highlight, highlightSpan.textContent);
expectEquals(code.message, highlightSpan.title);
expectEquals(
'1\n2\n3\n4', codeSection.$['line-numbers'].textContent.trim());
});
}
});
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -11,83 +11,81 @@ cr.define('extension_item_list_tests', function() {
ItemListNoSearchResultsMsg: 'empty item list filtering results',
};
function registerTests() {
suite('ExtensionItemListTest', function() {
/** @type {extensions.ItemList} */
var itemList;
var testVisible;
suite('ExtensionItemListTest', function() {
/** @type {extensions.ItemList} */
var itemList;
var testVisible;
suiteSetup(function() {
return PolymerTest.importHtml('chrome://extensions/item-list.html');
});
suiteSetup(function() {
return PolymerTest.importHtml('chrome://extensions/item-list.html');
});
// Initialize an extension item before each test.
setup(function() {
PolymerTest.clearBody();
itemList = new extensions.ItemList();
testVisible = extension_test_util.testVisible.bind(null, itemList);
// Initialize an extension item before each test.
setup(function() {
PolymerTest.clearBody();
itemList = new extensions.ItemList();
testVisible = extension_test_util.testVisible.bind(null, itemList);
var createExt = extension_test_util.createExtensionInfo;
var items =
[createExt({name: 'Alpha', id: 'a'.repeat(32)}),
createExt({name: 'Bravo', id: 'b'.repeat(32)}),
createExt({name: 'Charlie', id: 'c'.repeat(32)})];
itemList.items = items;
itemList.filter = '';
document.body.appendChild(itemList);
});
var createExt = extension_test_util.createExtensionInfo;
var items = [
createExt({name: 'Alpha', id: 'a'.repeat(32)}),
createExt({name: 'Bravo', id: 'b'.repeat(32)}),
createExt({name: 'Charlie', id: 'c'.repeat(32)})
];
itemList.items = items;
itemList.filter = '';
document.body.appendChild(itemList);
});
test(assert(TestNames.ItemListFiltering), function() {
var ironList = itemList.$.list;
assert(ironList);
test(assert(TestNames.ItemListFiltering), function() {
var ironList = itemList.$.list;
assert(ironList);
// We should initially show all the items.
expectEquals(3, ironList.items.length);
// We should initially show all the items.
expectEquals(3, ironList.items.length);
// All items have an 'a'.
itemList.filter = 'a';
expectEquals(3, ironList.items.length);
// Filtering is case-insensitive, so every item should be shown.
itemList.filter = 'A';
expectEquals(3, ironList.items.length);
// Only 'Bravo' has a 'b'.
itemList.filter = 'b';
expectEquals(1, ironList.items.length);
expectEquals('Bravo', ironList.items[0].name);
// Test inner substring (rather than prefix).
itemList.filter = 'lph';
expectEquals(1, ironList.items.length);
expectEquals('Alpha', ironList.items[0].name);
// Test string with no matching items.
itemList.filter = 'z';
expectEquals(0, ironList.items.length);
// A filter of '' should reset to show all items.
itemList.filter = '';
expectEquals(3, ironList.items.length);
});
// All items have an 'a'.
itemList.filter = 'a';
expectEquals(3, ironList.items.length);
// Filtering is case-insensitive, so every item should be shown.
itemList.filter = 'A';
expectEquals(3, ironList.items.length);
// Only 'Bravo' has a 'b'.
itemList.filter = 'b';
expectEquals(1, ironList.items.length);
expectEquals('Bravo', ironList.items[0].name);
// Test inner substring (rather than prefix).
itemList.filter = 'lph';
expectEquals(1, ironList.items.length);
expectEquals('Alpha', ironList.items[0].name);
// Test string with no matching items.
itemList.filter = 'z';
expectEquals(0, ironList.items.length);
// A filter of '' should reset to show all items.
itemList.filter = '';
expectEquals(3, ironList.items.length);
});
test(assert(TestNames.ItemListNoItemsMsg), function() {
testVisible('#no-items', false);
testVisible('#no-search-results', false);
test(assert(TestNames.ItemListNoItemsMsg), function() {
testVisible('#no-items', false);
testVisible('#no-search-results', false);
itemList.items = [];
testVisible('#no-items', true);
testVisible('#no-search-results', false);
});
itemList.items = [];
testVisible('#no-items', true);
testVisible('#no-search-results', false);
});
test(assert(TestNames.ItemListNoSearchResultsMsg), function() {
testVisible('#no-items', false);
testVisible('#no-search-results', false);
test(assert(TestNames.ItemListNoSearchResultsMsg), function() {
testVisible('#no-items', false);
testVisible('#no-search-results', false);
itemList.filter = 'non-existent name';
testVisible('#no-items', false);
testVisible('#no-search-results', true);
});
itemList.filter = 'non-existent name';
testVisible('#no-items', false);
testVisible('#no-search-results', true);
});
}
});
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -12,115 +12,116 @@ cr.define('extension_keyboard_shortcut_tests', function() {
ShortcutUtil: 'ExtensionShortcutUtilTest',
};
function registerTests() {
suite('ExtensionKeyboardShortcutTest', function() {
/** @type {extensions.KeyboardShortcuts} */
var keyboardShortcuts;
/** @type {chrome.developerPrivate.ExtensionInfo} */
var noCommand;
/** @type {chrome.developerPrivate.ExtensionInfo} */
var oneCommand;
/** @type {chrome.developerPrivate.ExtensionInfo} */
var twoCommands;
suite('ExtensionKeyboardShortcutTest', function() {
/** @type {extensions.KeyboardShortcuts} */
var keyboardShortcuts;
/** @type {chrome.developerPrivate.ExtensionInfo} */
var noCommand;
/** @type {chrome.developerPrivate.ExtensionInfo} */
var oneCommand;
/** @type {chrome.developerPrivate.ExtensionInfo} */
var twoCommands;
setup(function() {
PolymerTest.clearBody();
keyboardShortcuts = new extensions.KeyboardShortcuts();
setup(function() {
PolymerTest.clearBody();
keyboardShortcuts = new extensions.KeyboardShortcuts();
var createInfo = extension_test_util.createExtensionInfo;
noCommands = createInfo({id: 'a'.repeat(32)});
oneCommand = createInfo({
id: 'b'.repeat(32),
commands: [{
description: 'Description',
keybinding: 'Ctrl+W',
name: 'bCommand',
isActive: true,
scope: 'CHROME',
isExtensionAction: true,
}]
});
twoCommands = createInfo({
id: 'c'.repeat(32),
commands: [{
var createInfo = extension_test_util.createExtensionInfo;
noCommands = createInfo({id: 'a'.repeat(32)});
oneCommand = createInfo({
id: 'b'.repeat(32),
commands: [{
description: 'Description',
keybinding: 'Ctrl+W',
name: 'bCommand',
isActive: true,
scope: 'CHROME',
isExtensionAction: true,
}]
});
twoCommands = createInfo({
id: 'c'.repeat(32),
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]);
keyboardShortcuts.set('items', [noCommands, oneCommand, twoCommands]);
document.body.appendChild(keyboardShortcuts);
document.body.appendChild(keyboardShortcuts);
Polymer.dom.flush();
});
Polymer.dom.flush();
});
test(assert(TestNames.Layout), function() {
var isVisibleOnCard = function(e, s) {
// We check the light DOM in the card because it's a regular old div,
// rather than a fancy-schmancy custom element.
return extension_test_util.isVisible(e, s, true);
};
var cards =
keyboardShortcuts.$$('#main').querySelectorAll('.shortcut-card');
assertEquals(2, cards.length);
test(assert(TestNames.Layout), function() {
var isVisibleOnCard = function(e, s) {
// We check the light DOM in the card because it's a regular old div,
// rather than a fancy-schmancy custom element.
return extension_test_util.isVisible(e, s, true);
};
var cards =
keyboardShortcuts.$$('#main').querySelectorAll('.shortcut-card');
assertEquals(2, cards.length);
var card1 = cards[0];
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'));
expectTrue(isVisibleOnCard(commands[0], 'select.md-select'));
var card1 = cards[0];
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'));
expectTrue(isVisibleOnCard(commands[0], 'select.md-select'));
var card2 = cards[1];
commands = card2.querySelectorAll('.command-entry');
assertEquals(2, commands.length);
});
var card2 = cards[1];
commands = card2.querySelectorAll('.command-entry');
assertEquals(2, commands.length);
});
suite(assert(TestNames.ShortcutUtil), function() {
test('isValidKeyCode test', function() {
expectTrue(extensions.isValidKeyCode('A'.charCodeAt(0)));
expectTrue(extensions.isValidKeyCode('F'.charCodeAt(0)));
expectTrue(extensions.isValidKeyCode('Z'.charCodeAt(0)));
expectTrue(extensions.isValidKeyCode('4'.charCodeAt(0)));
expectTrue(extensions.isValidKeyCode(extensions.Key.PageUp));
expectTrue(extensions.isValidKeyCode(extensions.Key.MediaPlayPause));
expectTrue(extensions.isValidKeyCode(extensions.Key.Down));
expectFalse(extensions.isValidKeyCode(16)); // Shift
expectFalse(extensions.isValidKeyCode(17)); // Ctrl
expectFalse(extensions.isValidKeyCode(18)); // Alt
expectFalse(extensions.isValidKeyCode(113)); // F2
expectFalse(extensions.isValidKeyCode(144)); // Num Lock
expectFalse(extensions.isValidKeyCode(43)); // +
expectFalse(extensions.isValidKeyCode(27)); // Escape
});
});
test('keystrokeToString test', function() {
// Creating an event with the KeyboardEvent ctor doesn't work. Fake it.
var e = {keyCode: 'A'.charCodeAt(0)};
expectEquals('A', extensions.keystrokeToString(e));
e.ctrlKey = true;
expectEquals('Ctrl+A', extensions.keystrokeToString(e));
e.shiftKey = true;
expectEquals('Ctrl+Shift+A', extensions.keystrokeToString(e));
});
suite(assert(TestNames.ShortcutUtil), function() {
test('isValidKeyCode test', function() {
expectTrue(extensions.isValidKeyCode('A'.charCodeAt(0)));
expectTrue(extensions.isValidKeyCode('F'.charCodeAt(0)));
expectTrue(extensions.isValidKeyCode('Z'.charCodeAt(0)));
expectTrue(extensions.isValidKeyCode('4'.charCodeAt(0)));
expectTrue(extensions.isValidKeyCode(extensions.Key.PageUp));
expectTrue(extensions.isValidKeyCode(extensions.Key.MediaPlayPause));
expectTrue(extensions.isValidKeyCode(extensions.Key.Down));
expectFalse(extensions.isValidKeyCode(16)); // Shift
expectFalse(extensions.isValidKeyCode(17)); // Ctrl
expectFalse(extensions.isValidKeyCode(18)); // Alt
expectFalse(extensions.isValidKeyCode(113)); // F2
expectFalse(extensions.isValidKeyCode(144)); // Num Lock
expectFalse(extensions.isValidKeyCode(43)); // +
expectFalse(extensions.isValidKeyCode(27)); // Escape
});
test('keystrokeToString test', function() {
// Creating an event with the KeyboardEvent ctor doesn't work. Fake it.
var e = {keyCode: 'A'.charCodeAt(0)};
expectEquals('A', extensions.keystrokeToString(e));
e.ctrlKey = true;
expectEquals('Ctrl+A', extensions.keystrokeToString(e));
e.shiftKey = true;
expectEquals('Ctrl+Shift+A', extensions.keystrokeToString(e));
});
}
});
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -24,71 +24,68 @@ cr.define('extension_load_error_tests', function() {
retryLoadUnpacked: function() {},
};
function registerTests() {
suite('ExtensionLoadErrorTests', function() {
/** @type {extensions.LoadError} */
var loadError;
suite('ExtensionLoadErrorTests', function() {
/** @type {extensions.LoadError} */
var loadError;
/** @type {MockDelegate} */
var mockDelegate;
var fakeGuid = 'uniqueId';
var stubLoadError = {
error: 'error',
path: 'some/path/',
retryGuid: fakeGuid,
};
setup(function() {
PolymerTest.clearBody();
mockDelegate = new MockDelegate();
loadError = new extensions.LoadError();
loadError.delegate = mockDelegate;
loadError.loadError = stubLoadError;
document.body.appendChild(loadError);
});
test(assert(TestNames.Interaction), function() {
var dialogElement = loadError.$$('dialog');
var isDialogVisible = function() {
var rect = dialogElement.getBoundingClientRect();
return rect.width * rect.height > 0;
};
/** @type {MockDelegate} */
var mockDelegate;
expectFalse(isDialogVisible());
loadError.show();
expectTrue(isDialogVisible());
var fakeGuid = 'uniqueId';
mockDelegate.testClickingCalls(
loadError.$$('.action-button'), 'retryLoadUnpacked', [fakeGuid]);
expectFalse(isDialogVisible());
loadError.show();
MockInteractions.tap(loadError.$$('.cancel-button'));
expectFalse(isDialogVisible());
});
var stubLoadError = {
error: 'error',
path: 'some/path/',
retryGuid: fakeGuid,
test(assert(TestNames.CodeSection), function() {
expectTrue(loadError.$.code.isEmpty());
var loadErrorWithSource = {
error: 'Some error',
path: '/some/path',
source: {
beforeHighlight: 'before',
highlight: 'highlight',
afterHighlight: 'after',
},
};
setup(function() {
PolymerTest.clearBody();
mockDelegate = new MockDelegate();
loadError = new extensions.LoadError();
loadError.delegate = mockDelegate;
loadError.loadError = stubLoadError;
document.body.appendChild(loadError);
});
test(assert(TestNames.Interaction), function() {
var dialogElement = loadError.$$('dialog');
var isDialogVisible = function() {
var rect = dialogElement.getBoundingClientRect();
return rect.width * rect.height > 0;
};
expectFalse(isDialogVisible());
loadError.show();
expectTrue(isDialogVisible());
mockDelegate.testClickingCalls(
loadError.$$('.action-button'), 'retryLoadUnpacked', [fakeGuid]);
expectFalse(isDialogVisible());
loadError.show();
MockInteractions.tap(loadError.$$('.cancel-button'));
expectFalse(isDialogVisible());
});
test(assert(TestNames.CodeSection), function() {
expectTrue(loadError.$.code.isEmpty());
var loadErrorWithSource = {
error: 'Some error',
path: '/some/path',
source: {
beforeHighlight: 'before',
highlight: 'highlight',
afterHighlight: 'after',
},
};
loadError.loadError = loadErrorWithSource;
expectFalse(loadError.$.code.isEmpty());
});
loadError.loadError = loadErrorWithSource;
expectFalse(loadError.$.code.isEmpty());
});
}
});
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -24,137 +24,135 @@ cr.define('extension_navigation_helper_tests', function() {
});
}
function registerTests() {
suite('ExtensionNavigationHelperTest', function() {
setup(function() {
PolymerTest.clearBody();
Polymer.dom.flush();
});
suite('ExtensionNavigationHelperTest', function() {
setup(function() {
PolymerTest.clearBody();
Polymer.dom.flush();
});
test(assert(TestNames.Basic), function() {
var id = 'a'.repeat(32);
var mock = new MockMethod();
var changePage = function(state) {
mock.recordCall([state]);
};
var navigationHelper = new extensions.NavigationHelper(changePage);
expectEquals('chrome://extensions/navigation_helper.html',
location.href);
expectDeepEquals({page: Page.LIST}, navigationHelper.getCurrentPage());
var currentLength = history.length;
navigationHelper.updateHistory({page: Page.DETAILS, extensionId: id});
expectEquals(++currentLength, history.length);
navigationHelper.updateHistory({page: Page.ERRORS, extensionId: id});
expectEquals(++currentLength, history.length);
mock.addExpectation({page: Page.DETAILS, extensionId: id});
var waitForPop = getOnPopState();
history.back();
return waitForPop.then(() => {
mock.verifyMock();
mock.addExpectation({page: Page.LIST});
var waitForNextPop = getOnPopState();
history.back();
return waitForNextPop;
}).then(() => {
mock.verifyMock();
});
});
test(assert(TestNames.Basic), function() {
var id = 'a'.repeat(32);
var mock = new MockMethod();
var changePage = function(state) {
mock.recordCall([state]);
};
var navigationHelper = new extensions.NavigationHelper(changePage);
expectEquals('chrome://extensions/navigation_helper.html', location.href);
expectDeepEquals({page: Page.LIST}, navigationHelper.getCurrentPage());
var currentLength = history.length;
navigationHelper.updateHistory({page: Page.DETAILS, extensionId: id});
expectEquals(++currentLength, history.length);
navigationHelper.updateHistory({page: Page.ERRORS, extensionId: id});
expectEquals(++currentLength, history.length);
mock.addExpectation({page: Page.DETAILS, extensionId: id});
var waitForPop = getOnPopState();
history.back();
return waitForPop
.then(() => {
mock.verifyMock();
mock.addExpectation({page: Page.LIST});
var waitForNextPop = getOnPopState();
history.back();
return waitForNextPop;
})
.then(() => {
mock.verifyMock();
});
});
test(assert(TestNames.Conversions), function() {
var id = 'a'.repeat(32);
var stateUrlPairs = {
list: {
url: 'chrome://extensions/',
state: {page: Page.LIST},
},
details: {
url: 'chrome://extensions/?id=' + id,
state: {page: Page.DETAILS, extensionId: id},
},
options: {
url: 'chrome://extensions/?options=' + id,
state: {
page: Page.DETAILS,
extensionId: id,
subpage: Dialog.OPTIONS,
},
test(assert(TestNames.Conversions), function() {
var id = 'a'.repeat(32);
var stateUrlPairs = {
list: {
url: 'chrome://extensions/',
state: {page: Page.LIST},
},
details: {
url: 'chrome://extensions/?id=' + id,
state: {page: Page.DETAILS, extensionId: id},
},
options: {
url: 'chrome://extensions/?options=' + id,
state: {
page: Page.DETAILS,
extensionId: id,
subpage: Dialog.OPTIONS,
},
errors: {
url: 'chrome://extensions/?errors=' + id,
state: {page: Page.ERRORS, extensionId: id},
},
shortcuts: {
url: 'chrome://extensions/shortcuts',
state: {page: Page.SHORTCUTS},
},
};
var navigationHelper = new extensions.NavigationHelper(function() {});
// Test url -> state.
for (let key in stateUrlPairs) {
let entry = stateUrlPairs[key];
history.pushState({}, '', entry.url);
expectDeepEquals(entry.state, navigationHelper.getCurrentPage(), key);
}
// Test state -> url.
for (let key in stateUrlPairs) {
let entry = stateUrlPairs[key];
navigationHelper.updateHistory(entry.state);
expectEquals(entry.url, location.href, key);
}
});
},
errors: {
url: 'chrome://extensions/?errors=' + id,
state: {page: Page.ERRORS, extensionId: id},
},
shortcuts: {
url: 'chrome://extensions/shortcuts',
state: {page: Page.SHORTCUTS},
},
};
var navigationHelper = new extensions.NavigationHelper(function() {});
// Test url -> state.
for (let key in stateUrlPairs) {
let entry = stateUrlPairs[key];
history.pushState({}, '', entry.url);
expectDeepEquals(entry.state, navigationHelper.getCurrentPage(), key);
}
// Test state -> url.
for (let key in stateUrlPairs) {
let entry = stateUrlPairs[key];
navigationHelper.updateHistory(entry.state);
expectEquals(entry.url, location.href, key);
}
});
test(assert(TestNames.PushAndReplaceState), function() {
var id1 = 'a'.repeat(32);
var id2 = 'b'.repeat(32);
var navigationHelper = new extensions.NavigationHelper(function() {});
test(assert(TestNames.PushAndReplaceState), function() {
var id1 = 'a'.repeat(32);
var id2 = 'b'.repeat(32);
var navigationHelper = new extensions.NavigationHelper(function() {});
history.pushState({}, '', 'chrome://extensions/');
expectDeepEquals({page: Page.LIST}, navigationHelper.getCurrentPage());
history.pushState({}, '', 'chrome://extensions/');
expectDeepEquals({page: Page.LIST}, navigationHelper.getCurrentPage());
var expectedLength = history.length;
var expectedLength = history.length;
// Navigating to a new page pushes new state.
navigationHelper.updateHistory({page: Page.DETAILS, extensionId: id1});
expectEquals(++expectedLength, history.length);
// Navigating to a new page pushes new state.
navigationHelper.updateHistory({page: Page.DETAILS, extensionId: id1});
expectEquals(++expectedLength, history.length);
// Navigating to a subpage (like the options page) just opens a dialog,
// and shouldn't push new state.
navigationHelper.updateHistory(
{page: Page.DETAILS, extensionId: id1, subpage: Dialog.OPTIONS});
expectEquals(expectedLength, history.length);
// Navigating to a subpage (like the options page) just opens a dialog,
// and shouldn't push new state.
navigationHelper.updateHistory(
{page: Page.DETAILS, extensionId: id1, subpage: Dialog.OPTIONS});
expectEquals(expectedLength, history.length);
// Navigating away from a subpage also shouldn't push state (it just
// closes the dialog).
navigationHelper.updateHistory({page: Page.DETAILS, extensionId: id1});
expectEquals(expectedLength, history.length);
// Navigating away from a subpage also shouldn't push state (it just
// closes the dialog).
navigationHelper.updateHistory({page: Page.DETAILS, extensionId: id1});
expectEquals(expectedLength, history.length);
// Navigating away should push new state.
navigationHelper.updateHistory({page: Page.LIST});
expectEquals(++expectedLength, history.length);
// Navigating away should push new state.
navigationHelper.updateHistory({page: Page.LIST});
expectEquals(++expectedLength, history.length);
// Navigating to a subpage of a different page should push state.
navigationHelper.updateHistory(
{page: Page.DETAILS, extensionId: id1, subpage: Dialog.OPTIONS});
expectEquals(++expectedLength, history.length);
// Navigating to a subpage of a different page should push state.
navigationHelper.updateHistory(
{page: Page.DETAILS, extensionId: id1, subpage: Dialog.OPTIONS});
expectEquals(++expectedLength, history.length);
// Navigating away from a subpage to a page for a different item should
// push state.
navigationHelper.updateHistory({page: Page.DETAILS, extensionId: id2});
expectEquals(++expectedLength, history.length);
});
// Navigating away from a subpage to a page for a different item should
// push state.
navigationHelper.updateHistory({page: Page.DETAILS, extensionId: id2});
expectEquals(++expectedLength, history.length);
});
}
});
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -15,94 +15,90 @@ 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;
/** @type {chrome.developerPrivate.ExtensionInfo} */
var data;
setup(function() {
PolymerTest.clearBody();
data = extension_test_util.createExtensionInfo();
optionsDialog = new extensions.OptionsDialog();
document.body.appendChild(optionsDialog);
});
test(assert(TestNames.Layout), function() {
var dialogElement = optionsDialog.$$('dialog');
var isDialogVisible = function() {
var rect = dialogElement.getBoundingClientRect();
return rect.width * rect.height > 0;
};
// Try showing the dialog.
expectFalse(isDialogVisible());
optionsDialog.show(data);
expectTrue(isDialogVisible());
expectEquals(
data.name,
assert(optionsDialog.$$('#icon-and-name-wrapper span')).
textContent.trim());
var optionEle = optionsDialog.$$('extensionoptions');
// To start, the options page should be set to the min width/height.
expectEquals(MIN_HEIGHT, optionEle.style.height);
expectEquals(MIN_WIDTH, optionEle.style.width);
var mockOptions = optionsDialog.extensionOptions_;
expectEquals(data.id, mockOptions.extension);
// Setting the preferred size to something below the min width/height
// shouldn't change the actual width/height.
mockOptions.onpreferredsizechanged({height: 100, width: 100});
expectEquals(MIN_HEIGHT, optionEle.style.height);
expectEquals(MIN_WIDTH, optionEle.style.width);
// Setting the preferred size to between the min and max dimensions
// should change the dimensions.
mockOptions.onpreferredsizechanged({height: 500, width: 400});
expectEquals('500px', optionEle.style.height);
expectEquals('400px', optionEle.style.width);
// Max values should pin the dialog.
mockOptions.onpreferredsizechanged({height: 900, width: 400});
expectEquals(MAX_HEIGHT, optionEle.style.height);
expectEquals('400px', optionEle.style.width);
mockOptions.onclose();
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'
});
optionsDialog.show(secondExtension);
expectTrue(isDialogVisible());
expectEquals(secondExtension.id, mockOptions.extension);
expectEquals(
secondExtension.name,
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);
expectEquals(MIN_HEIGHT, optionEle.style.height);
// Going back to an extension with a shorter name should resize the
// dialog.
optionsDialog.close();
optionsDialog.show(data);
expectEquals(MIN_HEIGHT, optionEle.style.height);
expectEquals(MIN_WIDTH, optionEle.style.width);
});
suite('ExtensionOptionsDialogTests', function() {
/** @type {extensions.OptionsDialog} */
var optionsDialog;
/** @type {chrome.developerPrivate.ExtensionInfo} */
var data;
setup(function() {
PolymerTest.clearBody();
data = extension_test_util.createExtensionInfo();
optionsDialog = new extensions.OptionsDialog();
document.body.appendChild(optionsDialog);
});
}
test(assert(TestNames.Layout), function() {
var dialogElement = optionsDialog.$$('dialog');
var isDialogVisible = function() {
var rect = dialogElement.getBoundingClientRect();
return rect.width * rect.height > 0;
};
// Try showing the dialog.
expectFalse(isDialogVisible());
optionsDialog.show(data);
expectTrue(isDialogVisible());
expectEquals(
data.name,
assert(optionsDialog.$$('#icon-and-name-wrapper span'))
.textContent.trim());
var optionEle = optionsDialog.$$('extensionoptions');
// To start, the options page should be set to the min width/height.
expectEquals(MIN_HEIGHT, optionEle.style.height);
expectEquals(MIN_WIDTH, optionEle.style.width);
var mockOptions = optionsDialog.extensionOptions_;
expectEquals(data.id, mockOptions.extension);
// Setting the preferred size to something below the min width/height
// shouldn't change the actual width/height.
mockOptions.onpreferredsizechanged({height: 100, width: 100});
expectEquals(MIN_HEIGHT, optionEle.style.height);
expectEquals(MIN_WIDTH, optionEle.style.width);
// Setting the preferred size to between the min and max dimensions
// should change the dimensions.
mockOptions.onpreferredsizechanged({height: 500, width: 400});
expectEquals('500px', optionEle.style.height);
expectEquals('400px', optionEle.style.width);
// Max values should pin the dialog.
mockOptions.onpreferredsizechanged({height: 900, width: 400});
expectEquals(MAX_HEIGHT, optionEle.style.height);
expectEquals('400px', optionEle.style.width);
mockOptions.onclose();
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'});
optionsDialog.show(secondExtension);
expectTrue(isDialogVisible());
expectEquals(secondExtension.id, mockOptions.extension);
expectEquals(
secondExtension.name,
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);
expectEquals(MIN_HEIGHT, optionEle.style.height);
// Going back to an extension with a shorter name should resize the
// dialog.
optionsDialog.close();
optionsDialog.show(data);
expectEquals(MIN_HEIGHT, optionEle.style.height);
expectEquals(MIN_WIDTH, optionEle.style.width);
});
});
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -66,135 +66,139 @@ cr.define('extension_service_tests', function() {
ProfileSettings: 'profile settings',
};
function registerTests() {
suite('ExtensionServiceTest', function() {
/** @const{string} */
var kExtensionId = 'ldnnhddmnhbkjipkidpdiheffobcpfmf';
suite('ExtensionServiceTest', function() {
/** @const{string} */
var kExtensionId = 'ldnnhddmnhbkjipkidpdiheffobcpfmf';
/** @const */
var EventType = chrome.developerPrivate.EventType;
/** @const */
var EventType = chrome.developerPrivate.EventType;
/** @const */
var ExtensionState = chrome.developerPrivate.ExtensionState;
/** @const */
var ExtensionState = chrome.developerPrivate.ExtensionState;
/** @type {extensions.Service} */
var service;
/** @type {extensions.Service} */
var service;
/** @type {extensions.Manager} */
var manager;
/** @type {extensions.Manager} */
var manager;
var getItemData = function(id) {
var elMatches = function(el) { return el.id == id; };
return manager.extensions.find(elMatches) ||
manager.apps.find(elMatches);
var getItemData = function(id) {
var elMatches = function(el) {
return el.id == id;
};
return manager.extensions.find(elMatches) || manager.apps.find(elMatches);
};
suiteSetup(function() {
return PolymerTest.importHtml('chrome://extensions/service.html');
});
// Initialize an extension item before each test.
setup(function() {
service = extensions.Service.getInstance();
manager = document.getElementsByTagName('extensions-manager')[0];
});
suiteSetup(function() {
return PolymerTest.importHtml('chrome://extensions/service.html');
});
test(assert(TestNames.EnableAndDisable), function(done) {
var item = getItemData(kExtensionId);
assertTrue(!!item);
expectEquals(kExtensionId, item.id);
expectEquals('My extension 1', item.name);
expectEquals(ExtensionState.ENABLED, item.state);
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.
var item = getItemData(kExtensionId);
assertTrue(!!item);
expectEquals(ExtensionState.DISABLED, item.state);
enabledListener =
new ItemChangedListener(kExtensionId, EventType.LOADED);
service.setItemEnabled(kExtensionId, true);
return enabledListener.onUpdate;
}).then(function() {
var item = getItemData(kExtensionId);
assertTrue(!!item);
expectEquals(ExtensionState.ENABLED, item.state);
done();
});
});
// Initialize an extension item before each test.
setup(function() {
service = extensions.Service.getInstance();
manager = document.getElementsByTagName('extensions-manager')[0];
});
test(assert(TestNames.ToggleIncognitoMode), function(done) {
var item = getItemData(kExtensionId);
assertTrue(!!item);
expectTrue(item.incognitoAccess.isEnabled);
expectFalse(item.incognitoAccess.isActive);
var incognitoListener =
new ItemChangedListener(kExtensionId, EventType.LOADED);
chrome.test.runWithUserGesture(function() {
service.setItemAllowedIncognito(kExtensionId, true);
});
incognitoListener.onUpdate.then(function() {
var item = getItemData(kExtensionId);
assertTrue(!!item);
expectTrue(item.incognitoAccess.isActive);
var disabledIncognitoListener =
new ItemChangedListener(kExtensionId, EventType.LOADED);
chrome.test.runWithUserGesture(function() {
service.setItemAllowedIncognito(kExtensionId, false);
test(assert(TestNames.EnableAndDisable), function(done) {
var item = getItemData(kExtensionId);
assertTrue(!!item);
expectEquals(kExtensionId, item.id);
expectEquals('My extension 1', item.name);
expectEquals(ExtensionState.ENABLED, item.state);
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.
var item = getItemData(kExtensionId);
assertTrue(!!item);
expectEquals(ExtensionState.DISABLED, item.state);
enabledListener =
new ItemChangedListener(kExtensionId, EventType.LOADED);
service.setItemEnabled(kExtensionId, true);
return enabledListener.onUpdate;
})
.then(function() {
var item = getItemData(kExtensionId);
assertTrue(!!item);
expectEquals(ExtensionState.ENABLED, item.state);
done();
});
return disabledIncognitoListener.onUpdate;
}).then(function() {
var item = getItemData(kExtensionId);
assertTrue(!!item);
expectFalse(item.incognitoAccess.isActive);
done();
});
});
test(assert(TestNames.ToggleIncognitoMode), function(done) {
var item = getItemData(kExtensionId);
assertTrue(!!item);
expectTrue(item.incognitoAccess.isEnabled);
expectFalse(item.incognitoAccess.isActive);
var incognitoListener =
new ItemChangedListener(kExtensionId, EventType.LOADED);
chrome.test.runWithUserGesture(function() {
service.setItemAllowedIncognito(kExtensionId, true);
});
incognitoListener.onUpdate
.then(function() {
var item = getItemData(kExtensionId);
assertTrue(!!item);
expectTrue(item.incognitoAccess.isActive);
var disabledIncognitoListener =
new ItemChangedListener(kExtensionId, EventType.LOADED);
chrome.test.runWithUserGesture(function() {
service.setItemAllowedIncognito(kExtensionId, false);
});
return disabledIncognitoListener.onUpdate;
})
.then(function() {
var item = getItemData(kExtensionId);
assertTrue(!!item);
expectFalse(item.incognitoAccess.isActive);
done();
});
});
test(assert(TestNames.Uninstall), function(done) {
var item = getItemData(kExtensionId);
assertTrue(!!item);
var uninstallListener =
new ItemChangedListener(kExtensionId, EventType.UNINSTALLED);
chrome.test.runWithUserGesture(function() {
service.deleteItem(kExtensionId);
});
uninstallListener.onUpdate.then(function() {
expectFalse(!!getItemData(kExtensionId));
done();
});
test(assert(TestNames.Uninstall), function(done) {
var item = getItemData(kExtensionId);
assertTrue(!!item);
var uninstallListener =
new ItemChangedListener(kExtensionId, EventType.UNINSTALLED);
chrome.test.runWithUserGesture(function() {
service.deleteItem(kExtensionId);
});
uninstallListener.onUpdate.then(function() {
expectFalse(!!getItemData(kExtensionId));
done();
});
});
test(assert(TestNames.ProfileSettings), function(done) {
expectFalse(manager.inDevMode);
test(assert(TestNames.ProfileSettings), function(done) {
expectFalse(manager.inDevMode);
var profileListener = new ProfileChangedListener();
service.setProfileInDevMode(true);
var profileListener = new ProfileChangedListener();
service.setProfileInDevMode(true);
profileListener.onUpdate.then(function() {
expectTrue(manager.inDevMode);
profileListener.onUpdate
.then(function() {
expectTrue(manager.inDevMode);
var noDevModeProfileListener = new ProfileChangedListener();
service.setProfileInDevMode(false);
return noDevModeProfileListener.onUpdate;
}).then(function() {
expectFalse(manager.inDevMode);
done();
});
});
var noDevModeProfileListener = new ProfileChangedListener();
service.setProfileInDevMode(false);
return noDevModeProfileListener.onUpdate;
})
.then(function() {
expectFalse(manager.inDevMode);
done();
});
});
}
});
return {
ChangeListener: ChangeListener,
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -9,103 +9,100 @@ cr.define('extension_shortcut_input_tests', function() {
Basic: 'basic',
};
function registerTests() {
suite('ExtensionShortcutInputTest', function() {
/** @type {extensions.ShortcutInput} */
var input;
setup(function() {
PolymerTest.clearBody();
input = new extensions.ShortcutInput();
input.commandName = 'Command';
input.item = 'itemid';
document.body.appendChild(input);
Polymer.dom.flush();
});
suite('ExtensionShortcutInputTest', function() {
/** @type {extensions.ShortcutInput} */
var input;
setup(function() {
PolymerTest.clearBody();
input = new extensions.ShortcutInput();
input.commandName = 'Command';
input.item = 'itemid';
document.body.appendChild(input);
Polymer.dom.flush();
});
test(assert(TestNames.Basic), function() {
var field = input.$['input'];
var fieldText = function() { return field.value; };
expectEquals('', fieldText());
var isClearVisible = extension_test_util.isVisible.bind(
null, input, '#clear', false);
expectFalse(isClearVisible());
test(assert(TestNames.Basic), function() {
var field = input.$['input'];
var fieldText = function() {
return field.value;
};
expectEquals('', fieldText());
var isClearVisible =
extension_test_util.isVisible.bind(null, input, '#clear', false);
expectFalse(isClearVisible());
// Click the input. Capture should start.
{
let startCaptureListener = new extension_test_util.ListenerMock();
startCaptureListener.addListener(input, 'shortcut-capture-started');
MockInteractions.tap(field);
startCaptureListener.verify();
}
expectEquals('', fieldText());
expectTrue(input.capturing_);
expectFalse(isClearVisible());
// Click the input. Capture should start.
{
let startCaptureListener = new extension_test_util.ListenerMock();
startCaptureListener.addListener(input, 'shortcut-capture-started');
MockInteractions.tap(field);
startCaptureListener.verify();
}
expectEquals('', fieldText());
expectTrue(input.capturing_);
expectFalse(isClearVisible());
// Press ctrl.
MockInteractions.keyDownOn(field, 17, ['ctrl']);
expectEquals('Ctrl', fieldText());
expectTrue(input.capturing_);
// Add shift.
MockInteractions.keyDownOn(field, 16, ['ctrl', 'shift']);
expectEquals('Ctrl+Shift', fieldText());
expectTrue(input.capturing_);
// Remove shift.
MockInteractions.keyUpOn(field, 16, ['ctrl']);
expectEquals('Ctrl', fieldText());
// Add alt (ctrl + alt is invalid).
MockInteractions.keyDownOn(field, 18, ['ctrl', 'alt']);
expectEquals('invalid', fieldText());
expectTrue(input.capturing_);
// Remove alt.
MockInteractions.keyUpOn(field, 18, ['ctrl']);
expectEquals('Ctrl', fieldText());
expectTrue(input.capturing_);
{
// 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-capture-ended');
MockInteractions.keyDownOn(field, 65, ['ctrl']);
updatedListener.verify();
}
expectEquals('Ctrl+A', fieldText());
expectFalse(input.capturing_);
expectEquals('Ctrl+A', input.shortcut);
expectTrue(isClearVisible());
// Press ctrl.
MockInteractions.keyDownOn(field, 17, ['ctrl']);
expectEquals('Ctrl', fieldText());
expectTrue(input.capturing_);
// Add shift.
MockInteractions.keyDownOn(field, 16, ['ctrl', 'shift']);
expectEquals('Ctrl+Shift', fieldText());
expectTrue(input.capturing_);
// Remove shift.
MockInteractions.keyUpOn(field, 16, ['ctrl']);
expectEquals('Ctrl', fieldText());
// Add alt (ctrl + alt is invalid).
MockInteractions.keyDownOn(field, 18, ['ctrl', 'alt']);
expectEquals('invalid', fieldText());
expectTrue(input.capturing_);
// Remove alt.
MockInteractions.keyUpOn(field, 18, ['ctrl']);
expectEquals('Ctrl', fieldText());
expectTrue(input.capturing_);
{
// 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-capture-ended');
MockInteractions.keyDownOn(field, 65, ['ctrl']);
updatedListener.verify();
}
expectEquals('Ctrl+A', fieldText());
expectFalse(input.capturing_);
expectEquals('Ctrl+A', input.shortcut);
expectTrue(isClearVisible());
{
// Test clearing the shortcut.
let updatedListener = new extension_test_util.ListenerMock();
updatedListener.addListener(input, 'shortcut-updated',
{keybinding: '',
item: 'itemid',
commandName: 'Command'});
MockInteractions.tap(input.$['clear']);
updatedListener.verify();
}
expectEquals('', input.shortcut);
expectFalse(isClearVisible());
{
// Test clearing the shortcut.
let updatedListener = new extension_test_util.ListenerMock();
updatedListener.addListener(
input, 'shortcut-updated',
{keybinding: '', item: 'itemid', commandName: 'Command'});
MockInteractions.tap(input.$['clear']);
updatedListener.verify();
}
expectEquals('', input.shortcut);
expectFalse(isClearVisible());
MockInteractions.tap(field);
{
// Test ending capture using the escape key.
expectTrue(input.capturing_);
let captureEndedListener = new extension_test_util.ListenerMock();
captureEndedListener.addListener(input, 'shortcut-capture-ended');
MockInteractions.keyDownOn(field, 27); // Escape key.
expectFalse(input.capturing_);
captureEndedListener.verify();
}
});
MockInteractions.tap(field);
{
// Test ending capture using the escape key.
expectTrue(input.capturing_);
let captureEndedListener = new extension_test_util.ListenerMock();
captureEndedListener.addListener(input, 'shortcut-capture-ended');
MockInteractions.keyDownOn(field, 27); // Escape key.
expectFalse(input.capturing_);
captureEndedListener.verify();
}
});
}
});
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -27,50 +27,47 @@ cr.define('extension_sidebar_tests', function() {
LayoutAndClickHandlers: 'layout and click handlers',
};
function registerTests() {
suite('ExtensionSidebarTest', function() {
/** @type {MockDelegate} */
var mockDelegate;
suite('ExtensionSidebarTest', function() {
/** @type {MockDelegate} */
var mockDelegate;
/** @type {extensions.Sidebar} */
var sidebar;
/** @type {extensions.Sidebar} */
var sidebar;
// Import cr_settings_checkbox.html before running suite.
suiteSetup(function() {
return PolymerTest.importHtml('chrome://extensions/sidebar.html');
});
// Import cr_settings_checkbox.html before running suite.
suiteSetup(function() {
return PolymerTest.importHtml('chrome://extensions/sidebar.html');
});
setup(function() {
var manager = document.querySelector('extensions-manager');
manager.$.drawer.openDrawer();
sidebar = manager.sidebar;
mockDelegate = new MockDelegate();
sidebar.setListDelegate(mockDelegate);
});
setup(function() {
var manager = document.querySelector('extensions-manager');
manager.$.drawer.openDrawer();
sidebar = manager.sidebar;
mockDelegate = new MockDelegate();
sidebar.setListDelegate(mockDelegate);
});
test(assert(TestNames.LayoutAndClickHandlers), function() {
extension_test_util.testIronIcons(sidebar);
test(assert(TestNames.LayoutAndClickHandlers), function() {
extension_test_util.testIronIcons(sidebar);
var testVisible = extension_test_util.testVisible.bind(null, sidebar);
testVisible('#sections-extensions', true);
testVisible('#sections-apps', true);
testVisible('#sections-shortcuts', true);
testVisible('#more-extensions', true);
var testVisible = extension_test_util.testVisible.bind(null, sidebar);
testVisible('#sections-extensions', true);
testVisible('#sections-apps', true);
testVisible('#sections-shortcuts', true);
testVisible('#more-extensions', true);
mockDelegate.testClickingCalls(
sidebar.$$('#sections-extensions'), 'showType',
[extensions.ShowingType.EXTENSIONS]);
mockDelegate.testClickingCalls(
sidebar.$$('#sections-apps'), 'showType',
[extensions.ShowingType.APPS]);
mockDelegate.testClickingCalls(
sidebar.$$('#sections-shortcuts'), 'showKeyboardShortcuts', []);
});
mockDelegate.testClickingCalls(
sidebar.$$('#sections-extensions'), 'showType',
[extensions.ShowingType.EXTENSIONS]);
mockDelegate.testClickingCalls(
sidebar.$$('#sections-apps'), 'showType',
[extensions.ShowingType.APPS]);
mockDelegate.testClickingCalls(
sidebar.$$('#sections-shortcuts'), 'showKeyboardShortcuts', []);
});
}
});
return {
registerTests: registerTests,
TestNames: TestNames,
};
});
......@@ -31,63 +31,58 @@ cr.define('extension_toolbar_tests', function() {
ClickHandlers: 'click handlers',
};
function registerTests() {
suite('ExtensionToolbarTest', function() {
/** @type {MockDelegate} */
var mockDelegate;
/** @type {extensions.Toolbar} */
var toolbar;
setup(function() {
toolbar = document.querySelector('extensions-manager').toolbar;
mockDelegate = new MockDelegate();
toolbar.set('delegate', mockDelegate);
});
test(assert(TestNames.Layout), function() {
extension_test_util.testIronIcons(toolbar);
var testVisible = extension_test_util.testVisible.bind(null, toolbar);
testVisible('#dev-mode', true);
testVisible('#load-unpacked', false);
testVisible('#pack-extensions', false);
testVisible('#update-now', false);
toolbar.set('inDevMode', true);
Polymer.dom.flush();
testVisible('#dev-mode', true);
testVisible('#load-unpacked', true);
testVisible('#pack-extensions', true);
testVisible('#update-now', true);
});
test(assert(TestNames.ClickHandlers), function() {
toolbar.set('inDevMode', true);
Polymer.dom.flush();
mockDelegate.testClickingCalls(
toolbar.$['dev-mode'], 'setProfileInDevMode',
[false]);
mockDelegate.testClickingCalls(
toolbar.$['dev-mode'], 'setProfileInDevMode',
[true]);
mockDelegate.testClickingCalls(
toolbar.$$('#load-unpacked'), 'loadUnpacked', []);
mockDelegate.testClickingCalls(
toolbar.$$('#update-now'), 'updateAllExtensions', []);
var listener = new extension_test_util.ListenerMock();
listener.addListener(toolbar, 'pack-tap');
MockInteractions.tap(toolbar.$$('#pack-extensions'));
listener.verify();
});
suite('ExtensionToolbarTest', function() {
/** @type {MockDelegate} */
var mockDelegate;
/** @type {extensions.Toolbar} */
var toolbar;
setup(function() {
toolbar = document.querySelector('extensions-manager').toolbar;
mockDelegate = new MockDelegate();
toolbar.set('delegate', mockDelegate);
});
test(assert(TestNames.Layout), function() {
extension_test_util.testIronIcons(toolbar);
var testVisible = extension_test_util.testVisible.bind(null, toolbar);
testVisible('#dev-mode', true);
testVisible('#load-unpacked', false);
testVisible('#pack-extensions', false);
testVisible('#update-now', false);
toolbar.set('inDevMode', true);
Polymer.dom.flush();
testVisible('#dev-mode', true);
testVisible('#load-unpacked', true);
testVisible('#pack-extensions', true);
testVisible('#update-now', true);
});
test(assert(TestNames.ClickHandlers), function() {
toolbar.set('inDevMode', true);
Polymer.dom.flush();
mockDelegate.testClickingCalls(
toolbar.$['dev-mode'], 'setProfileInDevMode', [false]);
mockDelegate.testClickingCalls(
toolbar.$['dev-mode'], 'setProfileInDevMode', [true]);
mockDelegate.testClickingCalls(
toolbar.$$('#load-unpacked'), 'loadUnpacked', []);
mockDelegate.testClickingCalls(
toolbar.$$('#update-now'), 'updateAllExtensions', []);
var listener = new extension_test_util.ListenerMock();
listener.addListener(toolbar, 'pack-tap');
MockInteractions.tap(toolbar.$$('#pack-extensions'));
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