- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / browser_permissions_policy_delegate_unittest.cc
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.
4
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"
16
17 namespace extensions {
18
19 namespace {
20
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");
28   }
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();
33   }
34  protected:
35   content::TestBrowserThreadBundle thread_bundle_;
36   scoped_ptr<TestingProfileManager> profile_manager_;
37   TestingProfile* profile_;
38 };
39
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>")))
47       .SetID(id)
48       .Build();
49 }
50
51 }  // namespace
52
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) {
57   GURL kSigninUrl(
58       "https://accounts.google.com/ServiceLogin?service=chromiumsync");
59   ASSERT_TRUE(SigninManager::IsWebBasedSigninFlowURL(kSigninUrl));
60
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());
66
67   scoped_refptr<const Extension> extension(CreateTestExtension("a"));
68   std::string error;
69
70   // The same call should succeed with a normal process, but fail with a signin
71   // process.
72   EXPECT_TRUE(PermissionsData::CanExecuteScriptOnPage(extension.get(),
73                                                       kSigninUrl,
74                                                       kSigninUrl,
75                                                       -1,
76                                                       NULL,
77                                                       normal_process.GetID(),
78                                                       &error)) << error;
79   EXPECT_FALSE(PermissionsData::CanExecuteScriptOnPage(extension.get(),
80                                                        kSigninUrl,
81                                                        kSigninUrl,
82                                                        -1,
83                                                        NULL,
84                                                        signin_process.GetID(),
85                                                        &error)) << error;
86 }
87 #endif
88
89 }  // namespace extensions