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 "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/download/download_crx_util.h" | 8 #include "chrome/browser/download/download_crx_util.h" |
9 #include "chrome/browser/extensions/browser_action_test_util.h" | 9 #include "chrome/browser/extensions/browser_action_test_util.h" |
10 #include "chrome/browser/extensions/crx_installer.h" | 10 #include "chrome/browser/extensions/crx_installer.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 mock_prompt->set_record_oauth2_grant(record_oauth2_grant); | 224 mock_prompt->set_record_oauth2_grant(record_oauth2_grant); |
225 InstallWithPrompt("browsertest/scopes", std::string(), mock_prompt); | 225 InstallWithPrompt("browsertest/scopes", std::string(), mock_prompt); |
226 | 226 |
227 scoped_refptr<PermissionSet> permissions = | 227 scoped_refptr<PermissionSet> permissions = |
228 ExtensionPrefs::Get(browser()->profile()) | 228 ExtensionPrefs::Get(browser()->profile()) |
229 ->GetGrantedPermissions(mock_prompt->extension_id()); | 229 ->GetGrantedPermissions(mock_prompt->extension_id()); |
230 ASSERT_TRUE(permissions.get()); | 230 ASSERT_TRUE(permissions.get()); |
231 } | 231 } |
232 }; | 232 }; |
233 | 233 |
234 #if defined(OS_CHROMEOS) | 234 // This test is skipped on ChromeOS because it requires the NPAPI, |
235 #define MAYBE_Whitelisting DISABLED_Whitelisting | 235 // which is not available on that platform. |
236 #else | 236 #if !defined(OS_CHROMEOS) |
237 #define MAYBE_Whitelisting Whitelisting | |
238 #endif | |
239 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, MAYBE_Whitelisting) { | 237 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, MAYBE_Whitelisting) { |
not at google - send to devlin
2014/08/19 14:22:55
Remove the MAYBE_?
Joao da Silva
2014/08/20 07:37:11
Done.
| |
240 std::string id = "hdgllgikmikobbofgnabhfimcfoopgnd"; | 238 std::string id = "hdgllgikmikobbofgnabhfimcfoopgnd"; |
241 ExtensionService* service = extensions::ExtensionSystem::Get( | 239 ExtensionService* service = extensions::ExtensionSystem::Get( |
242 browser()->profile())->extension_service(); | 240 browser()->profile())->extension_service(); |
243 | 241 |
244 // Even whitelisted extensions with NPAPI should not prompt. | 242 // Even whitelisted extensions with NPAPI should not prompt. |
245 scoped_refptr<MockPromptProxy> mock_prompt = | 243 scoped_refptr<MockPromptProxy> mock_prompt = |
246 CreateMockPromptProxyForBrowser(browser()); | 244 CreateMockPromptProxyForBrowser(browser()); |
247 InstallWithPrompt("uitest/plugins", id, mock_prompt); | 245 InstallWithPrompt("uitest/plugins", id, mock_prompt); |
248 EXPECT_FALSE(mock_prompt->confirmation_requested()); | 246 EXPECT_FALSE(mock_prompt->confirmation_requested()); |
249 EXPECT_TRUE(service->GetExtensionById(id, false)); | 247 EXPECT_TRUE(service->GetExtensionById(id, false)); |
250 } | 248 } |
249 #endif | |
251 | 250 |
252 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, | 251 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
253 GalleryInstallGetsExperimental) { | 252 GalleryInstallGetsExperimental) { |
254 // We must modify the command line temporarily in order to pack an extension | 253 // We must modify the command line temporarily in order to pack an extension |
255 // that requests the experimental permission. | 254 // that requests the experimental permission. |
256 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 255 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
257 CommandLine old_command_line = *command_line; | 256 CommandLine old_command_line = *command_line; |
258 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 257 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
259 base::FilePath crx_path = PackExtension( | 258 base::FilePath crx_path = PackExtension( |
260 test_data_dir_.AppendASCII("experimental")); | 259 test_data_dir_.AppendASCII("experimental")); |
261 ASSERT_FALSE(crx_path.empty()); | 260 ASSERT_FALSE(crx_path.empty()); |
262 | 261 |
263 // Now reset the command line so that we are testing specifically whether | 262 // Now reset the command line so that we are testing specifically whether |
264 // installing from webstore enables experimental permissions. | 263 // installing from webstore enables experimental permissions. |
265 *(CommandLine::ForCurrentProcess()) = old_command_line; | 264 *(CommandLine::ForCurrentProcess()) = old_command_line; |
266 | 265 |
267 EXPECT_FALSE(InstallExtension(crx_path, 0)); | 266 EXPECT_FALSE(InstallExtension(crx_path, 0)); |
268 EXPECT_TRUE(InstallExtensionFromWebstore(crx_path, 1)); | 267 EXPECT_TRUE(InstallExtensionFromWebstore(crx_path, 1)); |
269 } | 268 } |
270 | 269 |
271 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, PlatformAppCrx) { | 270 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, PlatformAppCrx) { |
272 CommandLine::ForCurrentProcess()->AppendSwitch( | 271 CommandLine::ForCurrentProcess()->AppendSwitch( |
273 switches::kEnableExperimentalExtensionApis); | 272 switches::kEnableExperimentalExtensionApis); |
274 EXPECT_TRUE(InstallExtension( | 273 EXPECT_TRUE(InstallExtension( |
275 test_data_dir_.AppendASCII("minimal_platform_app.crx"), 1)); | 274 test_data_dir_.AppendASCII("minimal_platform_app.crx"), 1)); |
276 } | 275 } |
277 | 276 |
278 // http://crbug.com/136397 | 277 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, PackAndInstallExtension) { |
279 #if defined(OS_CHROMEOS) | |
280 #define MAYBE_PackAndInstallExtension DISABLED_PackAndInstallExtension | |
281 #else | |
282 #define MAYBE_PackAndInstallExtension PackAndInstallExtension | |
283 #endif | |
284 IN_PROC_BROWSER_TEST_F( | |
285 ExtensionCrxInstallerTest, MAYBE_PackAndInstallExtension) { | |
286 if (!FeatureSwitch::easy_off_store_install()->IsEnabled()) | 278 if (!FeatureSwitch::easy_off_store_install()->IsEnabled()) |
287 return; | 279 return; |
288 | 280 |
289 const int kNumDownloadsExpected = 1; | 281 const int kNumDownloadsExpected = 1; |
290 | 282 |
291 LOG(ERROR) << "PackAndInstallExtension: Packing extension"; | 283 LOG(ERROR) << "PackAndInstallExtension: Packing extension"; |
292 base::FilePath crx_path = PackExtension( | 284 base::FilePath crx_path = PackExtension( |
293 test_data_dir_.AppendASCII("common/background_page")); | 285 test_data_dir_.AppendASCII("common/background_page")); |
294 ASSERT_FALSE(crx_path.empty()); | 286 ASSERT_FALSE(crx_path.empty()); |
295 std::string crx_path_string(crx_path.value().begin(), crx_path.value().end()); | 287 std::string crx_path_string(crx_path.value().begin(), crx_path.value().end()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, MAYBE_GrantScopes) { | 321 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, MAYBE_GrantScopes) { |
330 EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall("browsertest/scopes", | 322 EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall("browsertest/scopes", |
331 true)); | 323 true)); |
332 } | 324 } |
333 | 325 |
334 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, DoNotGrantScopes) { | 326 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, DoNotGrantScopes) { |
335 EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall("browsertest/scopes", | 327 EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall("browsertest/scopes", |
336 false)); | 328 false)); |
337 } | 329 } |
338 | 330 |
339 // Off-store install cannot yet be disabled on Aura. | 331 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, AllowOffStore) { |
340 #if defined(USE_AURA) | |
341 #define MAYBE_AllowOffStore DISABLED_AllowOffStore | |
342 #else | |
343 #define MAYBE_AllowOffStore AllowOffStore | |
344 #endif | |
345 // Crashy: http://crbug.com/140893 | |
346 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, DISABLED_AllowOffStore) { | |
347 ExtensionService* service = extensions::ExtensionSystem::Get( | 332 ExtensionService* service = extensions::ExtensionSystem::Get( |
348 browser()->profile())->extension_service(); | 333 browser()->profile())->extension_service(); |
349 const bool kTestData[] = {false, true}; | 334 const bool kTestData[] = {false, true}; |
350 | 335 |
351 for (size_t i = 0; i < arraysize(kTestData); ++i) { | 336 for (size_t i = 0; i < arraysize(kTestData); ++i) { |
352 scoped_refptr<MockPromptProxy> mock_prompt = | 337 scoped_refptr<MockPromptProxy> mock_prompt = |
353 CreateMockPromptProxyForBrowser(browser()); | 338 CreateMockPromptProxyForBrowser(browser()); |
354 | 339 |
355 scoped_refptr<CrxInstaller> crx_installer( | 340 scoped_refptr<CrxInstaller> crx_installer( |
356 CrxInstaller::Create(service, mock_prompt->CreatePrompt())); | 341 CrxInstaller::Create(service, mock_prompt->CreatePrompt())); |
357 crx_installer->set_install_cause( | 342 crx_installer->set_install_cause( |
358 extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); | 343 extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); |
359 | 344 |
360 if (kTestData[i]) { | 345 if (kTestData[i]) { |
361 crx_installer->set_off_store_install_allow_reason( | 346 crx_installer->set_off_store_install_allow_reason( |
362 CrxInstaller::OffStoreInstallAllowedInTest); | 347 CrxInstaller::OffStoreInstallAllowedInTest); |
363 } | 348 } |
364 | 349 |
365 crx_installer->InstallCrx(test_data_dir_.AppendASCII("good.crx")); | 350 crx_installer->InstallCrx(test_data_dir_.AppendASCII("good.crx")); |
366 EXPECT_EQ(kTestData[i], | 351 // The |mock_prompt| will quit running the loop once the |crx_installer| |
367 WaitForExtensionInstall()) << kTestData[i]; | 352 // is done. |
353 content::RunMessageLoop(); | |
368 EXPECT_EQ(kTestData[i], mock_prompt->did_succeed()); | 354 EXPECT_EQ(kTestData[i], mock_prompt->did_succeed()); |
369 EXPECT_EQ(kTestData[i], mock_prompt->confirmation_requested()) << | 355 EXPECT_EQ(kTestData[i], mock_prompt->confirmation_requested()) << |
370 kTestData[i]; | 356 kTestData[i]; |
371 if (kTestData[i]) { | 357 if (kTestData[i]) { |
372 EXPECT_EQ(base::string16(), mock_prompt->error()) << kTestData[i]; | 358 EXPECT_EQ(base::string16(), mock_prompt->error()) << kTestData[i]; |
373 } else { | 359 } else { |
374 EXPECT_EQ(l10n_util::GetStringUTF16( | 360 EXPECT_EQ(l10n_util::GetStringUTF16( |
375 IDS_EXTENSION_INSTALL_DISALLOWED_ON_SITE), | 361 IDS_EXTENSION_INSTALL_DISALLOWED_ON_SITE), |
376 mock_prompt->error()) << kTestData[i]; | 362 mock_prompt->error()) << kTestData[i]; |
377 } | 363 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 ManagementPolicyMock policy; | 558 ManagementPolicyMock policy; |
573 extensions::ExtensionSystem::Get(profile()) | 559 extensions::ExtensionSystem::Get(profile()) |
574 ->management_policy() | 560 ->management_policy() |
575 ->RegisterProvider(&policy); | 561 ->RegisterProvider(&policy); |
576 | 562 |
577 base::FilePath crx_path = test_data_dir_.AppendASCII("crx_installer/v1.crx"); | 563 base::FilePath crx_path = test_data_dir_.AppendASCII("crx_installer/v1.crx"); |
578 EXPECT_FALSE(InstallExtension(crx_path, 0)); | 564 EXPECT_FALSE(InstallExtension(crx_path, 0)); |
579 } | 565 } |
580 | 566 |
581 } // namespace extensions | 567 } // namespace extensions |
OLD | NEW |