summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/browser_init.cc1
-rw-r--r--chrome/browser/extensions/extension_unittest.cc2
-rw-r--r--chrome/browser/extensions/extensions_service.cc20
-rw-r--r--chrome/browser/extensions/extensions_service_unittest.cc40
-rw-r--r--chrome/test/data/extensions/bad/invalid_manifest/1/manifest.json (renamed from chrome/test/data/extensions/invalid_manifest/manifest.json)0
-rw-r--r--chrome/test/data/extensions/bad/invalid_manifest/Current Version1
-rw-r--r--chrome/test/data/extensions/bad/no_manifest/1/not_a_manifest (renamed from chrome/test/data/extensions/no_manifest/not_a_manifest)0
-rw-r--r--chrome/test/data/extensions/bad/no_manifest/Current Version1
-rw-r--r--chrome/test/data/extensions/bad/no_version/git_abhors_empty_dirs1
-rw-r--r--chrome/test/data/extensions/good/extension1/1/manifest.json (renamed from chrome/test/data/extensions/extension1/manifest.json)0
-rw-r--r--chrome/test/data/extensions/good/extension1/Current Version1
-rw-r--r--chrome/test/data/extensions/good/extension2/2/manifest.json (renamed from chrome/test/data/extensions/extension2/manifest.json)0
-rw-r--r--chrome/test/data/extensions/good/extension2/Current Version1
-rw-r--r--chrome/test/data/extensions/good/extension3/1.0/manifest.json (renamed from chrome/test/data/extensions/extension3/1.0/manifest.json)0
-rw-r--r--chrome/test/data/extensions/good/extension3/Current0
-rw-r--r--chrome/test/data/extensions/good/extension3/Current Version (renamed from chrome/test/data/extensions/extension3/Current Version)0
16 files changed, 46 insertions, 22 deletions
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc
index 51541f4..c3f03bd 100644
--- a/chrome/browser/browser_init.cc
+++ b/chrome/browser/browser_init.cc
@@ -488,6 +488,7 @@ bool BrowserInit::ProcessCommandLine(
command_line.GetSwitchValue(switches::kLoadExtension);
FilePath path = FilePath::FromWStringHack(path_string);
profile->GetExtensionsService()->LoadExtension(path);
+ profile->GetUserScriptMaster()->AddWatchedPath(path);
}
if (command_line.HasSwitch(switches::kInstallExtension)) {
diff --git a/chrome/browser/extensions/extension_unittest.cc b/chrome/browser/extensions/extension_unittest.cc
index 125b939..fbce6ad 100644
--- a/chrome/browser/extensions/extension_unittest.cc
+++ b/chrome/browser/extensions/extension_unittest.cc
@@ -26,7 +26,9 @@ TEST(ExtensionTest, InitFromValueInvalid) {
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_dir));
FilePath extensions_path = FilePath::FromWStringHack(extensions_dir)
.AppendASCII("extensions")
+ .AppendASCII("good")
.AppendASCII("extension1")
+ .AppendASCII("1")
.AppendASCII(Extension::kManifestFilename);
JSONFileValueSerializer serializer(extensions_path.ToWStringHack());
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 05cb722..2ddcbb1 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -111,12 +111,7 @@ void ExtensionsService::OnExtensionsLoadedFromDirectory(
}
}
- // Tell UserScriptMaster to also watch the extensions directory for changes
- // and then kick off the first scan.
- // TODO(aa): This should go away when we implement the --extension flag, since
- // developing scripts in the Extensions directory will no longer be a common
- // use-case.
- user_script_master_->AddWatchedPath(install_directory_);
+ // Tell UserScriptMaster to kick off the first scan.
user_script_master_->StartScan();
NotificationService::current()->Notify(
@@ -179,15 +174,14 @@ bool ExtensionsServiceBackend::LoadExtensionsFromDirectory(
for (FilePath child_path = enumerator.Next(); !child_path.value().empty();
child_path = enumerator.Next()) {
std::string version_str;
- if (ReadCurrentVersion(child_path, &version_str)) {
- child_path = child_path.AppendASCII(version_str);
- } else {
- // For now, continue to allow fallback to a non-versioned directory
- // structure. This is so that we can use this same method to load
- // from local directories that developers are just hacking in place.
- // TODO(erikkay): perhaps we should use a different code path for this.
+ if (!ReadCurrentVersion(child_path, &version_str)) {
+ ReportExtensionLoadError(frontend.get(), child_path, StringPrintf(
+ "Could not read '%s' file.",
+ ExtensionsService::kCurrentVersionFileName));
+ continue;
}
+ child_path = child_path.AppendASCII(version_str);
Extension* extension = LoadExtension(child_path, frontend);
if (extension)
extensions->push_back(extension);
diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc
index 49e37a3..75a97a0 100644
--- a/chrome/browser/extensions/extensions_service_unittest.cc
+++ b/chrome/browser/extensions/extensions_service_unittest.cc
@@ -124,11 +124,12 @@ class ExtensionsServiceTestFrontend
// make the test a PlatformTest to setup autorelease pools properly on mac
typedef PlatformTest ExtensionsServiceTest;
-// Test loading extensions from the profile directory.
-TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectory) {
+// Test loading good extensions from the profile directory.
+TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectorySuccess) {
FilePath extensions_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
extensions_path = extensions_path.AppendASCII("extensions");
+ extensions_path = extensions_path.AppendASCII("good");
scoped_refptr<ExtensionsServiceBackend> backend(new ExtensionsServiceBackend);
scoped_refptr<ExtensionsServiceTestFrontend> frontend(
@@ -139,9 +140,6 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectory) {
scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get())));
frontend->GetMessageLoop()->RunAllPending();
- // Note: There can be more errors if there are extra directories, like .svn
- // directories.
- EXPECT_TRUE(frontend->errors()->size() >= 2u);
ASSERT_EQ(3u, frontend->extensions()->size());
EXPECT_EQ(std::string("com.google.myextension1"),
@@ -183,6 +181,28 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectory) {
ASSERT_EQ(0u, frontend->extensions()->at(2)->user_scripts().size());
};
+// Test loading bad extensions from the profile directory.
+TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectoryFail) {
+ FilePath extensions_path;
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
+ extensions_path = extensions_path.AppendASCII("extensions");
+ extensions_path = extensions_path.AppendASCII("bad");
+
+ scoped_refptr<ExtensionsServiceBackend> backend(new ExtensionsServiceBackend);
+ scoped_refptr<ExtensionsServiceTestFrontend> frontend(
+ new ExtensionsServiceTestFrontend);
+
+ std::vector<Extension*> extensions;
+ EXPECT_TRUE(backend->LoadExtensionsFromDirectory(extensions_path,
+ scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get())));
+ frontend->GetMessageLoop()->RunAllPending();
+
+ // Note: There can be more errors if there are extra directories, like .svn
+ // directories.
+ EXPECT_TRUE(frontend->errors()->size() >= 3u);
+ ASSERT_EQ(0u, frontend->extensions()->size());
+};
+
// Test installing extensions.
TEST_F(ExtensionsServiceTest, InstallExtension) {
FilePath extensions_path;
@@ -231,18 +251,20 @@ TEST_F(ExtensionsServiceTest, LoadExtension) {
scoped_refptr<ExtensionsServiceTestFrontend> frontend(
new ExtensionsServiceTestFrontend);
- FilePath ext1 = extensions_path.AppendASCII("extension1");
+ FilePath ext1 = extensions_path.AppendASCII("good").AppendASCII("extension1")
+ .AppendASCII("1");
EXPECT_TRUE(backend->LoadSingleExtension(ext1,
scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get())));
frontend->GetMessageLoop()->RunAllPending();
- EXPECT_EQ(frontend->errors()->size(), 0u);
+ EXPECT_EQ(0u, frontend->errors()->size());
ASSERT_EQ(1u, frontend->extensions()->size());
- FilePath no_manifest = extensions_path.AppendASCII("no_manifest");
+ FilePath no_manifest = extensions_path.AppendASCII("bad")
+ .AppendASCII("no_manifest").AppendASCII("1");
EXPECT_FALSE(backend->LoadSingleExtension(no_manifest,
scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get())));
frontend->GetMessageLoop()->RunAllPending();
- EXPECT_EQ(frontend->errors()->size(), 1u);
+ EXPECT_EQ(1u, frontend->errors()->size());
ASSERT_EQ(1u, frontend->extensions()->size());
}
diff --git a/chrome/test/data/extensions/invalid_manifest/manifest.json b/chrome/test/data/extensions/bad/invalid_manifest/1/manifest.json
index 3aac2d6..3aac2d6 100644
--- a/chrome/test/data/extensions/invalid_manifest/manifest.json
+++ b/chrome/test/data/extensions/bad/invalid_manifest/1/manifest.json
diff --git a/chrome/test/data/extensions/bad/invalid_manifest/Current Version b/chrome/test/data/extensions/bad/invalid_manifest/Current Version
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/chrome/test/data/extensions/bad/invalid_manifest/Current Version
@@ -0,0 +1 @@
+1
diff --git a/chrome/test/data/extensions/no_manifest/not_a_manifest b/chrome/test/data/extensions/bad/no_manifest/1/not_a_manifest
index 3aac2d6..3aac2d6 100644
--- a/chrome/test/data/extensions/no_manifest/not_a_manifest
+++ b/chrome/test/data/extensions/bad/no_manifest/1/not_a_manifest
diff --git a/chrome/test/data/extensions/bad/no_manifest/Current Version b/chrome/test/data/extensions/bad/no_manifest/Current Version
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/chrome/test/data/extensions/bad/no_manifest/Current Version
@@ -0,0 +1 @@
+1
diff --git a/chrome/test/data/extensions/bad/no_version/git_abhors_empty_dirs b/chrome/test/data/extensions/bad/no_version/git_abhors_empty_dirs
new file mode 100644
index 0000000..f1adef6
--- /dev/null
+++ b/chrome/test/data/extensions/bad/no_version/git_abhors_empty_dirs
@@ -0,0 +1 @@
+nothing here
diff --git a/chrome/test/data/extensions/extension1/manifest.json b/chrome/test/data/extensions/good/extension1/1/manifest.json
index 1f5e362..1f5e362 100644
--- a/chrome/test/data/extensions/extension1/manifest.json
+++ b/chrome/test/data/extensions/good/extension1/1/manifest.json
diff --git a/chrome/test/data/extensions/good/extension1/Current Version b/chrome/test/data/extensions/good/extension1/Current Version
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/chrome/test/data/extensions/good/extension1/Current Version
@@ -0,0 +1 @@
+1
diff --git a/chrome/test/data/extensions/extension2/manifest.json b/chrome/test/data/extensions/good/extension2/2/manifest.json
index 4e157c4..4e157c4 100644
--- a/chrome/test/data/extensions/extension2/manifest.json
+++ b/chrome/test/data/extensions/good/extension2/2/manifest.json
diff --git a/chrome/test/data/extensions/good/extension2/Current Version b/chrome/test/data/extensions/good/extension2/Current Version
new file mode 100644
index 0000000..0cfbf08
--- /dev/null
+++ b/chrome/test/data/extensions/good/extension2/Current Version
@@ -0,0 +1 @@
+2
diff --git a/chrome/test/data/extensions/extension3/1.0/manifest.json b/chrome/test/data/extensions/good/extension3/1.0/manifest.json
index 8292d0c..8292d0c 100644
--- a/chrome/test/data/extensions/extension3/1.0/manifest.json
+++ b/chrome/test/data/extensions/good/extension3/1.0/manifest.json
diff --git a/chrome/test/data/extensions/good/extension3/Current b/chrome/test/data/extensions/good/extension3/Current
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/chrome/test/data/extensions/good/extension3/Current
diff --git a/chrome/test/data/extensions/extension3/Current Version b/chrome/test/data/extensions/good/extension3/Current Version
index d3827e7..d3827e7 100644
--- a/chrome/test/data/extensions/extension3/Current Version
+++ b/chrome/test/data/extensions/good/extension3/Current Version