Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1016)

Side by Side Diff: chrome/browser/extensions/extension_process_manager_unittest.cc

Issue 57813003: Reland: Convert ExtensionProcessManager to BrowserContext, part 1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: disable on windows Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_process_manager.h" 5 #include "chrome/browser/extensions/extension_process_manager.h"
6
7 #include "chrome/browser/chrome_notification_types.h"
6 #include "chrome/browser/extensions/extension_error_reporter.h" 8 #include "chrome/browser/extensions/extension_error_reporter.h"
7 #include "chrome/test/base/testing_profile.h" 9 #include "chrome/test/base/testing_profile.h"
10 #include "content/public/browser/notification_service.h"
8 #include "content/public/browser/render_process_host.h" 11 #include "content/public/browser/render_process_host.h"
9 #include "content/public/browser/site_instance.h" 12 #include "content/public/browser/site_instance.h"
10 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h" 14 #include "testing/platform_test.h"
12 15
13 using content::SiteInstance; 16 using content::SiteInstance;
14 17
15 namespace {
16
17 // make the test a PlatformTest to setup autorelease pools properly on mac 18 // make the test a PlatformTest to setup autorelease pools properly on mac
18 class ExtensionProcessManagerTest : public testing::Test { 19 class ExtensionProcessManagerTest : public testing::Test {
19 public: 20 public:
20 static void SetUpTestCase() { 21 static void SetUpTestCase() {
21 ExtensionErrorReporter::Init(false); // no noisy errors 22 ExtensionErrorReporter::Init(false); // no noisy errors
22 } 23 }
23 24
24 virtual void SetUp() { 25 virtual void SetUp() {
25 ExtensionErrorReporter::GetInstance()->ClearErrors(); 26 ExtensionErrorReporter::GetInstance()->ClearErrors();
26 } 27 }
28
29 // Returns true if the notification |type| is registered for |manager| with
30 // source |profile|. Pass NULL for |profile| for all sources.
31 static bool IsRegistered(ExtensionProcessManager* manager,
32 int type,
33 TestingProfile* profile) {
34 return manager->registrar_.IsRegistered(
35 manager, type, content::Source<Profile>(profile));
36 }
37
38 // Allows access to a protected method.
39 static Profile* GetProfile(ExtensionProcessManager* manager) {
40 return manager->GetProfile();
41 }
27 }; 42 };
28 43
29 } // namespace 44 // Test that notification registration works properly.
45 TEST_F(ExtensionProcessManagerTest, ExtensionNotificationRegistration) {
46 // Test for a normal profile.
47 scoped_ptr<TestingProfile> original_profile(new TestingProfile);
48 scoped_ptr<ExtensionProcessManager> manager1(
49 ExtensionProcessManager::Create(original_profile.get()));
50
51 EXPECT_EQ(original_profile.get(), GetProfile(manager1.get()));
52 EXPECT_EQ(0u, manager1->background_hosts().size());
53
54 // It observes some notifications from all sources.
55 EXPECT_TRUE(IsRegistered(
56 manager1.get(), chrome::NOTIFICATION_BROWSER_WINDOW_READY, NULL));
57
58 // It observes other notifications from this profile.
59 EXPECT_TRUE(IsRegistered(manager1.get(),
60 chrome::NOTIFICATION_EXTENSIONS_READY,
61 original_profile.get()));
62 EXPECT_TRUE(IsRegistered(manager1.get(),
63 chrome::NOTIFICATION_EXTENSION_LOADED,
64 original_profile.get()));
65 EXPECT_TRUE(IsRegistered(manager1.get(),
66 chrome::NOTIFICATION_EXTENSION_UNLOADED,
67 original_profile.get()));
68 EXPECT_TRUE(IsRegistered(manager1.get(),
69 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
70 original_profile.get()));
71
72 // Now add an incognito profile associated with the master above.
73 TestingProfile::Builder builder;
74 builder.SetIncognito();
75 scoped_ptr<TestingProfile> incognito_profile = builder.Build();
76 incognito_profile->SetOriginalProfile(original_profile.get());
77 scoped_ptr<ExtensionProcessManager> manager2(
78 ExtensionProcessManager::Create(incognito_profile.get()));
79
80 EXPECT_EQ(incognito_profile.get(), GetProfile(manager2.get()));
81 EXPECT_EQ(0u, manager2->background_hosts().size());
82
83 // Some notifications are observed for the original profile.
84 EXPECT_TRUE(IsRegistered(manager2.get(),
85 chrome::NOTIFICATION_EXTENSION_LOADED,
86 original_profile.get()));
87
88 // Some notifications are observed for the incognito profile.
89 EXPECT_TRUE(IsRegistered(manager2.get(),
90 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
91 incognito_profile.get()));
92
93 // Some notifications are observed for both incognito and original.
94 EXPECT_TRUE(IsRegistered(manager2.get(),
95 chrome::NOTIFICATION_PROFILE_DESTROYED,
96 original_profile.get()));
97 EXPECT_TRUE(IsRegistered(manager2.get(),
98 chrome::NOTIFICATION_PROFILE_DESTROYED,
99 incognito_profile.get()));
100
101 // Some are not observed at all.
102 EXPECT_FALSE(IsRegistered(manager2.get(),
103 chrome::NOTIFICATION_EXTENSIONS_READY,
104 original_profile.get()));
105
106 // This notification is observed for incognito profiles only.
107 EXPECT_TRUE(IsRegistered(manager2.get(),
108 chrome::NOTIFICATION_PROFILE_DESTROYED,
109 incognito_profile.get()));
110 }
30 111
31 // Test that extensions get grouped in the right SiteInstance (and therefore 112 // Test that extensions get grouped in the right SiteInstance (and therefore
32 // process) based on their URLs. 113 // process) based on their URLs.
33 TEST_F(ExtensionProcessManagerTest, ProcessGrouping) { 114 TEST_F(ExtensionProcessManagerTest, ProcessGrouping) {
34 // Extensions in different profiles should always be different SiteInstances. 115 // Extensions in different profiles should always be different SiteInstances.
35 // Note: we don't initialize these, since we're not testing that 116 // Note: we don't initialize these, since we're not testing that
36 // functionality. This means we can get away with a NULL UserScriptMaster. 117 // functionality. This means we can get away with a NULL UserScriptMaster.
37 TestingProfile profile1; 118 TestingProfile profile1;
38 scoped_ptr<ExtensionProcessManager> manager1( 119 scoped_ptr<ExtensionProcessManager> manager1(
39 ExtensionProcessManager::Create(&profile1)); 120 ExtensionProcessManager::Create(&profile1));
(...skipping 15 matching lines...) Expand all
55 EXPECT_EQ(site11, site12); 136 EXPECT_EQ(site11, site12);
56 137
57 scoped_refptr<SiteInstance> site21 = 138 scoped_refptr<SiteInstance> site21 =
58 manager1->GetSiteInstanceForURL(ext2_url1); 139 manager1->GetSiteInstanceForURL(ext2_url1);
59 EXPECT_NE(site11, site21); 140 EXPECT_NE(site11, site21);
60 141
61 scoped_refptr<SiteInstance> other_profile_site = 142 scoped_refptr<SiteInstance> other_profile_site =
62 manager2->GetSiteInstanceForURL(ext1_url1); 143 manager2->GetSiteInstanceForURL(ext1_url1);
63 EXPECT_NE(site11, other_profile_site); 144 EXPECT_NE(site11, other_profile_site);
64 } 145 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698