summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authormpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-11 00:05:34 +0000
committermpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-11 00:05:34 +0000
commit1bd5413c93779467e15c402e5bb1c866792bcac6 (patch)
tree19615d0f974d67abadd8464d188c5a8a02b84fe0 /chrome/browser/extensions
parentd9fac60990a817c7ef7f1a7beef90dc319bf299b (diff)
downloadchromium_src-1bd5413c93779467e15c402e5bb1c866792bcac6.zip
chromium_src-1bd5413c93779467e15c402e5bb1c866792bcac6.tar.gz
chromium_src-1bd5413c93779467e15c402e5bb1c866792bcac6.tar.bz2
Disable extensions in incognito mode.
Add a browsertest to make sure we don't crash with an incognito window open. Had to finagle utility_process_host to make it work in a browsertest. BUG=12326 TEST=none Review URL: http://codereview.chromium.org/118476 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18116 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/extension_browsertest.cc (renamed from chrome/browser/extensions/extension_view_unittest.cc)47
-rw-r--r--chrome/browser/extensions/extension_shelf_model.cc3
-rw-r--r--chrome/browser/extensions/extensions_ui.cc5
-rw-r--r--chrome/browser/extensions/test_extension_loader.cc21
-rw-r--r--chrome/browser/extensions/test_extension_loader.h6
5 files changed, 72 insertions, 10 deletions
diff --git a/chrome/browser/extensions/extension_view_unittest.cc b/chrome/browser/extensions/extension_browsertest.cc
index 2f5abf8..c61c59d 100644
--- a/chrome/browser/extensions/extension_view_unittest.cc
+++ b/chrome/browser/extensions/extension_browsertest.cc
@@ -4,6 +4,7 @@
#include "base/ref_counted.h"
#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_list.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/extensions/extension_shelf.h"
#include "chrome/browser/extensions/extension_host.h"
@@ -15,6 +16,7 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_error_reporter.h"
+#include "chrome/common/url_constants.h"
#include "chrome/test/in_process_browser_test.h"
#include "chrome/test/ui_test_utils.h"
@@ -24,8 +26,9 @@ namespace {
// up.
const int kAlertTimeoutMs = 20000;
-// The extension we're using as our test case.
-const char* kExtensionId = "00123456789abcdef0123456789abcdef0123456";
+// The extensions we're using as our test case.
+const char* kGoodExtension1Id = "00123456789abcdef0123456789abcdef0123456";
+const char* kGoodCrxId = "00123456789abcdef0123456789abcdef0123456";
}; // namespace
@@ -88,8 +91,8 @@ class ExtensionViewTest : public InProcessBrowserTest {
};
// Tests that ExtensionView starts an extension process and runs the script
-// contained in the extension's "index.html" file.
-IN_PROC_BROWSER_TEST_F(ExtensionViewTest, Index) {
+// contained in the extension's toolstrip.
+IN_PROC_BROWSER_TEST_F(ExtensionViewTest, Toolstrip) {
// Get the path to our extension.
FilePath path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
@@ -99,7 +102,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionViewTest, Index) {
// Wait for the extension to load and grab a pointer to it.
TestExtensionLoader loader(browser()->profile());
- Extension* extension = loader.Load(kExtensionId, path);
+ Extension* extension = loader.Load(kGoodExtension1Id, path);
ASSERT_TRUE(extension);
GURL url = Extension::GetResourceURL(extension->url(), "toolstrip1.html");
@@ -129,12 +132,42 @@ IN_PROC_BROWSER_TEST_F(ExtensionViewTest, Shelf) {
// Wait for the extension to load and grab a pointer to it.
TestExtensionLoader loader(browser()->profile());
- Extension* extension = loader.Load(kExtensionId, path);
+ Extension* extension = loader.Load(kGoodExtension1Id, path);
ASSERT_TRUE(extension);
- GURL url = Extension::GetResourceURL(extension->url(), "toolstrip1.html");
// There should now be two extension views and preferred height of the view
// should be non-zero.
EXPECT_EQ(shelf->GetChildViewCount(), 2);
EXPECT_NE(shelf->GetPreferredSize().height(), 0);
}
+
+// Tests that installing and uninstalling extensions don't crash with an
+// incognito window open.
+IN_PROC_BROWSER_TEST_F(ExtensionViewTest, Incognito) {
+ // Open an incognito window to the extensions management page. We just
+ // want to make sure that we don't crash while playing with extensions when
+ // this guy is around.
+ Browser::OpenURLOffTheRecord(browser()->profile(),
+ GURL(chrome::kChromeUIExtensionsURL));
+
+ // Get the path to our extension.
+ FilePath path;
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
+ path = path.AppendASCII("extensions").AppendASCII("good.crx");
+ ASSERT_TRUE(file_util::PathExists(path)); // sanity check
+
+ // Wait for the extension to load and grab a pointer to it.
+ TestExtensionLoader loader(browser()->profile());
+ Extension* extension = loader.Install(kGoodCrxId, path);
+ ASSERT_TRUE(extension);
+
+ // TODO(mpcomplete): wait for uninstall to complete?
+ browser()->profile()->GetExtensionsService()->UninstallExtension(kGoodCrxId);
+
+ // Close our incognito window.
+ Browser* otr_browser = BrowserList::FindBrowserWithType(
+ browser()->profile()->GetOffTheRecordProfile(),
+ Browser::TYPE_NORMAL);
+ if (otr_browser)
+ otr_browser->CloseAllTabs();
+}
diff --git a/chrome/browser/extensions/extension_shelf_model.cc b/chrome/browser/extensions/extension_shelf_model.cc
index 37d3eb6..6af45c6 100644
--- a/chrome/browser/extensions/extension_shelf_model.cc
+++ b/chrome/browser/extensions/extension_shelf_model.cc
@@ -107,6 +107,9 @@ void ExtensionShelfModel::Observe(NotificationType type,
void ExtensionShelfModel::AddExtensions(const ExtensionList* extensions) {
ExtensionProcessManager* manager =
browser_->profile()->GetExtensionProcessManager();
+ if (!manager)
+ return;
+
for (ExtensionList::const_iterator extension = extensions->begin();
extension != extensions->end(); ++extension) {
for (std::vector<std::string>::const_iterator toolstrip_path =
diff --git a/chrome/browser/extensions/extensions_ui.cc b/chrome/browser/extensions/extensions_ui.cc
index c23dcb6..af69ec6 100644
--- a/chrome/browser/extensions/extensions_ui.cc
+++ b/chrome/browser/extensions/extensions_ui.cc
@@ -224,7 +224,7 @@ std::vector<ExtensionPage> ExtensionsDOMHandler::GetActivePagesForExtension(
std::vector<ExtensionPage> result;
ExtensionMessageService* ems = ExtensionMessageService::GetInstance(
- dom_ui_->GetProfile()->GetRequestContext());
+ dom_ui_->GetProfile()->GetOriginalProfile()->GetRequestContext());
RenderProcessHost* process_host = ems->GetProcessForExtension(extension_id);
if (!process_host)
return result;
@@ -260,7 +260,8 @@ void ExtensionsDOMHandler::Init() {
}
ExtensionsUI::ExtensionsUI(TabContents* contents) : DOMUI(contents) {
- ExtensionsService *exstension_service = GetProfile()->GetExtensionsService();
+ ExtensionsService *exstension_service =
+ GetProfile()->GetOriginalProfile()->GetExtensionsService();
ExtensionsDOMHandler* handler = new ExtensionsDOMHandler(this,
exstension_service);
diff --git a/chrome/browser/extensions/test_extension_loader.cc b/chrome/browser/extensions/test_extension_loader.cc
index d8bacb7..d17f557 100644
--- a/chrome/browser/extensions/test_extension_loader.cc
+++ b/chrome/browser/extensions/test_extension_loader.cc
@@ -15,6 +15,7 @@ namespace {
// How long to wait for the extension to load before giving up.
const int kLoadTimeoutMs = 5000;
+const int kInstallTimeoutMs = 10000;
} // namespace
@@ -25,7 +26,8 @@ TestExtensionLoader::TestExtensionLoader(Profile* profile)
NotificationService::AllSources());
profile_->GetExtensionsService()->Init();
- DCHECK(profile_->GetExtensionsService()->extensions()->empty());
+ profile_->GetExtensionsService()->set_show_extensions_prompts(false);
+ DCHECK(profile_->GetExtensionsService()->extensions()->empty());
}
Extension* TestExtensionLoader::Load(const char* extension_id,
@@ -45,6 +47,23 @@ Extension* TestExtensionLoader::Load(const char* extension_id,
return extension_;
}
+Extension* TestExtensionLoader::Install(const char* extension_id,
+ const FilePath& path) {
+ loading_extension_id_ = extension_id;
+
+ // Install the extension. When installed, the extension will automatically
+ // be loaded.
+ profile_->GetExtensionsService()->InstallExtension(path);
+
+ // Wait for the load to complete.
+ extension_ = NULL;
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ new MessageLoop::QuitTask, kInstallTimeoutMs);
+ ui_test_utils::RunMessageLoop();
+
+ return extension_;
+}
+
void TestExtensionLoader::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
diff --git a/chrome/browser/extensions/test_extension_loader.h b/chrome/browser/extensions/test_extension_loader.h
index 60ca84f..e0ef193 100644
--- a/chrome/browser/extensions/test_extension_loader.h
+++ b/chrome/browser/extensions/test_extension_loader.h
@@ -17,8 +17,14 @@ class TestExtensionLoader : public NotificationObserver {
public:
explicit TestExtensionLoader(Profile* profile);
+ // Tells the extension service to load the extension at the given path. It
+ // waits for the extension with the expected ID to load, then returns a
+ // handle to it.
Extension* Load(const char* extension_id, const FilePath& path);
+ // Same as above, but installs from a CRX first.
+ Extension* Install(const char* extension_id, const FilePath& path);
+
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details);