Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Side by Side Diff: chrome/browser/extensions/api/management/management_browsertest.cc

Issue 11293252: Change Interceptors into URLRequestJobFactory::ProtocolHandlers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: some cleanup Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "chrome/browser/extensions/autoupdate_interceptor.h" 9 #include "chrome/browser/extensions/autoupdate_interceptor.h"
10 #include "chrome/browser/extensions/extension_browsertest.h" 10 #include "chrome/browser/extensions/extension_browsertest.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 #else 243 #else
244 #define MAYBE_AutoUpdate AutoUpdate 244 #define MAYBE_AutoUpdate AutoUpdate
245 #endif 245 #endif
246 #endif 246 #endif
247 247
248 // Tests extension autoupdate. 248 // Tests extension autoupdate.
249 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, MAYBE_AutoUpdate) { 249 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, MAYBE_AutoUpdate) {
250 NotificationListener notification_listener; 250 NotificationListener notification_listener;
251 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); 251 FilePath basedir = test_data_dir_.AppendASCII("autoupdate");
252 // Note: This interceptor gets requests on the IO thread. 252 // Note: This interceptor gets requests on the IO thread.
253 scoped_refptr<extensions::AutoUpdateInterceptor> interceptor( 253 extensions::AutoUpdateInterceptor interceptor;
254 new extensions::AutoUpdateInterceptor());
255 net::URLFetcher::SetEnableInterceptionForTests(true); 254 net::URLFetcher::SetEnableInterceptionForTests(true);
256 255
257 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", 256 interceptor.SetResponse("http://localhost/autoupdate/manifest",
258 basedir.AppendASCII("manifest_v2.xml")); 257 basedir.AppendASCII("manifest_v2.xml"));
259 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", 258 interceptor.SetResponse("http://localhost/autoupdate/v2.crx",
260 basedir.AppendASCII("v2.crx")); 259 basedir.AppendASCII("v2.crx"));
261 260
262 // Install version 1 of the extension. 261 // Install version 1 of the extension.
263 ExtensionTestMessageListener listener1("v1 installed", false); 262 ExtensionTestMessageListener listener1("v1 installed", false);
264 ExtensionService* service = extensions::ExtensionSystem::Get( 263 ExtensionService* service = extensions::ExtensionSystem::Get(
265 browser()->profile())->extension_service(); 264 browser()->profile())->extension_service();
266 const size_t size_before = service->extensions()->size(); 265 const size_t size_before = service->extensions()->size();
267 ASSERT_TRUE(service->disabled_extensions()->is_empty()); 266 ASSERT_TRUE(service->disabled_extensions()->is_empty());
268 const Extension* extension = 267 const Extension* extension =
269 InstallExtension(basedir.AppendASCII("v1.crx"), 1); 268 InstallExtension(basedir.AppendASCII("v1.crx"), 1);
270 ASSERT_TRUE(extension); 269 ASSERT_TRUE(extension);
(...skipping 20 matching lines...) Expand all
291 ASSERT_TRUE(extension); 290 ASSERT_TRUE(extension);
292 ASSERT_EQ("2.0", extension->VersionString()); 291 ASSERT_EQ("2.0", extension->VersionString());
293 ASSERT_TRUE(notification_listener.started()); 292 ASSERT_TRUE(notification_listener.started());
294 ASSERT_TRUE(notification_listener.finished()); 293 ASSERT_TRUE(notification_listener.finished());
295 ASSERT_TRUE(ContainsKey(notification_listener.updates(), 294 ASSERT_TRUE(ContainsKey(notification_listener.updates(),
296 "ogjcoiohnmldgjemafoockdghcjciccf")); 295 "ogjcoiohnmldgjemafoockdghcjciccf"));
297 notification_listener.Reset(); 296 notification_listener.Reset();
298 297
299 // Now try doing an update to version 3, which has been incorrectly 298 // Now try doing an update to version 3, which has been incorrectly
300 // signed. This should fail. 299 // signed. This should fail.
301 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", 300 interceptor.SetResponse("http://localhost/autoupdate/manifest",
302 basedir.AppendASCII("manifest_v3.xml")); 301 basedir.AppendASCII("manifest_v3.xml"));
303 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v3.crx", 302 interceptor.SetResponse("http://localhost/autoupdate/v3.crx",
304 basedir.AppendASCII("v3.crx")); 303 basedir.AppendASCII("v3.crx"));
305 304
306 service->updater()->CheckNow(params); 305 service->updater()->CheckNow(params);
307 ASSERT_TRUE(WaitForExtensionInstallError()); 306 ASSERT_TRUE(WaitForExtensionInstallError());
308 ASSERT_TRUE(notification_listener.started()); 307 ASSERT_TRUE(notification_listener.started());
309 ASSERT_TRUE(notification_listener.finished()); 308 ASSERT_TRUE(notification_listener.finished());
310 ASSERT_TRUE(ContainsKey(notification_listener.updates(), 309 ASSERT_TRUE(ContainsKey(notification_listener.updates(),
311 "ogjcoiohnmldgjemafoockdghcjciccf")); 310 "ogjcoiohnmldgjemafoockdghcjciccf"));
312 311
313 // Make sure the extension state is the same as before. 312 // Make sure the extension state is the same as before.
314 ASSERT_EQ(size_before + 1, service->extensions()->size()); 313 ASSERT_EQ(size_before + 1, service->extensions()->size());
(...skipping 13 matching lines...) Expand all
328 #define MAYBE_AutoUpdateDisabledExtensions AutoUpdateDisabledExtensions 327 #define MAYBE_AutoUpdateDisabledExtensions AutoUpdateDisabledExtensions
329 #endif 328 #endif
330 #endif 329 #endif
331 330
332 // Tests extension autoupdate. 331 // Tests extension autoupdate.
333 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, 332 IN_PROC_BROWSER_TEST_F(ExtensionManagementTest,
334 MAYBE_AutoUpdateDisabledExtensions) { 333 MAYBE_AutoUpdateDisabledExtensions) {
335 NotificationListener notification_listener; 334 NotificationListener notification_listener;
336 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); 335 FilePath basedir = test_data_dir_.AppendASCII("autoupdate");
337 // Note: This interceptor gets requests on the IO thread. 336 // Note: This interceptor gets requests on the IO thread.
338 scoped_refptr<extensions::AutoUpdateInterceptor> interceptor( 337 extensions::AutoUpdateInterceptor interceptor;
339 new extensions::AutoUpdateInterceptor());
340 net::URLFetcher::SetEnableInterceptionForTests(true); 338 net::URLFetcher::SetEnableInterceptionForTests(true);
341 339
342 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", 340 interceptor.SetResponse("http://localhost/autoupdate/manifest",
343 basedir.AppendASCII("manifest_v2.xml")); 341 basedir.AppendASCII("manifest_v2.xml"));
344 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", 342 interceptor.SetResponse("http://localhost/autoupdate/v2.crx",
345 basedir.AppendASCII("v2.crx")); 343 basedir.AppendASCII("v2.crx"));
346 344
347 // Install version 1 of the extension. 345 // Install version 1 of the extension.
348 ExtensionTestMessageListener listener1("v1 installed", false); 346 ExtensionTestMessageListener listener1("v1 installed", false);
349 ExtensionService* service = extensions::ExtensionSystem::Get( 347 ExtensionService* service = extensions::ExtensionSystem::Get(
350 browser()->profile())->extension_service(); 348 browser()->profile())->extension_service();
351 const size_t enabled_size_before = service->extensions()->size(); 349 const size_t enabled_size_before = service->extensions()->size();
352 const size_t disabled_size_before = service->disabled_extensions()->size(); 350 const size_t disabled_size_before = service->disabled_extensions()->size();
353 const Extension* extension = 351 const Extension* extension =
354 InstallExtension(basedir.AppendASCII("v1.crx"), 1); 352 InstallExtension(basedir.AppendASCII("v1.crx"), 1);
355 ASSERT_TRUE(extension); 353 ASSERT_TRUE(extension);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 ExtensionService* service = extensions::ExtensionSystem::Get( 395 ExtensionService* service = extensions::ExtensionSystem::Get(
398 browser()->profile())->extension_service(); 396 browser()->profile())->extension_service();
399 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; 397 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf";
400 // We don't want autoupdate blacklist checks. 398 // We don't want autoupdate blacklist checks.
401 extensions::ExtensionUpdater::CheckParams params; 399 extensions::ExtensionUpdater::CheckParams params;
402 params.check_blacklist = false; 400 params.check_blacklist = false;
403 401
404 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); 402 FilePath basedir = test_data_dir_.AppendASCII("autoupdate");
405 403
406 // Note: This interceptor gets requests on the IO thread. 404 // Note: This interceptor gets requests on the IO thread.
407 scoped_refptr<extensions::AutoUpdateInterceptor> interceptor( 405 extensions::AutoUpdateInterceptor interceptor;
408 new extensions::AutoUpdateInterceptor());
409 net::URLFetcher::SetEnableInterceptionForTests(true); 406 net::URLFetcher::SetEnableInterceptionForTests(true);
410 407
411 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", 408 interceptor.SetResponse("http://localhost/autoupdate/manifest",
412 basedir.AppendASCII("manifest_v2.xml")); 409 basedir.AppendASCII("manifest_v2.xml"));
413 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", 410 interceptor.SetResponse("http://localhost/autoupdate/v2.crx",
414 basedir.AppendASCII("v2.crx")); 411 basedir.AppendASCII("v2.crx"));
415 412
416 const size_t size_before = service->extensions()->size(); 413 const size_t size_before = service->extensions()->size();
417 ASSERT_TRUE(service->disabled_extensions()->is_empty()); 414 ASSERT_TRUE(service->disabled_extensions()->is_empty());
418 415
419 extensions::PendingExtensionManager* pending_extension_manager = 416 extensions::PendingExtensionManager* pending_extension_manager =
420 service->pending_extension_manager(); 417 service->pending_extension_manager();
421 418
422 // The code that reads external_extensions.json uses this method to inform 419 // The code that reads external_extensions.json uses this method to inform
423 // the ExtensionService of an extension to download. Using the real code 420 // the ExtensionService of an extension to download. Using the real code
424 // is race-prone, because instantating the ExtensionService starts a read 421 // is race-prone, because instantating the ExtensionService starts a read
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 ExtensionService* service = extensions::ExtensionSystem::Get( 480 ExtensionService* service = extensions::ExtensionSystem::Get(
484 browser()->profile())->extension_service(); 481 browser()->profile())->extension_service();
485 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; 482 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf";
486 // We don't want autoupdate blacklist checks. 483 // We don't want autoupdate blacklist checks.
487 extensions::ExtensionUpdater::CheckParams params; 484 extensions::ExtensionUpdater::CheckParams params;
488 params.check_blacklist = false; 485 params.check_blacklist = false;
489 486
490 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); 487 FilePath basedir = test_data_dir_.AppendASCII("autoupdate");
491 488
492 // Note: This interceptor gets requests on the IO thread. 489 // Note: This interceptor gets requests on the IO thread.
493 scoped_refptr<extensions::AutoUpdateInterceptor> interceptor( 490 extensions::AutoUpdateInterceptor interceptor;
494 new extensions::AutoUpdateInterceptor());
495 net::URLFetcher::SetEnableInterceptionForTests(true); 491 net::URLFetcher::SetEnableInterceptionForTests(true);
496 492
497 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", 493 interceptor.SetResponse("http://localhost/autoupdate/manifest",
498 basedir.AppendASCII("manifest_v2.xml")); 494 basedir.AppendASCII("manifest_v2.xml"));
499 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", 495 interceptor.SetResponse("http://localhost/autoupdate/v2.crx",
500 basedir.AppendASCII("v2.crx")); 496 basedir.AppendASCII("v2.crx"));
501 497
502 const size_t size_before = service->extensions()->size(); 498 const size_t size_before = service->extensions()->size();
503 ASSERT_TRUE(service->disabled_extensions()->is_empty()); 499 ASSERT_TRUE(service->disabled_extensions()->is_empty());
504 500
505 PrefService* prefs = browser()->profile()->GetPrefs(); 501 PrefService* prefs = browser()->profile()->GetPrefs();
506 const ListValue* forcelist = 502 const ListValue* forcelist =
507 prefs->GetList(prefs::kExtensionInstallForceList); 503 prefs->GetList(prefs::kExtensionInstallForceList);
508 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; 504 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp;
509 505
510 { 506 {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 browser()->profile())->extension_service(); 558 browser()->profile())->extension_service();
563 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf"; 559 const char* kExtensionId = "ogjcoiohnmldgjemafoockdghcjciccf";
564 extensions::ExtensionUpdater::CheckParams params; 560 extensions::ExtensionUpdater::CheckParams params;
565 params.check_blacklist = false; 561 params.check_blacklist = false;
566 service->updater()->set_default_check_params(params); 562 service->updater()->set_default_check_params(params);
567 const size_t size_before = service->extensions()->size(); 563 const size_t size_before = service->extensions()->size();
568 FilePath basedir = test_data_dir_.AppendASCII("autoupdate"); 564 FilePath basedir = test_data_dir_.AppendASCII("autoupdate");
569 ASSERT_TRUE(service->disabled_extensions()->is_empty()); 565 ASSERT_TRUE(service->disabled_extensions()->is_empty());
570 566
571 // Note: This interceptor gets requests on the IO thread. 567 // Note: This interceptor gets requests on the IO thread.
572 scoped_refptr<extensions::AutoUpdateInterceptor> interceptor( 568 extensions::AutoUpdateInterceptor interceptor;
573 new extensions::AutoUpdateInterceptor());
574 net::URLFetcher::SetEnableInterceptionForTests(true); 569 net::URLFetcher::SetEnableInterceptionForTests(true);
575 570
576 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/manifest", 571 interceptor.SetResponse("http://localhost/autoupdate/manifest",
577 basedir.AppendASCII("manifest_v2.xml")); 572 basedir.AppendASCII("manifest_v2.xml"));
578 interceptor->SetResponseOnIOThread("http://localhost/autoupdate/v2.crx", 573 interceptor.SetResponse("http://localhost/autoupdate/v2.crx",
579 basedir.AppendASCII("v2.crx")); 574 basedir.AppendASCII("v2.crx"));
580 575
581 // Check that the policy is initially empty. 576 // Check that the policy is initially empty.
582 PrefService* prefs = browser()->profile()->GetPrefs(); 577 PrefService* prefs = browser()->profile()->GetPrefs();
583 const ListValue* forcelist = 578 const ListValue* forcelist =
584 prefs->GetList(prefs::kExtensionInstallForceList); 579 prefs->GetList(prefs::kExtensionInstallForceList);
585 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; 580 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp;
586 581
587 // User install of the extension. 582 // User install of the extension.
588 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); 583 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1));
589 ASSERT_EQ(size_before + 1, service->extensions()->size()); 584 ASSERT_EQ(size_before + 1, service->extensions()->size());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 std::string(kExtensionId) + ";http://localhost/autoupdate/manifest")); 641 std::string(kExtensionId) + ";http://localhost/autoupdate/manifest"));
647 } 642 }
648 ASSERT_TRUE(WaitForExtensionInstall()); 643 ASSERT_TRUE(WaitForExtensionInstall());
649 ASSERT_EQ(size_before + 1, service->extensions()->size()); 644 ASSERT_EQ(size_before + 1, service->extensions()->size());
650 extension = service->GetExtensionById(kExtensionId, false); 645 extension = service->GetExtensionById(kExtensionId, false);
651 ASSERT_TRUE(extension); 646 ASSERT_TRUE(extension);
652 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location()); 647 EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location());
653 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); 648 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId));
654 EXPECT_TRUE(service->disabled_extensions()->is_empty()); 649 EXPECT_TRUE(service->disabled_extensions()->is_empty());
655 } 650 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698