Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / extensions / browser_permissions_policy_delegate_unittest.cc
blob401ac5c40bb794a1a722e93d3889e0d39fe7cac0
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 {
19 namespace {
21 class BrowserPermissionsPolicyDelegateTest : public testing::Test {
22 protected:
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();
34 protected:
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>")))
48 .SetID(id)
49 .Build();
51 #endif
53 } // namespace
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) {
59 GURL kSigninUrl(
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"));
70 std::string error;
72 // The same call should succeed with a normal process, but fail with a signin
73 // process.
74 EXPECT_TRUE(PermissionsData::CanExecuteScriptOnPage(extension.get(),
75 kSigninUrl,
76 kSigninUrl,
77 -1,
78 NULL,
79 normal_process.GetID(),
80 &error)) << error;
81 EXPECT_FALSE(PermissionsData::CanExecuteScriptOnPage(extension.get(),
82 kSigninUrl,
83 kSigninUrl,
84 -1,
85 NULL,
86 signin_process.GetID(),
87 &error)) << error;
89 #endif
91 } // namespace extensions