OLD | NEW |
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 | 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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 } | 27 } |
28 | 28 |
29 // Returns true if the notification |type| is registered for |manager| with | 29 // Returns true if the notification |type| is registered for |manager| with |
30 // source |profile|. Pass NULL for |profile| for all sources. | 30 // source |profile|. Pass NULL for |profile| for all sources. |
31 static bool IsRegistered(ExtensionProcessManager* manager, | 31 static bool IsRegistered(ExtensionProcessManager* manager, |
32 int type, | 32 int type, |
33 TestingProfile* profile) { | 33 TestingProfile* profile) { |
34 return manager->registrar_.IsRegistered( | 34 return manager->registrar_.IsRegistered( |
35 manager, type, content::Source<Profile>(profile)); | 35 manager, type, content::Source<Profile>(profile)); |
36 } | 36 } |
37 | |
38 // Allows access to a protected method. | |
39 static Profile* GetProfile(ExtensionProcessManager* manager) { | |
40 return manager->GetProfile(); | |
41 } | |
42 }; | 37 }; |
43 | 38 |
44 // Test that notification registration works properly. | 39 // Test that notification registration works properly. |
45 TEST_F(ExtensionProcessManagerTest, ExtensionNotificationRegistration) { | 40 TEST_F(ExtensionProcessManagerTest, ExtensionNotificationRegistration) { |
46 // Test for a normal profile. | 41 // Test for a normal profile. |
47 scoped_ptr<TestingProfile> original_profile(new TestingProfile); | 42 scoped_ptr<TestingProfile> original_profile(new TestingProfile); |
48 scoped_ptr<ExtensionProcessManager> manager1( | 43 scoped_ptr<ExtensionProcessManager> manager1( |
49 ExtensionProcessManager::Create(original_profile.get())); | 44 ExtensionProcessManager::Create(original_profile.get())); |
50 | 45 |
51 EXPECT_EQ(original_profile.get(), GetProfile(manager1.get())); | 46 EXPECT_EQ(original_profile.get(), manager1->GetBrowserContext()); |
52 EXPECT_EQ(0u, manager1->background_hosts().size()); | 47 EXPECT_EQ(0u, manager1->background_hosts().size()); |
53 | 48 |
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. | 49 // It observes other notifications from this profile. |
59 EXPECT_TRUE(IsRegistered(manager1.get(), | 50 EXPECT_TRUE(IsRegistered(manager1.get(), |
60 chrome::NOTIFICATION_EXTENSIONS_READY, | 51 chrome::NOTIFICATION_EXTENSIONS_READY, |
61 original_profile.get())); | 52 original_profile.get())); |
62 EXPECT_TRUE(IsRegistered(manager1.get(), | 53 EXPECT_TRUE(IsRegistered(manager1.get(), |
63 chrome::NOTIFICATION_EXTENSION_LOADED, | 54 chrome::NOTIFICATION_EXTENSION_LOADED, |
64 original_profile.get())); | 55 original_profile.get())); |
65 EXPECT_TRUE(IsRegistered(manager1.get(), | 56 EXPECT_TRUE(IsRegistered(manager1.get(), |
66 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 57 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
67 original_profile.get())); | 58 original_profile.get())); |
68 EXPECT_TRUE(IsRegistered(manager1.get(), | 59 EXPECT_TRUE(IsRegistered(manager1.get(), |
69 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 60 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
70 original_profile.get())); | 61 original_profile.get())); |
71 | 62 |
72 // Now add an incognito profile associated with the master above. | 63 // Now add an incognito profile associated with the master above. |
73 TestingProfile::Builder builder; | 64 TestingProfile::Builder builder; |
74 builder.SetIncognito(); | 65 builder.SetIncognito(); |
75 scoped_ptr<TestingProfile> incognito_profile = builder.Build(); | 66 scoped_ptr<TestingProfile> incognito_profile = builder.Build(); |
76 incognito_profile->SetOriginalProfile(original_profile.get()); | 67 incognito_profile->SetOriginalProfile(original_profile.get()); |
77 scoped_ptr<ExtensionProcessManager> manager2( | 68 scoped_ptr<ExtensionProcessManager> manager2( |
78 ExtensionProcessManager::Create(incognito_profile.get())); | 69 ExtensionProcessManager::Create(incognito_profile.get())); |
79 | 70 |
80 EXPECT_EQ(incognito_profile.get(), GetProfile(manager2.get())); | 71 EXPECT_EQ(incognito_profile.get(), manager2->GetBrowserContext()); |
81 EXPECT_EQ(0u, manager2->background_hosts().size()); | 72 EXPECT_EQ(0u, manager2->background_hosts().size()); |
82 | 73 |
83 // Some notifications are observed for the original profile. | 74 // Some notifications are observed for the original profile. |
84 EXPECT_TRUE(IsRegistered(manager2.get(), | 75 EXPECT_TRUE(IsRegistered(manager2.get(), |
85 chrome::NOTIFICATION_EXTENSION_LOADED, | 76 chrome::NOTIFICATION_EXTENSION_LOADED, |
86 original_profile.get())); | 77 original_profile.get())); |
87 | 78 |
88 // Some notifications are observed for the incognito profile. | 79 // Some notifications are observed for the incognito profile. |
89 EXPECT_TRUE(IsRegistered(manager2.get(), | 80 EXPECT_TRUE(IsRegistered(manager2.get(), |
90 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 81 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 EXPECT_EQ(site11, site12); | 127 EXPECT_EQ(site11, site12); |
137 | 128 |
138 scoped_refptr<SiteInstance> site21 = | 129 scoped_refptr<SiteInstance> site21 = |
139 manager1->GetSiteInstanceForURL(ext2_url1); | 130 manager1->GetSiteInstanceForURL(ext2_url1); |
140 EXPECT_NE(site11, site21); | 131 EXPECT_NE(site11, site21); |
141 | 132 |
142 scoped_refptr<SiteInstance> other_profile_site = | 133 scoped_refptr<SiteInstance> other_profile_site = |
143 manager2->GetSiteInstanceForURL(ext1_url1); | 134 manager2->GetSiteInstanceForURL(ext1_url1); |
144 EXPECT_NE(site11, other_profile_site); | 135 EXPECT_NE(site11, other_profile_site); |
145 } | 136 } |
OLD | NEW |