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

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

Issue 2798503002: Extensions: Pull duplicated functionality into ExtensionsTest fixture. (Closed)
Patch Set: Nits Created 3 years, 8 months 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
« no previous file with comments | « extensions/browser/extensions_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/process_manager.h" 5 #include "extensions/browser/process_manager.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "content/public/browser/content_browser_client.h" 8 #include "content/public/browser/content_browser_client.h"
9 #include "content/public/browser/notification_service.h" 9 #include "content/public/browser/notification_service.h"
10 #include "content/public/browser/site_instance.h" 10 #include "content/public/browser/site_instance.h"
11 #include "content/public/common/content_client.h" 11 #include "content/public/common/content_client.h"
12 #include "content/public/test/test_browser_context.h" 12 #include "content/public/test/test_browser_context.h"
13 #include "extensions/browser/extension_registry.h" 13 #include "extensions/browser/extension_registry.h"
14 #include "extensions/browser/extensions_test.h" 14 #include "extensions/browser/extensions_test.h"
15 #include "extensions/browser/notification_types.h" 15 #include "extensions/browser/notification_types.h"
16 #include "extensions/browser/process_manager_delegate.h" 16 #include "extensions/browser/process_manager_delegate.h"
17 #include "extensions/browser/test_extensions_browser_client.h" 17 #include "extensions/browser/test_extensions_browser_client.h"
18 18
19 using content::BrowserContext; 19 using content::BrowserContext;
20 using content::SiteInstance; 20 using content::SiteInstance;
21 using content::TestBrowserContext; 21 using content::TestBrowserContext;
22 22
23 namespace extensions { 23 namespace extensions {
24 24
25 namespace { 25 namespace {
26 26
27 // An incognito version of a TestBrowserContext.
28 class TestBrowserContextIncognito : public TestBrowserContext {
29 public:
30 TestBrowserContextIncognito() {}
31 ~TestBrowserContextIncognito() override {}
32
33 // TestBrowserContext implementation.
34 bool IsOffTheRecord() const override { return true; }
35
36 private:
37 DISALLOW_COPY_AND_ASSIGN(TestBrowserContextIncognito);
38 };
39
40 // A trivial ProcessManagerDelegate. 27 // A trivial ProcessManagerDelegate.
41 class TestProcessManagerDelegate : public ProcessManagerDelegate { 28 class TestProcessManagerDelegate : public ProcessManagerDelegate {
42 public: 29 public:
43 TestProcessManagerDelegate() 30 TestProcessManagerDelegate()
44 : is_background_page_allowed_(true), 31 : is_background_page_allowed_(true),
45 defer_creating_startup_background_hosts_(false) {} 32 defer_creating_startup_background_hosts_(false) {}
46 ~TestProcessManagerDelegate() override {} 33 ~TestProcessManagerDelegate() override {}
47 34
48 // ProcessManagerDelegate implementation. 35 // ProcessManagerDelegate implementation.
49 bool AreBackgroundPagesAllowedForContext( 36 bool AreBackgroundPagesAllowedForContext(
(...skipping 12 matching lines...) Expand all
62 49
63 bool is_background_page_allowed_; 50 bool is_background_page_allowed_;
64 bool defer_creating_startup_background_hosts_; 51 bool defer_creating_startup_background_hosts_;
65 }; 52 };
66 53
67 } // namespace 54 } // namespace
68 55
69 class ProcessManagerTest : public ExtensionsTest { 56 class ProcessManagerTest : public ExtensionsTest {
70 public: 57 public:
71 ProcessManagerTest() : extension_registry_(browser_context()) { 58 ProcessManagerTest() : extension_registry_(browser_context()) {
72 extensions_browser_client()->SetIncognitoContext(&incognito_context_);
73 extensions_browser_client()->set_process_manager_delegate( 59 extensions_browser_client()->set_process_manager_delegate(
74 &process_manager_delegate_); 60 &process_manager_delegate_);
75 } 61 }
76 62
77 ~ProcessManagerTest() override {} 63 ~ProcessManagerTest() override {}
78 64
79 // Use original_context() to make it clear it is a non-incognito context. 65 // Use original_context() to make it clear it is a non-incognito context.
80 BrowserContext* original_context() { return browser_context(); } 66 BrowserContext* original_context() { return browser_context(); }
81 BrowserContext* incognito_context() { return &incognito_context_; }
82 ExtensionRegistry* extension_registry() { return &extension_registry_; } 67 ExtensionRegistry* extension_registry() { return &extension_registry_; }
83 TestProcessManagerDelegate* process_manager_delegate() { 68 TestProcessManagerDelegate* process_manager_delegate() {
84 return &process_manager_delegate_; 69 return &process_manager_delegate_;
85 } 70 }
86 71
87 // Returns true if the notification |type| is registered for |manager| with 72 // Returns true if the notification |type| is registered for |manager| with
88 // source |context|. Pass NULL for |context| for all sources. 73 // source |context|. Pass NULL for |context| for all sources.
89 static bool IsRegistered(ProcessManager* manager, 74 static bool IsRegistered(ProcessManager* manager,
90 int type, 75 int type,
91 BrowserContext* context) { 76 BrowserContext* context) {
92 return manager->registrar_.IsRegistered( 77 return manager->registrar_.IsRegistered(
93 manager, type, content::Source<BrowserContext>(context)); 78 manager, type, content::Source<BrowserContext>(context));
94 } 79 }
95 80
96 private: 81 private:
97 TestBrowserContextIncognito incognito_context_;
98 ExtensionRegistry extension_registry_; // Shared between BrowserContexts. 82 ExtensionRegistry extension_registry_; // Shared between BrowserContexts.
99 TestProcessManagerDelegate process_manager_delegate_; 83 TestProcessManagerDelegate process_manager_delegate_;
100 84
101 DISALLOW_COPY_AND_ASSIGN(ProcessManagerTest); 85 DISALLOW_COPY_AND_ASSIGN(ProcessManagerTest);
102 }; 86 };
103 87
104 // Test that notification registration works properly. 88 // Test that notification registration works properly.
105 TEST_F(ProcessManagerTest, ExtensionNotificationRegistration) { 89 TEST_F(ProcessManagerTest, ExtensionNotificationRegistration) {
106 // Test for a normal context ProcessManager. 90 // Test for a normal context ProcessManager.
107 std::unique_ptr<ProcessManager> manager1(ProcessManager::CreateForTesting( 91 std::unique_ptr<ProcessManager> manager1(ProcessManager::CreateForTesting(
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 scoped_refptr<SiteInstance> site21 = 228 scoped_refptr<SiteInstance> site21 =
245 manager1->GetSiteInstanceForURL(ext2_url1); 229 manager1->GetSiteInstanceForURL(ext2_url1);
246 EXPECT_NE(site11, site21); 230 EXPECT_NE(site11, site21);
247 231
248 scoped_refptr<SiteInstance> other_profile_site = 232 scoped_refptr<SiteInstance> other_profile_site =
249 manager2->GetSiteInstanceForURL(ext1_url1); 233 manager2->GetSiteInstanceForURL(ext1_url1);
250 EXPECT_NE(site11, other_profile_site); 234 EXPECT_NE(site11, other_profile_site);
251 } 235 }
252 236
253 } // namespace extensions 237 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/extensions_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698