1 // Copyright 2013 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.
5 #include "chrome/browser/signin/signin_manager.h"
6 #include "chrome/browser/signin/signin_manager_factory.h"
7 #include "chrome/common/extensions/extension.h"
8 #include "chrome/common/extensions/extension_builder.h"
9 #include "chrome/common/extensions/permissions/permissions_data.h"
10 #include "chrome/test/base/testing_browser_process.h"
11 #include "chrome/test/base/testing_profile.h"
12 #include "chrome/test/base/testing_profile_manager.h"
13 #include "content/public/test/mock_render_process_host.h"
14 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace extensions {
21 class BrowserPermissionsPolicyDelegateTest : public testing::Test {
23 virtual void SetUp() {
24 profile_manager_.reset(
25 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
26 ASSERT_TRUE(profile_manager_->SetUp());
27 profile_ = profile_manager_->CreateTestingProfile("test");
29 virtual void TearDown() {
30 // Need to delete profile here before the UI thread is destroyed.
31 profile_manager_->DeleteTestingProfile("test");
32 profile_manager_.reset();
35 content::TestBrowserThreadBundle thread_bundle_;
36 scoped_ptr<TestingProfileManager> profile_manager_;
37 TestingProfile* profile_;
40 scoped_refptr<const Extension> CreateTestExtension(const std::string& id) {
41 return ExtensionBuilder()
42 .SetManifest(DictionaryBuilder()
43 .Set("name", "Extension with ID " + id)
44 .Set("version", "1.0")
45 .Set("manifest_version", 2)
46 .Set("permissions", ListBuilder().Append("<all_urls>")))
53 #if !defined(OS_CHROMEOS)
54 // Tests that CanExecuteScriptOnPage returns false for the signin process,
55 // all else being equal.
56 TEST_F(BrowserPermissionsPolicyDelegateTest, CanExecuteScriptOnPage) {
58 "https://accounts.google.com/ServiceLogin?service=chromiumsync");
59 ASSERT_TRUE(SigninManager::IsWebBasedSigninFlowURL(kSigninUrl));
61 content::MockRenderProcessHost signin_process(profile_);
62 content::MockRenderProcessHost normal_process(profile_);
63 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile_);
64 ASSERT_TRUE(signin_manager);
65 signin_manager->SetSigninProcess(signin_process.GetID());
67 scoped_refptr<const Extension> extension(CreateTestExtension("a"));
70 // The same call should succeed with a normal process, but fail with a signin
72 EXPECT_TRUE(PermissionsData::CanExecuteScriptOnPage(extension.get(),
77 normal_process.GetID(),
79 EXPECT_FALSE(PermissionsData::CanExecuteScriptOnPage(extension.get(),
84 signin_process.GetID(),
89 } // namespace extensions