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/chrome_signin_client.h"
6 #include "chrome/browser/signin/chrome_signin_client_factory.h"
7 #include "chrome/browser/signin/signin_manager_factory.h"
8 #include "chrome/test/base/testing_browser_process.h"
9 #include "chrome/test/base/testing_profile.h"
10 #include "chrome/test/base/testing_profile_manager.h"
11 #include "components/signin/core/browser/signin_manager.h"
12 #include "content/public/test/mock_render_process_host.h"
13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "extensions/common/extension.h"
15 #include "extensions/common/extension_builder.h"
16 #include "extensions/common/permissions/permissions_data.h"
17 #include "testing/gtest/include/gtest/gtest.h"
19 namespace extensions
{
23 class BrowserPermissionsPolicyDelegateTest
: public testing::Test
{
25 void SetUp() override
{
26 profile_manager_
.reset(
27 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
28 ASSERT_TRUE(profile_manager_
->SetUp());
29 profile_
= profile_manager_
->CreateTestingProfile("test");
31 void TearDown() override
{
32 // Need to delete profile here before the UI thread is destroyed.
33 profile_manager_
->DeleteTestingProfile("test");
34 profile_manager_
.reset();
37 content::TestBrowserThreadBundle thread_bundle_
;
38 scoped_ptr
<TestingProfileManager
> profile_manager_
;
39 TestingProfile
* profile_
;
42 #if !defined(OS_CHROMEOS)
43 scoped_refptr
<const Extension
> CreateTestExtension(const std::string
& id
) {
44 return ExtensionBuilder()
45 .SetManifest(DictionaryBuilder()
46 .Set("name", "Extension with ID " + id
)
47 .Set("version", "1.0")
48 .Set("manifest_version", 2)
49 .Set("permissions", ListBuilder().Append("<all_urls>")))
57 #if !defined(OS_CHROMEOS)
58 // Tests that CanExecuteScriptOnPage returns false for the signin process,
59 // all else being equal.
60 TEST_F(BrowserPermissionsPolicyDelegateTest
, CanExecuteScriptOnPage
) {
62 "https://accounts.google.com/ServiceLogin?service=chromiumsync");
63 ASSERT_TRUE(SigninManager::IsWebBasedSigninFlowURL(kSigninUrl
));
65 content::MockRenderProcessHost
signin_process(profile_
);
66 content::MockRenderProcessHost
normal_process(profile_
);
67 SigninClient
* signin_client
=
68 ChromeSigninClientFactory::GetForProfile(profile_
);
69 ASSERT_TRUE(signin_client
);
70 signin_client
->SetSigninProcess(signin_process
.GetID());
72 scoped_refptr
<const Extension
> extension(CreateTestExtension("a"));
75 // The same call should succeed with a normal process, but fail with a signin
77 const PermissionsData
* permissions_data
= extension
->permissions_data();
78 EXPECT_TRUE(permissions_data
->CanAccessPage(extension
.get(),
82 normal_process
.GetID(),
85 EXPECT_FALSE(permissions_data
->CanAccessPage(extension
.get(),
89 signin_process
.GetID(),
95 } // namespace extensions