| Index: extensions/browser/process_manager_unittest.cc
|
| diff --git a/chrome/browser/extensions/process_manager_unittest.cc b/extensions/browser/process_manager_unittest.cc
|
| similarity index 51%
|
| rename from chrome/browser/extensions/process_manager_unittest.cc
|
| rename to extensions/browser/process_manager_unittest.cc
|
| index d799df44ae97f4a3c5802d108f9a1bfee1a41d71..f6cf310dce6ba9b1014ac8c509ee1e9d11444fde 100644
|
| --- a/chrome/browser/extensions/process_manager_unittest.cc
|
| +++ b/extensions/browser/process_manager_unittest.cc
|
| @@ -5,119 +5,138 @@
|
| #include "extensions/browser/process_manager.h"
|
|
|
| #include "chrome/browser/chrome_notification_types.h"
|
| -#include "chrome/browser/extensions/extension_error_reporter.h"
|
| -#include "chrome/test/base/testing_profile.h"
|
| +#include "content/public/browser/content_browser_client.h"
|
| #include "content/public/browser/notification_service.h"
|
| -#include "content/public/browser/render_process_host.h"
|
| #include "content/public/browser/site_instance.h"
|
| +#include "content/public/test/test_browser_context.h"
|
| +#include "extensions/browser/test_extensions_browser_client.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| -#include "testing/platform_test.h"
|
|
|
| +using content::BrowserContext;
|
| using content::SiteInstance;
|
| +using content::TestBrowserContext;
|
|
|
| namespace extensions {
|
|
|
| -// TODO(jamescook): Convert this from TestingProfile to TestBrowserContext and
|
| -// move to extensions/browser. This is dependent on ExtensionPrefs being
|
| -// converted and ExtensionSystem being converted or eliminated.
|
| -// http://crbug.com/315855
|
| +namespace {
|
| +
|
| +// An incognito version of a TestBrowserContext.
|
| +class TestBrowserContextIncognito : public TestBrowserContext {
|
| + public:
|
| + TestBrowserContextIncognito() {}
|
| + virtual ~TestBrowserContextIncognito() {}
|
| +
|
| + // TestBrowserContext implementation.
|
| + virtual bool IsOffTheRecord() const OVERRIDE { return true; }
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(TestBrowserContextIncognito);
|
| +};
|
| +
|
| +} // namespace
|
|
|
| -// make the test a PlatformTest to setup autorelease pools properly on mac
|
| class ProcessManagerTest : public testing::Test {
|
| public:
|
| - static void SetUpTestCase() {
|
| - ExtensionErrorReporter::Init(false); // no noisy errors
|
| + ProcessManagerTest() : extensions_browser_client_(&original_context_) {
|
| + extensions_browser_client_.SetIncognitoContext(&incognito_context_);
|
| + ExtensionsBrowserClient::Set(&extensions_browser_client_);
|
| }
|
|
|
| - virtual void SetUp() {
|
| - ExtensionErrorReporter::GetInstance()->ClearErrors();
|
| + virtual ~ProcessManagerTest() {
|
| + ExtensionsBrowserClient::Set(NULL);
|
| }
|
|
|
| + BrowserContext* original_context() { return &original_context_; }
|
| + BrowserContext* incognito_context() { return &incognito_context_; }
|
| +
|
| // Returns true if the notification |type| is registered for |manager| with
|
| - // source |profile|. Pass NULL for |profile| for all sources.
|
| + // source |context|. Pass NULL for |context| for all sources.
|
| static bool IsRegistered(ProcessManager* manager,
|
| int type,
|
| - TestingProfile* profile) {
|
| + BrowserContext* context) {
|
| return manager->registrar_.IsRegistered(
|
| - manager, type, content::Source<Profile>(profile));
|
| + manager, type, content::Source<BrowserContext>(context));
|
| }
|
| +
|
| + private:
|
| + TestBrowserContext original_context_;
|
| + TestBrowserContextIncognito incognito_context_;
|
| + TestExtensionsBrowserClient extensions_browser_client_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ProcessManagerTest);
|
| };
|
|
|
| // Test that notification registration works properly.
|
| TEST_F(ProcessManagerTest, ExtensionNotificationRegistration) {
|
| - // Test for a normal profile.
|
| - scoped_ptr<TestingProfile> original_profile(new TestingProfile);
|
| + // Test for a normal context ProcessManager.
|
| scoped_ptr<ProcessManager> manager1(
|
| - ProcessManager::Create(original_profile.get()));
|
| + ProcessManager::Create(original_context()));
|
|
|
| - EXPECT_EQ(original_profile.get(), manager1->GetBrowserContext());
|
| + EXPECT_EQ(original_context(), manager1->GetBrowserContext());
|
| EXPECT_EQ(0u, manager1->background_hosts().size());
|
|
|
| - // It observes other notifications from this profile.
|
| + // It observes other notifications from this context.
|
| EXPECT_TRUE(IsRegistered(manager1.get(),
|
| chrome::NOTIFICATION_EXTENSIONS_READY,
|
| - original_profile.get()));
|
| + original_context()));
|
| EXPECT_TRUE(IsRegistered(manager1.get(),
|
| chrome::NOTIFICATION_EXTENSION_LOADED,
|
| - original_profile.get()));
|
| + original_context()));
|
| EXPECT_TRUE(IsRegistered(manager1.get(),
|
| chrome::NOTIFICATION_EXTENSION_UNLOADED,
|
| - original_profile.get()));
|
| + original_context()));
|
| EXPECT_TRUE(IsRegistered(manager1.get(),
|
| chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
|
| - original_profile.get()));
|
| + original_context()));
|
|
|
| - // Now add an incognito profile associated with the master above.
|
| - TestingProfile::Builder builder;
|
| - builder.SetIncognito();
|
| - scoped_ptr<TestingProfile> incognito_profile = builder.Build();
|
| - incognito_profile->SetOriginalProfile(original_profile.get());
|
| - scoped_ptr<ProcessManager> manager2(
|
| - ProcessManager::Create(incognito_profile.get()));
|
| + // Test for an incognito context ProcessManager.
|
| + scoped_ptr<ProcessManager> manager2(ProcessManager::CreateIncognitoForTesting(
|
| + incognito_context(), original_context(), manager1.get()));
|
|
|
| - EXPECT_EQ(incognito_profile.get(), manager2->GetBrowserContext());
|
| + EXPECT_EQ(incognito_context(), manager2->GetBrowserContext());
|
| EXPECT_EQ(0u, manager2->background_hosts().size());
|
|
|
| - // Some notifications are observed for the original profile.
|
| + // Some notifications are observed for the original context.
|
| EXPECT_TRUE(IsRegistered(manager2.get(),
|
| chrome::NOTIFICATION_EXTENSION_LOADED,
|
| - original_profile.get()));
|
| + original_context()));
|
|
|
| - // Some notifications are observed for the incognito profile.
|
| + // Some notifications are observed for the incognito context.
|
| EXPECT_TRUE(IsRegistered(manager2.get(),
|
| chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
|
| - incognito_profile.get()));
|
| + incognito_context()));
|
|
|
| // Some notifications are observed for both incognito and original.
|
| EXPECT_TRUE(IsRegistered(manager2.get(),
|
| chrome::NOTIFICATION_PROFILE_DESTROYED,
|
| - original_profile.get()));
|
| + original_context()));
|
| EXPECT_TRUE(IsRegistered(manager2.get(),
|
| chrome::NOTIFICATION_PROFILE_DESTROYED,
|
| - incognito_profile.get()));
|
| + incognito_context()));
|
|
|
| // Some are not observed at all.
|
| EXPECT_FALSE(IsRegistered(manager2.get(),
|
| chrome::NOTIFICATION_EXTENSIONS_READY,
|
| - original_profile.get()));
|
| + original_context()));
|
|
|
| - // This notification is observed for incognito profiles only.
|
| + // This notification is observed for incognito contexts only.
|
| EXPECT_TRUE(IsRegistered(manager2.get(),
|
| chrome::NOTIFICATION_PROFILE_DESTROYED,
|
| - incognito_profile.get()));
|
| + incognito_context()));
|
| }
|
|
|
| // Test that extensions get grouped in the right SiteInstance (and therefore
|
| // process) based on their URLs.
|
| TEST_F(ProcessManagerTest, ProcessGrouping) {
|
| - // Extensions in different profiles should always be different SiteInstances.
|
| - // Note: we don't initialize these, since we're not testing that
|
| - // functionality. This means we can get away with a NULL UserScriptMaster.
|
| - TestingProfile profile1;
|
| - scoped_ptr<ProcessManager> manager1(ProcessManager::Create(&profile1));
|
| -
|
| - TestingProfile profile2;
|
| - scoped_ptr<ProcessManager> manager2(ProcessManager::Create(&profile2));
|
| + content::ContentBrowserClient content_browser_client;
|
| + content::SetBrowserClientForTesting(&content_browser_client);
|
| +
|
| + // Extensions in different browser contexts should always be different
|
| + // SiteInstances.
|
| + TestBrowserContext context1;
|
| + scoped_ptr<ProcessManager> manager1(ProcessManager::Create(&context1));
|
| + TestBrowserContext context2;
|
| + scoped_ptr<ProcessManager> manager2(ProcessManager::Create(&context2));
|
|
|
| // Extensions with common origins ("scheme://id/") should be grouped in the
|
| // same SiteInstance.
|
|
|