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 #include "chrome/browser/extensions/extension_error_reporter.h" | 6 #include "chrome/browser/extensions/extension_error_reporter.h" |
7 #include "chrome/test/base/testing_profile.h" | 7 #include "chrome/test/base/testing_profile.h" |
8 #include "content/public/browser/render_process_host.h" | 8 #include "content/public/browser/render_process_host.h" |
9 #include "content/public/browser/site_instance.h" | 9 #include "content/public/browser/site_instance.h" |
10 #include "content/public/test/test_browser_thread_bundle.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
13 | 12 |
14 using content::SiteInstance; | 13 using content::SiteInstance; |
15 | 14 |
16 namespace { | 15 namespace { |
17 | 16 |
18 // make the test a PlatformTest to setup autorelease pools properly on mac | 17 // make the test a PlatformTest to setup autorelease pools properly on mac |
19 class ExtensionProcessManagerTest : public testing::Test { | 18 class ExtensionProcessManagerTest : public testing::Test { |
20 public: | 19 public: |
21 static void SetUpTestCase() { | 20 static void SetUpTestCase() { |
22 ExtensionErrorReporter::Init(false); // no noisy errors | 21 ExtensionErrorReporter::Init(false); // no noisy errors |
23 } | 22 } |
24 | 23 |
25 virtual void SetUp() { | 24 virtual void SetUp() { |
26 ExtensionErrorReporter::GetInstance()->ClearErrors(); | 25 ExtensionErrorReporter::GetInstance()->ClearErrors(); |
27 } | 26 } |
28 }; | 27 }; |
29 | 28 |
30 } // namespace | 29 } // namespace |
31 | 30 |
32 // Test that extensions get grouped in the right SiteInstance (and therefore | 31 // Test that extensions get grouped in the right SiteInstance (and therefore |
33 // process) based on their URLs. | 32 // process) based on their URLs. |
34 TEST_F(ExtensionProcessManagerTest, ProcessGrouping) { | 33 TEST_F(ExtensionProcessManagerTest, ProcessGrouping) { |
35 // Extensions in different profiles should always be different SiteInstances. | 34 // Extensions in different profiles should always be different SiteInstances. |
36 // Note: we don't initialize these, since we're not testing that | 35 // Note: we don't initialize these, since we're not testing that |
37 // functionality. This means we can get away with a NULL UserScriptMaster. | 36 // functionality. This means we can get away with a NULL UserScriptMaster. |
38 content::TestBrowserThreadBundle thread_bundle; | |
39 TestingProfile profile1; | 37 TestingProfile profile1; |
40 scoped_ptr<ExtensionProcessManager> manager1( | 38 scoped_ptr<ExtensionProcessManager> manager1( |
41 ExtensionProcessManager::Create(&profile1)); | 39 ExtensionProcessManager::Create(&profile1)); |
42 | 40 |
43 TestingProfile profile2; | 41 TestingProfile profile2; |
44 scoped_ptr<ExtensionProcessManager> manager2( | 42 scoped_ptr<ExtensionProcessManager> manager2( |
45 ExtensionProcessManager::Create(&profile2)); | 43 ExtensionProcessManager::Create(&profile2)); |
46 | 44 |
47 // Extensions with common origins ("scheme://id/") should be grouped in the | 45 // Extensions with common origins ("scheme://id/") should be grouped in the |
48 // same SiteInstance. | 46 // same SiteInstance. |
49 GURL ext1_url1("chrome-extension://ext1_id/index.html"); | 47 GURL ext1_url1("chrome-extension://ext1_id/index.html"); |
50 GURL ext1_url2("chrome-extension://ext1_id/monkey/monkey.html"); | 48 GURL ext1_url2("chrome-extension://ext1_id/monkey/monkey.html"); |
51 GURL ext2_url1("chrome-extension://ext2_id/index.html"); | 49 GURL ext2_url1("chrome-extension://ext2_id/index.html"); |
52 | 50 |
53 scoped_refptr<SiteInstance> site11 = | 51 scoped_refptr<SiteInstance> site11 = |
54 manager1->GetSiteInstanceForURL(ext1_url1); | 52 manager1->GetSiteInstanceForURL(ext1_url1); |
55 scoped_refptr<SiteInstance> site12 = | 53 scoped_refptr<SiteInstance> site12 = |
56 manager1->GetSiteInstanceForURL(ext1_url2); | 54 manager1->GetSiteInstanceForURL(ext1_url2); |
57 EXPECT_EQ(site11, site12); | 55 EXPECT_EQ(site11, site12); |
58 | 56 |
59 scoped_refptr<SiteInstance> site21 = | 57 scoped_refptr<SiteInstance> site21 = |
60 manager1->GetSiteInstanceForURL(ext2_url1); | 58 manager1->GetSiteInstanceForURL(ext2_url1); |
61 EXPECT_NE(site11, site21); | 59 EXPECT_NE(site11, site21); |
62 | 60 |
63 scoped_refptr<SiteInstance> other_profile_site = | 61 scoped_refptr<SiteInstance> other_profile_site = |
64 manager2->GetSiteInstanceForURL(ext1_url1); | 62 manager2->GetSiteInstanceForURL(ext1_url1); |
65 EXPECT_NE(site11, other_profile_site); | 63 EXPECT_NE(site11, other_profile_site); |
66 } | 64 } |
OLD | NEW |