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

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

Issue 67253003: Reland: Move ExtensionProcessManager to src/extensions, part 4 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase process_manager 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 "extensions/browser/process_manager.h"
6 6
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/extensions/extension_error_reporter.h" 8 #include "chrome/browser/extensions/extension_error_reporter.h"
9 #include "chrome/test/base/testing_profile.h" 9 #include "chrome/test/base/testing_profile.h"
10 #include "content/public/browser/notification_service.h" 10 #include "content/public/browser/notification_service.h"
11 #include "content/public/browser/render_process_host.h" 11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/site_instance.h" 12 #include "content/public/browser/site_instance.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/platform_test.h" 14 #include "testing/platform_test.h"
15 15
16 using content::SiteInstance; 16 using content::SiteInstance;
17 17
18 namespace extensions {
19
20 // TODO(jamescook): Convert this from TestingProfile to TestBrowserContext and
21 // move to extensions/browser. This is dependent on ExtensionPrefs being
22 // converted and ExtensionSystem being converted or eliminated.
23 // http://crbug.com/315855
24
18 // make the test a PlatformTest to setup autorelease pools properly on mac 25 // make the test a PlatformTest to setup autorelease pools properly on mac
19 class ExtensionProcessManagerTest : public testing::Test { 26 class ProcessManagerTest : public testing::Test {
20 public: 27 public:
21 static void SetUpTestCase() { 28 static void SetUpTestCase() {
22 ExtensionErrorReporter::Init(false); // no noisy errors 29 ExtensionErrorReporter::Init(false); // no noisy errors
23 } 30 }
24 31
25 virtual void SetUp() { 32 virtual void SetUp() {
26 ExtensionErrorReporter::GetInstance()->ClearErrors(); 33 ExtensionErrorReporter::GetInstance()->ClearErrors();
27 } 34 }
28 35
29 // Returns true if the notification |type| is registered for |manager| with 36 // Returns true if the notification |type| is registered for |manager| with
30 // source |profile|. Pass NULL for |profile| for all sources. 37 // source |profile|. Pass NULL for |profile| for all sources.
31 static bool IsRegistered(ExtensionProcessManager* manager, 38 static bool IsRegistered(ProcessManager* manager,
32 int type, 39 int type,
33 TestingProfile* profile) { 40 TestingProfile* profile) {
34 return manager->registrar_.IsRegistered( 41 return manager->registrar_.IsRegistered(
35 manager, type, content::Source<Profile>(profile)); 42 manager, type, content::Source<Profile>(profile));
36 } 43 }
37 }; 44 };
38 45
39 // Test that notification registration works properly. 46 // Test that notification registration works properly.
40 TEST_F(ExtensionProcessManagerTest, ExtensionNotificationRegistration) { 47 TEST_F(ProcessManagerTest, ExtensionNotificationRegistration) {
41 // Test for a normal profile. 48 // Test for a normal profile.
42 scoped_ptr<TestingProfile> original_profile(new TestingProfile); 49 scoped_ptr<TestingProfile> original_profile(new TestingProfile);
43 scoped_ptr<ExtensionProcessManager> manager1( 50 scoped_ptr<ProcessManager> manager1(
44 ExtensionProcessManager::Create(original_profile.get())); 51 ProcessManager::Create(original_profile.get()));
45 52
46 EXPECT_EQ(original_profile.get(), manager1->GetBrowserContext()); 53 EXPECT_EQ(original_profile.get(), manager1->GetBrowserContext());
47 EXPECT_EQ(0u, manager1->background_hosts().size()); 54 EXPECT_EQ(0u, manager1->background_hosts().size());
48 55
49 // It observes other notifications from this profile. 56 // It observes other notifications from this profile.
50 EXPECT_TRUE(IsRegistered(manager1.get(), 57 EXPECT_TRUE(IsRegistered(manager1.get(),
51 chrome::NOTIFICATION_EXTENSIONS_READY, 58 chrome::NOTIFICATION_EXTENSIONS_READY,
52 original_profile.get())); 59 original_profile.get()));
53 EXPECT_TRUE(IsRegistered(manager1.get(), 60 EXPECT_TRUE(IsRegistered(manager1.get(),
54 chrome::NOTIFICATION_EXTENSION_LOADED, 61 chrome::NOTIFICATION_EXTENSION_LOADED,
55 original_profile.get())); 62 original_profile.get()));
56 EXPECT_TRUE(IsRegistered(manager1.get(), 63 EXPECT_TRUE(IsRegistered(manager1.get(),
57 chrome::NOTIFICATION_EXTENSION_UNLOADED, 64 chrome::NOTIFICATION_EXTENSION_UNLOADED,
58 original_profile.get())); 65 original_profile.get()));
59 EXPECT_TRUE(IsRegistered(manager1.get(), 66 EXPECT_TRUE(IsRegistered(manager1.get(),
60 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, 67 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
61 original_profile.get())); 68 original_profile.get()));
62 69
63 // Now add an incognito profile associated with the master above. 70 // Now add an incognito profile associated with the master above.
64 TestingProfile::Builder builder; 71 TestingProfile::Builder builder;
65 builder.SetIncognito(); 72 builder.SetIncognito();
66 scoped_ptr<TestingProfile> incognito_profile = builder.Build(); 73 scoped_ptr<TestingProfile> incognito_profile = builder.Build();
67 incognito_profile->SetOriginalProfile(original_profile.get()); 74 incognito_profile->SetOriginalProfile(original_profile.get());
68 scoped_ptr<ExtensionProcessManager> manager2( 75 scoped_ptr<ProcessManager> manager2(
69 ExtensionProcessManager::Create(incognito_profile.get())); 76 ProcessManager::Create(incognito_profile.get()));
70 77
71 EXPECT_EQ(incognito_profile.get(), manager2->GetBrowserContext()); 78 EXPECT_EQ(incognito_profile.get(), manager2->GetBrowserContext());
72 EXPECT_EQ(0u, manager2->background_hosts().size()); 79 EXPECT_EQ(0u, manager2->background_hosts().size());
73 80
74 // Some notifications are observed for the original profile. 81 // Some notifications are observed for the original profile.
75 EXPECT_TRUE(IsRegistered(manager2.get(), 82 EXPECT_TRUE(IsRegistered(manager2.get(),
76 chrome::NOTIFICATION_EXTENSION_LOADED, 83 chrome::NOTIFICATION_EXTENSION_LOADED,
77 original_profile.get())); 84 original_profile.get()));
78 85
79 // Some notifications are observed for the incognito profile. 86 // Some notifications are observed for the incognito profile.
(...skipping 15 matching lines...) Expand all
95 original_profile.get())); 102 original_profile.get()));
96 103
97 // This notification is observed for incognito profiles only. 104 // This notification is observed for incognito profiles only.
98 EXPECT_TRUE(IsRegistered(manager2.get(), 105 EXPECT_TRUE(IsRegistered(manager2.get(),
99 chrome::NOTIFICATION_PROFILE_DESTROYED, 106 chrome::NOTIFICATION_PROFILE_DESTROYED,
100 incognito_profile.get())); 107 incognito_profile.get()));
101 } 108 }
102 109
103 // Test that extensions get grouped in the right SiteInstance (and therefore 110 // Test that extensions get grouped in the right SiteInstance (and therefore
104 // process) based on their URLs. 111 // process) based on their URLs.
105 TEST_F(ExtensionProcessManagerTest, ProcessGrouping) { 112 TEST_F(ProcessManagerTest, ProcessGrouping) {
106 // Extensions in different profiles should always be different SiteInstances. 113 // Extensions in different profiles should always be different SiteInstances.
107 // Note: we don't initialize these, since we're not testing that 114 // Note: we don't initialize these, since we're not testing that
108 // functionality. This means we can get away with a NULL UserScriptMaster. 115 // functionality. This means we can get away with a NULL UserScriptMaster.
109 TestingProfile profile1; 116 TestingProfile profile1;
110 scoped_ptr<ExtensionProcessManager> manager1( 117 scoped_ptr<ProcessManager> manager1(ProcessManager::Create(&profile1));
111 ExtensionProcessManager::Create(&profile1));
112 118
113 TestingProfile profile2; 119 TestingProfile profile2;
114 scoped_ptr<ExtensionProcessManager> manager2( 120 scoped_ptr<ProcessManager> manager2(ProcessManager::Create(&profile2));
115 ExtensionProcessManager::Create(&profile2));
116 121
117 // Extensions with common origins ("scheme://id/") should be grouped in the 122 // Extensions with common origins ("scheme://id/") should be grouped in the
118 // same SiteInstance. 123 // same SiteInstance.
119 GURL ext1_url1("chrome-extension://ext1_id/index.html"); 124 GURL ext1_url1("chrome-extension://ext1_id/index.html");
120 GURL ext1_url2("chrome-extension://ext1_id/monkey/monkey.html"); 125 GURL ext1_url2("chrome-extension://ext1_id/monkey/monkey.html");
121 GURL ext2_url1("chrome-extension://ext2_id/index.html"); 126 GURL ext2_url1("chrome-extension://ext2_id/index.html");
122 127
123 scoped_refptr<SiteInstance> site11 = 128 scoped_refptr<SiteInstance> site11 =
124 manager1->GetSiteInstanceForURL(ext1_url1); 129 manager1->GetSiteInstanceForURL(ext1_url1);
125 scoped_refptr<SiteInstance> site12 = 130 scoped_refptr<SiteInstance> site12 =
126 manager1->GetSiteInstanceForURL(ext1_url2); 131 manager1->GetSiteInstanceForURL(ext1_url2);
127 EXPECT_EQ(site11, site12); 132 EXPECT_EQ(site11, site12);
128 133
129 scoped_refptr<SiteInstance> site21 = 134 scoped_refptr<SiteInstance> site21 =
130 manager1->GetSiteInstanceForURL(ext2_url1); 135 manager1->GetSiteInstanceForURL(ext2_url1);
131 EXPECT_NE(site11, site21); 136 EXPECT_NE(site11, site21);
132 137
133 scoped_refptr<SiteInstance> other_profile_site = 138 scoped_refptr<SiteInstance> other_profile_site =
134 manager2->GetSiteInstanceForURL(ext1_url1); 139 manager2->GetSiteInstanceForURL(ext1_url1);
135 EXPECT_NE(site11, other_profile_site); 140 EXPECT_NE(site11, other_profile_site);
136 } 141 }
142
143 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/process_manager_browsertest.cc ('k') | chrome/browser/extensions/process_map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698