mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Remove methods that modify cookie storage at runtime (see issue #2622).
This change removes cookie and request handler functionality that will not supported by the NetworkService. Specifically, it is no longer possible to change cookie storage locations at runime by returning a different CefCookieManager for an already initialized CefRequestContext. After this change you will need to use a separate CefRequestContext when creating a CefBrowser if you require separate cookie storage. The following methods have been removed: - CefCookieManager::CreateManager - CefCookieManager::GetBlockingManager - CefCookieManager::SetStoragePath - CefRequestContextHandler::GetCookieManager The following methods have been renamed: - CefRequestContext::GetDefaultCookieManager to GetCookieManager. This change substantially simplifies the network implementation in CEF because it is no longer necessary to proxy objects that are normally owned by Chromium. Chromium patches that are no longer necessary will be removed as a follow-up commit. To test: Verify that `ceftests --gtest_filter=-PluginTest.*` pass with NetworkService disabled. Plugin tests will be fixed in a follow-up commit.
This commit is contained in:
@@ -34,7 +34,6 @@ TEST(RequestContextTest, CreateContext) {
|
||||
class Handler : public CefRequestContextHandler {
|
||||
public:
|
||||
Handler() {}
|
||||
CefRefPtr<CefCookieManager> GetCookieManager() override { return NULL; }
|
||||
|
||||
private:
|
||||
IMPLEMENT_REFCOUNTING(Handler);
|
||||
@@ -197,157 +196,8 @@ TEST(RequestContextTest, CreateContextSharedOnDisk) {
|
||||
|
||||
namespace {
|
||||
|
||||
class CookieTestHandler : public TestHandler {
|
||||
public:
|
||||
class RequestContextHandler : public CefRequestContextHandler {
|
||||
public:
|
||||
explicit RequestContextHandler(CookieTestHandler* handler)
|
||||
: handler_(handler) {}
|
||||
|
||||
CefRefPtr<CefCookieManager> GetCookieManager() override {
|
||||
EXPECT_TRUE(handler_);
|
||||
handler_->got_get_cookie_manager_.yes();
|
||||
return handler_->cookie_manager_;
|
||||
}
|
||||
|
||||
void Detach() { handler_ = NULL; }
|
||||
|
||||
private:
|
||||
CookieTestHandler* handler_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(RequestContextHandler);
|
||||
};
|
||||
|
||||
CookieTestHandler(const std::string& url) : url_(url) {}
|
||||
|
||||
void RunTest() override {
|
||||
AddResource(url_,
|
||||
"<html>"
|
||||
"<head><script>document.cookie='name1=value1';</script></head>"
|
||||
"<body>Nav1</body>"
|
||||
"</html>",
|
||||
"text/html");
|
||||
|
||||
CefRequestContextSettings settings;
|
||||
|
||||
context_handler_ = new RequestContextHandler(this);
|
||||
context_ =
|
||||
CefRequestContext::CreateContext(settings, context_handler_.get());
|
||||
cookie_manager_ = CefCookieManager::CreateManager(CefString(), true, NULL);
|
||||
|
||||
// Create browser that loads the 1st URL.
|
||||
CreateBrowser(url_, context_);
|
||||
|
||||
// Time out the test after a reasonable period of time.
|
||||
SetTestTimeout();
|
||||
}
|
||||
|
||||
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
int httpStatusCode) override {
|
||||
CefRefPtr<CefRequestContext> context =
|
||||
browser->GetHost()->GetRequestContext();
|
||||
EXPECT_TRUE(context.get());
|
||||
EXPECT_TRUE(context->IsSame(context_));
|
||||
EXPECT_FALSE(context->IsGlobal());
|
||||
EXPECT_EQ(context->GetHandler().get(), context_handler_.get());
|
||||
|
||||
FinishTest();
|
||||
}
|
||||
|
||||
protected:
|
||||
void FinishTest() {
|
||||
// Verify that the cookie was set correctly.
|
||||
class TestVisitor : public CefCookieVisitor {
|
||||
public:
|
||||
explicit TestVisitor(CookieTestHandler* handler) : handler_(handler) {}
|
||||
~TestVisitor() override {
|
||||
// Destroy the test.
|
||||
CefPostTask(TID_UI,
|
||||
base::Bind(&CookieTestHandler::DestroyTest, handler_));
|
||||
}
|
||||
|
||||
bool Visit(const CefCookie& cookie,
|
||||
int count,
|
||||
int total,
|
||||
bool& deleteCookie) override {
|
||||
const std::string& name = CefString(&cookie.name);
|
||||
const std::string& value = CefString(&cookie.value);
|
||||
if (name == "name1" && value == "value1")
|
||||
handler_->got_cookie_.yes();
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
CookieTestHandler* handler_;
|
||||
IMPLEMENT_REFCOUNTING(TestVisitor);
|
||||
};
|
||||
|
||||
cookie_manager_->VisitAllCookies(new TestVisitor(this));
|
||||
}
|
||||
|
||||
void DestroyTest() override {
|
||||
// Verify test expectations.
|
||||
EXPECT_TRUE(got_get_cookie_manager_);
|
||||
EXPECT_TRUE(got_cookie_);
|
||||
|
||||
context_handler_->Detach();
|
||||
context_handler_ = NULL;
|
||||
context_ = NULL;
|
||||
|
||||
TestHandler::DestroyTest();
|
||||
}
|
||||
|
||||
std::string url_;
|
||||
CefRefPtr<CefRequestContext> context_;
|
||||
CefRefPtr<RequestContextHandler> context_handler_;
|
||||
CefRefPtr<CefCookieManager> cookie_manager_;
|
||||
|
||||
TrackCallback got_get_cookie_manager_;
|
||||
TrackCallback got_cookie_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(CookieTestHandler);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// Test that the cookie manager is retrieved via the associated request context.
|
||||
TEST(RequestContextTest, GetCookieManager) {
|
||||
CefRefPtr<CookieTestHandler> handler =
|
||||
new CookieTestHandler("http://tests-simple-rch.com/nav1.html");
|
||||
handler->ExecuteTest();
|
||||
ReleaseAndWaitForDestructor(handler);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class PopupTestHandler : public TestHandler {
|
||||
public:
|
||||
class RequestContextHandler : public CefRequestContextHandler {
|
||||
public:
|
||||
explicit RequestContextHandler(PopupTestHandler* handler)
|
||||
: handler_(handler) {}
|
||||
|
||||
CefRefPtr<CefCookieManager> GetCookieManager() override {
|
||||
EXPECT_TRUE(handler_);
|
||||
if (url_ == handler_->url_)
|
||||
handler_->got_get_cookie_manager1_.yes();
|
||||
else if (url_ == handler_->popup_url_)
|
||||
handler_->got_get_cookie_manager2_.yes();
|
||||
return handler_->cookie_manager_;
|
||||
}
|
||||
|
||||
void SetURL(const std::string& url) { url_ = url; }
|
||||
|
||||
void Detach() { handler_ = NULL; }
|
||||
|
||||
private:
|
||||
PopupTestHandler* handler_;
|
||||
std::string url_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(RequestContextHandler);
|
||||
};
|
||||
|
||||
enum Mode {
|
||||
MODE_WINDOW_OPEN,
|
||||
MODE_TARGETED_LINK,
|
||||
@@ -394,11 +244,8 @@ class PopupTestHandler : public TestHandler {
|
||||
|
||||
CefRequestContextSettings settings;
|
||||
|
||||
context_handler_ = new RequestContextHandler(this);
|
||||
context_handler_->SetURL(url_);
|
||||
context_ =
|
||||
CefRequestContext::CreateContext(settings, context_handler_.get());
|
||||
cookie_manager_ = CefCookieManager::CreateManager(CefString(), true, NULL);
|
||||
context_ = CefRequestContext::CreateContext(settings, NULL);
|
||||
cookie_manager_ = context_->GetCookieManager(NULL);
|
||||
|
||||
// Create browser that loads the 1st URL.
|
||||
CreateBrowser(url_, context_);
|
||||
@@ -421,7 +268,6 @@ class PopupTestHandler : public TestHandler {
|
||||
const std::string& url = frame->GetURL();
|
||||
if (url == url_) {
|
||||
got_load_end1_.yes();
|
||||
context_handler_->SetURL(popup_url_);
|
||||
LaunchPopup(browser);
|
||||
} else if (url == popup_url_) {
|
||||
got_load_end2_.yes();
|
||||
@@ -497,10 +343,13 @@ class PopupTestHandler : public TestHandler {
|
||||
bool& deleteCookie) override {
|
||||
const std::string& name = CefString(&cookie.name);
|
||||
const std::string& value = CefString(&cookie.value);
|
||||
if (name == "name1" && value == "value1")
|
||||
if (name == "name1" && value == "value1") {
|
||||
handler_->got_cookie1_.yes();
|
||||
else if (name == "name2" && value == "value2")
|
||||
deleteCookie = true;
|
||||
} else if (name == "name2" && value == "value2") {
|
||||
handler_->got_cookie2_.yes();
|
||||
deleteCookie = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -514,16 +363,11 @@ class PopupTestHandler : public TestHandler {
|
||||
|
||||
void DestroyTest() override {
|
||||
// Verify test expectations.
|
||||
EXPECT_TRUE(got_get_cookie_manager1_);
|
||||
EXPECT_TRUE(got_load_end1_);
|
||||
EXPECT_TRUE(got_on_before_popup_);
|
||||
EXPECT_TRUE(got_get_cookie_manager2_);
|
||||
EXPECT_TRUE(got_load_end2_);
|
||||
EXPECT_TRUE(got_cookie1_);
|
||||
EXPECT_TRUE(got_cookie2_);
|
||||
|
||||
context_handler_->Detach();
|
||||
context_handler_ = NULL;
|
||||
context_ = NULL;
|
||||
|
||||
TestHandler::DestroyTest();
|
||||
@@ -534,13 +378,10 @@ class PopupTestHandler : public TestHandler {
|
||||
Mode mode_;
|
||||
|
||||
CefRefPtr<CefRequestContext> context_;
|
||||
CefRefPtr<RequestContextHandler> context_handler_;
|
||||
CefRefPtr<CefCookieManager> cookie_manager_;
|
||||
|
||||
TrackCallback got_get_cookie_manager1_;
|
||||
TrackCallback got_load_end1_;
|
||||
TrackCallback got_on_before_popup_;
|
||||
TrackCallback got_get_cookie_manager2_;
|
||||
TrackCallback got_load_end2_;
|
||||
TrackCallback got_cookie1_;
|
||||
TrackCallback got_cookie2_;
|
||||
|
||||
Reference in New Issue
Block a user