summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-12 19:35:35 +0000
committerdmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-12 19:35:35 +0000
commita576851e5e00f1d8ef88ef20396a487cc2c027d4 (patch)
tree6b742d12e49603b36e7d4079ed0a8534919621aa /chrome
parentef0eb3230ac3f8915a98bb80724df85655d0dbc1 (diff)
downloadchromium_src-a576851e5e00f1d8ef88ef20396a487cc2c027d4.zip
chromium_src-a576851e5e00f1d8ef88ef20396a487cc2c027d4.tar.gz
chromium_src-a576851e5e00f1d8ef88ef20396a487cc2c027d4.tar.bz2
Revert 193974 "Test extension reloading behavior."
ExtensionServiceTest.ReloadExtension failed on Linux. > Test extension reloading behavior. > > By testing the actual interaction with renderer processes and the > notification system, I can expose the fact that we're starting a whole > extra process and loading the extension around 3 times. > > > BUG=178542 > > Review URL: https://chromiumcodereview.appspot.com/13533007 TBR=jyasskin@chromium.org Review URL: https://codereview.chromium.org/13844013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193986 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/extension_service_unittest.cc215
-rw-r--r--chrome/browser/extensions/extension_service_unittest.h15
-rw-r--r--chrome/browser/extensions/user_script_listener_unittest.cc2
-rw-r--r--chrome/browser/managed_mode/managed_user_service_unittest.cc3
4 files changed, 21 insertions, 214 deletions
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index 7aab32f..c171bcc 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -21,7 +21,6 @@
#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "base/path_service.h"
-#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/string16.h"
#include "base/string_util.h"
@@ -59,7 +58,6 @@
#include "chrome/browser/prefs/pref_service_mock_builder.h"
#include "chrome/browser/prefs/pref_service_syncable.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
-#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
@@ -70,14 +68,12 @@
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_l10n_util.h"
#include "chrome/common/extensions/extension_manifest_constants.h"
-#include "chrome/common/extensions/extension_messages.h"
#include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
#include "chrome/common/extensions/manifest_handlers/requirements_handler.h"
#include "chrome/common/extensions/manifest_url_handler.h"
#include "chrome/common/extensions/permissions/permission_set.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
-#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "components/user_prefs/pref_registry_syncable.h"
#include "content/public/browser/dom_storage_context.h"
@@ -89,9 +85,7 @@
#include "content/public/browser/storage_partition.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/gpu_info.h"
-#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_thread.h"
-#include "content/public/test/test_notification_tracker.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension_resource.h"
#include "extensions/common/url_pattern.h"
@@ -108,7 +102,6 @@
#include "sync/protocol/app_specifics.pb.h"
#include "sync/protocol/extension_specifics.pb.h"
#include "sync/protocol/sync.pb.h"
-#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#include "webkit/database/database_tracker.h"
@@ -120,10 +113,6 @@
#include "chrome/browser/chromeos/extensions/install_limiter.h"
#endif
-#if defined(OS_WIN)
-#include "ui/base/win/scoped_ole_initializer.h"
-#endif
-
using content::BrowserContext;
using content::BrowserThread;
using content::DOMStorageContext;
@@ -420,13 +409,8 @@ class MockProviderVisitor
};
// Our message loop may be used in tests which require it to be an IO loop.
-ExtensionServiceTestBase::ExtensionServiceTestBase(
- MessageLoop::Type main_loop_type)
- : loop_(main_loop_type),
- local_state_(TestingBrowserProcess::GetGlobal()),
-#if defined(OS_WIN)
- ole_initializer_(new ui::ScopedOleInitializer()),
-#endif
+ExtensionServiceTestBase::ExtensionServiceTestBase()
+ : loop_(MessageLoop::TYPE_IO),
service_(NULL),
management_policy_(NULL),
expected_extensions_count_(0),
@@ -435,13 +419,9 @@ ExtensionServiceTestBase::ExtensionServiceTestBase(
webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &loop_),
file_thread_(BrowserThread::FILE, &loop_),
file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, &loop_),
- io_thread_(main_loop_type == MessageLoop::TYPE_IO
- ? new content::TestBrowserThread(BrowserThread::IO, &loop_)
- : new content::TestBrowserThread(BrowserThread::IO)),
+ io_thread_(BrowserThread::IO, &loop_),
override_sideload_wipeout_(
FeatureSwitch::sideload_wipeout(), false) {
- if (main_loop_type != MessageLoop::TYPE_IO)
- io_thread_->StartIOThread();
base::FilePath test_data_dir;
if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) {
ADD_FAILURE();
@@ -458,8 +438,6 @@ ExtensionServiceTestBase::~ExtensionServiceTestBase() {
MessageLoop::current()->RunUntilIdle();
profile_.reset(NULL);
MessageLoop::current()->RunUntilIdle();
-
- TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
}
void ExtensionServiceTestBase::InitializeExtensionService(
@@ -529,10 +507,6 @@ void ExtensionServiceTestBase::InitializeEmptyExtensionService() {
}
void ExtensionServiceTestBase::InitializeExtensionProcessManager() {
- // Needed in order to look up RenderProcessHosts.
- TestingBrowserProcess::GetGlobal()->SetProfileManager(
- new ProfileManagerWithoutInit(temp_dir_.path()));
-
static_cast<extensions::TestExtensionSystem*>(
ExtensionSystem::Get(profile_.get()))->
CreateExtensionProcessManager();
@@ -582,32 +556,6 @@ void ExtensionServiceTestBase::SetUp() {
(new extensions::RequirementsHandler)->Register();
}
-template<typename Result>
-static Result PostTaskAndWaitForResult(
- content::BrowserThread::ID thread,
- const tracked_objects::Location& from_here,
- const base::Callback<Result(void)>& task) {
- struct ResultSaver {
- static void UpdateResult(base::RunLoop* loop,
- Result* saved,
- Result from_task) {
- using std::swap;
- swap(*saved, from_task);
- loop->Quit();
- }
- };
-
- Result result;
- base::RunLoop loop;
- content::BrowserThread::PostTaskAndReplyWithResult(
- thread, from_here, task,
- base::Bind(&ResultSaver::UpdateResult,
- base::Unretained(&loop),
- base::Unretained(&result)));
- loop.Run();
- return result;
-}
-
class ExtensionServiceTest
: public ExtensionServiceTestBase, public content::NotificationObserver {
public:
@@ -3659,70 +3607,10 @@ TEST_F(ExtensionServiceTest, ReloadExtensions) {
EXPECT_EQ(0u, service_->disabled_extensions()->size());
}
-namespace {
-std::vector<uint32> ExtensionMessageTypes(const IPC::TestSink& sink) {
- std::vector<uint32> message_types;
- for (size_t i = 0; i < sink.message_count(); ++i) {
- uint32 type = sink.GetMessageAt(i)->type();
- if (IPC_MESSAGE_ID_CLASS(type) == ExtensionMsgStart)
- message_types.push_back(type);
- }
- return message_types;
-}
-
-struct ProcessObserver
- : public content::MockRenderProcessHostFactory::Observer {
- explicit ProcessObserver(content::MockRenderProcessHostFactory* factory)
- : Observer(factory) {}
-
- ~ProcessObserver() {
- for (size_t i = 0; i < hosts.size(); ++i) {
- if (destroyed_processes.count(process_ids[i]) == 0)
- hosts[i]->sink().RemoveFilter(process_messages[i]);
- delete process_messages[i];
- }
- }
-
- virtual void OnRenderProcessHostCreated(
- content::MockRenderProcessHost* host) {
- IPC::TestSink* sink = new IPC::TestSink;
- hosts.push_back(host);
- process_ids.push_back(host->GetID());
- process_messages.push_back(sink);
- host->sink().AddFilter(sink);
- }
- virtual void OnRenderProcessHostDestroyed(
- content::MockRenderProcessHost* host) {
- destroyed_processes.insert(host->GetID());
- }
-
- std::vector<content::MockRenderProcessHost*> hosts;
- std::vector<int> process_ids;
- std::vector<IPC::TestSink*> process_messages;
- std::set<int> destroyed_processes;
-};
-} // namespace
-
// Tests reloading an extension.
TEST_F(ExtensionServiceTest, ReloadExtension) {
- ProcessObserver observer(rvh_enabler_.rph_factory());
-
- content::TestNotificationTracker notifications;
- notifications.ListenForAll(chrome::NOTIFICATION_EXTENSIONS_READY);
- notifications.ListenForAll(chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED);
- notifications.ListenForAll(chrome::NOTIFICATION_EXTENSION_LOADED);
- notifications.ListenForAll(chrome::NOTIFICATION_EXTENSION_UNLOADED);
- notifications.ListenForAll(content::NOTIFICATION_RENDERER_PROCESS_CLOSING);
- notifications.ListenForAll(content::NOTIFICATION_RENDERER_PROCESS_CREATED);
- notifications.ListenForAll(content::NOTIFICATION_RENDERER_PROCESS_TERMINATED);
- notifications.ListenForAll(
- content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW);
-
InitializeEmptyExtensionService();
InitializeExtensionProcessManager();
- service_->Init();
- EXPECT_THAT(notifications.GetTypesAndReset(),
- testing::ElementsAre(chrome::NOTIFICATION_EXTENSIONS_READY));
// Simple extension that should install without error.
const char* extension_id = "behllobkkfkfnphdnhnkndlbkcpglgmj";
@@ -3734,81 +3622,23 @@ TEST_F(ExtensionServiceTest, ReloadExtension) {
extensions::UnpackedInstaller::Create(service_)->Load(ext);
loop_.RunUntilIdle();
- EXPECT_THAT(notifications.GetTypesAndReset(),
- testing::ElementsAre(chrome::NOTIFICATION_EXTENSION_LOADED));
- ASSERT_EQ(1u, observer.process_messages.size());
- EXPECT_THAT(ExtensionMessageTypes(*observer.process_messages[0]),
- testing::ElementsAre(ExtensionMsg_Loaded::ID,
- ExtensionMsg_ActivateExtension::ID,
- ExtensionMsg_Loaded::ID,
- ExtensionMsg_ActivateExtension::ID));
- observer.process_messages[0]->ClearMessages();
-
EXPECT_EQ(1u, service_->extensions()->size());
EXPECT_EQ(0u, service_->disabled_extensions()->size());
service_->ReloadExtension(extension_id);
- EXPECT_THAT(notifications.GetTypesAndReset(),
- testing::ElementsAre(
- chrome::NOTIFICATION_EXTENSION_UNLOADED,
- content::NOTIFICATION_RENDERER_PROCESS_CLOSING,
- chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
- content::NOTIFICATION_RENDERER_PROCESS_TERMINATED));
-
- ASSERT_EQ(1u, observer.process_messages.size());
- EXPECT_THAT(ExtensionMessageTypes(*observer.process_messages[0]),
- testing::ElementsAre());
- observer.process_messages[0]->ClearMessages();
-
// Extension should be disabled now, waiting to be reloaded.
EXPECT_EQ(0u, service_->extensions()->size());
EXPECT_EQ(1u, service_->disabled_extensions()->size());
EXPECT_EQ(Extension::DISABLE_RELOAD,
service_->extension_prefs()->GetDisableReasons(extension_id));
- // Reloading again before iterating the MessageLoop should not crash and
- // shouldn't cause an extra reload.
+ // Reloading again should not crash.
service_->ReloadExtension(extension_id);
- EXPECT_THAT(notifications.GetTypesAndReset(),
- testing::ElementsAre());
- ASSERT_EQ(1u, observer.process_messages.size());
- EXPECT_THAT(ExtensionMessageTypes(*observer.process_messages[0]),
- testing::ElementsAre());
- observer.process_messages[0]->ClearMessages();
// Finish reloading
loop_.RunUntilIdle();
- EXPECT_THAT(notifications.GetTypesAndReset(),
- testing::ElementsAre(
- chrome::NOTIFICATION_EXTENSION_LOADED,
- chrome::NOTIFICATION_EXTENSION_UNLOADED,
- content::NOTIFICATION_RENDERER_PROCESS_CLOSING,
- chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
- content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
- chrome::NOTIFICATION_EXTENSION_LOADED));
-
- ASSERT_EQ(3u, observer.process_messages.size());
- EXPECT_THAT(observer.destroyed_processes,
- testing::ElementsAre(observer.process_ids[0],
- observer.process_ids[1]));
- EXPECT_THAT(ExtensionMessageTypes(*observer.process_messages[0]),
- testing::ElementsAre());
- observer.process_messages[0]->ClearMessages();
- EXPECT_THAT(ExtensionMessageTypes(*observer.process_messages[1]),
- testing::ElementsAre(ExtensionMsg_Loaded::ID,
- ExtensionMsg_ActivateExtension::ID,
- ExtensionMsg_Loaded::ID,
- ExtensionMsg_ActivateExtension::ID));
- observer.process_messages[1]->ClearMessages();
- EXPECT_THAT(ExtensionMessageTypes(*observer.process_messages[2]),
- testing::ElementsAre(ExtensionMsg_Loaded::ID,
- ExtensionMsg_ActivateExtension::ID,
- ExtensionMsg_Loaded::ID,
- ExtensionMsg_ActivateExtension::ID));
- observer.process_messages[2]->ClearMessages();
-
// Extension should be enabled again.
EXPECT_EQ(1u, service_->extensions()->size());
EXPECT_EQ(0u, service_->disabled_extensions()->size());
@@ -3953,8 +3783,8 @@ TEST_F(ExtensionServiceTest, UnpackedRequirements) {
class ExtensionCookieCallback {
public:
ExtensionCookieCallback()
- : result_(false),
- weak_factory_(MessageLoop::current()) {}
+ : result_(false),
+ weak_factory_(MessageLoop::current()) {}
void SetCookieCallback(bool result) {
MessageLoop::current()->PostTask(
@@ -3967,18 +3797,11 @@ class ExtensionCookieCallback {
FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr()));
list_ = list;
}
-
net::CookieList list_;
bool result_;
base::WeakPtrFactory<MessageLoop> weak_factory_;
};
-// Must run on IO thread to set up ThreadCheckers correctly.
-static net::CookieMonster* GetCookieMonsterFromIOThread(
- net::URLRequestContextGetter* getter) {
- return getter->GetURLRequestContext()->cookie_store()->GetCookieMonster();
-}
-
// Verifies extension state is removed upon uninstall.
TEST_F(ExtensionServiceTest, ClearExtensionData) {
InitializeEmptyExtensionService();
@@ -3994,26 +3817,23 @@ TEST_F(ExtensionServiceTest, ClearExtensionData) {
webkit_database::DatabaseUtil::GetOriginIdentifier(ext_url);
// Set a cookie for the extension.
- net::CookieMonster* cookie_monster = PostTaskAndWaitForResult(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&GetCookieMonsterFromIOThread,
- make_scoped_refptr(
- profile_->GetRequestContextForExtensions())));
+ net::CookieMonster* cookie_monster =
+ profile_->GetRequestContextForExtensions()->GetURLRequestContext()->
+ cookie_store()->GetCookieMonster();
ASSERT_TRUE(cookie_monster);
-
net::CookieOptions options;
cookie_monster->SetCookieWithOptionsAsync(
- ext_url, "dummy=value", options,
- base::Bind(&ExtensionCookieCallback::SetCookieCallback,
- base::Unretained(&callback)));
- MessageLoop::current()->RunUntilIdle();
+ ext_url, "dummy=value", options,
+ base::Bind(&ExtensionCookieCallback::SetCookieCallback,
+ base::Unretained(&callback)));
+ loop_.RunUntilIdle();
EXPECT_TRUE(callback.result_);
cookie_monster->GetAllCookiesForURLAsync(
ext_url,
base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
base::Unretained(&callback)));
- MessageLoop::current()->RunUntilIdle();
+ loop_.RunUntilIdle();
EXPECT_EQ(1U, callback.list_.size());
// Open a database.
@@ -4111,10 +3931,9 @@ TEST_F(ExtensionServiceTest, ClearAppData) {
IsStorageUnlimited(origin2));
// Set a cookie for the extension.
- net::CookieMonster* cookie_monster = PostTaskAndWaitForResult(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&GetCookieMonsterFromIOThread,
- make_scoped_refptr(profile_->GetRequestContext())));
+ net::CookieMonster* cookie_monster =
+ profile_->GetRequestContext()->GetURLRequestContext()->
+ cookie_store()->GetCookieMonster();
ASSERT_TRUE(cookie_monster);
net::CookieOptions options;
cookie_monster->SetCookieWithOptionsAsync(
diff --git a/chrome/browser/extensions/extension_service_unittest.h b/chrome/browser/extensions/extension_service_unittest.h
index 8d1cc6c..6f46f77 100644
--- a/chrome/browser/extensions/extension_service_unittest.h
+++ b/chrome/browser/extensions/extension_service_unittest.h
@@ -14,9 +14,7 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/common/extensions/extension_unittest.h"
#include "chrome/common/extensions/feature_switch.h"
-#include "chrome/test/base/scoped_testing_local_state.h"
#include "content/public/test/test_browser_thread.h"
-#include "content/public/test/test_renderer_host.h"
#include "testing/gtest/include/gtest/gtest.h"
class TestingProfile;
@@ -24,14 +22,10 @@ class TestingProfile;
namespace extensions {
class ManagementPolicy;
}
-namespace ui {
-class ScopedOleInitializer;
-}
class ExtensionServiceTestBase : public extensions::ExtensionTest {
public:
- ExtensionServiceTestBase(
- MessageLoop::Type main_loop_type = MessageLoop::TYPE_UI);
+ ExtensionServiceTestBase();
virtual ~ExtensionServiceTestBase();
void InitializeExtensionService(const base::FilePath& profile_path,
@@ -65,11 +59,6 @@ class ExtensionServiceTestBase : public extensions::ExtensionTest {
MessageLoop loop_;
base::ShadowingAtExitManager at_exit_manager_;
base::ScopedTempDir temp_dir_;
- content::RenderViewHostTestEnabler rvh_enabler_;
- ScopedTestingLocalState local_state_;
-#if defined(OS_WIN)
- scoped_ptr<ui::ScopedOleInitializer> ole_initializer_;
-#endif
scoped_ptr<TestingProfile> profile_;
base::FilePath extensions_install_dir_;
base::FilePath data_dir_;
@@ -82,7 +71,7 @@ class ExtensionServiceTestBase : public extensions::ExtensionTest {
content::TestBrowserThread webkit_thread_;
content::TestBrowserThread file_thread_;
content::TestBrowserThread file_user_blocking_thread_;
- scoped_ptr<content::TestBrowserThread> io_thread_;
+ content::TestBrowserThread io_thread_;
extensions::FeatureSwitch::ScopedOverride override_sideload_wipeout_;
};
diff --git a/chrome/browser/extensions/user_script_listener_unittest.cc b/chrome/browser/extensions/user_script_listener_unittest.cc
index 210a18e..06d46f49 100644
--- a/chrome/browser/extensions/user_script_listener_unittest.cc
+++ b/chrome/browser/extensions/user_script_listener_unittest.cc
@@ -120,7 +120,7 @@ class SimpleTestJobProtocolHandler
class UserScriptListenerTest : public ExtensionServiceTestBase {
public:
- UserScriptListenerTest() : ExtensionServiceTestBase(MessageLoop::TYPE_IO) {
+ UserScriptListenerTest() {
net::URLRequestFilter::GetInstance()->AddHostnameProtocolHandler(
"http", "google.com",
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>(
diff --git a/chrome/browser/managed_mode/managed_user_service_unittest.cc b/chrome/browser/managed_mode/managed_user_service_unittest.cc
index 04a3193..f4a234e 100644
--- a/chrome/browser/managed_mode/managed_user_service_unittest.cc
+++ b/chrome/browser/managed_mode/managed_user_service_unittest.cc
@@ -148,8 +148,7 @@ TEST(ManagedUserServiceTest, GetManualExceptionsForHost) {
class ManagedUserServiceExtensionTest : public ExtensionServiceTestBase {
public:
- ManagedUserServiceExtensionTest()
- : ExtensionServiceTestBase(MessageLoop::TYPE_IO) {}
+ ManagedUserServiceExtensionTest() {}
virtual ~ManagedUserServiceExtensionTest() {}
virtual void SetUp() OVERRIDE {