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