Commit 929746b6 authored by Robbie McElrath's avatar Robbie McElrath Committed by Commit Bot

Remove StoragePartition::GetURLRequestContext calls from ChromeOS login tests

StoragePartition::GetURLRequestContext won't work with the network
service enabled.

Bug: 966633
Change-Id: Ic1442e75315fa3e84d5e155c188ae5707cfa29de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1659198Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Robbie McElrath <rmcelrath@chromium.org>
Cr-Commit-Position: refs/heads/master@{#668968}
parent ceaa2666
......@@ -18,8 +18,10 @@
#include "base/time/time.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_utils.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_constants.h"
#include "net/http/http_auth.h"
......@@ -28,6 +30,8 @@
#include "net/http/http_transaction_factory.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "services/network/network_context.h"
#include "services/network/network_service.h"
#include "services/network/public/mojom/cookie_manager.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
......@@ -51,10 +55,37 @@ const char kGAIACookieDomain[] = "google.com";
const char kSAMLIdPCookieDomain[] = "example.com";
const char kSAMLIdPCookieDomainWithWildcard[] = ".example.com";
class TestingProfileWithNetworkContext : public TestingProfile {
public:
explicit TestingProfileWithNetworkContext(
network::NetworkService* network_service) {
auto network_context = std::make_unique<network::NetworkContext>(
network_service, mojo::MakeRequest(&network_context_ptr_),
network::mojom::NetworkContextParams::New());
network_context_ = network_context.get();
SetNetworkContext(std::move(network_context));
}
network::NetworkContext* network_context() { return network_context_; }
private:
network::mojom::NetworkContextPtr network_context_ptr_;
network::NetworkContext* network_context_;
};
network::NetworkService* GetNetworkService() {
content::GetNetworkService();
// Wait for the Network Service to initialize on the IO thread.
content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
return network::NetworkService::GetNetworkServiceForTesting();
}
} // namespace
class ProfileAuthDataTest : public testing::Test {
public:
ProfileAuthDataTest();
// testing::Test:
void SetUp() override;
......@@ -70,22 +101,26 @@ class ProfileAuthDataTest : public testing::Test {
const std::string& expected_saml_idp_cookie_value);
private:
void PopulateBrowserContext(content::BrowserContext* browser_context,
void PopulateBrowserContext(TestingProfileWithNetworkContext* browser_context,
const std::string& proxy_auth_password,
const std::string& cookie_value);
net::URLRequestContext* GetRequestContext(
content::BrowserContext* browser_context);
net::HttpAuthCache* GetProxyAuth(content::BrowserContext* browser_context);
net::HttpAuthCache* GetProxyAuth(network::NetworkContext* network_context);
network::mojom::CookieManager* GetCookies(
content::BrowserContext* browser_context);
content::TestBrowserThreadBundle thread_bundle_;
TestingProfile login_browser_context_;
TestingProfile user_browser_context_;
network::NetworkService* network_service_;
TestingProfileWithNetworkContext login_browser_context_;
TestingProfileWithNetworkContext user_browser_context_;
};
ProfileAuthDataTest::ProfileAuthDataTest()
: network_service_(GetNetworkService()),
login_browser_context_(network_service_),
user_browser_context_(network_service_) {}
void ProfileAuthDataTest::SetUp() {
PopulateBrowserContext(&login_browser_context_, kProxyAuthPassword1,
kCookieValue1);
......@@ -132,7 +167,7 @@ net::CookieList ProfileAuthDataTest::GetUserCookies() {
void ProfileAuthDataTest::VerifyTransferredUserProxyAuthEntry() {
net::HttpAuthCache::Entry* entry =
GetProxyAuth(&user_browser_context_)
GetProxyAuth(user_browser_context_.network_context())
->Lookup(GURL(kProxyAuthURL), kProxyAuthRealm,
net::HttpAuth::AUTH_SCHEME_BASIC);
ASSERT_TRUE(entry);
......@@ -164,10 +199,10 @@ void ProfileAuthDataTest::VerifyUserCookies(
}
void ProfileAuthDataTest::PopulateBrowserContext(
content::BrowserContext* browser_context,
TestingProfileWithNetworkContext* browser_context,
const std::string& proxy_auth_password,
const std::string& cookie_value) {
GetProxyAuth(browser_context)
GetProxyAuth(browser_context->network_context())
->Add(GURL(kProxyAuthURL), kProxyAuthRealm,
net::HttpAuth::AUTH_SCHEME_BASIC, kProxyAuthChallenge,
net::AuthCredentials(base::string16(),
......@@ -206,16 +241,9 @@ void ProfileAuthDataTest::PopulateBrowserContext(
"https", options, base::DoNothing());
}
net::URLRequestContext* ProfileAuthDataTest::GetRequestContext(
content::BrowserContext* browser_context) {
return content::BrowserContext::GetDefaultStoragePartition(browser_context)
->GetURLRequestContext()
->GetURLRequestContext();
}
net::HttpAuthCache* ProfileAuthDataTest::GetProxyAuth(
content::BrowserContext* browser_context) {
return GetRequestContext(browser_context)
network::NetworkContext* network_context) {
return network_context->url_request_context()
->http_transaction_factory()
->GetSession()
->http_auth_cache();
......
......@@ -21,6 +21,7 @@
#include "content/public/browser/site_instance.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/test_utils.h"
#include "content/public/test/web_contents_tester.h"
#include "net/cookies/cookie_store.h"
#include "net/http/http_transaction_factory.h"
......@@ -43,26 +44,23 @@ void StorePartitionNameAndQuitLoop(base::RunLoop* loop,
loop->Quit();
}
void AddEntryToHttpAuthCache(net::URLRequestContext* url_request_context) {
net::HttpAuthCache* http_auth_cache =
url_request_context->http_transaction_factory()
->GetSession()
->http_auth_cache();
http_auth_cache->Add(GURL("http://whatever.com/"), "",
net::HttpAuth::AUTH_SCHEME_BASIC, "",
net::AuthCredentials(), "");
void AddEntryToHttpAuthCache(network::NetworkContext* network_context) {
net::HttpAuthCache* http_auth_cache = network_context->url_request_context()
->http_transaction_factory()
->GetSession()
->http_auth_cache();
http_auth_cache->Add(GURL(kEmbedderUrl), "", net::HttpAuth::AUTH_SCHEME_BASIC,
"", net::AuthCredentials(), "");
}
void IsEntryInHttpAuthCache(
net::URLRequestContextGetter* url_request_context_getter,
bool* out_entry_found) {
net::HttpAuthCache* http_auth_cache =
url_request_context_getter->GetURLRequestContext()
->http_transaction_factory()
->GetSession()
->http_auth_cache();
void IsEntryInHttpAuthCache(network::NetworkContext* network_context,
bool* out_entry_found) {
net::HttpAuthCache* http_auth_cache = network_context->url_request_context()
->http_transaction_factory()
->GetSession()
->http_auth_cache();
*out_entry_found =
http_auth_cache->Lookup(GURL("http://whatever.com/"), "",
http_auth_cache->Lookup(GURL(kEmbedderUrl), "",
net::HttpAuth::AUTH_SCHEME_BASIC) != nullptr;
}
......@@ -77,25 +75,34 @@ class SigninPartitionManagerTest : public ChromeRenderViewHostTestHarness {
ChromeRenderViewHostTestHarness::SetUp();
signin_browser_context_ = std::make_unique<TestingProfile>();
// Wait for the Network Service to initialize on the IO thread.
content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
auto network_context = std::make_unique<network::NetworkContext>(
network::NetworkService::GetNetworkServiceForTesting(),
mojo::MakeRequest(&signin_network_context_ptr_),
network::mojom::NetworkContextParams::New());
signin_network_context_ = network_context.get();
TestingProfile::Builder()
.BuildIncognito(signin_browser_context_.get())
->SetNetworkContext(std::move(network_context));
signin_ui_web_contents_ = content::WebContentsTester::CreateTestWebContents(
GetSigninProfile(), content::SiteInstance::Create(GetSigninProfile()));
// Let Profile creation finish, which creates the NetworkService instance.
base::RunLoop().RunUntilIdle();
network::mojom::NetworkContextParamsPtr params =
network::mojom::NetworkContextParams::New();
system_network_context_ = std::make_unique<network::NetworkContext>(
network::NetworkService::GetNetworkServiceForTesting(),
mojo::MakeRequest(&system_network_context_ptr_), std::move(params));
mojo::MakeRequest(&system_network_context_ptr_),
network::mojom::NetworkContextParams::New());
GURL url(kEmbedderUrl);
content::WebContentsTester::For(signin_ui_web_contents())
->NavigateAndCommit(url);
GetSigninPartitionManager()->SetClearStoragePartitionTaskForTesting(
base::Bind(&SigninPartitionManagerTest::ClearStoragePartitionTask,
base::Unretained(this)));
base::BindRepeating(
&SigninPartitionManagerTest::ClearStoragePartitionTask,
base::Unretained(this)));
GetSigninPartitionManager()->SetGetSystemNetworkContextForTesting(
base::BindRepeating(
&SigninPartitionManagerTest::GetSystemNetworkContext,
......@@ -150,24 +157,30 @@ class SigninPartitionManagerTest : public ChromeRenderViewHostTestHarness {
return partition_name;
}
net::URLRequestContext* GetSystemURLRequestContext() {
return system_network_context_->url_request_context();
network::mojom::NetworkContext* GetSystemNetworkContext() {
return system_network_context_.get();
}
network::mojom::NetworkContext* GetSystemNetworkContext() {
network::NetworkContext* GetSystemNetworkContextImpl() {
return system_network_context_.get();
}
network::NetworkContext* GetSigninNetworkContextImpl() {
return signin_network_context_;
}
private:
void ClearStoragePartitionTask(content::StoragePartition* partition,
base::OnceClosure clear_done_closure) {
pending_clear_tasks_.push_back({partition, std::move(clear_done_closure)});
}
std::unique_ptr<network::NetworkContext> system_network_context_;
network::mojom::NetworkContextPtr system_network_context_ptr_;
std::unique_ptr<network::NetworkContext> system_network_context_;
std::unique_ptr<TestingProfile> signin_browser_context_;
network::mojom::NetworkContextPtr signin_network_context_ptr_;
network::NetworkContext* signin_network_context_;
// Web contents of the sign-in UI, embedder of the signin-frame webview.
std::unique_ptr<content::WebContents> signin_ui_web_contents_;
......@@ -227,22 +240,18 @@ TEST_F(SigninPartitionManagerTest, HttpAuthCacheTransferred) {
base::PostTaskWithTraitsAndReply(
FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(AddEntryToHttpAuthCache,
base::Unretained(GetSystemURLRequestContext())),
base::Unretained(GetSystemNetworkContextImpl())),
loop_prepare.QuitClosure());
loop_prepare.Run();
RunStartSigninSesssion(signin_ui_web_contents());
net::URLRequestContextGetter* signin_url_request_context_getter =
GetSigninPartitionManager()
->GetCurrentStoragePartition()
->GetURLRequestContext();
bool entry_found = false;
base::RunLoop loop_check;
base::PostTaskWithTraitsAndReply(
FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(IsEntryInHttpAuthCache,
base::RetainedRef(signin_url_request_context_getter),
base::Unretained(GetSigninNetworkContextImpl()),
&entry_found),
loop_check.QuitClosure());
loop_check.Run();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment