Structural improvements for request handling (issue #1044)

- Add new CefRequestContext and CefRequestContextHandler classes.
- Add CefRequestContext argument to CefBrowserHost static factory methods.
- Move GetCookieManager from CefRequestHandler to CefRequestContextHandler.
- Use BrowserContext as the root proxy object for network requests.
- Move accessors for CefBrowserMainParts members from CefContext to CefContentBrowserClient.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1424 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2013-09-03 16:43:31 +00:00
parent 935a35f21c
commit 385be456c3
57 changed files with 2288 additions and 440 deletions

View File

@@ -359,7 +359,7 @@ int main(int argc, char* argv[]) {
CefBrowserHost::CreateBrowserSync(
window_info, g_handler.get(),
g_handler->GetStartupURL(), browserSettings);
g_handler->GetStartupURL(), browserSettings, NULL);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show_all(GTK_WIDGET(window));

View File

@@ -360,7 +360,7 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
}
CefBrowserHost::CreateBrowser(window_info, g_handler.get(),
g_handler->GetStartupURL(), settings);
g_handler->GetStartupURL(), settings, NULL);
// Show the window.
[mainWnd makeKeyAndOrderFront: nil];

View File

@@ -329,7 +329,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
// Creat the new child browser window
CefBrowserHost::CreateBrowser(info, g_handler.get(),
g_handler->GetStartupURL(), settings);
g_handler->GetStartupURL(), settings, NULL);
return 0;
}

View File

@@ -659,6 +659,41 @@ const char* kCookieJSUrl2 = "http://tests/cookie2.html";
class CookieTestJSHandler : public TestHandler {
public:
class RequestContextHandler : public CefRequestContextHandler {
public:
explicit RequestContextHandler(CookieTestJSHandler* handler)
: handler_(handler) {}
virtual CefRefPtr<CefCookieManager> GetCookieManager() OVERRIDE {
EXPECT_TRUE(handler_);
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
if (url_ == kCookieJSUrl1) {
// Return the first cookie manager.
handler_->got_cookie_manager1_.yes();
return handler_->manager1_;
} else {
// Return the second cookie manager.
handler_->got_cookie_manager2_.yes();
return handler_->manager2_;
}
}
void SetURL(const std::string& url) {
url_ = url;
}
void Detach() {
handler_ = NULL;
}
private:
std::string url_;
CookieTestJSHandler* handler_;
IMPLEMENT_REFCOUNTING(RequestContextHandler);
};
CookieTestJSHandler() {}
virtual void RunTest() OVERRIDE {
@@ -682,8 +717,12 @@ class CookieTestJSHandler : public TestHandler {
"</head><body>COOKIE TEST2</body></html>";
AddResource(kCookieJSUrl2, page, "text/html");
context_handler_ = new RequestContextHandler(this);
context_handler_->SetURL(kCookieJSUrl1);
// Create the browser
CreateBrowser(kCookieJSUrl1);
CreateBrowser(kCookieJSUrl1,
CefRequestContext::CreateContext(context_handler_.get()));
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
@@ -695,6 +734,7 @@ class CookieTestJSHandler : public TestHandler {
VerifyCookie(manager1_, url, "name1", "value1", got_cookie1_);
// Go to the next URL
context_handler_->SetURL(kCookieJSUrl2);
frame->LoadURL(kCookieJSUrl2);
} else {
got_load_end2_.yes();
@@ -704,18 +744,11 @@ class CookieTestJSHandler : public TestHandler {
}
}
virtual CefRefPtr<CefCookieManager> GetCookieManager(
CefRefPtr<CefBrowser> browser,
const CefString& main_url) OVERRIDE {
if (main_url == kCookieJSUrl1) {
// Return the first cookie manager.
got_cookie_manager1_.yes();
return manager1_;
} else {
// Return the second cookie manager.
got_cookie_manager2_.yes();
return manager2_;
}
virtual void DestroyTest() OVERRIDE {
context_handler_->Detach();
context_handler_ = NULL;
TestHandler::DestroyTest();
}
// Verify that the cookie was set successfully.
@@ -736,6 +769,8 @@ class CookieTestJSHandler : public TestHandler {
}
}
CefRefPtr<RequestContextHandler> context_handler_;
CefRefPtr<CefCookieManager> manager1_;
CefRefPtr<CefCookieManager> manager2_;
@@ -880,6 +915,41 @@ class CookieTestSchemeHandler : public TestHandler {
IMPLEMENT_REFCOUNTING(SchemeHandlerFactory);
};
class RequestContextHandler : public CefRequestContextHandler {
public:
explicit RequestContextHandler(CookieTestSchemeHandler* handler)
: handler_(handler) {}
virtual CefRefPtr<CefCookieManager> GetCookieManager() OVERRIDE {
EXPECT_TRUE(handler_);
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
if (url_ == handler_->url1_) {
// Return the first cookie manager.
handler_->got_cookie_manager1_.yes();
return handler_->manager1_;
} else {
// Return the second cookie manager.
handler_->got_cookie_manager2_.yes();
return handler_->manager2_;
}
}
void SetURL(const std::string& url) {
url_ = url;
}
void Detach() {
handler_ = NULL;
}
private:
std::string url_;
CookieTestSchemeHandler* handler_;
IMPLEMENT_REFCOUNTING(RequestContextHandler);
};
CookieTestSchemeHandler(const std::string& scheme) : scheme_(scheme) {
url1_ = scheme + "://cookie-tests/cookie1.html";
url2_ = scheme + "://cookie-tests/cookie2.html";
@@ -905,8 +975,12 @@ class CookieTestSchemeHandler : public TestHandler {
CefRegisterSchemeHandlerFactory(scheme_, "cookie-tests",
new SchemeHandlerFactory(this));
context_handler_ = new RequestContextHandler(this);
context_handler_->SetURL(url1_);
// Create the browser
CreateBrowser(url1_);
CreateBrowser(url1_,
CefRequestContext::CreateContext(context_handler_.get()));
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
@@ -918,12 +992,14 @@ class CookieTestSchemeHandler : public TestHandler {
VerifyCookie(manager1_, url, "name1", "value1", got_cookie1_);
// Go to the next URL
context_handler_->SetURL(url2_);
frame->LoadURL(url2_);
} else if (url == url2_) {
got_load_end2_.yes();
VerifyCookie(manager2_, url, "name2", "value2", got_cookie2_);
// Go to the next URL
context_handler_->SetURL(url3_);
frame->LoadURL(url3_);
} else {
got_load_end3_.yes();
@@ -936,19 +1012,12 @@ class CookieTestSchemeHandler : public TestHandler {
}
}
virtual CefRefPtr<CefCookieManager> GetCookieManager(
CefRefPtr<CefBrowser> browser,
const CefString& main_url) OVERRIDE {
if (main_url == url1_) {
// Return the first cookie manager.
got_cookie_manager1_.yes();
return manager1_;
} else {
// Return the second cookie manager.
got_cookie_manager2_.yes();
return manager2_;
}
}
virtual void DestroyTest() OVERRIDE {
context_handler_->Detach();
context_handler_ = NULL;
TestHandler::DestroyTest();
}
// Verify that the cookie was set successfully.
void VerifyCookie(CefRefPtr<CefCookieManager> manager,
@@ -973,6 +1042,8 @@ class CookieTestSchemeHandler : public TestHandler {
std::string url2_;
std::string url3_;
CefRefPtr<RequestContextHandler> context_handler_;
CefRefPtr<CefCookieManager> manager1_;
CefRefPtr<CefCookieManager> manager2_;

View File

@@ -845,7 +845,7 @@ class OSRTestHandler : public TestHandler,
#endif
if (test_type_ == OSR_TEST_TRANSPARENCY)
windowInfo.SetTransparentPainting(TRUE);
CefBrowserHost::CreateBrowser(windowInfo, this, url, settings);
CefBrowserHost::CreateBrowser(windowInfo, this, url, settings, NULL);
}
bool IsFullRepaint(const CefRect& rc, int width = kOsrWidth,

View File

@@ -0,0 +1,472 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "tests/unittests/test_handler.h"
#include "include/cef_request_context.h"
#include "include/cef_request_context_handler.h"
#include "include/cef_runnable.h"
#include "testing/gtest/include/gtest/gtest.h"
TEST(RequestContextTest, GetGlobalContext) {
CefRefPtr<CefRequestContext> context1 =
CefRequestContext::GetGlobalContext();
EXPECT_TRUE(context1.get());
EXPECT_TRUE(context1->IsGlobal());
EXPECT_TRUE(context1->IsSame(context1));
CefRefPtr<CefRequestContext> context2 =
CefRequestContext::GetGlobalContext();
EXPECT_TRUE(context2.get());
EXPECT_TRUE(context2->IsGlobal());
EXPECT_TRUE(context2->IsSame(context2));
EXPECT_TRUE(context1->IsSame(context2));
EXPECT_TRUE(context2->IsSame(context1));
}
TEST(RequestContextTest, CreateContext) {
class Handler : public CefRequestContextHandler {
public:
Handler() {}
virtual CefRefPtr<CefCookieManager> GetCookieManager() { return NULL; }
private:
IMPLEMENT_REFCOUNTING(Handler);
};
CefRefPtr<Handler> handler = new Handler();
CefRefPtr<CefRequestContext> context1 =
CefRequestContext::CreateContext(handler.get());
EXPECT_TRUE(context1.get());
EXPECT_FALSE(context1->IsGlobal());
EXPECT_TRUE(context1->IsSame(context1));
EXPECT_EQ(context1->GetHandler().get(), handler.get());
CefRefPtr<CefRequestContext> context2 =
CefRequestContext::CreateContext(handler.get());
EXPECT_TRUE(context2.get());
EXPECT_FALSE(context2->IsGlobal());
EXPECT_TRUE(context2->IsSame(context2));
EXPECT_EQ(context2->GetHandler().get(), handler.get());
EXPECT_FALSE(context1->IsSame(context2));
EXPECT_FALSE(context2->IsSame(context1));
CefRefPtr<CefRequestContext> context3 =
CefRequestContext::GetGlobalContext();
EXPECT_TRUE(context3.get());
EXPECT_FALSE(context3->IsSame(context1));
EXPECT_FALSE(context3->IsSame(context2));
EXPECT_FALSE(context1->IsSame(context3));
EXPECT_FALSE(context2->IsSame(context3));
}
TEST(RequestContextTest, CreateContextNoHandler) {
CefRefPtr<CefRequestContext> context1 =
CefRequestContext::CreateContext(NULL);
EXPECT_TRUE(context1.get());
EXPECT_FALSE(context1->IsGlobal());
EXPECT_TRUE(context1->IsSame(context1));
EXPECT_FALSE(context1->GetHandler().get());
CefRefPtr<CefRequestContext> context2 =
CefRequestContext::CreateContext(NULL);
EXPECT_TRUE(context2.get());
EXPECT_FALSE(context2->IsGlobal());
EXPECT_TRUE(context2->IsSame(context2));
EXPECT_FALSE(context2->GetHandler().get());
EXPECT_FALSE(context1->IsSame(context2));
EXPECT_FALSE(context2->IsSame(context1));
CefRefPtr<CefRequestContext> context3 =
CefRequestContext::GetGlobalContext();
EXPECT_TRUE(context3.get());
EXPECT_FALSE(context3->IsSame(context1));
EXPECT_FALSE(context3->IsSame(context2));
EXPECT_FALSE(context1->IsSame(context3));
EXPECT_FALSE(context2->IsSame(context3));
}
namespace {
class CookieTestHandler : public TestHandler {
public:
class RequestContextHandler : public CefRequestContextHandler {
public:
explicit RequestContextHandler(CookieTestHandler* handler)
: handler_(handler) {}
virtual 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) {}
virtual void RunTest() OVERRIDE {
AddResource(url_,
"<html>"
"<head><script>document.cookie='name1=value1';</script></head>"
"<body>Nav1</body>"
"</html>", "text/html");
context_handler_ = new RequestContextHandler(this);
context_ = CefRequestContext::CreateContext(context_handler_.get());
cookie_manager_ = CefCookieManager::CreateManager(CefString(), true);
// Create browser that loads the 1st URL.
CreateBrowser(url_, context_);
}
virtual 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) {
}
virtual ~TestVisitor() {
// Destroy the test.
CefPostTask(TID_UI,
NewCefRunnableMethod(handler_, &CookieTestHandler::DestroyTest));
}
virtual bool Visit(const CefCookie& cookie, int count, int total,
bool& deleteCookie) {
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));
}
virtual 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_;
};
} // 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();
}
namespace {
class PopupTestHandler : public TestHandler {
public:
class RequestContextHandler : public CefRequestContextHandler {
public:
explicit RequestContextHandler(PopupTestHandler* handler)
: handler_(handler) {}
virtual 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,
MODE_NOREFERRER_LINK,
};
PopupTestHandler(bool same_origin,
Mode mode)
: mode_(mode) {
url_ = "http://tests-simple-rch1.com/nav1.html";
if (same_origin)
popup_url_ = "http://tests-simple-rch1.com/pop1.html";
else
popup_url_ = "http://tests-simple-rch2.com/pop1.html";
}
virtual void RunTest() OVERRIDE {
std::string link;
if (mode_ == MODE_TARGETED_LINK) {
link = "<a href=\"" + std::string(popup_url_) +
"\" target=\"mytarget\"\">CLICK ME</a>";
} else if (mode_ == MODE_NOREFERRER_LINK) {
link = "<a href=\"" + std::string(popup_url_) +
"\" rel=\"noreferrer\" target=\"_blank\"\">CLICK ME</a>";
}
AddResource(url_,
"<html>"
"<head><script>document.cookie='name1=value1';"
"function doPopup() { window.open('" + std::string(popup_url_) + "'); }"
"</script></head>"
"<body><h1>" + link + "</h1></body>"
"</html>", "text/html");
AddResource(popup_url_,
"<html>"
"<head><script>document.cookie='name2=value2';</script></head>"
"<body>Nav1</body>"
"</html>", "text/html");
context_handler_ = new RequestContextHandler(this);
context_handler_->SetURL(url_);
context_ = CefRequestContext::CreateContext(context_handler_.get());
cookie_manager_ = CefCookieManager::CreateManager(CefString(), true);
// Create browser that loads the 1st URL.
CreateBrowser(url_, context_);
}
virtual 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_TRUE(frame->IsMain());
const std::string& url = frame->GetURL();
if (url == url_) {
got_load_end1_.yes();
context_handler_->SetURL(popup_url_);
LaunchPopup(browser);
} if (url == popup_url_) {
got_load_end2_.yes();
EXPECT_TRUE(browser->IsPopup());
// Close the popup window.
browser->GetHost()->CloseBrowser(true);
}
}
virtual bool OnBeforePopup(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& target_url,
const CefString& target_frame_name,
const CefPopupFeatures& popupFeatures,
CefWindowInfo& windowInfo,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings,
bool* no_javascript_access) OVERRIDE {
got_on_before_popup_.yes();
const std::string& url = target_url;
EXPECT_STREQ(url.c_str(), popup_url_.c_str());
return false;
}
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) {
TestHandler::OnBeforeClose(browser);
if (browser->IsPopup())
FinishTest();
}
protected:
void LaunchPopup(CefRefPtr<CefBrowser> browser) {
if (mode_ == MODE_WINDOW_OPEN) {
browser->GetMainFrame()->ExecuteJavaScript("doPopup()", url_, 0);
} else if (mode_ == MODE_TARGETED_LINK ||
mode_ == MODE_NOREFERRER_LINK) {
CefMouseEvent mouse_event;
mouse_event.x = 20;
mouse_event.y = 20;
mouse_event.modifiers = 0;
browser->GetHost()->SendMouseClickEvent(
mouse_event, MBT_LEFT, false, 1);
browser->GetHost()->SendMouseClickEvent(
mouse_event, MBT_LEFT, true, 1);
} else {
EXPECT_TRUE(false); // Not reached.
}
}
void FinishTest() {
// Verify that the cookies were set correctly.
class TestVisitor : public CefCookieVisitor {
public:
explicit TestVisitor(PopupTestHandler* handler)
: handler_(handler) {
}
virtual ~TestVisitor() {
// Destroy the test.
CefPostTask(TID_UI,
NewCefRunnableMethod(handler_, &PopupTestHandler::DestroyTest));
}
virtual bool Visit(const CefCookie& cookie, int count, int total,
bool& deleteCookie) {
const std::string& name = CefString(&cookie.name);
const std::string& value = CefString(&cookie.value);
if (name == "name1" && value == "value1")
handler_->got_cookie1_.yes();
else if (name == "name2" && value == "value2")
handler_->got_cookie2_.yes();
return true;
}
private:
PopupTestHandler* handler_;
IMPLEMENT_REFCOUNTING(TestVisitor);
};
cookie_manager_->VisitAllCookies(new TestVisitor(this));
}
virtual 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();
}
std::string url_;
std::string popup_url_;
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_;
};
} // namespace
// Test that a popup created using window.open() will get the same request
// context as the parent browser.
TEST(RequestContextTest, WindowOpenSameOrigin) {
CefRefPtr<PopupTestHandler> handler =
new PopupTestHandler(true,
PopupTestHandler::MODE_WINDOW_OPEN);
handler->ExecuteTest();
}
TEST(RequestContextTest, WindowOpenDifferentOrigin) {
CefRefPtr<PopupTestHandler> handler =
new PopupTestHandler(false,
PopupTestHandler::MODE_WINDOW_OPEN);
handler->ExecuteTest();
}
// Test that a popup created using a targeted link will get the same request
// context as the parent browser.
TEST(RequestContextTest, TargetedLinkSameOrigin) {
CefRefPtr<PopupTestHandler> handler =
new PopupTestHandler(true,
PopupTestHandler::MODE_TARGETED_LINK);
handler->ExecuteTest();
}
TEST(RequestContextTest, TargetedLinkDifferentOrigin) {
CefRefPtr<PopupTestHandler> handler =
new PopupTestHandler(false,
PopupTestHandler::MODE_TARGETED_LINK);
handler->ExecuteTest();
}
// Test that a popup created using a noreferrer link will get the same
// request context as the parent browser. A new render process will
// be created for the popup browser.
TEST(RequestContextTest, NoReferrerLinkSameOrigin) {
CefRefPtr<PopupTestHandler> handler =
new PopupTestHandler(true,
PopupTestHandler::MODE_NOREFERRER_LINK);
handler->ExecuteTest();
}
TEST(RequestContextTest, NoReferrerLinkDifferentOrigin) {
CefRefPtr<PopupTestHandler> handler =
new PopupTestHandler(false,
PopupTestHandler::MODE_NOREFERRER_LINK);
handler->ExecuteTest();
}

View File

@@ -26,6 +26,40 @@ const char kNetNotifyMsg[] = "RequestHandlerTest.NetNotify";
// Browser side.
class NetNotifyTestHandler : public TestHandler {
public:
class RequestContextHandler : public CefRequestContextHandler {
public:
explicit RequestContextHandler(NetNotifyTestHandler* handler)
: handler_(handler) {}
virtual CefRefPtr<CefCookieManager> GetCookieManager() OVERRIDE {
EXPECT_TRUE(handler_);
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
if (url_.find(handler_->url1_) == 0)
handler_->got_get_cookie_manager1_.yes();
else if (url_.find(handler_->url2_) == 0)
handler_->got_get_cookie_manager2_.yes();
else
EXPECT_TRUE(false); // Not reached
return handler_->cookie_manager_;
}
void SetURL(const std::string& url) {
url_ = url;
}
void Detach() {
handler_ = NULL;
}
private:
std::string url_;
NetNotifyTestHandler* handler_;
IMPLEMENT_REFCOUNTING(RequestContextHandler);
};
NetNotifyTestHandler(CompletionState* completion_state,
NetNotifyTestType test_type,
bool same_origin)
@@ -52,12 +86,17 @@ class NetNotifyTestHandler : public TestHandler {
"<body>Nav2</body>"
"</html>", "text/html");
context_handler_ = new RequestContextHandler(this);
context_handler_->SetURL(url1_);
// Create browser that loads the 1st URL.
CreateBrowser(url1_);
CreateBrowser(url1_,
CefRequestContext::CreateContext(context_handler_.get()));
}
virtual void RunTest() OVERRIDE {
// Navigate to the 2nd URL.
context_handler_->SetURL(url2_);
GetBrowser()->GetMainFrame()->LoadURL(url2_);
}
@@ -94,22 +133,6 @@ class NetNotifyTestHandler : public TestHandler {
return TestHandler::GetResourceHandler(browser, frame, request);
}
virtual CefRefPtr<CefCookieManager> GetCookieManager(
CefRefPtr<CefBrowser> browser,
const CefString& main_url) OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
const std::string& url = main_url;
if (url.find(url1_) == 0)
got_get_cookie_manager1_.yes();
else if (url.find(url2_) == 0)
got_get_cookie_manager2_.yes();
else
EXPECT_TRUE(false); // Not reached
return cookie_manager_;
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE {
@@ -227,8 +250,10 @@ class NetNotifyTestHandler : public TestHandler {
EXPECT_FALSE(got_process_message2_) << " browser " << browser_id;
}
context_handler_->Detach();
context_handler_ = NULL;
cookie_manager_ = NULL;
TestHandler::DestroyTest();
}
@@ -237,6 +262,8 @@ class NetNotifyTestHandler : public TestHandler {
std::string url1_;
std::string url2_;
CefRefPtr<RequestContextHandler> context_handler_;
CefRefPtr<CefCookieManager> cookie_manager_;
TrackCallback got_load_end1_;

View File

@@ -171,14 +171,17 @@ void TestHandler::DestroyTest() {
browser_->GetHost()->CloseBrowser(false);
}
void TestHandler::CreateBrowser(const CefString& url) {
void TestHandler::CreateBrowser(
const CefString& url,
CefRefPtr<CefRequestContext> request_context) {
CefWindowInfo windowInfo;
CefBrowserSettings settings;
#if defined(OS_WIN)
windowInfo.SetAsPopup(NULL, "CefUnitTest");
windowInfo.style |= WS_VISIBLE;
#endif
CefBrowserHost::CreateBrowser(windowInfo, this, url, settings);
CefBrowserHost::CreateBrowser(windowInfo, this, url, settings,
request_context);
}
void TestHandler::AddResource(const std::string& url,

View File

@@ -170,7 +170,8 @@ class TestHandler : public CefClient,
// will be signaled.
virtual void DestroyTest();
void CreateBrowser(const CefString& url);
void CreateBrowser(const CefString& url,
CefRefPtr<CefRequestContext> request_context = NULL);
void AddResource(const std::string& url,
const std::string& content,