diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-21 16:32:40 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-21 16:32:40 +0000 |
commit | 82b8664b1250c39412af70c6278061ab5c346e01 (patch) | |
tree | c27101dbebbf0475c5dcb55654c621c49f8508b7 /chrome/browser/extensions/test_extension_loader.cc | |
parent | 167b1403caab4d655888fe9798aaf9b525e7d4ff (diff) | |
download | chromium_src-82b8664b1250c39412af70c6278061ab5c346e01.zip chromium_src-82b8664b1250c39412af70c6278061ab5c346e01.tar.gz chromium_src-82b8664b1250c39412af70c6278061ab5c346e01.tar.bz2 |
Committing issue 39299:
Test for extension user script load and inject.
This add a test that a user script actually gets injected into
pages and runs. Before we only had unit tests for the various
classes and weren't testing the system end-to-end.
Review URL: http://codereview.chromium.org/51003
Patch from Steve Krulewitz <skrulx@gmail.com>.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12247 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/test_extension_loader.cc')
-rwxr-xr-x | chrome/browser/extensions/test_extension_loader.cc | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/chrome/browser/extensions/test_extension_loader.cc b/chrome/browser/extensions/test_extension_loader.cc new file mode 100755 index 0000000..4012833 --- /dev/null +++ b/chrome/browser/extensions/test_extension_loader.cc @@ -0,0 +1,64 @@ +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/extensions/test_extension_loader.h" + +#include "base/file_path.h" +#include "base/message_loop.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/extensions/extensions_service.h" +#include "chrome/common/notification_service.h" +#include "chrome/test/ui_test_utils.h" + +namespace { + +// How long to wait for the extension to load before giving up. +const int kLoadTimeoutMs = 5000; + +} // namespace + +TestExtensionLoader::TestExtensionLoader(Profile* profile) + : profile_(profile), + extension_(NULL), + loading_extension_id_(NULL) { + registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, + NotificationService::AllSources()); + + profile_->GetExtensionsService()->Init(); + DCHECK(profile_->GetExtensionsService()->extensions()->empty()); +} + +Extension* TestExtensionLoader::Load(const char* extension_id, + const FilePath& path) { + loading_extension_id_ = extension_id; + + // Load the extension. + profile_->GetExtensionsService()->LoadExtension(path); + + // Wait for the load to complete. Stick a QuitTask into the message loop + // with the timeout so it will exit if the extension never loads. + extension_ = NULL; + MessageLoop::current()->PostDelayedTask(FROM_HERE, + new MessageLoop::QuitTask, kLoadTimeoutMs); + ui_test_utils::RunMessageLoop(); + + return extension_; +} + +void TestExtensionLoader::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() == loading_extension_id_) { + extension_ = (*extensions)[i]; + MessageLoopForUI::current()->Quit(); + break; + } + } + } else { + NOTREACHED(); + } +} |