| 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.h" | 7 #include "chrome/common/extensions/extension.h" |
| 8 #include "chrome/common/extensions/extension_builder.h" | 8 #include "chrome/common/extensions/extension_builder.h" |
| 9 #include "chrome/common/extensions/extension_messages.h" | 9 #include "chrome/common/extensions/extension_messages.h" |
| 10 #include "chrome/common/extensions/permissions/permissions_data.h" | 10 #include "chrome/common/extensions/permissions/permissions_data.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 } // namespace | 49 } // namespace |
| 50 | 50 |
| 51 // Tests that CanExecuteScriptOnPage returns false for the signin process, | 51 // Tests that CanExecuteScriptOnPage returns false for the signin process, |
| 52 // all else being equal. | 52 // all else being equal. |
| 53 TEST_F(RendererPermissionsPolicyDelegateTest, CannotScriptSigninProcess) { | 53 TEST_F(RendererPermissionsPolicyDelegateTest, CannotScriptSigninProcess) { |
| 54 GURL kSigninUrl( | 54 GURL kSigninUrl( |
| 55 "https://accounts.google.com/ServiceLogin?service=chromiumsync"); | 55 "https://accounts.google.com/ServiceLogin?service=chromiumsync"); |
| 56 scoped_refptr<const Extension> extension(CreateTestExtension("a")); | 56 scoped_refptr<const Extension> extension(CreateTestExtension("a")); |
| 57 std::string error; | 57 std::string error; |
| 58 | 58 |
| 59 EXPECT_TRUE(PermissionsData::CanExecuteScriptOnPage(extension, | 59 EXPECT_TRUE(PermissionsData::CanExecuteScriptOnPage( |
| 60 kSigninUrl, | 60 extension.get(), kSigninUrl, kSigninUrl, -1, NULL, -1, &error)) << error; |
| 61 kSigninUrl, | |
| 62 -1, | |
| 63 NULL, | |
| 64 -1, | |
| 65 &error)) << error; | |
| 66 // Pretend we are in the signin process. We should not be able to execute | 61 // Pretend we are in the signin process. We should not be able to execute |
| 67 // script. | 62 // script. |
| 68 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kSigninProcess); | 63 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kSigninProcess); |
| 69 EXPECT_FALSE(PermissionsData::CanExecuteScriptOnPage(extension, | 64 EXPECT_FALSE(PermissionsData::CanExecuteScriptOnPage( |
| 70 kSigninUrl, | 65 extension.get(), kSigninUrl, kSigninUrl, -1, NULL, -1, &error)) << error; |
| 71 kSigninUrl, | |
| 72 -1, | |
| 73 NULL, | |
| 74 -1, | |
| 75 &error)) << error; | |
| 76 } | 66 } |
| 77 | 67 |
| 78 // Tests that CanExecuteScriptOnPage returns false for the any process | 68 // Tests that CanExecuteScriptOnPage returns false for the any process |
| 79 // which hosts the webstore. | 69 // which hosts the webstore. |
| 80 TEST_F(RendererPermissionsPolicyDelegateTest, CannotScriptWebstore) { | 70 TEST_F(RendererPermissionsPolicyDelegateTest, CannotScriptWebstore) { |
| 81 GURL kAnyUrl("http://example.com/"); | 71 GURL kAnyUrl("http://example.com/"); |
| 82 scoped_refptr<const Extension> extension(CreateTestExtension("a")); | 72 scoped_refptr<const Extension> extension(CreateTestExtension("a")); |
| 83 std::string error; | 73 std::string error; |
| 84 | 74 |
| 85 EXPECT_TRUE(PermissionsData::CanExecuteScriptOnPage(extension, | 75 EXPECT_TRUE(PermissionsData::CanExecuteScriptOnPage( |
| 86 kAnyUrl, | 76 extension.get(), kAnyUrl, kAnyUrl, -1, NULL, -1, &error)) << error; |
| 87 kAnyUrl, | |
| 88 -1, | |
| 89 NULL, | |
| 90 -1, | |
| 91 &error)) << error; | |
| 92 | 77 |
| 93 // Pretend we are in the webstore process. We should not be able to execute | 78 // Pretend we are in the webstore process. We should not be able to execute |
| 94 // script. | 79 // script. |
| 95 scoped_refptr<const Extension> webstore_extension( | 80 scoped_refptr<const Extension> webstore_extension( |
| 96 CreateTestExtension(extension_misc::kWebStoreAppId)); | 81 CreateTestExtension(extension_misc::kWebStoreAppId)); |
| 97 extension_dispatcher_->OnLoadedInternal(webstore_extension); | 82 extension_dispatcher_->OnLoadedInternal(webstore_extension); |
| 98 extension_dispatcher_->OnActivateExtension(extension_misc::kWebStoreAppId); | 83 extension_dispatcher_->OnActivateExtension(extension_misc::kWebStoreAppId); |
| 99 EXPECT_FALSE(PermissionsData::CanExecuteScriptOnPage(extension, | 84 EXPECT_FALSE(PermissionsData::CanExecuteScriptOnPage( |
| 100 kAnyUrl, | 85 extension.get(), kAnyUrl, kAnyUrl, -1, NULL, -1, &error)) << error; |
| 101 kAnyUrl, | |
| 102 -1, | |
| 103 NULL, | |
| 104 -1, | |
| 105 &error)) << error; | |
| 106 } | 86 } |
| 107 | 87 |
| 108 } // namespace extensions | 88 } // namespace extensions |
| OLD | NEW |