summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-15 04:30:12 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-15 04:30:12 +0000
commit919ddc8c4928d69c3db02c68c0dbf573ebc54899 (patch)
tree74d8d509008427576fddfcf01282b897df23d261 /chrome/browser/extensions
parent6f317586c5b00ab2196d9f3dbff571bad34b8352 (diff)
downloadchromium_src-919ddc8c4928d69c3db02c68c0dbf573ebc54899.zip
chromium_src-919ddc8c4928d69c3db02c68c0dbf573ebc54899.tar.gz
chromium_src-919ddc8c4928d69c3db02c68c0dbf573ebc54899.tar.bz2
Various minor fixes:
* --load-extension no longer requires --enable-extensions * No longer support chrome:// URLs for user scripts * Remove old unused Greasemonkey test * Enable Greasemonkey API emulation in linux/mac BUG=16720,16007,4476 TEST=Added several unit tests Original review: http://codereview.chromium.org/149619 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20719 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/extension_startup_unittest.cc152
-rw-r--r--chrome/browser/extensions/extensions_service.cc1
-rw-r--r--chrome/browser/extensions/extensions_service.h1
3 files changed, 90 insertions, 64 deletions
diff --git a/chrome/browser/extensions/extension_startup_unittest.cc b/chrome/browser/extensions/extension_startup_unittest.cc
index 540671e..74d40a9 100644
--- a/chrome/browser/extensions/extension_startup_unittest.cc
+++ b/chrome/browser/extensions/extension_startup_unittest.cc
@@ -71,6 +71,11 @@ class ExtensionStartupTestBase
file_util::CopyFile(src_dir.AppendASCII("script2.js"),
user_scripts_dir_.AppendASCII("script2.user.js"));
}
+
+ if (!load_extension_.value().empty()) {
+ command_line->AppendSwitchWithValue(switches::kLoadExtension,
+ load_extension_.ToWStringHack());
+ }
}
// NotificationObserver
@@ -91,11 +96,65 @@ class ExtensionStartupTestBase
file_util::Delete(extensions_dir_, true);
}
+ void WaitForServicesToStart(int num_expected_extensions,
+ bool expect_extensions_enabled) {
+ ExtensionsService* service = browser()->profile()->GetExtensionsService();
+ if (!service->is_ready()) {
+ registrar_.Add(this, NotificationType::EXTENSIONS_READY,
+ NotificationService::AllSources());
+ ui_test_utils::RunMessageLoop();
+ registrar_.Remove(this, NotificationType::EXTENSIONS_READY,
+ NotificationService::AllSources());
+ }
+
+ ASSERT_EQ(static_cast<uint32>(num_expected_extensions),
+ service->extensions()->size());
+ ASSERT_EQ(expect_extensions_enabled, service->extensions_enabled());
+
+ UserScriptMaster* master = browser()->profile()->GetUserScriptMaster();
+ if (!master->ScriptsReady()) {
+ // Wait for UserScriptMaster to finish its scan.
+ registrar_.Add(this, NotificationType::USER_SCRIPTS_UPDATED,
+ NotificationService::AllSources());
+ ui_test_utils::RunMessageLoop();
+ registrar_.Remove(this, NotificationType::USER_SCRIPTS_UPDATED,
+ NotificationService::AllSources());
+ }
+ ASSERT_TRUE(master->ScriptsReady());
+ }
+
+ void TestInjection(bool expect_css, bool expect_script) {
+ // Load a page affected by the content script and test to see the effect.
+ FilePath test_file;
+ PathService::Get(chrome::DIR_TEST_DATA, &test_file);
+ test_file = test_file.AppendASCII("extensions")
+ .AppendASCII("test_file.html");
+
+ ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(test_file));
+
+ bool result = false;
+ ui_test_utils::ExecuteJavaScriptAndExtractBool(
+ browser()->GetSelectedTabContents()->render_view_host(), L"",
+ L"window.domAutomationController.send("
+ L"document.defaultView.getComputedStyle(document.body, null)."
+ L"getPropertyValue('background-color') == 'rgb(245, 245, 220)')",
+ &result);
+ EXPECT_EQ(expect_css, result);
+
+ result = false;
+ ui_test_utils::ExecuteJavaScriptAndExtractBool(
+ browser()->GetSelectedTabContents()->render_view_host(), L"",
+ L"window.domAutomationController.send(document.title == 'Modified')",
+ &result);
+ EXPECT_EQ(expect_script, result);
+ }
+
FilePath preferences_file_;
FilePath extensions_dir_;
FilePath user_scripts_dir_;
bool enable_extensions_;
bool enable_user_scripts_;
+ FilePath load_extension_;
NotificationRegistrar registrar_;
};
@@ -112,58 +171,36 @@ class ExtensionsStartupTest : public ExtensionStartupTestBase {
};
IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, Test) {
- ExtensionsService* service = browser()->profile()->GetExtensionsService();
- if (!service->is_ready()) {
- registrar_.Add(this, NotificationType::EXTENSIONS_READY,
- NotificationService::AllSources());
- ui_test_utils::RunMessageLoop();
- registrar_.Remove(this, NotificationType::EXTENSIONS_READY,
- NotificationService::AllSources());
- }
- ASSERT_EQ(3u, service->extensions()->size());
- ASSERT_TRUE(service->extensions_enabled());
-
- UserScriptMaster* master = browser()->profile()->GetUserScriptMaster();
- if (!master->ScriptsReady()) {
- // Wait for UserScriptMaster to finish its scan.
- registrar_.Add(this, NotificationType::USER_SCRIPTS_UPDATED,
- NotificationService::AllSources());
- ui_test_utils::RunMessageLoop();
- registrar_.Remove(this, NotificationType::USER_SCRIPTS_UPDATED,
- NotificationService::AllSources());
- }
- ASSERT_TRUE(master->ScriptsReady());
+ WaitForServicesToStart(3, true);
+ TestInjection(true, true);
+}
- FilePath test_file;
- PathService::Get(chrome::DIR_TEST_DATA, &test_file);
- test_file = test_file.AppendASCII("extensions")
- .AppendASCII("test_file.html");
- // Now we should be able to load a page affected by the content script and see
- // the effect.
- ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(test_file));
+// ExtensionsLoadTest
+// Ensures that we can startup the browser with --load-extension and see them
+// run.
- // Test that the content script ran.
- bool result = false;
- ui_test_utils::ExecuteJavaScriptAndExtractBool(
- browser()->GetSelectedTabContents()->render_view_host(), L"",
- L"window.domAutomationController.send("
- L"document.defaultView.getComputedStyle(document.body, null)."
- L"getPropertyValue('background-color') == 'rgb(245, 245, 220)')",
- &result);
- EXPECT_TRUE(result);
+class ExtensionsLoadTest : public ExtensionStartupTestBase {
+ public:
+ ExtensionsLoadTest() {
+ PathService::Get(chrome::DIR_TEST_DATA, &load_extension_);
+ load_extension_ = load_extension_
+ .AppendASCII("extensions")
+ .AppendASCII("good")
+ .AppendASCII("Extensions")
+ .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
+ .AppendASCII("1.0.0.0");
+ }
+};
- result = false;
- ui_test_utils::ExecuteJavaScriptAndExtractBool(
- browser()->GetSelectedTabContents()->render_view_host(), L"",
- L"window.domAutomationController.send(document.title == 'Modified')",
- &result);
- EXPECT_TRUE(result);
+IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest, Test) {
+ WaitForServicesToStart(1, false);
+ TestInjection(true, true);
}
// ExtensionsStartupUserScriptTest
-// Tests that we can startup with --enable-user-scripts and run user sripts and
+// Tests that we can startup with --enable-user-scripts and run user scripts and
// see them do basic things.
class ExtensionsStartupUserScriptTest : public ExtensionStartupTestBase {
@@ -174,31 +211,20 @@ class ExtensionsStartupUserScriptTest : public ExtensionStartupTestBase {
};
IN_PROC_BROWSER_TEST_F(ExtensionsStartupUserScriptTest, Test) {
- UserScriptMaster* master = browser()->profile()->GetUserScriptMaster();
- if (!master->ScriptsReady()) {
- // Wait for UserScriptMaster to finish its scan.
- registrar_.Add(this, NotificationType::USER_SCRIPTS_UPDATED,
- NotificationService::AllSources());
- ui_test_utils::RunMessageLoop();
- registrar_.Remove(this, NotificationType::USER_SCRIPTS_UPDATED,
- NotificationService::AllSources());
- }
- ASSERT_TRUE(master->ScriptsReady());
+ WaitForServicesToStart(0, false);
+ TestInjection(false, true);
+}
- FilePath test_file;
- PathService::Get(chrome::DIR_TEST_DATA, &test_file);
- test_file = test_file.AppendASCII("extensions")
- .AppendASCII("test_file.html");
+// Ensure we don't inject into chrome:// URLs
+IN_PROC_BROWSER_TEST_F(ExtensionsStartupUserScriptTest, NoInjectIntoChrome) {
+ WaitForServicesToStart(0, false);
- // Now we should be able to load a page affected by the content script and see
- // the effect.
- ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(test_file));
+ ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab"));
- // Test that the user script ran.
bool result = false;
ui_test_utils::ExecuteJavaScriptAndExtractBool(
browser()->GetSelectedTabContents()->render_view_host(), L"",
L"window.domAutomationController.send(document.title == 'Modified')",
&result);
- EXPECT_TRUE(result);
+ EXPECT_FALSE(result);
}
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 27031d8..17fd390 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -430,6 +430,7 @@ void ExtensionsService::OnExtensionsLoaded(ExtensionList* new_extensions) {
for (ExtensionList::iterator iter = new_extensions->begin();
iter != new_extensions->end(); ++iter) {
if (extensions_enabled() || (*iter)->IsTheme() ||
+ (*iter)->location() == Extension::LOAD ||
(*iter)->location() == Extension::EXTERNAL_REGISTRY) {
Extension* old = GetExtensionById((*iter)->id());
if (old) {
diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h
index 8ae2759..87c0dc7 100644
--- a/chrome/browser/extensions/extensions_service.h
+++ b/chrome/browser/extensions/extensions_service.h
@@ -34,7 +34,6 @@ class Profile;
class ResourceDispatcherHost;
class SkBitmap;
class SiteInstance;
-class UserScriptMaster;
typedef std::vector<Extension*> ExtensionList;