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

Side by Side Diff: chrome/browser/profiles/profile_browsertest.cc

Issue 1814543002: Fix callsites to URLRequestContext::CopyFrom (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add browser tests Created 4 years, 8 months 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
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 "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
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
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 FetchURLRequestContext(net::URLRequestContextGetter* getter,
456 net::URLRequestContext** context) {
457 *context = getter->GetURLRequestContext();
458 }
459
460 } // namespace
461
462 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, URLRequestContextIsolation) {
463 base::ScopedTempDir temp_dir;
464 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
465
466 MockProfileDelegate delegate;
467 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true));
468
469 {
470 std::unique_ptr<Profile> profile(CreateProfile(
471 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS));
472
473 scoped_refptr<const extensions::Extension> app =
474 BuildTestApp(profile.get());
475 content::StoragePartition* extension_partition =
476 content::BrowserContext::GetStoragePartitionForSite(
477 profile.get(),
478 extensions::Extension::GetBaseURLFromExtensionId(app->id()));
479 net::URLRequestContextGetter* extension_context_getter =
480 extension_partition->GetURLRequestContext();
481 net::URLRequestContextGetter* main_context_getter =
482 profile->GetRequestContext();
483
484 net::URLRequestContext* extension_context = nullptr;
485 net::URLRequestContext* main_context = nullptr;
486 base::RunLoop run_loop;
487 content::BrowserThread::PostTask(
488 content::BrowserThread::IO, FROM_HERE,
489 base::Bind(&FetchURLRequestContext, extension_context_getter,
490 &extension_context));
491 content::BrowserThread::PostTaskAndReply(
492 content::BrowserThread::IO, FROM_HERE,
493 base::Bind(&FetchURLRequestContext, main_context_getter, &main_context),
494 run_loop.QuitClosure());
495 run_loop.Run();
496
497 CHECK(extension_context);
498 CHECK(main_context);
mmenke 2016/04/27 02:28:47 We'd crash just below if these aren't true, anyway
nharper 2016/04/27 22:25:44 Done.
499
500 EXPECT_NE(extension_context, main_context);
501 EXPECT_NE(extension_context->channel_id_service(),
502 main_context->channel_id_service());
mmenke 2016/04/27 02:28:47 Dereferencing the context on the UI thread just do
nharper 2016/04/27 22:25:44 Done.
503 }
504
505 FlushIoTaskRunnerAndSpinThreads();
506 }
507
508 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
509 OffTheRecordURLRequestContextIsolation) {
510 base::ScopedTempDir temp_dir;
511 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
512
513 MockProfileDelegate delegate;
514 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true));
515
516 {
517 std::unique_ptr<Profile> profile(CreateProfile(
518 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS));
519 Profile* otr_profile = profile->GetOffTheRecordProfile();
520
521 scoped_refptr<const extensions::Extension> app = BuildTestApp(otr_profile);
522 content::StoragePartition* extension_partition =
523 content::BrowserContext::GetStoragePartitionForSite(
524 otr_profile,
525 extensions::Extension::GetBaseURLFromExtensionId(app->id()));
526 net::URLRequestContextGetter* extension_context_getter =
527 extension_partition->GetURLRequestContext();
528 net::URLRequestContextGetter* main_context_getter =
529 otr_profile->GetRequestContext();
530
531 net::URLRequestContext* extension_context = nullptr;
532 net::URLRequestContext* main_context = nullptr;
533 base::RunLoop run_loop;
534 content::BrowserThread::PostTask(
535 content::BrowserThread::IO, FROM_HERE,
536 base::Bind(&FetchURLRequestContext, extension_context_getter,
537 &extension_context));
538 content::BrowserThread::PostTaskAndReply(
539 content::BrowserThread::IO, FROM_HERE,
540 base::Bind(&FetchURLRequestContext, main_context_getter, &main_context),
541 run_loop.QuitClosure());
542 run_loop.Run();
543
544 CHECK(extension_context);
545 CHECK(main_context);
546
547 EXPECT_NE(extension_context, main_context);
548 EXPECT_NE(extension_context->channel_id_service(),
549 main_context->channel_id_service());
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
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 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/off_the_record_profile_io_data.cc ('k') | chrome/browser/profiles/profile_impl_io_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698