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/profiles/profile.h" | 5 #include "chrome/browser/profiles/profile.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "chrome/common/chrome_constants.h" | 31 #include "chrome/common/chrome_constants.h" |
32 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
33 #include "chrome/test/base/in_process_browser_test.h" | 33 #include "chrome/test/base/in_process_browser_test.h" |
34 #include "chrome/test/base/ui_test_utils.h" | 34 #include "chrome/test/base/ui_test_utils.h" |
35 #include "components/bookmarks/browser/startup_task_runner_service.h" | 35 #include "components/bookmarks/browser/startup_task_runner_service.h" |
36 #include "components/prefs/pref_service.h" | 36 #include "components/prefs/pref_service.h" |
37 #include "components/version_info/version_info.h" | 37 #include "components/version_info/version_info.h" |
38 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
39 #include "content/public/browser/storage_partition.h" | 39 #include "content/public/browser/storage_partition.h" |
40 #include "content/public/test/test_utils.h" | 40 #include "content/public/test/test_utils.h" |
| 41 #include "extensions/browser/extension_registry.h" |
| 42 #include "extensions/common/extension.h" |
| 43 #include "extensions/common/extension_builder.h" |
| 44 #include "extensions/common/value_builder.h" |
41 #include "net/base/net_errors.h" | 45 #include "net/base/net_errors.h" |
42 #include "net/test/url_request/url_request_failed_job.h" | 46 #include "net/test/url_request/url_request_failed_job.h" |
43 #include "net/url_request/url_fetcher.h" | 47 #include "net/url_request/url_fetcher.h" |
44 #include "net/url_request/url_fetcher_delegate.h" | 48 #include "net/url_request/url_fetcher_delegate.h" |
45 #include "net/url_request/url_request_context_getter.h" | 49 #include "net/url_request/url_request_context_getter.h" |
46 #include "net/url_request/url_request_status.h" | 50 #include "net/url_request/url_request_status.h" |
47 #include "testing/gmock/include/gmock/gmock.h" | 51 #include "testing/gmock/include/gmock/gmock.h" |
48 #include "testing/gtest/include/gtest/gtest.h" | 52 #include "testing/gtest/include/gtest/gtest.h" |
49 #include "url/gurl.h" | 53 #include "url/gurl.h" |
50 | 54 |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 | 418 |
415 // Setting back to a crashed value should work. | 419 // Setting back to a crashed value should work. |
416 profile->SetExitType(Profile::EXIT_CRASHED); | 420 profile->SetExitType(Profile::EXIT_CRASHED); |
417 std::string final_value(prefs->GetString(prefs::kSessionExitType)); | 421 std::string final_value(prefs->GetString(prefs::kSessionExitType)); |
418 EXPECT_EQ(crash_value, final_value); | 422 EXPECT_EQ(crash_value, final_value); |
419 } | 423 } |
420 | 424 |
421 FlushIoTaskRunnerAndSpinThreads(); | 425 FlushIoTaskRunnerAndSpinThreads(); |
422 } | 426 } |
423 | 427 |
| 428 namespace { |
| 429 |
| 430 scoped_refptr<const extensions::Extension> BuildTestApp(Profile* profile) { |
| 431 scoped_refptr<const extensions::Extension> app; |
| 432 app = |
| 433 extensions::ExtensionBuilder() |
| 434 .SetManifest( |
| 435 extensions::DictionaryBuilder() |
| 436 .Set("name", "test app") |
| 437 .Set("version", "1") |
| 438 .Set("app", |
| 439 extensions::DictionaryBuilder() |
| 440 .Set("background", |
| 441 extensions::DictionaryBuilder() |
| 442 .Set("scripts", extensions::ListBuilder() |
| 443 .Append("background.js") |
| 444 .Build()) |
| 445 .Build()) |
| 446 .Build()) |
| 447 .Build()) |
| 448 .Build(); |
| 449 extensions::ExtensionRegistry* registry = |
| 450 extensions::ExtensionRegistry::Get(profile); |
| 451 EXPECT_TRUE(registry->AddEnabled(app)); |
| 452 return app; |
| 453 } |
| 454 |
| 455 void CompareURLRequestContexts( |
| 456 net::URLRequestContextGetter* extension_context_getter, |
| 457 net::URLRequestContextGetter* main_context_getter) { |
| 458 net::URLRequestContext* extension_context = |
| 459 extension_context_getter->GetURLRequestContext(); |
| 460 net::URLRequestContext* main_context = |
| 461 main_context_getter->GetURLRequestContext(); |
| 462 |
| 463 // Check that the URLRequestContexts are different and that their |
| 464 // ChannelIDServices and CookieStores are different. |
| 465 EXPECT_NE(extension_context, main_context); |
| 466 EXPECT_NE(extension_context->channel_id_service(), |
| 467 main_context->channel_id_service()); |
| 468 EXPECT_NE(extension_context->cookie_store(), main_context->cookie_store()); |
| 469 |
| 470 // Check that the ChannelIDService in the HttpNetworkSession is the same as |
| 471 // the one directly on the URLRequestContext. |
| 472 EXPECT_EQ(extension_context->http_transaction_factory() |
| 473 ->GetSession() |
| 474 ->params() |
| 475 .channel_id_service, |
| 476 extension_context->channel_id_service()); |
| 477 EXPECT_EQ(main_context->http_transaction_factory() |
| 478 ->GetSession() |
| 479 ->params() |
| 480 .channel_id_service, |
| 481 main_context->channel_id_service()); |
| 482 } |
| 483 |
| 484 } // namespace |
| 485 |
| 486 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, URLRequestContextIsolation) { |
| 487 base::ScopedTempDir temp_dir; |
| 488 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 489 |
| 490 MockProfileDelegate delegate; |
| 491 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); |
| 492 |
| 493 { |
| 494 std::unique_ptr<Profile> profile(CreateProfile( |
| 495 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); |
| 496 |
| 497 scoped_refptr<const extensions::Extension> app = |
| 498 BuildTestApp(profile.get()); |
| 499 content::StoragePartition* extension_partition = |
| 500 content::BrowserContext::GetStoragePartitionForSite( |
| 501 profile.get(), |
| 502 extensions::Extension::GetBaseURLFromExtensionId(app->id())); |
| 503 net::URLRequestContextGetter* extension_context_getter = |
| 504 extension_partition->GetURLRequestContext(); |
| 505 net::URLRequestContextGetter* main_context_getter = |
| 506 profile->GetRequestContext(); |
| 507 |
| 508 base::RunLoop run_loop; |
| 509 content::BrowserThread::PostTaskAndReply( |
| 510 content::BrowserThread::IO, FROM_HERE, |
| 511 base::Bind(&CompareURLRequestContexts, extension_context_getter, |
| 512 main_context_getter), |
| 513 run_loop.QuitClosure()); |
| 514 run_loop.Run(); |
| 515 } |
| 516 |
| 517 FlushIoTaskRunnerAndSpinThreads(); |
| 518 } |
| 519 |
| 520 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, |
| 521 OffTheRecordURLRequestContextIsolation) { |
| 522 base::ScopedTempDir temp_dir; |
| 523 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 524 |
| 525 MockProfileDelegate delegate; |
| 526 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); |
| 527 |
| 528 { |
| 529 std::unique_ptr<Profile> profile(CreateProfile( |
| 530 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); |
| 531 Profile* otr_profile = profile->GetOffTheRecordProfile(); |
| 532 |
| 533 scoped_refptr<const extensions::Extension> app = BuildTestApp(otr_profile); |
| 534 content::StoragePartition* extension_partition = |
| 535 content::BrowserContext::GetStoragePartitionForSite( |
| 536 otr_profile, |
| 537 extensions::Extension::GetBaseURLFromExtensionId(app->id())); |
| 538 net::URLRequestContextGetter* extension_context_getter = |
| 539 extension_partition->GetURLRequestContext(); |
| 540 net::URLRequestContextGetter* main_context_getter = |
| 541 otr_profile->GetRequestContext(); |
| 542 |
| 543 base::RunLoop run_loop; |
| 544 content::BrowserThread::PostTaskAndReply( |
| 545 content::BrowserThread::IO, FROM_HERE, |
| 546 base::Bind(&CompareURLRequestContexts, extension_context_getter, |
| 547 main_context_getter), |
| 548 run_loop.QuitClosure()); |
| 549 run_loop.Run(); |
| 550 } |
| 551 |
| 552 FlushIoTaskRunnerAndSpinThreads(); |
| 553 } |
| 554 |
424 // The EndSession IO synchronization is only critical on Windows, but also | 555 // The EndSession IO synchronization is only critical on Windows, but also |
425 // happens under the USE_X11 define. See BrowserProcessImpl::EndSession. | 556 // happens under the USE_X11 define. See BrowserProcessImpl::EndSession. |
426 #if defined(USE_X11) || defined(OS_WIN) || defined(USE_OZONE) | 557 #if defined(USE_X11) || defined(OS_WIN) || defined(USE_OZONE) |
427 | 558 |
428 namespace { | 559 namespace { |
429 | 560 |
430 std::string GetExitTypePreferenceFromDisk(Profile* profile) { | 561 std::string GetExitTypePreferenceFromDisk(Profile* profile) { |
431 base::FilePath prefs_path = | 562 base::FilePath prefs_path = |
432 profile->GetPath().Append(chrome::kPreferencesFilename); | 563 profile->GetPath().Append(chrome::kPreferencesFilename); |
433 std::string prefs; | 564 std::string prefs; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 | 679 |
549 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, | 680 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, |
550 URLFetcherUsingExtensionContextDuringIncognitoTeardown) { | 681 URLFetcherUsingExtensionContextDuringIncognitoTeardown) { |
551 Browser* incognito_browser = | 682 Browser* incognito_browser = |
552 OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); | 683 OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); |
553 | 684 |
554 RunURLFetcherActiveDuringIncognitoTeardownTest( | 685 RunURLFetcherActiveDuringIncognitoTeardownTest( |
555 incognito_browser, | 686 incognito_browser, |
556 incognito_browser->profile()->GetRequestContextForExtensions()); | 687 incognito_browser->profile()->GetRequestContextForExtensions()); |
557 } | 688 } |
OLD | NEW |