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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profiles/profile_browsertest.cc
diff --git a/chrome/browser/profiles/profile_browsertest.cc b/chrome/browser/profiles/profile_browsertest.cc
index 2dc806412e2af30c8451e48337b6bb54d1389f2c..0a51c21efb947dad85f3c11aafcffd253e3e4959 100644
--- a/chrome/browser/profiles/profile_browsertest.cc
+++ b/chrome/browser/profiles/profile_browsertest.cc
@@ -38,6 +38,10 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/test/test_utils.h"
+#include "extensions/browser/extension_registry.h"
+#include "extensions/common/extension.h"
+#include "extensions/common/extension_builder.h"
+#include "extensions/common/value_builder.h"
#include "net/base/net_errors.h"
#include "net/test/url_request/url_request_failed_job.h"
#include "net/url_request/url_fetcher.h"
@@ -421,6 +425,133 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ExitType) {
FlushIoTaskRunnerAndSpinThreads();
}
+namespace {
+
+scoped_refptr<const extensions::Extension> BuildTestApp(Profile* profile) {
+ scoped_refptr<const extensions::Extension> app;
+ app =
+ extensions::ExtensionBuilder()
+ .SetManifest(
+ extensions::DictionaryBuilder()
+ .Set("name", "test app")
+ .Set("version", "1")
+ .Set("app",
+ extensions::DictionaryBuilder()
+ .Set("background",
+ extensions::DictionaryBuilder()
+ .Set("scripts", extensions::ListBuilder()
+ .Append("background.js")
+ .Build())
+ .Build())
+ .Build())
+ .Build())
+ .Build();
+ extensions::ExtensionRegistry* registry =
+ extensions::ExtensionRegistry::Get(profile);
+ EXPECT_TRUE(registry->AddEnabled(app));
+ return app;
+}
+
+void FetchURLRequestContext(net::URLRequestContextGetter* getter,
+ net::URLRequestContext** context) {
+ *context = getter->GetURLRequestContext();
+}
+
+} // namespace
+
+IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, URLRequestContextIsolation) {
+ base::ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+
+ MockProfileDelegate delegate;
+ EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true));
+
+ {
+ std::unique_ptr<Profile> profile(CreateProfile(
+ temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS));
+
+ scoped_refptr<const extensions::Extension> app =
+ BuildTestApp(profile.get());
+ content::StoragePartition* extension_partition =
+ content::BrowserContext::GetStoragePartitionForSite(
+ profile.get(),
+ extensions::Extension::GetBaseURLFromExtensionId(app->id()));
+ net::URLRequestContextGetter* extension_context_getter =
+ extension_partition->GetURLRequestContext();
+ net::URLRequestContextGetter* main_context_getter =
+ profile->GetRequestContext();
+
+ net::URLRequestContext* extension_context = nullptr;
+ net::URLRequestContext* main_context = nullptr;
+ base::RunLoop run_loop;
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO, FROM_HERE,
+ base::Bind(&FetchURLRequestContext, extension_context_getter,
+ &extension_context));
+ content::BrowserThread::PostTaskAndReply(
+ content::BrowserThread::IO, FROM_HERE,
+ base::Bind(&FetchURLRequestContext, main_context_getter, &main_context),
+ run_loop.QuitClosure());
+ run_loop.Run();
+
+ CHECK(extension_context);
+ 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.
+
+ EXPECT_NE(extension_context, main_context);
+ EXPECT_NE(extension_context->channel_id_service(),
+ 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.
+ }
+
+ FlushIoTaskRunnerAndSpinThreads();
+}
+
+IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
+ OffTheRecordURLRequestContextIsolation) {
+ base::ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+
+ MockProfileDelegate delegate;
+ EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true));
+
+ {
+ std::unique_ptr<Profile> profile(CreateProfile(
+ temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS));
+ Profile* otr_profile = profile->GetOffTheRecordProfile();
+
+ scoped_refptr<const extensions::Extension> app = BuildTestApp(otr_profile);
+ content::StoragePartition* extension_partition =
+ content::BrowserContext::GetStoragePartitionForSite(
+ otr_profile,
+ extensions::Extension::GetBaseURLFromExtensionId(app->id()));
+ net::URLRequestContextGetter* extension_context_getter =
+ extension_partition->GetURLRequestContext();
+ net::URLRequestContextGetter* main_context_getter =
+ otr_profile->GetRequestContext();
+
+ net::URLRequestContext* extension_context = nullptr;
+ net::URLRequestContext* main_context = nullptr;
+ base::RunLoop run_loop;
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO, FROM_HERE,
+ base::Bind(&FetchURLRequestContext, extension_context_getter,
+ &extension_context));
+ content::BrowserThread::PostTaskAndReply(
+ content::BrowserThread::IO, FROM_HERE,
+ base::Bind(&FetchURLRequestContext, main_context_getter, &main_context),
+ run_loop.QuitClosure());
+ run_loop.Run();
+
+ CHECK(extension_context);
+ CHECK(main_context);
+
+ EXPECT_NE(extension_context, main_context);
+ EXPECT_NE(extension_context->channel_id_service(),
+ main_context->channel_id_service());
+ }
+
+ FlushIoTaskRunnerAndSpinThreads();
+}
+
// The EndSession IO synchronization is only critical on Windows, but also
// happens under the USE_X11 define. See BrowserProcessImpl::EndSession.
#if defined(USE_X11) || defined(OS_WIN) || defined(USE_OZONE)
« 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