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/test/base/testing_browser_process.h"
8 #include "chrome/test/base/testing_profile.h"
9 #include "chrome/test/base/testing_profile_manager.h"
10 #include "content/public/test/mock_render_process_host.h"
11 #include "content/public/test/test_browser_thread_bundle.h"
12 #include "extensions/common/extension.h"
13 #include "extensions/common/extension_builder.h"
14 #include "extensions/common/permissions/permissions_data.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 #if !defined(OS_CHROMEOS)
41 scoped_refptr
<const Extension
> CreateTestExtension(const std::string
& id
) {
42 return ExtensionBuilder()
43 .SetManifest(DictionaryBuilder()
44 .Set("name", "Extension with ID " + id
)
45 .Set("version", "1.0")
46 .Set("manifest_version", 2)
47 .Set("permissions", ListBuilder().Append("<all_urls>")))
55 #if !defined(OS_CHROMEOS)
56 // Tests that CanExecuteScriptOnPage returns false for the signin process,
57 // all else being equal.
58 TEST_F(BrowserPermissionsPolicyDelegateTest
, CanExecuteScriptOnPage
) {
60 "https://accounts.google.com/ServiceLogin?service=chromiumsync");
61 ASSERT_TRUE(SigninManager::IsWebBasedSigninFlowURL(kSigninUrl
));
63 content::MockRenderProcessHost
signin_process(profile_
);
64 content::MockRenderProcessHost
normal_process(profile_
);
65 SigninManager
* signin_manager
= SigninManagerFactory::GetForProfile(profile_
);
66 ASSERT_TRUE(signin_manager
);
67 signin_manager
->SetSigninProcess(signin_process
.GetID());
69 scoped_refptr
<const Extension
> extension(CreateTestExtension("a"));
72 // The same call should succeed with a normal process, but fail with a signin
74 EXPECT_TRUE(PermissionsData::CanExecuteScriptOnPage(extension
.get(),
79 normal_process
.GetID(),
81 EXPECT_FALSE(PermissionsData::CanExecuteScriptOnPage(extension
.get(),
86 signin_process
.GetID(),
91 } // namespace extensions