OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "chrome/common/chrome_switches.h" | 6 #include "chrome/common/chrome_switches.h" |
7 #include "chrome/common/extensions/extension_constants.h" | 7 #include "chrome/common/extensions/extension_constants.h" |
8 #include "chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.h" | 8 #include "chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.h" |
9 #include "chrome/renderer/extensions/renderer_permissions_policy_delegate.h" | 9 #include "chrome/renderer/extensions/renderer_permissions_policy_delegate.h" |
10 #include "content/public/test/mock_render_process_host.h" | 10 #include "content/public/test/mock_render_process_host.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 } // namespace | 61 } // namespace |
62 | 62 |
63 // Tests that CanExecuteScriptOnPage returns false for the signin process, | 63 // Tests that CanExecuteScriptOnPage returns false for the signin process, |
64 // all else being equal. | 64 // all else being equal. |
65 TEST_F(RendererPermissionsPolicyDelegateTest, CannotScriptSigninProcess) { | 65 TEST_F(RendererPermissionsPolicyDelegateTest, CannotScriptSigninProcess) { |
66 GURL kSigninUrl( | 66 GURL kSigninUrl( |
67 "https://accounts.google.com/ServiceLogin?service=chromiumsync"); | 67 "https://accounts.google.com/ServiceLogin?service=chromiumsync"); |
68 scoped_refptr<const Extension> extension(CreateTestExtension("a")); | 68 scoped_refptr<const Extension> extension(CreateTestExtension("a")); |
69 std::string error; | 69 std::string error; |
70 | 70 |
71 EXPECT_TRUE(PermissionsData::CanExecuteScriptOnPage( | 71 EXPECT_TRUE(PermissionsData::ForExtension(extension)->CanExecuteScriptOnPage( |
72 extension.get(), kSigninUrl, kSigninUrl, -1, NULL, -1, &error)) << error; | 72 extension, kSigninUrl, kSigninUrl, -1, NULL, -1, &error)) |
| 73 << error; |
73 // Pretend we are in the signin process. We should not be able to execute | 74 // Pretend we are in the signin process. We should not be able to execute |
74 // script. | 75 // script. |
75 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kSigninProcess); | 76 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kSigninProcess); |
76 EXPECT_FALSE(PermissionsData::CanExecuteScriptOnPage( | 77 EXPECT_FALSE(PermissionsData::ForExtension(extension)->CanExecuteScriptOnPage( |
77 extension.get(), kSigninUrl, kSigninUrl, -1, NULL, -1, &error)) << error; | 78 extension, kSigninUrl, kSigninUrl, -1, NULL, -1, &error)) |
| 79 << error; |
78 } | 80 } |
79 | 81 |
80 // Tests that CanExecuteScriptOnPage returns false for the any process | 82 // Tests that CanExecuteScriptOnPage returns false for the any process |
81 // which hosts the webstore. | 83 // which hosts the webstore. |
82 TEST_F(RendererPermissionsPolicyDelegateTest, CannotScriptWebstore) { | 84 TEST_F(RendererPermissionsPolicyDelegateTest, CannotScriptWebstore) { |
83 GURL kAnyUrl("http://example.com/"); | 85 GURL kAnyUrl("http://example.com/"); |
84 scoped_refptr<const Extension> extension(CreateTestExtension("a")); | 86 scoped_refptr<const Extension> extension(CreateTestExtension("a")); |
85 std::string error; | 87 std::string error; |
86 | 88 |
87 EXPECT_TRUE(PermissionsData::CanExecuteScriptOnPage( | 89 EXPECT_TRUE(PermissionsData::ForExtension(extension)->CanExecuteScriptOnPage( |
88 extension.get(), kAnyUrl, kAnyUrl, -1, NULL, -1, &error)) << error; | 90 extension, kAnyUrl, kAnyUrl, -1, NULL, -1, &error)) |
| 91 << error; |
89 | 92 |
90 // Pretend we are in the webstore process. We should not be able to execute | 93 // Pretend we are in the webstore process. We should not be able to execute |
91 // script. | 94 // script. |
92 scoped_refptr<const Extension> webstore_extension( | 95 scoped_refptr<const Extension> webstore_extension( |
93 CreateTestExtension(extension_misc::kWebStoreAppId)); | 96 CreateTestExtension(extension_misc::kWebStoreAppId)); |
94 extension_dispatcher_->OnLoadedInternal(webstore_extension); | 97 extension_dispatcher_->OnLoadedInternal(webstore_extension); |
95 extension_dispatcher_->OnActivateExtension(extension_misc::kWebStoreAppId); | 98 extension_dispatcher_->OnActivateExtension(extension_misc::kWebStoreAppId); |
96 EXPECT_FALSE(PermissionsData::CanExecuteScriptOnPage( | 99 EXPECT_FALSE(PermissionsData::ForExtension(extension)->CanExecuteScriptOnPage( |
97 extension.get(), kAnyUrl, kAnyUrl, -1, NULL, -1, &error)) << error; | 100 extension, kAnyUrl, kAnyUrl, -1, NULL, -1, &error)) |
| 101 << error; |
98 } | 102 } |
99 | 103 |
100 } // namespace extensions | 104 } // namespace extensions |
OLD | NEW |