diff options
author | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-03 00:15:59 +0000 |
---|---|---|
committer | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-03 00:15:59 +0000 |
commit | e92475f94e575bbfb63a7b50164eb5e6177583a0 (patch) | |
tree | 130a8113719514d35ebe8d58ef0d238f2e7a160d /chrome | |
parent | 0c7638d7ba98fe1793d54c1e299a0fd4e9c570f0 (diff) | |
download | chromium_src-e92475f94e575bbfb63a7b50164eb5e6177583a0.zip chromium_src-e92475f94e575bbfb63a7b50164eb5e6177583a0.tar.gz chromium_src-e92475f94e575bbfb63a7b50164eb5e6177583a0.tar.bz2 |
Fix ExtensionViewTest and reenable it.
Also, normalize extension IDs to lower case when reading them in. GURL
lower cases them when used as hostnames, so string comparisons need to be done
in lower case to work.
Review URL: http://codereview.chromium.org/28331
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10750 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
4 files changed, 38 insertions, 10 deletions
diff --git a/chrome/browser/extensions/extension.cc b/chrome/browser/extensions/extension.cc index 4f7a514..918268f 100644 --- a/chrome/browser/extensions/extension.cc +++ b/chrome/browser/extensions/extension.cc @@ -175,6 +175,10 @@ bool Extension::InitFromValue(const DictionaryValue& source, return false; } + // Normalize the string to lowercase, so it can be used as an URL component + // (where GURL will lowercase it). + StringToLowerASCII(&id_); + // Verify that the id is legal. The id is a hex string of the SHA-1 hash of // the public key. std::vector<uint8> id_bytes; diff --git a/chrome/browser/extensions/extension_unittest.cc b/chrome/browser/extensions/extension_unittest.cc index 528a10c..aa8d791 100644 --- a/chrome/browser/extensions/extension_unittest.cc +++ b/chrome/browser/extensions/extension_unittest.cc @@ -177,7 +177,7 @@ TEST(ExtensionTest, InitFromValueValid) { EXPECT_TRUE(extension.InitFromValue(input_value, &error)); EXPECT_EQ("", error); - EXPECT_EQ("00123456789ABCDEF0123456789ABCDEF0123456", extension.id()); + EXPECT_EQ("00123456789abcdef0123456789abcdef0123456", extension.id()); EXPECT_EQ("1.0.0.0", extension.VersionString()); EXPECT_EQ("my extension", extension.name()); EXPECT_EQ("chrome-extension://00123456789abcdef0123456789abcdef0123456/", diff --git a/chrome/browser/extensions/extension_view_unittest.cc b/chrome/browser/extensions/extension_view_unittest.cc index 3b6e545..61cd8de 100755 --- a/chrome/browser/extensions/extension_view_unittest.cc +++ b/chrome/browser/extensions/extension_view_unittest.cc @@ -6,6 +6,7 @@ #include "chrome/browser/browser.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/profile.h" +#include "chrome/browser/extensions/extension_error_reporter.h" #include "chrome/browser/extensions/extension_view.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/common/chrome_paths.h" @@ -19,15 +20,18 @@ namespace { // up. const int kAlertTimeoutMs = 10000; +// How long to wait for the extension to load before giving up. +const int kLoadTimeoutMs = 5000; + // The extension we're using as our test case. -const char* kExtensionId = "com.google.myextension1"; +const char* kExtensionId = "00123456789abcdef0123456789abcdef0123456"; // This class starts up an extension process and waits until it tries to put // up a javascript alert. class MockExtensionView : public ExtensionView { public: MockExtensionView(const GURL& url, Profile* profile) - : ExtensionView(url, profile), got_message_(false) { + : ExtensionView(url, profile), got_message_(false) { InitHidden(); MessageLoop::current()->PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, kAlertTimeoutMs); @@ -52,13 +56,18 @@ class MockExtensionView : public ExtensionView { // This class waits for a specific extension to be loaded. class ExtensionLoadedObserver : public NotificationObserver { public: - explicit ExtensionLoadedObserver() : extension_(NULL) { + explicit ExtensionLoadedObserver() : extension_(NULL) { registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, NotificationService::AllSources()); + } + + Extension* WaitForExtension() { + MessageLoop::current()->PostDelayedTask(FROM_HERE, + new MessageLoop::QuitTask, kLoadTimeoutMs); ui_test_utils::RunMessageLoop(); + return extension_; } - Extension* extension() { return extension_; } private: virtual void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { @@ -83,14 +92,29 @@ class ExtensionLoadedObserver : public NotificationObserver { } // namespace class ExtensionViewTest : public InProcessBrowserTest { + public: + virtual void SetUp() { + // Initialize the error reporter here, otherwise BrowserMain will create it + // with the wrong MessageLoop. + ExtensionErrorReporter::Init(false); + + InProcessBrowserTest::SetUp(); + } }; -IN_PROC_BROWSER_TEST_F(ExtensionViewTest, DISABLED_TestMe) { +// 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) { + // Create an observer first to be sure we have the notification registered + // before it's sent. + ExtensionLoadedObserver observer; + // Get the path to our extension. FilePath path; ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); path = path.AppendASCII("extensions"). AppendASCII("good").AppendASCII("extension1").AppendASCII("1"); + ASSERT_TRUE(file_util::DirectoryExists(path)); // sanity check // Load it. Profile* profile = browser()->profile(); @@ -98,7 +122,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionViewTest, DISABLED_TestMe) { profile->GetExtensionsService()->LoadExtension(path); // Now wait for it to load, and grab a pointer to it. - Extension* extension = ExtensionLoadedObserver().extension(); + Extension* extension = observer.WaitForExtension(); ASSERT_TRUE(extension); GURL url = Extension::GetResourceURL(extension->url(), "index.html"); diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index b3ab36a..5544876 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -169,7 +169,7 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectorySuccess) { } ASSERT_EQ(3u, frontend->extensions()->size()); - EXPECT_EQ(std::string("00123456789ABCDEF0123456789ABCDEF0123456"), + EXPECT_EQ(std::string("00123456789abcdef0123456789abcdef0123456"), frontend->extensions()->at(0)->id()); EXPECT_EQ(std::string("My extension 1"), frontend->extensions()->at(0)->name()); @@ -191,7 +191,7 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectorySuccess) { EXPECT_EQ(extension->path().AppendASCII("script2.js").value(), scripts[1].path().value()); - EXPECT_EQ(std::string("10123456789ABCDEF0123456789ABCDEF0123456"), + EXPECT_EQ(std::string("10123456789abcdef0123456789abcdef0123456"), frontend->extensions()->at(1)->id()); EXPECT_EQ(std::string("My extension 2"), frontend->extensions()->at(1)->name()); @@ -201,7 +201,7 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectorySuccess) { frontend->extensions()->at(1)->plugins_dir().value()); ASSERT_EQ(0u, frontend->extensions()->at(1)->content_scripts().size()); - EXPECT_EQ(std::string("20123456789ABCDEF0123456789ABCDEF0123456"), + EXPECT_EQ(std::string("20123456789abcdef0123456789abcdef0123456"), frontend->extensions()->at(2)->id()); EXPECT_EQ(std::string("My extension 3"), frontend->extensions()->at(2)->name()); |