summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_view_unittest.cc
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-07 10:26:31 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-07 10:26:31 +0000
commitb9a622b9fe09868974a5af845bc474752b239566 (patch)
tree939d1e3947e35bbd960a925992bc7f049fe5775f /chrome/browser/extensions/extension_view_unittest.cc
parent72cbd32707a2ede460bcc1b3cb199e653282a8ed (diff)
downloadchromium_src-b9a622b9fe09868974a5af845bc474752b239566.zip
chromium_src-b9a622b9fe09868974a5af845bc474752b239566.tar.gz
chromium_src-b9a622b9fe09868974a5af845bc474752b239566.tar.bz2
Revert "Implement chromium.self in content scripts..."
This reverts commit 61ab30f52667e739602ab2af4fd8f2d8a0a2a2f0. Still seeing memory errors. Review URL: http://codereview.chromium.org/63056 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13243 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_view_unittest.cc')
-rwxr-xr-xchrome/browser/extensions/extension_view_unittest.cc63
1 files changed, 56 insertions, 7 deletions
diff --git a/chrome/browser/extensions/extension_view_unittest.cc b/chrome/browser/extensions/extension_view_unittest.cc
index 69a1fb9..4cdb91c 100755
--- a/chrome/browser/extensions/extension_view_unittest.cc
+++ b/chrome/browser/extensions/extension_view_unittest.cc
@@ -2,14 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/message_loop.h"
#include "base/ref_counted.h"
#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/browser/extensions/test_extension_loader.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/notification_service.h"
#include "chrome/test/in_process_browser_test.h"
#include "chrome/test/ui_test_utils.h"
@@ -19,11 +21,12 @@ namespace {
// up.
const int kAlertTimeoutMs = 20000;
+// How long to wait for the extension to load before giving up.
+const int kLoadTimeoutMs = 10000;
+
// The extension we're using as our test case.
const char* kExtensionId = "00123456789abcdef0123456789abcdef0123456";
-}; // namespace
-
// This class starts up an extension process and waits until it tries to put
// up a javascript alert.
class MockExtensionView : public ExtensionView {
@@ -57,6 +60,44 @@ class MockExtensionView : public ExtensionView {
bool got_message_;
};
+// This class waits for a specific extension to be loaded.
+class ExtensionLoadedObserver : public NotificationObserver {
+ public:
+ 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_;
+ }
+
+ private:
+ virtual void Observe(NotificationType type, const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::EXTENSIONS_LOADED) {
+ ExtensionList* extensions = Details<ExtensionList>(details).ptr();
+ for (size_t i = 0; i < (*extensions).size(); i++) {
+ if ((*extensions)[i]->id() == kExtensionId) {
+ extension_ = (*extensions)[i];
+ MessageLoopForUI::current()->Quit();
+ break;
+ }
+ }
+ } else {
+ NOTREACHED();
+ }
+ }
+
+ NotificationRegistrar registrar_;
+ Extension* extension_;
+};
+
+} // namespace
+
class ExtensionViewTest : public InProcessBrowserTest {
public:
virtual void SetUp() {
@@ -74,6 +115,10 @@ 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) {
+ // 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));
@@ -81,13 +126,17 @@ IN_PROC_BROWSER_TEST_F(ExtensionViewTest, Index) {
AppendASCII("good").AppendASCII("extension1").AppendASCII("1");
ASSERT_TRUE(file_util::DirectoryExists(path)); // sanity check
- // Wait for the extension to load and grab a pointer to it.
- TestExtensionLoader loader(browser()->profile());
- Extension* extension = loader.Load(kExtensionId, path);
+ // Load it.
+ Profile* profile = browser()->profile();
+ profile->GetExtensionsService()->Init();
+ profile->GetExtensionsService()->LoadExtension(path);
+
+ // Now wait for it to load, and grab a pointer to it.
+ Extension* extension = observer.WaitForExtension();
ASSERT_TRUE(extension);
GURL url = Extension::GetResourceURL(extension->url(), "toolstrip1.html");
// Start the extension process and wait for it to show a javascript alert.
- MockExtensionView view(extension, url, browser()->profile());
+ MockExtensionView view(extension, url, profile);
EXPECT_TRUE(view.got_message());
}