1 // Copyright (c) 2012 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.
5 // TODO(dbeam): test for loading upacked extensions?
7 GEN('#include "chrome/browser/ui/webui/extensions/' +
8 'extension_settings_browsertest.h"');
10 // The id of the extension from |InstallGoodExtension|.
11 var GOOD_EXTENSION_ID = 'ldnnhddmnhbkjipkidpdiheffobcpfmf';
13 // The id of the extension from |InstallErrorsExtension|.
14 var ERROR_EXTENSION_ID = 'pdlpifnclfacjobnmbpngemkalkjamnf';
17 * Test C++ fixture for settings WebUI testing.
19 * @extends {testing.Test}
21 function ExtensionSettingsUIBrowserTest() {}
24 * TestFixture for extension settings WebUI testing.
25 * @extends {testing.Test}
28 function ExtensionSettingsWebUITest() {}
30 ExtensionSettingsWebUITest.prototype = {
31 __proto__: testing.Test.prototype,
37 runAccessibilityChecks: true,
40 accessibilityIssuesAreErrors: true,
43 * A URL to load before starting each test.
47 browsePreload: 'chrome://extensions-frame/',
50 typedefCppFixture: 'ExtensionSettingsUIBrowserTest',
54 testing.Test.disableAnimationsAndTransitions();
58 * Holds an array of steps that should happen in order during a test.
59 * The last step should be |testDone|.
60 * @protected {Array<!Function>}
65 * Advances to the next step in the test. Every step should call this.
68 nextStep: function() {
69 assertTrue(this.steps.length > 0);
70 this.steps.shift().call(this);
74 * Will wait for the page to load before calling the next step. This should be
75 * the first step in every test.
78 waitForPageLoad: function() {
79 assertEquals(this.browsePreload, document.location.href);
80 var extensionList = getRequiredElement('extension-settings-list');
81 extensionList.loadFinished.then(this.nextStep.bind(this));
85 enableDeveloperMode: function() {
86 var next = this.nextStep.bind(this);
87 extensions.ExtensionSettings.getInstance().testingDeveloperModeCallback =
89 chrome.developerPrivate.getProfileConfiguration(function(profileInfo) {
90 assertTrue(extensionSettings.classList.contains('dev-mode'));
91 assertTrue(profileInfo.inDeveloperMode);
94 // This event isn't thrown because transitions are disabled.
95 // Ensure transition here so that any dependent code does not break.
96 ensureTransitionEndEvent($('dev-controls'), 0);
100 var extensionSettings = getRequiredElement('extension-settings');
101 assertFalse(extensionSettings.classList.contains('dev-mode'));
102 $('toggle-dev-on').click();
106 testDeveloperMode: function() {
107 var next = this.nextStep.bind(this);
108 var checkDevModeIsOff = function() {
109 chrome.developerPrivate.getProfileConfiguration(function(profileInfo) {
110 assertFalse(profileInfo.inDeveloperMode);
114 this.steps = [this.waitForPageLoad,
116 this.enableDeveloperMode,
122 // Verify that developer mode doesn't change behavior when the number of
123 // extensions changes.
124 TEST_F('ExtensionSettingsWebUITest', 'testDeveloperModeNoExtensions',
126 this.testDeveloperMode();
129 TEST_F('ExtensionSettingsWebUITest', 'testEmptyExtensionList', function() {
130 var verifyListIsHiddenAndEmpty = function() {
131 assertTrue($('extension-list-wrapper').hidden);
132 assertFalse($('no-extensions').hidden);
133 assertEquals(0, $('extension-settings-list').childNodes.length);
137 this.steps = [this.waitForPageLoad, verifyListIsHiddenAndEmpty, testDone];
141 TEST_F('ExtensionSettingsWebUITest', 'testChromeSendHandled', function() {
142 var testPackExtenion = function() {
143 // This dialog should be hidden at first.
144 assertFalse($('pack-extension-overlay').classList.contains('showing'));
146 // Show the dialog, which triggers a chrome.send() for metrics purposes.
147 cr.dispatchSimpleEvent($('pack-extension'), 'click');
148 assertTrue($('pack-extension-overlay').classList.contains('showing'));
152 this.steps = [this.waitForPageLoad, testPackExtenion, testDone];
157 * @param {chrome.developerPrivate.EventType} eventType
158 * @param {function():void} callback
161 function UpdateListener(eventType, callback) {
162 this.callback_ = callback;
163 this.eventType_ = eventType;
164 this.onItemStateChangedListener_ = this.onItemStateChanged_.bind(this);
165 chrome.developerPrivate.onItemStateChanged.addListener(
166 this.onItemStateChangedListener_);
169 UpdateListener.prototype = {
171 onItemStateChanged_: function(data) {
172 if (this.eventType_ == data.event_type) {
173 window.setTimeout(function() {
174 chrome.developerPrivate.onItemStateChanged.removeListener(
175 this.onItemStateChangedListener_);
182 function BasicExtensionSettingsWebUITest() {}
184 BasicExtensionSettingsWebUITest.prototype = {
185 __proto__: ExtensionSettingsWebUITest.prototype,
188 testGenPreamble: function() {
189 // Install multiple types of extensions to ensure we handle each type.
190 // TODO(devlin): There are more types to add here.
191 GEN(' InstallGoodExtension();');
192 GEN(' InstallErrorsExtension();');
193 GEN(' InstallSharedModule();');
194 GEN(' InstallPackagedApp();');
196 GEN(' SetAutoConfirmUninstall();');
200 verifyDisabledWorks: function() {
201 var listener = new UpdateListener(
202 chrome.developerPrivate.EventType.UNLOADED,
204 var node = getRequiredElement(GOOD_EXTENSION_ID);
205 assertTrue(node.classList.contains('inactive-extension'));
208 chrome.management.setEnabled(GOOD_EXTENSION_ID, false);
212 verifyEnabledWorks: function() {
213 var listener = new UpdateListener(
214 chrome.developerPrivate.EventType.LOADED,
216 var node = getRequiredElement(GOOD_EXTENSION_ID);
217 assertFalse(node.classList.contains('inactive-extension'));
220 chrome.management.setEnabled(GOOD_EXTENSION_ID, true);
224 verifyUninstallWorks: function() {
225 var listener = new UpdateListener(
226 chrome.developerPrivate.EventType.UNINSTALLED,
228 assertEquals(null, $(GOOD_EXTENSION_ID));
231 chrome.test.runWithUserGesture(function() {
232 chrome.management.uninstall(GOOD_EXTENSION_ID);
237 // Verify that developer mode doesn't change behavior when the number of
238 // extensions changes.
239 TEST_F('BasicExtensionSettingsWebUITest', 'testDeveloperModeManyExtensions',
241 this.testDeveloperMode();
245 TEST_F('BasicExtensionSettingsWebUITest', 'testDisable', function() {
246 this.steps = [this.waitForPageLoad, this.verifyDisabledWorks, testDone];
250 TEST_F('BasicExtensionSettingsWebUITest', 'testEnable', function() {
251 this.steps = [this.waitForPageLoad,
252 this.verifyDisabledWorks,
253 this.verifyEnabledWorks,
258 TEST_F('BasicExtensionSettingsWebUITest', 'testUninstall', function() {
259 this.steps = [this.waitForPageLoad, this.verifyUninstallWorks, testDone];
263 TEST_F('BasicExtensionSettingsWebUITest', 'testNonEmptyExtensionList',
265 var verifyListIsNotHiddenAndEmpty = function() {
266 assertFalse($('extension-list-wrapper').hidden);
267 assertTrue($('no-extensions').hidden);
268 assertGT($('extension-settings-list').childNodes.length, 0);
272 this.steps = [this.waitForPageLoad, verifyListIsNotHiddenAndEmpty, testDone];
276 function ErrorConsoleExtensionSettingsWebUITest() {}
278 ErrorConsoleExtensionSettingsWebUITest.prototype = {
279 __proto__: ExtensionSettingsWebUITest.prototype,
282 testGenPreamble: function() {
283 GEN(' EnableErrorConsole();');
284 GEN(' InstallGoodExtension();');
285 GEN(' InstallErrorsExtension();');
289 TEST_F('ErrorConsoleExtensionSettingsWebUITest',
290 'testErrorListButtonVisibility', function() {
291 var testButtonVisibility = function() {
292 var extensionList = $('extension-list-wrapper');
294 var visibleButtons = extensionList.querySelectorAll(
295 '.errors-link:not([hidden])');
296 expectEquals(1, visibleButtons.length);
298 if (visibleButtons.length > 0) {
299 var errorLink = $(ERROR_EXTENSION_ID).querySelector('.errors-link');
300 expectEquals(visibleButtons[0], errorLink);
302 var errorIcon = errorLink.querySelector('img');
303 expectTrue(errorIcon.classList.contains('extension-error-warning-icon'));
306 var hiddenButtons = extensionList.querySelectorAll('.errors-link[hidden]');
307 expectEquals(1, hiddenButtons.length);
312 this.steps = [this.waitForPageLoad,
313 this.enableDeveloperMode,
314 testButtonVisibility,
320 * TestFixture for extension settings WebUI testing (commands config edition).
321 * @extends {testing.Test}
324 function SettingsCommandsExtensionSettingsWebUITest() {}
326 SettingsCommandsExtensionSettingsWebUITest.prototype = {
327 __proto__: ExtensionSettingsWebUITest.prototype,
330 * A URL to load before starting each test.
334 browsePreload: 'chrome://extensions-frame/configureCommands',
337 TEST_F('SettingsCommandsExtensionSettingsWebUITest', 'testChromeSendHandler',
339 // Just navigating to the page should trigger the chrome.send().
340 var assertOverlayVisible = function() {
341 assertTrue($('extension-commands-overlay').classList.contains('showing'));
345 this.steps = [this.waitForPageLoad, assertOverlayVisible, testDone];
351 * @extends {ExtensionSettingsWebUITest}
353 function InstallGoodExtensionSettingsWebUITest() {}
355 InstallGoodExtensionSettingsWebUITest.prototype = {
356 __proto__: ExtensionSettingsWebUITest.prototype,
359 testGenPreamble: function() {
360 GEN(' InstallGoodExtension();');
363 emptyTestForAccessibility() {
364 this.steps = [this.waitForPageLoad, testDone];
369 TEST_F('InstallGoodExtensionSettingsWebUITest', 'testAccessibility',
371 this.emptyTestForAccessibility();
374 TEST_F('InstallGoodExtensionSettingsWebUITest', 'showOptions', function() {
375 var showExtensionOptions = function() {
376 var optionsOverlay = extensions.ExtensionOptionsOverlay.getInstance();
377 optionsOverlay.setExtensionAndShow(GOOD_EXTENSION_ID, 'GOOD!', '',
378 this.nextStep.bind(this));
380 // Preferred size changes don't happen in browser tests. Just fake it.
381 document.querySelector('extensionoptions').onpreferredsizechanged(
382 {width: 500, height: 500});
385 this.steps = [this.waitForPageLoad, showExtensionOptions, testDone];
391 * @extends {InstallGoodExtensionSettingsWebUITest}
393 function ManagedExtensionSettingsWebUITest() {}
395 ManagedExtensionSettingsWebUITest.prototype = {
396 __proto__: InstallGoodExtensionSettingsWebUITest.prototype,
399 testGenPreamble: function() {
400 GEN(' AddManagedPolicyProvider();');
401 InstallGoodExtensionSettingsWebUITest.prototype.testGenPreamble.call(this);
405 TEST_F('ManagedExtensionSettingsWebUITest', 'testAccessibility', function() {
406 this.emptyTestForAccessibility();
411 * @extends {InstallGoodExtensionSettingsWebUITest}
413 function OptionsDialogExtensionSettingsWebUITest() {}
415 OptionsDialogExtensionSettingsWebUITest.prototype = {
416 __proto__: InstallGoodExtensionSettingsWebUITest.prototype,
419 browsePreload: ExtensionSettingsWebUITest.prototype.browsePreload +
420 '?options=' + GOOD_EXTENSION_ID,
423 TEST_F('OptionsDialogExtensionSettingsWebUITest', 'testAccessibility',
425 this.emptyTestForAccessibility();