| 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" | |
| 7 #include "chrome/common/extensions/extension_constants.h" | 6 #include "chrome/common/extensions/extension_constants.h" |
| 8 #include "chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.h" | 7 #include "chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.h" |
| 9 #include "chrome/renderer/extensions/renderer_permissions_policy_delegate.h" | 8 #include "chrome/renderer/extensions/renderer_permissions_policy_delegate.h" |
| 10 #include "content/public/test/mock_render_process_host.h" | 9 #include "content/public/test/mock_render_process_host.h" |
| 11 #include "content/public/test/mock_render_thread.h" | 10 #include "content/public/test/mock_render_thread.h" |
| 12 #include "extensions/common/constants.h" | 11 #include "extensions/common/constants.h" |
| 13 #include "extensions/common/extension.h" | 12 #include "extensions/common/extension.h" |
| 14 #include "extensions/common/extension_builder.h" | 13 #include "extensions/common/extension_builder.h" |
| 15 #include "extensions/common/permissions/permissions_data.h" | 14 #include "extensions/common/permissions/permissions_data.h" |
| 16 #include "extensions/renderer/dispatcher.h" | 15 #include "extensions/renderer/dispatcher.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 .Set("name", "Extension with ID " + id) | 52 .Set("name", "Extension with ID " + id) |
| 54 .Set("version", "1.0") | 53 .Set("version", "1.0") |
| 55 .Set("manifest_version", 2) | 54 .Set("manifest_version", 2) |
| 56 .Set("permissions", ListBuilder().Append("<all_urls>"))) | 55 .Set("permissions", ListBuilder().Append("<all_urls>"))) |
| 57 .SetID(id) | 56 .SetID(id) |
| 58 .Build(); | 57 .Build(); |
| 59 } | 58 } |
| 60 | 59 |
| 61 } // namespace | 60 } // namespace |
| 62 | 61 |
| 63 // Tests that CanAccessPage returns false for the signin process, | |
| 64 // all else being equal. | |
| 65 TEST_F(RendererPermissionsPolicyDelegateTest, CannotScriptSigninProcess) { | |
| 66 GURL kSigninUrl( | |
| 67 "https://accounts.google.com/ServiceLogin?service=chromiumsync"); | |
| 68 scoped_refptr<const Extension> extension(CreateTestExtension("a")); | |
| 69 std::string error; | |
| 70 | |
| 71 EXPECT_TRUE(extension->permissions_data()->CanAccessPage( | |
| 72 extension.get(), kSigninUrl, kSigninUrl, -1, -1, &error)) | |
| 73 << error; | |
| 74 // Pretend we are in the signin process. We should not be able to execute | |
| 75 // script. | |
| 76 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 77 switches::kSigninProcess); | |
| 78 EXPECT_FALSE(extension->permissions_data()->CanAccessPage( | |
| 79 extension.get(), kSigninUrl, kSigninUrl, -1, -1, &error)) | |
| 80 << error; | |
| 81 } | |
| 82 | |
| 83 // Tests that CanAccessPage returns false for the any process | 62 // Tests that CanAccessPage returns false for the any process |
| 84 // which hosts the webstore. | 63 // which hosts the webstore. |
| 85 TEST_F(RendererPermissionsPolicyDelegateTest, CannotScriptWebstore) { | 64 TEST_F(RendererPermissionsPolicyDelegateTest, CannotScriptWebstore) { |
| 86 GURL kAnyUrl("http://example.com/"); | 65 GURL kAnyUrl("http://example.com/"); |
| 87 scoped_refptr<const Extension> extension(CreateTestExtension("a")); | 66 scoped_refptr<const Extension> extension(CreateTestExtension("a")); |
| 88 std::string error; | 67 std::string error; |
| 89 | 68 |
| 90 EXPECT_TRUE(extension->permissions_data()->CanAccessPage( | 69 EXPECT_TRUE(extension->permissions_data()->CanAccessPage( |
| 91 extension.get(), kAnyUrl, kAnyUrl, -1, -1, &error)) | 70 extension.get(), kAnyUrl, kAnyUrl, -1, -1, &error)) |
| 92 << error; | 71 << error; |
| 93 | 72 |
| 94 // Pretend we are in the webstore process. We should not be able to execute | 73 // Pretend we are in the webstore process. We should not be able to execute |
| 95 // script. | 74 // script. |
| 96 scoped_refptr<const Extension> webstore_extension( | 75 scoped_refptr<const Extension> webstore_extension( |
| 97 CreateTestExtension(extensions::kWebStoreAppId)); | 76 CreateTestExtension(extensions::kWebStoreAppId)); |
| 98 extension_dispatcher_->OnLoadedInternal(webstore_extension); | 77 extension_dispatcher_->OnLoadedInternal(webstore_extension); |
| 99 extension_dispatcher_->OnActivateExtension(extensions::kWebStoreAppId); | 78 extension_dispatcher_->OnActivateExtension(extensions::kWebStoreAppId); |
| 100 EXPECT_FALSE(extension->permissions_data()->CanAccessPage( | 79 EXPECT_FALSE(extension->permissions_data()->CanAccessPage( |
| 101 extension.get(), kAnyUrl, kAnyUrl, -1, -1, &error)) | 80 extension.get(), kAnyUrl, kAnyUrl, -1, -1, &error)) |
| 102 << error; | 81 << error; |
| 103 } | 82 } |
| 104 | 83 |
| 105 } // namespace extensions | 84 } // namespace extensions |
| OLD | NEW |