| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 .Set("name", "Extension with ID " + id) | 53 .Set("name", "Extension with ID " + id) |
| 54 .Set("version", "1.0") | 54 .Set("version", "1.0") |
| 55 .Set("manifest_version", 2) | 55 .Set("manifest_version", 2) |
| 56 .Set("permissions", ListBuilder().Append("<all_urls>"))) | 56 .Set("permissions", ListBuilder().Append("<all_urls>"))) |
| 57 .SetID(id) | 57 .SetID(id) |
| 58 .Build(); | 58 .Build(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 } // namespace | 61 } // namespace |
| 62 | 62 |
| 63 // Tests that CanExecuteScriptOnPage returns false for the signin process, | 63 // Tests that CanAccessPage 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(extension->permissions_data()->CanExecuteScriptOnPage( | 71 EXPECT_TRUE(extension->permissions_data()->CanAccessPage( |
| 72 extension, kSigninUrl, kSigninUrl, -1, NULL, -1, &error)) | 72 extension, kSigninUrl, kSigninUrl, -1, -1, &error)) |
| 73 << error; | 73 << error; |
| 74 // 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 |
| 75 // script. | 75 // script. |
| 76 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kSigninProcess); | 76 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kSigninProcess); |
| 77 EXPECT_FALSE(extension->permissions_data()->CanExecuteScriptOnPage( | 77 EXPECT_FALSE(extension->permissions_data()->CanAccessPage( |
| 78 extension, kSigninUrl, kSigninUrl, -1, NULL, -1, &error)) | 78 extension, kSigninUrl, kSigninUrl, -1, -1, &error)) |
| 79 << error; | 79 << error; |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Tests that CanExecuteScriptOnPage returns false for the any process | 82 // Tests that CanAccessPage returns false for the any process |
| 83 // which hosts the webstore. | 83 // which hosts the webstore. |
| 84 TEST_F(RendererPermissionsPolicyDelegateTest, CannotScriptWebstore) { | 84 TEST_F(RendererPermissionsPolicyDelegateTest, CannotScriptWebstore) { |
| 85 GURL kAnyUrl("http://example.com/"); | 85 GURL kAnyUrl("http://example.com/"); |
| 86 scoped_refptr<const Extension> extension(CreateTestExtension("a")); | 86 scoped_refptr<const Extension> extension(CreateTestExtension("a")); |
| 87 std::string error; | 87 std::string error; |
| 88 | 88 |
| 89 EXPECT_TRUE(extension->permissions_data()->CanExecuteScriptOnPage( | 89 EXPECT_TRUE(extension->permissions_data()->CanAccessPage( |
| 90 extension, kAnyUrl, kAnyUrl, -1, NULL, -1, &error)) | 90 extension, kAnyUrl, kAnyUrl, -1, -1, &error)) |
| 91 << error; | 91 << error; |
| 92 | 92 |
| 93 // 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 |
| 94 // script. | 94 // script. |
| 95 scoped_refptr<const Extension> webstore_extension( | 95 scoped_refptr<const Extension> webstore_extension( |
| 96 CreateTestExtension(extension_misc::kWebStoreAppId)); | 96 CreateTestExtension(extension_misc::kWebStoreAppId)); |
| 97 extension_dispatcher_->OnLoadedInternal(webstore_extension); | 97 extension_dispatcher_->OnLoadedInternal(webstore_extension); |
| 98 extension_dispatcher_->OnActivateExtension(extension_misc::kWebStoreAppId); | 98 extension_dispatcher_->OnActivateExtension(extension_misc::kWebStoreAppId); |
| 99 EXPECT_FALSE(extension->permissions_data()->CanExecuteScriptOnPage( | 99 EXPECT_FALSE(extension->permissions_data()->CanAccessPage( |
| 100 extension, kAnyUrl, kAnyUrl, -1, NULL, -1, &error)) | 100 extension, kAnyUrl, kAnyUrl, -1, -1, &error)) |
| 101 << error; | 101 << error; |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace extensions | 104 } // namespace extensions |
| OLD | NEW |