Commit 8363aa5d authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

[Extensions UI] Add tests for disabling/enabling/uninstalling extensions

Add some tests for disabling/enabling/uninstalling extensions from the
chrome://extensions page. Since we don't have any, these will help us determine
if we break anything during the transition to observing events from the
developerPrivate API.

BUG=461039

Review URL: https://codereview.chromium.org/1063863004

Cr-Commit-Position: refs/heads/master@{#324076}
parent 6fef54c5
...@@ -218,7 +218,8 @@ cr.define('extensions', function() { ...@@ -218,7 +218,8 @@ cr.define('extensions', function() {
// consider passing in the full object from the ExtensionSettings. // consider passing in the full object from the ExtensionSettings.
this.incognitoAvailable_ = incognitoAvailable; this.incognitoAvailable_ = incognitoAvailable;
this.enableAppInfoDialog_ = enableAppInfoDialog; this.enableAppInfoDialog_ = enableAppInfoDialog;
return new Promise(function(resolve, reject) { /** @private {Promise} */
this.extensionsUpdated_ = new Promise(function(resolve, reject) {
chrome.developerPrivate.getExtensionsInfo( chrome.developerPrivate.getExtensionsInfo(
{includeDisabled: true, includeTerminated: true}, {includeDisabled: true, includeTerminated: true},
function(extensions) { function(extensions) {
...@@ -241,6 +242,7 @@ cr.define('extensions', function() { ...@@ -241,6 +242,7 @@ cr.define('extensions', function() {
resolve(); resolve();
}.bind(this)); }.bind(this));
}.bind(this)); }.bind(this));
return this.extensionsUpdated_;
}, },
/** @return {number} The number of extensions being displayed. */ /** @return {number} The number of extensions being displayed. */
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "extensions/browser/api/management/management_api.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "extensions/browser/test_extension_registry_observer.h" #include "extensions/browser/test_extension_registry_observer.h"
...@@ -36,7 +37,10 @@ ExtensionSettingsUIBrowserTest::ExtensionSettingsUIBrowserTest() ...@@ -36,7 +37,10 @@ ExtensionSettingsUIBrowserTest::ExtensionSettingsUIBrowserTest()
: profile_(NULL), : profile_(NULL),
policy_provider_(TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS | policy_provider_(TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS |
TestManagementPolicyProvider::MUST_REMAIN_ENABLED | TestManagementPolicyProvider::MUST_REMAIN_ENABLED |
TestManagementPolicyProvider::MUST_REMAIN_INSTALLED) {} TestManagementPolicyProvider::MUST_REMAIN_INSTALLED) {
CHECK(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_));
test_data_dir_ = test_data_dir_.AppendASCII("extensions");
}
ExtensionSettingsUIBrowserTest::~ExtensionSettingsUIBrowserTest() {} ExtensionSettingsUIBrowserTest::~ExtensionSettingsUIBrowserTest() {}
...@@ -54,26 +58,27 @@ void ExtensionSettingsUIBrowserTest::SetUpOnMainThread() { ...@@ -54,26 +58,27 @@ void ExtensionSettingsUIBrowserTest::SetUpOnMainThread() {
} }
void ExtensionSettingsUIBrowserTest::InstallGoodExtension() { void ExtensionSettingsUIBrowserTest::InstallGoodExtension() {
base::FilePath test_data_dir; EXPECT_TRUE(InstallExtension(test_data_dir_.AppendASCII("good.crx")));
if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) {
ADD_FAILURE();
return;
}
base::FilePath extensions_data_dir = test_data_dir.AppendASCII("extensions");
EXPECT_TRUE(InstallExtension(extensions_data_dir.AppendASCII("good.crx")));
} }
void ExtensionSettingsUIBrowserTest::InstallErrorsExtension() { void ExtensionSettingsUIBrowserTest::InstallErrorsExtension() {
base::FilePath test_data_dir;
if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) {
ADD_FAILURE();
return;
}
base::FilePath extensions_data_dir = test_data_dir.AppendASCII("extensions");
extensions_data_dir = extensions_data_dir.AppendASCII("error_console");
EXPECT_TRUE(InstallUnpackedExtension( EXPECT_TRUE(InstallUnpackedExtension(
extensions_data_dir.AppendASCII("runtime_and_manifest_errors"), test_data_dir_.AppendASCII("error_console")
"pdlpifnclfacjobnmbpngemkalkjamnf")); .AppendASCII("runtime_and_manifest_errors")));
}
void ExtensionSettingsUIBrowserTest::InstallSharedModule() {
base::FilePath shared_module_path =
test_data_dir_.AppendASCII("api_test").AppendASCII("shared_module");
EXPECT_TRUE(InstallUnpackedExtension(
shared_module_path.AppendASCII("shared")));
EXPECT_TRUE(InstallUnpackedExtension(
shared_module_path.AppendASCII("import_pass")));
}
void ExtensionSettingsUIBrowserTest::InstallPackagedApp() {
EXPECT_TRUE(InstallUnpackedExtension(
test_data_dir_.AppendASCII("packaged_app")));
} }
void ExtensionSettingsUIBrowserTest::AddManagedPolicyProvider() { void ExtensionSettingsUIBrowserTest::AddManagedPolicyProvider() {
...@@ -81,6 +86,10 @@ void ExtensionSettingsUIBrowserTest::AddManagedPolicyProvider() { ...@@ -81,6 +86,10 @@ void ExtensionSettingsUIBrowserTest::AddManagedPolicyProvider() {
extension_service->management_policy()->RegisterProvider(&policy_provider_); extension_service->management_policy()->RegisterProvider(&policy_provider_);
} }
void ExtensionSettingsUIBrowserTest::SetAutoConfirmUninstall() {
extensions::ManagementUninstallFunctionBase::SetAutoConfirmForTest(true);
}
class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt { class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt {
public: public:
explicit MockAutoConfirmExtensionInstallPrompt( explicit MockAutoConfirmExtensionInstallPrompt(
...@@ -96,7 +105,7 @@ class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt { ...@@ -96,7 +105,7 @@ class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt {
}; };
const Extension* ExtensionSettingsUIBrowserTest::InstallUnpackedExtension( const Extension* ExtensionSettingsUIBrowserTest::InstallUnpackedExtension(
const base::FilePath& path, const char* id) { const base::FilePath& path) {
if (path.empty()) if (path.empty())
return NULL; return NULL;
...@@ -106,13 +115,15 @@ const Extension* ExtensionSettingsUIBrowserTest::InstallUnpackedExtension( ...@@ -106,13 +115,15 @@ const Extension* ExtensionSettingsUIBrowserTest::InstallUnpackedExtension(
service->set_show_extensions_prompts(false); service->set_show_extensions_prompts(false);
extensions::ExtensionRegistry* registry = extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(profile); extensions::ExtensionRegistry::Get(profile);
extensions::TestExtensionRegistryObserver observer(registry, id); extensions::TestExtensionRegistryObserver observer(registry);
extensions::UnpackedInstaller::Create(service)->Load(path); extensions::UnpackedInstaller::Create(service)->Load(path);
base::FilePath extension_path = base::MakeAbsoluteFilePath(path);
const Extension* extension = nullptr;
do {
extension = observer.WaitForExtensionLoaded();
} while (extension->path() != extension_path);
// Test will timeout if extension is not loaded. return extension;
observer.WaitForExtensionLoaded();
return service->GetExtensionById(last_loaded_extension_id(), false);
} }
const Extension* ExtensionSettingsUIBrowserTest::InstallExtension( const Extension* ExtensionSettingsUIBrowserTest::InstallExtension(
......
...@@ -32,12 +32,18 @@ class ExtensionSettingsUIBrowserTest : public WebUIBrowserTest { ...@@ -32,12 +32,18 @@ class ExtensionSettingsUIBrowserTest : public WebUIBrowserTest {
void InstallErrorsExtension(); void InstallErrorsExtension();
void InstallSharedModule();
void InstallPackagedApp();
void AddManagedPolicyProvider(); void AddManagedPolicyProvider();
void SetAutoConfirmUninstall();
private: private:
bool WaitForExtensionViewsToLoad(); bool WaitForExtensionViewsToLoad();
const extensions::Extension* InstallUnpackedExtension( const extensions::Extension* InstallUnpackedExtension(
const base::FilePath& path, const char* id); const base::FilePath& path);
const extensions::Extension* InstallExtension(const base::FilePath& path); const extensions::Extension* InstallExtension(const base::FilePath& path);
scoped_ptr<ExtensionTestNotificationObserver> observer_; scoped_ptr<ExtensionTestNotificationObserver> observer_;
...@@ -48,6 +54,8 @@ class ExtensionSettingsUIBrowserTest : public WebUIBrowserTest { ...@@ -48,6 +54,8 @@ class ExtensionSettingsUIBrowserTest : public WebUIBrowserTest {
// Used to simulate managed extensions (by being registered as a provider). // Used to simulate managed extensions (by being registered as a provider).
extensions::TestManagementPolicyProvider policy_provider_; extensions::TestManagementPolicyProvider policy_provider_;
base::FilePath test_data_dir_;
DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsUIBrowserTest); DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsUIBrowserTest);
}; };
......
...@@ -56,6 +56,108 @@ TEST_F('ExtensionSettingsWebUITest', 'testChromeSendHandled', function() { ...@@ -56,6 +56,108 @@ TEST_F('ExtensionSettingsWebUITest', 'testChromeSendHandled', function() {
assertTrue($('pack-extension-overlay').classList.contains('showing')); assertTrue($('pack-extension-overlay').classList.contains('showing'));
}); });
function BasicExtensionSettingsWebUITest() {}
BasicExtensionSettingsWebUITest.prototype = {
__proto__: ExtensionSettingsWebUITest.prototype,
/** @override */
isAsync: true,
/** @override */
testGenPreamble: function() {
// Install multiple types of extensions to ensure we handle each type.
// TODO(devlin): There are more types to add here.
GEN(' InstallGoodExtension();');
GEN(' InstallErrorsExtension();');
GEN(' InstallSharedModule();');
GEN(' InstallPackagedApp();');
GEN(' SetAutoConfirmUninstall();');
},
/** @protected {Array<!Function>} */
steps: [],
/** @protected */
nextStep: function() {
assertTrue(this.steps.length > 0);
this.steps.shift().call(this);
},
/** @protected */
waitForPageLoad: function() {
var extensionList = getRequiredElement('extension-settings-list');
extensionList.extensionsUpdated_.then(this.nextStep.bind(this));
},
/**
* A silly hack because we re-fetch extension data after every event, which is
* asynchronous. This will be unneeded once we transition to observing events
* on the developerPrivate API.
* @param {Function} after The function to run after the pending requests.
* @protected
*/
runPendingRequests: function(after) {
window.setTimeout(function() {
chrome.developerPrivate.getExtensionsInfo(after);
}, 0);
},
/** @protected */
verifyDisabledWorks: function() {
chrome.management.setEnabled(GOOD_CRX_ID, false,
this.runPendingRequests.bind(this, function() {
var node = getRequiredElement(GOOD_CRX_ID);
assertTrue(node.classList.contains('inactive-extension'));
this.nextStep();
}.bind(this)));
},
/** @protected */
verifyEnabledWorks: function() {
chrome.management.setEnabled(GOOD_CRX_ID, true,
this.runPendingRequests.bind(this, function() {
var node = getRequiredElement(GOOD_CRX_ID);
assertFalse(node.classList.contains('inactive-extension'));
this.nextStep();
}.bind(this)));
},
/** @protected */
verifyUninstallWorks: function() {
chrome.test.runWithUserGesture(function() {
chrome.management.uninstall(GOOD_CRX_ID,
this.runPendingRequests.bind(this, function() {
assertEquals(null, $(GOOD_CRX_ID));
this.nextStep();
}.bind(this)));
}.bind(this));
},
};
TEST_F('BasicExtensionSettingsWebUITest', 'testDisable', function() {
this.steps = [this.waitForPageLoad,
this.verifyDisabledWorks,
testDone];
this.nextStep();
});
TEST_F('BasicExtensionSettingsWebUITest', 'testEnable', function() {
this.steps = [this.waitForPageLoad,
this.verifyDisabledWorks,
this.verifyEnabledWorks,
testDone];
this.nextStep();
});
TEST_F('BasicExtensionSettingsWebUITest', 'testUninstall', function() {
this.steps = [this.waitForPageLoad,
this.verifyUninstallWorks,
testDone];
this.nextStep();
});
function AsyncExtensionSettingsWebUITest() {} function AsyncExtensionSettingsWebUITest() {}
AsyncExtensionSettingsWebUITest.prototype = { AsyncExtensionSettingsWebUITest.prototype = {
......
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