mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
chrome: Support client-created request contexts (see issue #2969)
RequestContextTest and URLRequestTest suites now pass with the Chrome runtime enabled.
This commit is contained in:
@@ -26,9 +26,8 @@ ExtensionTestHandler::ExtensionTestHandler(
|
||||
|
||||
ExtensionTestHandler::~ExtensionTestHandler() {
|
||||
if (!request_context_temp_dir_.IsEmpty()) {
|
||||
// Delete temporary directories on shutdown.
|
||||
CefTestSuite::GetInstance()->RegisterTempDirectory(
|
||||
request_context_temp_dir_.Take());
|
||||
// Temporary directory will be deleted on shutdown.
|
||||
request_context_temp_dir_.Take();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +64,8 @@ void ExtensionTestHandler::RunTest() {
|
||||
|
||||
if (request_context_on_disk()) {
|
||||
// Create a new temporary directory.
|
||||
EXPECT_TRUE(request_context_temp_dir_.CreateUniqueTempDir());
|
||||
EXPECT_TRUE(request_context_temp_dir_.CreateUniqueTempDirUnderPath(
|
||||
CefTestSuite::GetInstance()->root_cache_path()));
|
||||
CefString(&settings.cache_path) = request_context_temp_dir_.GetPath();
|
||||
}
|
||||
|
||||
|
@@ -136,7 +136,8 @@ TEST(RequestContextTest, BasicCreateSharedGlobal) {
|
||||
|
||||
TEST(RequestContextTest, BasicCreateSharedOnDisk) {
|
||||
CefScopedTempDir tempdir;
|
||||
EXPECT_TRUE(tempdir.CreateUniqueTempDir());
|
||||
EXPECT_TRUE(tempdir.CreateUniqueTempDirUnderPath(
|
||||
CefTestSuite::GetInstance()->root_cache_path()));
|
||||
|
||||
CefRequestContextSettings settings;
|
||||
CefString(&settings.cache_path) = tempdir.GetPath();
|
||||
|
@@ -5,6 +5,7 @@
|
||||
#include "tests/ceftests/test_suite.h"
|
||||
|
||||
#include "include/cef_file_util.h"
|
||||
#include "include/wrapper/cef_scoped_temp_dir.h"
|
||||
#include "tests/gtest/include/gtest/gtest.h"
|
||||
#include "tests/shared/common/client_switches.h"
|
||||
|
||||
@@ -92,6 +93,18 @@ CefTestSuite::CefTestSuite(int argc, char** argv)
|
||||
#else
|
||||
command_line_->InitFromArgv(argc, argv);
|
||||
#endif
|
||||
|
||||
if (!command_line_->HasSwitch("type")) {
|
||||
// Initialize in the main process only.
|
||||
root_cache_path_ =
|
||||
command_line_->GetSwitchValue(client::switches::kCachePath);
|
||||
if (root_cache_path_.empty()) {
|
||||
CefScopedTempDir temp_dir;
|
||||
CHECK(temp_dir.CreateUniqueTempDir());
|
||||
root_cache_path_ = temp_dir.Take();
|
||||
RegisterTempDirectory(root_cache_path_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CefTestSuite::~CefTestSuite() {
|
||||
@@ -133,8 +146,9 @@ void CefTestSuite::GetSettings(CefSettings& settings) const {
|
||||
command_line_->HasSwitch(client::switches::kExternalMessagePump);
|
||||
}
|
||||
|
||||
CefString(&settings.cache_path) =
|
||||
command_line_->GetSwitchValue(client::switches::kCachePath);
|
||||
CefString(&settings.cache_path) = root_cache_path_;
|
||||
CefString(&settings.root_cache_path) = root_cache_path_;
|
||||
CefString(&settings.user_data_path) = root_cache_path_;
|
||||
|
||||
// Always expose the V8 gc() function to give tests finer-grained control over
|
||||
// memory management.
|
||||
@@ -156,17 +170,6 @@ void CefTestSuite::GetSettings(CefSettings& settings) const {
|
||||
CefString(&settings.accept_language_list) = CEF_SETTINGS_ACCEPT_LANGUAGE;
|
||||
}
|
||||
|
||||
// static
|
||||
bool CefTestSuite::GetCachePath(std::string& path) const {
|
||||
if (command_line_->HasSwitch(client::switches::kCachePath)) {
|
||||
// Set the cache_path value.
|
||||
path = command_line_->GetSwitchValue(client::switches::kCachePath);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CefTestSuite::RegisterTempDirectory(const CefString& directory) {
|
||||
base::AutoLock lock_scope(temp_directories_lock_);
|
||||
temp_directories_.push_back(directory);
|
||||
|
@@ -25,7 +25,6 @@ class CefTestSuite {
|
||||
int Run();
|
||||
|
||||
void GetSettings(CefSettings& settings) const;
|
||||
bool GetCachePath(std::string& path) const;
|
||||
|
||||
// Register a temp directory that should be deleted on shutdown.
|
||||
void RegisterTempDirectory(const CefString& directory);
|
||||
@@ -34,6 +33,7 @@ class CefTestSuite {
|
||||
void DeleteTempDirectories();
|
||||
|
||||
CefRefPtr<CefCommandLine> command_line() const { return command_line_; }
|
||||
CefString root_cache_path() const { return root_cache_path_; }
|
||||
|
||||
// The return value from Run().
|
||||
int retval() const { return retval_; }
|
||||
@@ -50,6 +50,8 @@ class CefTestSuite {
|
||||
std::vector<CefString> temp_directories_;
|
||||
base::Lock temp_directories_lock_;
|
||||
|
||||
CefString root_cache_path_;
|
||||
|
||||
int retval_;
|
||||
};
|
||||
|
||||
|
@@ -99,7 +99,8 @@ CefRefPtr<CefRequestContext> CreateTestRequestContext(
|
||||
CefScopedTempDir scoped_temp_dir; \
|
||||
std::string cache_path; \
|
||||
if (with_cache_path) { \
|
||||
EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); \
|
||||
EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDirUnderPath( \
|
||||
CefTestSuite::GetInstance()->root_cache_path())); \
|
||||
cache_path = scoped_temp_dir.GetPath(); \
|
||||
} \
|
||||
CefRefPtr<test_class> handler = \
|
||||
@@ -107,8 +108,7 @@ CefRefPtr<CefRequestContext> CreateTestRequestContext(
|
||||
handler->ExecuteTest(); \
|
||||
ReleaseAndWaitForDestructor(handler); \
|
||||
if (!scoped_temp_dir.IsEmpty()) { \
|
||||
CefTestSuite::GetInstance()->RegisterTempDirectory( \
|
||||
scoped_temp_dir.Take()); \
|
||||
scoped_temp_dir.Take(); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
@@ -47,6 +47,11 @@ class URLRequestBrowserTest : public client::ClientAppBrowser::Delegate {
|
||||
CefRefPtr<CefCommandLine> command_line) override {
|
||||
// Delegate auth callbacks to GetAuthCredentials with the chrome runtime.
|
||||
command_line->AppendSwitch("disable-chrome-login-prompt");
|
||||
|
||||
// Disable component extensions that require creation of a background
|
||||
// WebContents because they slow down test runs.
|
||||
command_line->AppendSwitch(
|
||||
"disable-component-extensions-with-background-pages");
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -2843,7 +2848,7 @@ class RequestTestHandler : public TestHandler {
|
||||
|
||||
void RunTest() override {
|
||||
// Time out the test after a reasonable period of time.
|
||||
SetTestTimeout();
|
||||
SetTestTimeout(IsChromeRuntimeEnabled() ? 10000 : 5000);
|
||||
|
||||
// Start pre-setup actions.
|
||||
PreSetupStart();
|
||||
@@ -2858,7 +2863,8 @@ class RequestTestHandler : public TestHandler {
|
||||
EXPECT_TRUE(CefCurrentlyOn(TID_FILE_USER_VISIBLE));
|
||||
|
||||
if (context_mode_ == CONTEXT_ONDISK) {
|
||||
EXPECT_TRUE(context_tmpdir_.CreateUniqueTempDir());
|
||||
EXPECT_TRUE(context_tmpdir_.CreateUniqueTempDirUnderPath(
|
||||
CefTestSuite::GetInstance()->root_cache_path()));
|
||||
context_tmpdir_path_ = context_tmpdir_.GetPath();
|
||||
EXPECT_FALSE(context_tmpdir_path_.empty());
|
||||
}
|
||||
@@ -2894,26 +2900,29 @@ class RequestTestHandler : public TestHandler {
|
||||
CefString(&settings.cache_path) = context_tmpdir_path_;
|
||||
}
|
||||
|
||||
// Create a new temporary request context.
|
||||
CefRefPtr<CefRequestContext> request_context =
|
||||
CefRequestContext::CreateContext(settings,
|
||||
new RequestContextHandler(this));
|
||||
EXPECT_TRUE(request_context.get());
|
||||
test_runner_->SetRequestContext(request_context);
|
||||
// Create a new temporary request context. Calls OnContextInitialized.
|
||||
CefRequestContext::CreateContext(settings,
|
||||
new RequestContextHandler(this));
|
||||
}
|
||||
}
|
||||
|
||||
if (!test_server_backend_) {
|
||||
// Set the schemes that are allowed to store cookies.
|
||||
std::vector<CefString> supported_schemes;
|
||||
supported_schemes.push_back(GetRequestScheme(false));
|
||||
void OnContextInitialized(CefRefPtr<CefRequestContext> request_context) {
|
||||
EXPECT_TRUE(CefCurrentlyOn(TID_UI));
|
||||
EXPECT_TRUE(request_context.get());
|
||||
test_runner_->SetRequestContext(request_context);
|
||||
|
||||
// Continue the test once supported schemes has been set.
|
||||
request_context->GetCookieManager(nullptr)->SetSupportedSchemes(
|
||||
supported_schemes, true,
|
||||
new TestCompletionCallback(
|
||||
base::Bind(&RequestTestHandler::PreSetupComplete, this)));
|
||||
} else {
|
||||
PreSetupComplete();
|
||||
}
|
||||
if (!test_server_backend_) {
|
||||
// Set the schemes that are allowed to store cookies.
|
||||
std::vector<CefString> supported_schemes;
|
||||
supported_schemes.push_back(GetRequestScheme(false));
|
||||
|
||||
// Continue the test once supported schemes has been set.
|
||||
request_context->GetCookieManager(nullptr)->SetSupportedSchemes(
|
||||
supported_schemes, true,
|
||||
new TestCompletionCallback(
|
||||
base::Bind(&RequestTestHandler::PreSetupComplete, this)));
|
||||
} else {
|
||||
PreSetupComplete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3182,9 +3191,8 @@ class RequestTestHandler : public TestHandler {
|
||||
got_on_test_complete_.yes();
|
||||
|
||||
if (!context_tmpdir_.IsEmpty()) {
|
||||
// Delete the temp directory on application shutdown.
|
||||
CefTestSuite::GetInstance()->RegisterTempDirectory(
|
||||
context_tmpdir_.Take());
|
||||
// Temp directory will be deleted on application shutdown.
|
||||
context_tmpdir_.Take();
|
||||
}
|
||||
|
||||
TestComplete();
|
||||
@@ -3199,6 +3207,11 @@ class RequestTestHandler : public TestHandler {
|
||||
: test_handler_(test_handler) {}
|
||||
~RequestContextHandler() override { test_handler_->OnTestComplete(); }
|
||||
|
||||
void OnRequestContextInitialized(
|
||||
CefRefPtr<CefRequestContext> request_context) override {
|
||||
test_handler_->OnContextInitialized(request_context);
|
||||
}
|
||||
|
||||
private:
|
||||
CefRefPtr<RequestTestHandler> test_handler_;
|
||||
|
||||
|
Reference in New Issue
Block a user