| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/download/download_crx_util.h" | 5 #include "chrome/browser/download/download_crx_util.h" |
| 6 #include "chrome/browser/download/download_service.h" | 6 #include "chrome/browser/download/download_service.h" |
| 7 #include "chrome/browser/download/download_service_factory.h" | 7 #include "chrome/browser/download/download_service_factory.h" |
| 8 #include "chrome/browser/extensions/crx_installer.h" | 8 #include "chrome/browser/extensions/crx_installer.h" |
| 9 #include "chrome/browser/extensions/extension_browsertest.h" | 9 #include "chrome/browser/extensions/extension_browsertest.h" |
| 10 #include "chrome/browser/extensions/extension_install_prompt.h" | 10 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/extension_system.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
| 18 #include "chrome/common/extensions/extension_file_util.h" | 19 #include "chrome/common/extensions/extension_file_util.h" |
| 19 #include "chrome/common/extensions/feature_switch.h" | 20 #include "chrome/common/extensions/feature_switch.h" |
| 20 #include "chrome/common/extensions/permissions/permission_set.h" | 21 #include "chrome/common/extensions/permissions/permission_set.h" |
| 21 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } // namespace | 76 } // namespace |
| 76 | 77 |
| 77 class ExtensionCrxInstallerTest : public ExtensionBrowserTest { | 78 class ExtensionCrxInstallerTest : public ExtensionBrowserTest { |
| 78 public: | 79 public: |
| 79 // Installs a crx from |crx_relpath| (a path relative to the extension test | 80 // Installs a crx from |crx_relpath| (a path relative to the extension test |
| 80 // data dir) with expected id |id|. Returns the installer. | 81 // data dir) with expected id |id|. Returns the installer. |
| 81 scoped_refptr<CrxInstaller> InstallWithPrompt( | 82 scoped_refptr<CrxInstaller> InstallWithPrompt( |
| 82 const std::string& ext_relpath, | 83 const std::string& ext_relpath, |
| 83 const std::string& id, | 84 const std::string& id, |
| 84 MockInstallPrompt* mock_install_prompt) { | 85 MockInstallPrompt* mock_install_prompt) { |
| 85 ExtensionService* service = browser()->profile()->GetExtensionService(); | 86 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 87 browser()->profile())->extension_service(); |
| 86 FilePath ext_path = test_data_dir_.AppendASCII(ext_relpath); | 88 FilePath ext_path = test_data_dir_.AppendASCII(ext_relpath); |
| 87 | 89 |
| 88 std::string error; | 90 std::string error; |
| 89 base::DictionaryValue* parsed_manifest = | 91 base::DictionaryValue* parsed_manifest = |
| 90 extension_file_util::LoadManifest(ext_path, &error); | 92 extension_file_util::LoadManifest(ext_path, &error); |
| 91 if (!parsed_manifest) | 93 if (!parsed_manifest) |
| 92 return scoped_refptr<CrxInstaller>(); | 94 return scoped_refptr<CrxInstaller>(); |
| 93 | 95 |
| 94 scoped_ptr<WebstoreInstaller::Approval> approval; | 96 scoped_ptr<WebstoreInstaller::Approval> approval; |
| 95 if (!id.empty()) { | 97 if (!id.empty()) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 112 return installer; | 114 return installer; |
| 113 } | 115 } |
| 114 | 116 |
| 115 // Installs an extension and checks that it has scopes granted IFF | 117 // Installs an extension and checks that it has scopes granted IFF |
| 116 // |record_oauth2_grant| is true. | 118 // |record_oauth2_grant| is true. |
| 117 void CheckHasEmptyScopesAfterInstall(const std::string& ext_relpath, | 119 void CheckHasEmptyScopesAfterInstall(const std::string& ext_relpath, |
| 118 bool record_oauth2_grant) { | 120 bool record_oauth2_grant) { |
| 119 CommandLine::ForCurrentProcess()->AppendSwitch( | 121 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 120 switches::kEnableExperimentalExtensionApis); | 122 switches::kEnableExperimentalExtensionApis); |
| 121 | 123 |
| 122 ExtensionService* service = browser()->profile()->GetExtensionService(); | 124 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 125 browser()->profile())->extension_service(); |
| 123 | 126 |
| 124 MockInstallPrompt* mock_prompt = | 127 MockInstallPrompt* mock_prompt = |
| 125 CreateMockInstallPromptForBrowser(browser()); | 128 CreateMockInstallPromptForBrowser(browser()); |
| 126 mock_prompt->set_record_oauth2_grant(record_oauth2_grant); | 129 mock_prompt->set_record_oauth2_grant(record_oauth2_grant); |
| 127 scoped_refptr<CrxInstaller> installer = | 130 scoped_refptr<CrxInstaller> installer = |
| 128 InstallWithPrompt("browsertest/scopes", std::string(), mock_prompt); | 131 InstallWithPrompt("browsertest/scopes", std::string(), mock_prompt); |
| 129 | 132 |
| 130 scoped_refptr<PermissionSet> permissions = | 133 scoped_refptr<PermissionSet> permissions = |
| 131 service->extension_prefs()->GetGrantedPermissions( | 134 service->extension_prefs()->GetGrantedPermissions( |
| 132 mock_prompt->extension()->id()); | 135 mock_prompt->extension()->id()); |
| 133 ASSERT_TRUE(permissions.get()); | 136 ASSERT_TRUE(permissions.get()); |
| 134 EXPECT_EQ(record_oauth2_grant, installer->record_oauth2_grant_); | 137 EXPECT_EQ(record_oauth2_grant, installer->record_oauth2_grant_); |
| 135 } | 138 } |
| 136 }; | 139 }; |
| 137 | 140 |
| 138 #if defined(OS_CHROMEOS) | 141 #if defined(OS_CHROMEOS) |
| 139 #define MAYBE_Whitelisting DISABLED_Whitelisting | 142 #define MAYBE_Whitelisting DISABLED_Whitelisting |
| 140 #else | 143 #else |
| 141 #define MAYBE_Whitelisting Whitelisting | 144 #define MAYBE_Whitelisting Whitelisting |
| 142 #endif | 145 #endif |
| 143 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, MAYBE_Whitelisting) { | 146 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, MAYBE_Whitelisting) { |
| 144 std::string id = "hdgllgikmikobbofgnabhfimcfoopgnd"; | 147 std::string id = "hdgllgikmikobbofgnabhfimcfoopgnd"; |
| 145 ExtensionService* service = browser()->profile()->GetExtensionService(); | 148 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 149 browser()->profile())->extension_service(); |
| 146 | 150 |
| 147 // Even whitelisted extensions with NPAPI should not prompt. | 151 // Even whitelisted extensions with NPAPI should not prompt. |
| 148 MockInstallPrompt* mock_prompt = | 152 MockInstallPrompt* mock_prompt = |
| 149 CreateMockInstallPromptForBrowser(browser()); | 153 CreateMockInstallPromptForBrowser(browser()); |
| 150 scoped_refptr<CrxInstaller> installer = | 154 scoped_refptr<CrxInstaller> installer = |
| 151 InstallWithPrompt("uitest/plugins", id, mock_prompt); | 155 InstallWithPrompt("uitest/plugins", id, mock_prompt); |
| 152 EXPECT_FALSE(mock_prompt->confirmation_requested()); | 156 EXPECT_FALSE(mock_prompt->confirmation_requested()); |
| 153 EXPECT_TRUE(service->GetExtensionById(id, false)); | 157 EXPECT_TRUE(service->GetExtensionById(id, false)); |
| 154 } | 158 } |
| 155 | 159 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 244 } |
| 241 | 245 |
| 242 // Off-store install cannot yet be disabled on Aura. | 246 // Off-store install cannot yet be disabled on Aura. |
| 243 #if defined(USE_AURA) | 247 #if defined(USE_AURA) |
| 244 #define MAYBE_AllowOffStore DISABLED_AllowOffStore | 248 #define MAYBE_AllowOffStore DISABLED_AllowOffStore |
| 245 #else | 249 #else |
| 246 #define MAYBE_AllowOffStore AllowOffStore | 250 #define MAYBE_AllowOffStore AllowOffStore |
| 247 #endif | 251 #endif |
| 248 // Crashy: http://crbug.com/140893 | 252 // Crashy: http://crbug.com/140893 |
| 249 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, DISABLED_AllowOffStore) { | 253 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, DISABLED_AllowOffStore) { |
| 250 ExtensionService* service = browser()->profile()->GetExtensionService(); | 254 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 255 browser()->profile())->extension_service(); |
| 251 const bool kTestData[] = {false, true}; | 256 const bool kTestData[] = {false, true}; |
| 252 | 257 |
| 253 for (size_t i = 0; i < arraysize(kTestData); ++i) { | 258 for (size_t i = 0; i < arraysize(kTestData); ++i) { |
| 254 MockInstallPrompt* mock_prompt = | 259 MockInstallPrompt* mock_prompt = |
| 255 CreateMockInstallPromptForBrowser(browser()); | 260 CreateMockInstallPromptForBrowser(browser()); |
| 256 scoped_refptr<CrxInstaller> crx_installer( | 261 scoped_refptr<CrxInstaller> crx_installer( |
| 257 CrxInstaller::Create(service, mock_prompt)); | 262 CrxInstaller::Create(service, mock_prompt)); |
| 258 crx_installer->set_install_cause( | 263 crx_installer->set_install_cause( |
| 259 extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); | 264 extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); |
| 260 | 265 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 272 EXPECT_EQ(string16(), mock_prompt->error()) << kTestData[i]; | 277 EXPECT_EQ(string16(), mock_prompt->error()) << kTestData[i]; |
| 273 } else { | 278 } else { |
| 274 EXPECT_EQ(l10n_util::GetStringUTF16( | 279 EXPECT_EQ(l10n_util::GetStringUTF16( |
| 275 IDS_EXTENSION_INSTALL_DISALLOWED_ON_SITE), | 280 IDS_EXTENSION_INSTALL_DISALLOWED_ON_SITE), |
| 276 mock_prompt->error()) << kTestData[i]; | 281 mock_prompt->error()) << kTestData[i]; |
| 277 } | 282 } |
| 278 } | 283 } |
| 279 } | 284 } |
| 280 | 285 |
| 281 } // namespace extensions | 286 } // namespace extensions |
| OLD | NEW |