Remove CefRenderProcessHandler::OnBeforeNavigation (issue #1076).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1443 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
71125f76d8
commit
8adb86e7e6
1
cef.gyp
1
cef.gyp
|
@ -1265,7 +1265,6 @@
|
|||
'tests/unittests/navigation_unittest.cc',
|
||||
'tests/unittests/process_message_unittest.cc',
|
||||
'tests/unittests/request_handler_unittest.cc',
|
||||
'tests/unittests/request_unittest.cc',
|
||||
'tests/unittests/scheme_handler_unittest.cc',
|
||||
'tests/unittests/urlrequest_unittest.cc',
|
||||
'tests/unittests/test_handler.cc',
|
||||
|
|
|
@ -94,17 +94,6 @@ typedef struct _cef_render_process_handler_t {
|
|||
struct _cef_load_handler_t* (CEF_CALLBACK *get_load_handler)(
|
||||
struct _cef_render_process_handler_t* self);
|
||||
|
||||
///
|
||||
// Called before browser navigation. Return true (1) to cancel the navigation
|
||||
// or false (0) to allow the navigation to proceed. The |request| object
|
||||
// cannot be modified in this callback.
|
||||
///
|
||||
int (CEF_CALLBACK *on_before_navigation)(
|
||||
struct _cef_render_process_handler_t* self,
|
||||
struct _cef_browser_t* browser, struct _cef_frame_t* frame,
|
||||
struct _cef_request_t* request,
|
||||
enum cef_navigation_type_t navigation_type, int is_redirect);
|
||||
|
||||
///
|
||||
// Called immediately after the V8 context for a frame has been created. To
|
||||
// retrieve the JavaScript 'window' object use the
|
||||
|
|
|
@ -55,8 +55,6 @@
|
|||
/*--cef(source=client)--*/
|
||||
class CefRenderProcessHandler : public virtual CefBase {
|
||||
public:
|
||||
typedef cef_navigation_type_t NavigationType;
|
||||
|
||||
///
|
||||
// Called after the render process main thread has been created. |extra_info|
|
||||
// is a read-only value originating from
|
||||
|
@ -94,18 +92,6 @@ class CefRenderProcessHandler : public virtual CefBase {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
///
|
||||
// Called before browser navigation. Return true to cancel the navigation or
|
||||
// false to allow the navigation to proceed. The |request| object cannot be
|
||||
// modified in this callback.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual bool OnBeforeNavigation(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
NavigationType navigation_type,
|
||||
bool is_redirect) { return false; }
|
||||
|
||||
///
|
||||
// Called immediately after the V8 context for a frame has been created. To
|
||||
// retrieve the JavaScript 'window' object use the CefV8Context::GetGlobal()
|
||||
|
|
|
@ -1486,18 +1486,6 @@ enum cef_focus_source_t {
|
|||
FOCUS_SOURCE_SYSTEM,
|
||||
};
|
||||
|
||||
///
|
||||
// Navigation types.
|
||||
///
|
||||
enum cef_navigation_type_t {
|
||||
NAVIGATION_LINK_CLICKED = 0,
|
||||
NAVIGATION_FORM_SUBMITTED,
|
||||
NAVIGATION_BACK_FORWARD,
|
||||
NAVIGATION_RELOAD,
|
||||
NAVIGATION_FORM_RESUBMITTED,
|
||||
NAVIGATION_OTHER,
|
||||
};
|
||||
|
||||
///
|
||||
// Supported XML encoding types. The parser supports ASCII, ISO-8859-1, and
|
||||
// UTF16 (LE and BE) by default. All other types must be translated to UTF8
|
||||
|
|
|
@ -19,7 +19,6 @@ MSVC_POP_WARNING();
|
|||
#include "libcef/common/cef_messages.h"
|
||||
#include "libcef/common/cef_switches.h"
|
||||
#include "libcef/common/content_client.h"
|
||||
#include "libcef/common/request_impl.h"
|
||||
#include "libcef/common/values_impl.h"
|
||||
#include "libcef/renderer/browser_impl.h"
|
||||
#include "libcef/renderer/chrome_bindings.h"
|
||||
|
@ -532,62 +531,6 @@ bool CefContentRendererClient::OverrideCreatePlugin(
|
|||
return false;
|
||||
}
|
||||
|
||||
bool CefContentRendererClient::HandleNavigation(
|
||||
WebKit::WebFrame* frame,
|
||||
const WebKit::WebURLRequest& request,
|
||||
WebKit::WebNavigationType type,
|
||||
WebKit::WebNavigationPolicy default_policy,
|
||||
bool is_redirect) {
|
||||
CefRefPtr<CefApp> application = CefContentClient::Get()->application();
|
||||
if (application.get()) {
|
||||
CefRefPtr<CefRenderProcessHandler> handler =
|
||||
application->GetRenderProcessHandler();
|
||||
if (handler.get()) {
|
||||
CefRefPtr<CefBrowserImpl> browserPtr =
|
||||
CefBrowserImpl::GetBrowserForMainFrame(frame->top());
|
||||
DCHECK(browserPtr.get());
|
||||
if (browserPtr.get()) {
|
||||
CefRefPtr<CefFrameImpl> framePtr = browserPtr->GetWebFrameImpl(frame);
|
||||
CefRefPtr<CefRequest> requestPtr(CefRequest::Create());
|
||||
CefRequestImpl* requestImpl =
|
||||
static_cast<CefRequestImpl*>(requestPtr.get());
|
||||
requestImpl->Set(request);
|
||||
requestImpl->SetReadOnly(true);
|
||||
|
||||
cef_navigation_type_t navigation_type = NAVIGATION_OTHER;
|
||||
switch (type) {
|
||||
case WebKit::WebNavigationTypeLinkClicked:
|
||||
navigation_type = NAVIGATION_LINK_CLICKED;
|
||||
break;
|
||||
case WebKit::WebNavigationTypeFormSubmitted:
|
||||
navigation_type = NAVIGATION_FORM_SUBMITTED;
|
||||
break;
|
||||
case WebKit::WebNavigationTypeBackForward:
|
||||
navigation_type = NAVIGATION_BACK_FORWARD;
|
||||
break;
|
||||
case WebKit::WebNavigationTypeReload:
|
||||
navigation_type = NAVIGATION_RELOAD;
|
||||
break;
|
||||
case WebKit::WebNavigationTypeFormResubmitted:
|
||||
navigation_type = NAVIGATION_FORM_RESUBMITTED;
|
||||
break;
|
||||
case WebKit::WebNavigationTypeOther:
|
||||
navigation_type = NAVIGATION_OTHER;
|
||||
break;
|
||||
}
|
||||
|
||||
if (handler->OnBeforeNavigation(browserPtr.get(), framePtr.get(),
|
||||
requestPtr.get(), navigation_type,
|
||||
is_redirect)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CefContentRendererClient::DidCreateScriptContext(
|
||||
WebKit::WebFrame* frame, v8::Handle<v8::Context> context,
|
||||
int extension_group, int world_id) {
|
||||
|
|
|
@ -81,11 +81,6 @@ class CefContentRendererClient : public content::ContentRendererClient,
|
|||
WebKit::WebFrame* frame,
|
||||
const WebKit::WebPluginParams& params,
|
||||
WebKit::WebPlugin** plugin) OVERRIDE;
|
||||
virtual bool HandleNavigation(WebKit::WebFrame* frame,
|
||||
const WebKit::WebURLRequest& request,
|
||||
WebKit::WebNavigationType type,
|
||||
WebKit::WebNavigationPolicy default_policy,
|
||||
bool is_redirect) OVERRIDE;
|
||||
virtual void DidCreateScriptContext(WebKit::WebFrame* frame,
|
||||
v8::Handle<v8::Context> context,
|
||||
int extension_group,
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include "libcef_dll/ctocpp/frame_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/list_value_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/process_message_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/request_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/v8context_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/v8exception_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/v8stack_trace_ctocpp.h"
|
||||
|
@ -105,40 +104,6 @@ cef_load_handler_t* CEF_CALLBACK render_process_handler_get_load_handler(
|
|||
return CefLoadHandlerCppToC::Wrap(_retval);
|
||||
}
|
||||
|
||||
int CEF_CALLBACK render_process_handler_on_before_navigation(
|
||||
struct _cef_render_process_handler_t* self, cef_browser_t* browser,
|
||||
cef_frame_t* frame, struct _cef_request_t* request,
|
||||
enum cef_navigation_type_t navigation_type, int is_redirect) {
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return 0;
|
||||
// Verify param: browser; type: refptr_diff
|
||||
DCHECK(browser);
|
||||
if (!browser)
|
||||
return 0;
|
||||
// Verify param: frame; type: refptr_diff
|
||||
DCHECK(frame);
|
||||
if (!frame)
|
||||
return 0;
|
||||
// Verify param: request; type: refptr_diff
|
||||
DCHECK(request);
|
||||
if (!request)
|
||||
return 0;
|
||||
|
||||
// Execute
|
||||
bool _retval = CefRenderProcessHandlerCppToC::Get(self)->OnBeforeNavigation(
|
||||
CefBrowserCToCpp::Wrap(browser),
|
||||
CefFrameCToCpp::Wrap(frame),
|
||||
CefRequestCToCpp::Wrap(request),
|
||||
navigation_type,
|
||||
is_redirect?true:false);
|
||||
|
||||
// Return type: bool
|
||||
return _retval;
|
||||
}
|
||||
|
||||
void CEF_CALLBACK render_process_handler_on_context_created(
|
||||
struct _cef_render_process_handler_t* self, cef_browser_t* browser,
|
||||
cef_frame_t* frame, struct _cef_v8context_t* context) {
|
||||
|
@ -300,8 +265,6 @@ CefRenderProcessHandlerCppToC::CefRenderProcessHandlerCppToC(
|
|||
struct_.struct_.on_browser_destroyed =
|
||||
render_process_handler_on_browser_destroyed;
|
||||
struct_.struct_.get_load_handler = render_process_handler_get_load_handler;
|
||||
struct_.struct_.on_before_navigation =
|
||||
render_process_handler_on_before_navigation;
|
||||
struct_.struct_.on_context_created =
|
||||
render_process_handler_on_context_created;
|
||||
struct_.struct_.on_context_released =
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "libcef_dll/cpptoc/frame_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/list_value_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/process_message_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/request_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/v8context_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/v8exception_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/v8stack_trace_cpptoc.h"
|
||||
|
@ -99,40 +98,6 @@ CefRefPtr<CefLoadHandler> CefRenderProcessHandlerCToCpp::GetLoadHandler() {
|
|||
return CefLoadHandlerCToCpp::Wrap(_retval);
|
||||
}
|
||||
|
||||
bool CefRenderProcessHandlerCToCpp::OnBeforeNavigation(
|
||||
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request, NavigationType navigation_type,
|
||||
bool is_redirect) {
|
||||
if (CEF_MEMBER_MISSING(struct_, on_before_navigation))
|
||||
return false;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: browser; type: refptr_diff
|
||||
DCHECK(browser.get());
|
||||
if (!browser.get())
|
||||
return false;
|
||||
// Verify param: frame; type: refptr_diff
|
||||
DCHECK(frame.get());
|
||||
if (!frame.get())
|
||||
return false;
|
||||
// Verify param: request; type: refptr_diff
|
||||
DCHECK(request.get());
|
||||
if (!request.get())
|
||||
return false;
|
||||
|
||||
// Execute
|
||||
int _retval = struct_->on_before_navigation(struct_,
|
||||
CefBrowserCppToC::Wrap(browser),
|
||||
CefFrameCppToC::Wrap(frame),
|
||||
CefRequestCppToC::Wrap(request),
|
||||
navigation_type,
|
||||
is_redirect);
|
||||
|
||||
// Return type: bool
|
||||
return _retval?true:false;
|
||||
}
|
||||
|
||||
void CefRenderProcessHandlerCToCpp::OnContextCreated(
|
||||
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context) {
|
||||
|
|
|
@ -40,9 +40,6 @@ class CefRenderProcessHandlerCToCpp
|
|||
virtual void OnBrowserCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
virtual void OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE;
|
||||
virtual bool OnBeforeNavigation(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request,
|
||||
NavigationType navigation_type, bool is_redirect) OVERRIDE;
|
||||
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) OVERRIDE;
|
||||
virtual void OnContextReleased(CefRefPtr<CefBrowser> browser,
|
||||
|
|
|
@ -289,22 +289,6 @@ CefRefPtr<CefLoadHandler> ClientApp::GetLoadHandler() {
|
|||
return load_handler;
|
||||
}
|
||||
|
||||
bool ClientApp::OnBeforeNavigation(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
NavigationType navigation_type,
|
||||
bool is_redirect) {
|
||||
RenderDelegateSet::iterator it = render_delegates_.begin();
|
||||
for (; it != render_delegates_.end(); ++it) {
|
||||
if ((*it)->OnBeforeNavigation(this, browser, frame, request,
|
||||
navigation_type, is_redirect)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ClientApp::OnContextCreated(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context) {
|
||||
|
|
|
@ -55,15 +55,6 @@ class ClientApp : public CefApp,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
virtual bool OnBeforeNavigation(CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
cef_navigation_type_t navigation_type,
|
||||
bool is_redirect) {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void OnContextCreated(CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
|
@ -156,11 +147,6 @@ class ClientApp : public CefApp,
|
|||
virtual void OnBrowserCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
virtual void OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE;
|
||||
virtual bool OnBeforeNavigation(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
NavigationType navigation_type,
|
||||
bool is_redirect) OVERRIDE;
|
||||
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context) OVERRIDE;
|
||||
|
|
|
@ -13,6 +13,10 @@ void ClientApp::CreateBrowserDelegates(BrowserDelegateSet& delegates) {
|
|||
// Bring in the Navigation tests.
|
||||
extern void CreateNavigationBrowserTests(BrowserDelegateSet& delegates);
|
||||
CreateNavigationBrowserTests(delegates);
|
||||
|
||||
// Bring in the RequestHandler tests.
|
||||
extern void CreateRequestHandlerBrowserTests(BrowserDelegateSet& delegates);
|
||||
CreateRequestHandlerBrowserTests(delegates);
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -38,10 +42,6 @@ void ClientApp::CreateRenderDelegates(RenderDelegateSet& delegates) {
|
|||
extern void CreateNavigationRendererTests(RenderDelegateSet& delegates);
|
||||
CreateNavigationRendererTests(delegates);
|
||||
|
||||
// Bring in the Request tests.
|
||||
extern void CreateRequestRendererTests(RenderDelegateSet& delegates);
|
||||
CreateRequestRendererTests(delegates);
|
||||
|
||||
// Bring in the RequestHandler tests.
|
||||
extern void CreateRequestHandlerRendererTests(RenderDelegateSet& delegates);
|
||||
CreateRequestHandlerRendererTests(delegates);
|
||||
|
|
|
@ -166,40 +166,6 @@ class HistoryNavRendererTest : public ClientApp::RenderDelegate,
|
|||
SendTestResultsIfDone(browser);
|
||||
}
|
||||
|
||||
virtual bool OnBeforeNavigation(CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
cef_navigation_type_t navigation_type,
|
||||
bool is_redirect) OVERRIDE {
|
||||
if (!run_test_)
|
||||
return false;
|
||||
|
||||
const NavListItem& item = kHNavList[nav_];
|
||||
|
||||
std::string url = request->GetURL();
|
||||
EXPECT_STREQ(item.target, url.c_str());
|
||||
|
||||
EXPECT_EQ(RT_SUB_RESOURCE, request->GetResourceType());
|
||||
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
|
||||
|
||||
if (item.action == NA_LOAD)
|
||||
EXPECT_EQ(NAVIGATION_OTHER, navigation_type);
|
||||
else if (item.action == NA_BACK || item.action == NA_FORWARD)
|
||||
EXPECT_EQ(NAVIGATION_BACK_FORWARD, navigation_type);
|
||||
|
||||
if (nav_ > 0) {
|
||||
const NavListItem& last_item = kHNavList[nav_ - 1];
|
||||
EXPECT_EQ(last_item.can_go_back, browser->CanGoBack());
|
||||
EXPECT_EQ(last_item.can_go_forward, browser->CanGoForward());
|
||||
} else {
|
||||
EXPECT_FALSE(browser->CanGoBack());
|
||||
EXPECT_FALSE(browser->CanGoForward());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
void SendTestResultsIfDone(CefRefPtr<CefBrowser> browser) {
|
||||
if (got_load_end_ && got_loading_state_end_)
|
||||
|
|
|
@ -23,6 +23,27 @@ const char kNetNotifyOrigin1[] = "http://tests-netnotify1/";
|
|||
const char kNetNotifyOrigin2[] = "http://tests-netnotify2/";
|
||||
const char kNetNotifyMsg[] = "RequestHandlerTest.NetNotify";
|
||||
|
||||
bool g_net_notify_test = false;
|
||||
|
||||
// Browser side.
|
||||
class NetNotifyBrowserTest : public ClientApp::BrowserDelegate {
|
||||
public:
|
||||
NetNotifyBrowserTest() {}
|
||||
|
||||
virtual void OnBeforeChildProcessLaunch(
|
||||
CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefCommandLine> command_line) OVERRIDE {
|
||||
if (!g_net_notify_test)
|
||||
return;
|
||||
|
||||
// Indicate to the render process that the test should be run.
|
||||
command_line->AppendSwitchWithValue("test", kNetNotifyMsg);
|
||||
}
|
||||
|
||||
protected:
|
||||
IMPLEMENT_REFCOUNTING(HistoryNavBrowserTest);
|
||||
};
|
||||
|
||||
// Browser side.
|
||||
class NetNotifyTestHandler : public TestHandler {
|
||||
public:
|
||||
|
@ -133,16 +154,66 @@ class NetNotifyTestHandler : public TestHandler {
|
|||
return TestHandler::GetResourceHandler(browser, frame, request);
|
||||
}
|
||||
|
||||
virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
bool is_redirect) OVERRIDE {
|
||||
std::string url = request->GetURL();
|
||||
|
||||
// Check if the load has already been delayed.
|
||||
bool delay_loaded = (url.find("delayed=true") != std::string::npos);
|
||||
|
||||
if (url.find(url1_) == 0) {
|
||||
got_before_browse1_.yes();
|
||||
EXPECT_FALSE(delay_loaded);
|
||||
} else if (url.find(url2_) == 0) {
|
||||
got_before_browse2_.yes();
|
||||
if (delay_loaded) {
|
||||
got_before_browse2_delayed_.yes();
|
||||
} else if (test_type_ == NNTT_DELAYED_RENDERER ||
|
||||
test_type_ == NNTT_DELAYED_BROWSER) {
|
||||
got_before_browse2_will_delay_.yes();
|
||||
|
||||
// Navigating cross-origin from the browser process will cause a new
|
||||
// render process to be created. We therefore need some information in
|
||||
// the request itself to tell us that the navigation has already been
|
||||
// delayed.
|
||||
url += "&delayed=true";
|
||||
|
||||
if (test_type_ == NNTT_DELAYED_RENDERER) {
|
||||
// Load the URL from the render process.
|
||||
CefRefPtr<CefProcessMessage> message =
|
||||
CefProcessMessage::Create(kNetNotifyMsg);
|
||||
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
||||
args->SetInt(0, test_type_);
|
||||
args->SetString(1, url);
|
||||
EXPECT_TRUE(browser->SendProcessMessage(PID_RENDERER, message));
|
||||
} else {
|
||||
// Load the URL from the browser process.
|
||||
browser->GetMainFrame()->LoadURL(url);
|
||||
}
|
||||
|
||||
// Cancel the load.
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
EXPECT_TRUE(false); // Not reached
|
||||
}
|
||||
|
||||
// Allow the load to continue.
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
int httpStatusCode) OVERRIDE {
|
||||
const std::string& url = frame->GetURL();
|
||||
if (url.find(url1_) == 0) {
|
||||
got_load_end1_.yes();
|
||||
SetupComplete();
|
||||
SetupCompleteIfDone();
|
||||
} else if (url.find(url2_) == 0) {
|
||||
got_load_end2_.yes();
|
||||
FinishTest();
|
||||
FinishTestIfDone();
|
||||
} else {
|
||||
EXPECT_TRUE(false); // Not reached
|
||||
}
|
||||
|
@ -156,36 +227,17 @@ class NetNotifyTestHandler : public TestHandler {
|
|||
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
||||
EXPECT_TRUE(args.get());
|
||||
|
||||
NetNotifyTestType test_type =
|
||||
static_cast<NetNotifyTestType>(args->GetInt(0));
|
||||
EXPECT_EQ(test_type, test_type_);
|
||||
|
||||
std::string url = args->GetString(1);
|
||||
if (url.find(url1_) == 0)
|
||||
std::string url = args->GetString(0);
|
||||
if (url.find(url1_) == 0) {
|
||||
got_process_message1_.yes();
|
||||
else if (url.find(url2_) == 0)
|
||||
SetupCompleteIfDone();
|
||||
} else if (url.find(url2_) == 0) {
|
||||
got_process_message2_.yes();
|
||||
else
|
||||
EXPECT_TRUE(false); // Not reached
|
||||
|
||||
// Navigating cross-origin from the browser process will cause a new
|
||||
// render process to be created. We therefore need some information in
|
||||
// the request itself to tell us that the navigation has already been
|
||||
// delayed.
|
||||
url += "&delayed=true";
|
||||
|
||||
if (test_type == NNTT_DELAYED_RENDERER) {
|
||||
// Load the URL from the render process.
|
||||
CefRefPtr<CefProcessMessage> message =
|
||||
CefProcessMessage::Create(kNetNotifyMsg);
|
||||
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
||||
args->SetInt(0, test_type);
|
||||
args->SetString(1, url);
|
||||
EXPECT_TRUE(browser->SendProcessMessage(PID_RENDERER, message));
|
||||
FinishTestIfDone();
|
||||
} else {
|
||||
// Load the URL from the browser process.
|
||||
browser->GetMainFrame()->LoadURL(url);
|
||||
EXPECT_TRUE(false); // Not reached
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -194,8 +246,18 @@ class NetNotifyTestHandler : public TestHandler {
|
|||
}
|
||||
|
||||
protected:
|
||||
void SetupCompleteIfDone() {
|
||||
if (got_load_end1_ && got_process_message1_)
|
||||
SetupComplete();
|
||||
}
|
||||
|
||||
void FinishTestIfDone() {
|
||||
if (got_load_end2_ && got_process_message2_)
|
||||
FinishTest();
|
||||
}
|
||||
|
||||
void FinishTest() {
|
||||
//Verify that cookies were set correctly.
|
||||
// Verify that cookies were set correctly.
|
||||
class TestVisitor : public CefCookieVisitor {
|
||||
public:
|
||||
explicit TestVisitor(NetNotifyTestHandler* handler)
|
||||
|
@ -230,24 +292,28 @@ class NetNotifyTestHandler : public TestHandler {
|
|||
int browser_id = GetBrowser()->GetIdentifier();
|
||||
|
||||
// Verify test expectations.
|
||||
EXPECT_TRUE(got_before_browse1_) << " browser " << browser_id;
|
||||
EXPECT_TRUE(got_load_end1_) << " browser " << browser_id;
|
||||
EXPECT_TRUE(got_before_resource_load1_) << " browser " << browser_id;
|
||||
EXPECT_TRUE(got_get_resource_handler1_) << " browser " << browser_id;
|
||||
EXPECT_TRUE(got_get_cookie_manager1_) << " browser " << browser_id;
|
||||
EXPECT_TRUE(got_cookie1_) << " browser " << browser_id;
|
||||
EXPECT_TRUE(got_process_message1_) << " browser " << browser_id;
|
||||
EXPECT_TRUE(got_before_browse2_) << " browser " << browser_id;
|
||||
EXPECT_TRUE(got_load_end2_) << " browser " << browser_id;
|
||||
EXPECT_TRUE(got_before_resource_load2_) << " browser " << browser_id;
|
||||
EXPECT_TRUE(got_get_resource_handler2_) << " browser " << browser_id;
|
||||
EXPECT_TRUE(got_get_cookie_manager2_) << " browser " << browser_id;
|
||||
EXPECT_TRUE(got_cookie2_) << " browser " << browser_id;
|
||||
EXPECT_TRUE(got_process_message2_) << " browser " << browser_id;
|
||||
|
||||
if (test_type_ == NNTT_DELAYED_RENDERER ||
|
||||
test_type_ == NNTT_DELAYED_BROWSER) {
|
||||
EXPECT_TRUE(got_process_message1_) << " browser " << browser_id;
|
||||
EXPECT_TRUE(got_process_message2_) << " browser " << browser_id;
|
||||
EXPECT_TRUE(got_before_browse2_will_delay_) << " browser " << browser_id;
|
||||
EXPECT_TRUE(got_before_browse2_delayed_) << " browser " << browser_id;
|
||||
} else {
|
||||
EXPECT_FALSE(got_process_message1_) << " browser " << browser_id;
|
||||
EXPECT_FALSE(got_process_message2_) << " browser " << browser_id;
|
||||
EXPECT_FALSE(got_before_browse2_will_delay_) << " browser " << browser_id;
|
||||
EXPECT_FALSE(got_before_browse2_delayed_) << " browser " << browser_id;
|
||||
}
|
||||
|
||||
context_handler_->Detach();
|
||||
|
@ -266,65 +332,67 @@ class NetNotifyTestHandler : public TestHandler {
|
|||
|
||||
CefRefPtr<CefCookieManager> cookie_manager_;
|
||||
|
||||
TrackCallback got_before_browse1_;
|
||||
TrackCallback got_load_end1_;
|
||||
TrackCallback got_before_resource_load1_;
|
||||
TrackCallback got_get_resource_handler1_;
|
||||
TrackCallback got_get_cookie_manager1_;
|
||||
TrackCallback got_cookie1_;
|
||||
TrackCallback got_process_message1_;
|
||||
TrackCallback got_before_browse2_;
|
||||
TrackCallback got_load_end2_;
|
||||
TrackCallback got_before_resource_load2_;
|
||||
TrackCallback got_get_resource_handler2_;
|
||||
TrackCallback got_get_cookie_manager2_;
|
||||
TrackCallback got_cookie2_;
|
||||
TrackCallback got_process_message2_;
|
||||
TrackCallback got_before_browse2_will_delay_;
|
||||
TrackCallback got_before_browse2_delayed_;
|
||||
};
|
||||
|
||||
// Renderer side.
|
||||
class NetNotifyRendererTest : public ClientApp::RenderDelegate {
|
||||
class NetNotifyRendererTest : public ClientApp::RenderDelegate,
|
||||
public CefLoadHandler {
|
||||
public:
|
||||
NetNotifyRendererTest() {}
|
||||
NetNotifyRendererTest()
|
||||
: run_test_(false) {}
|
||||
|
||||
virtual bool OnBeforeNavigation(CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
cef_navigation_type_t navigation_type,
|
||||
bool is_redirect) OVERRIDE {
|
||||
const std::string& url = request->GetURL();
|
||||
|
||||
// Don't execute this method for unrelated tests.
|
||||
if (url.find(kNetNotifyOrigin1) == std::string::npos &&
|
||||
url.find(kNetNotifyOrigin2) == std::string::npos) {
|
||||
return false;
|
||||
virtual void OnRenderThreadCreated(
|
||||
CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefListValue> extra_info) OVERRIDE {
|
||||
if (!g_net_notify_test) {
|
||||
// Check that the test should be run.
|
||||
CefRefPtr<CefCommandLine> command_line =
|
||||
CefCommandLine::GetGlobalCommandLine();
|
||||
const std::string& test = command_line->GetSwitchValue("test");
|
||||
if (test != kNetNotifyMsg)
|
||||
return;
|
||||
}
|
||||
|
||||
NetNotifyTestType test_type = NNTT_NONE;
|
||||
run_test_ = true;
|
||||
}
|
||||
|
||||
// Extract the test type.
|
||||
size_t pos = url.find("t=");
|
||||
int intval = 0;
|
||||
if (pos > 0 && base::StringToInt(url.substr(pos + 2, 1), &intval))
|
||||
test_type = static_cast<NetNotifyTestType>(intval);
|
||||
EXPECT_GT(test_type, NNTT_NONE);
|
||||
virtual CefRefPtr<CefLoadHandler> GetLoadHandler(
|
||||
CefRefPtr<ClientApp> app) OVERRIDE {
|
||||
if (run_test_)
|
||||
return this;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Check if the load has already been delayed.
|
||||
bool delay_loaded = (url.find("delayed=true") != std::string::npos);
|
||||
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
int httpStatusCode) OVERRIDE {
|
||||
if (!run_test_)
|
||||
return;
|
||||
|
||||
if (!delay_loaded && (test_type == NNTT_DELAYED_RENDERER ||
|
||||
test_type == NNTT_DELAYED_BROWSER)) {
|
||||
// Delay load the URL.
|
||||
CefRefPtr<CefProcessMessage> message =
|
||||
CefProcessMessage::Create(kNetNotifyMsg);
|
||||
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
||||
args->SetInt(0, test_type);
|
||||
args->SetString(1, url);
|
||||
EXPECT_TRUE(browser->SendProcessMessage(PID_BROWSER, message));
|
||||
const std::string& url = frame->GetURL();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
// Continue in the browser process.
|
||||
CefRefPtr<CefProcessMessage> message =
|
||||
CefProcessMessage::Create(kNetNotifyMsg);
|
||||
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
||||
args->SetString(0, url);
|
||||
EXPECT_TRUE(browser->SendProcessMessage(PID_BROWSER, message));
|
||||
}
|
||||
|
||||
virtual bool OnProcessMessageReceived(
|
||||
|
@ -351,10 +419,15 @@ class NetNotifyRendererTest : public ClientApp::RenderDelegate {
|
|||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
bool run_test_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(NetNotifyRendererTest);
|
||||
};
|
||||
|
||||
void RunNetNotifyTest(NetNotifyTestType test_type, bool same_origin) {
|
||||
g_net_notify_test = true;
|
||||
|
||||
TestHandler::CompletionState completion_state(3);
|
||||
|
||||
CefRefPtr<NetNotifyTestHandler> handler1 =
|
||||
|
@ -370,6 +443,8 @@ void RunNetNotifyTest(NetNotifyTestType test_type, bool same_origin) {
|
|||
collection.AddTestHandler(handler3.get());
|
||||
|
||||
collection.ExecuteTests();
|
||||
|
||||
g_net_notify_test = false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -415,6 +490,13 @@ TEST(RequestHandlerTest, NotificationsCrossOriginDelayedBrowser) {
|
|||
}
|
||||
|
||||
|
||||
// Entry point for creating request handler browser test objects.
|
||||
// Called from client_app_delegates.cc.
|
||||
void CreateRequestHandlerBrowserTests(
|
||||
ClientApp::BrowserDelegateSet& delegates) {
|
||||
delegates.insert(new NetNotifyBrowserTest);
|
||||
}
|
||||
|
||||
// Entry point for creating request handler renderer test objects.
|
||||
// Called from client_app_delegates.cc.
|
||||
void CreateRequestHandlerRendererTests(
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include "include/cef_request.h"
|
||||
#include "include/cef_runnable.h"
|
||||
#include "tests/cefclient/client_app.h"
|
||||
#include "tests/unittests/test_handler.h"
|
||||
#include "tests/unittests/test_util.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
@ -206,45 +205,40 @@ const char kTypeTestOrigin[] = "http://tests-requesttt.com/";
|
|||
|
||||
static struct TypeExpected {
|
||||
const char* file;
|
||||
bool browser_side; // True if this expectation applies to the browser side.
|
||||
bool navigation; // True if this expectation represents a navigation.
|
||||
cef_transition_type_t transition_type;
|
||||
cef_resource_type_t resource_type;
|
||||
int expected_count;
|
||||
} g_type_expected[] = {
|
||||
// Initial main frame load due to browser creation.
|
||||
{"main.html", true, true, TT_EXPLICIT, RT_MAIN_FRAME, 1},
|
||||
{"main.html", false, true, TT_EXPLICIT, RT_SUB_RESOURCE, 1},
|
||||
{"main.html", true, TT_EXPLICIT, RT_MAIN_FRAME, 1},
|
||||
|
||||
// Sub frame load.
|
||||
{"sub.html", true, true, TT_LINK, RT_SUB_FRAME, 1},
|
||||
{"sub.html", false, true, TT_EXPLICIT, RT_SUB_RESOURCE, 1},
|
||||
{"sub.html", true, TT_LINK, RT_SUB_FRAME, 1},
|
||||
|
||||
// Stylesheet load.
|
||||
{"style.css", true, false, TT_LINK, RT_STYLESHEET, 1},
|
||||
{"style.css", false, TT_LINK, RT_STYLESHEET, 1},
|
||||
|
||||
// Script load.
|
||||
{"script.js", true, false, TT_LINK, RT_SCRIPT, 1},
|
||||
{"script.js", false, TT_LINK, RT_SCRIPT, 1},
|
||||
|
||||
// Image load.
|
||||
{"image.png", true, false, TT_LINK, RT_IMAGE, 1},
|
||||
{"image.png", false, TT_LINK, RT_IMAGE, 1},
|
||||
|
||||
// Font load.
|
||||
{"font.ttf", true, false, TT_LINK, RT_FONT_RESOURCE, 1},
|
||||
{"font.ttf", false, TT_LINK, RT_FONT_RESOURCE, 1},
|
||||
|
||||
// XHR load.
|
||||
{"xhr.html", true, false, TT_LINK, RT_XHR, 1},
|
||||
{"xhr.html", false, TT_LINK, RT_XHR, 1},
|
||||
};
|
||||
|
||||
class TypeExpectations {
|
||||
public:
|
||||
TypeExpectations(bool browser_side, bool navigation)
|
||||
: browser_side_(browser_side),
|
||||
navigation_(navigation) {
|
||||
explicit TypeExpectations(bool navigation)
|
||||
: navigation_(navigation) {
|
||||
// Build the map of relevant requests.
|
||||
for (size_t i = 0; i < sizeof(g_type_expected) / sizeof(TypeExpected); ++i) {
|
||||
if (g_type_expected[i].browser_side != browser_side_ ||
|
||||
(navigation_ && g_type_expected[i].navigation != navigation_))
|
||||
if (navigation_ && g_type_expected[i].navigation != navigation_)
|
||||
continue;
|
||||
|
||||
request_count_.insert(std::make_pair(i, 0));
|
||||
|
@ -265,7 +259,6 @@ class TypeExpectations {
|
|||
const int index = GetExpectedIndex(file, transition_type, resource_type);
|
||||
EXPECT_GE(index, 0)
|
||||
<< "File: " << file.c_str()
|
||||
<< "; Browser Side: " << browser_side_
|
||||
<< "; Navigation: " << navigation_
|
||||
<< "; Transition Type: " << transition_type
|
||||
<< "; Resource Type: " << resource_type;
|
||||
|
@ -277,7 +270,6 @@ class TypeExpectations {
|
|||
const int expected_count = g_type_expected[index].expected_count;
|
||||
EXPECT_LE(actual_count, expected_count)
|
||||
<< "File: " << file.c_str()
|
||||
<< "; Browser Side: " << browser_side_
|
||||
<< "; Navigation: " << navigation_
|
||||
<< "; Transition Type: " << transition_type
|
||||
<< "; Resource Type: " << resource_type;
|
||||
|
@ -288,8 +280,7 @@ class TypeExpectations {
|
|||
// Test if all expectations have been met.
|
||||
bool IsDone(bool assert) {
|
||||
for (size_t i = 0; i < sizeof(g_type_expected) / sizeof(TypeExpected); ++i) {
|
||||
if (g_type_expected[i].browser_side != browser_side_ ||
|
||||
(navigation_ && g_type_expected[i].navigation != navigation_))
|
||||
if (navigation_ && g_type_expected[i].navigation != navigation_)
|
||||
continue;
|
||||
|
||||
RequestCount::const_iterator it = request_count_.find(i);
|
||||
|
@ -298,7 +289,6 @@ class TypeExpectations {
|
|||
if (assert) {
|
||||
EXPECT_EQ(g_type_expected[i].expected_count, it->second)
|
||||
<< "File: " << g_type_expected[i].file
|
||||
<< "; Browser Side: " << browser_side_
|
||||
<< "; Navigation: " << navigation_
|
||||
<< "; Transition Type: " << g_type_expected[i].transition_type
|
||||
<< "; Resource Type: " << g_type_expected[i].resource_type;
|
||||
|
@ -316,7 +306,6 @@ class TypeExpectations {
|
|||
cef_resource_type_t resource_type) {
|
||||
for (size_t i = 0; i < sizeof(g_type_expected) / sizeof(TypeExpected); ++i) {
|
||||
if (g_type_expected[i].file == file &&
|
||||
g_type_expected[i].browser_side == browser_side_ &&
|
||||
(!navigation_ || g_type_expected[i].navigation == navigation_) &&
|
||||
g_type_expected[i].transition_type == transition_type &&
|
||||
g_type_expected[i].resource_type == resource_type) {
|
||||
|
@ -326,7 +315,6 @@ class TypeExpectations {
|
|||
return -1;
|
||||
}
|
||||
|
||||
bool browser_side_;
|
||||
bool navigation_;
|
||||
|
||||
// Map of TypeExpected index to actual request count.
|
||||
|
@ -334,52 +322,14 @@ class TypeExpectations {
|
|||
RequestCount request_count_;
|
||||
};
|
||||
|
||||
// Renderer side.
|
||||
class TypeRendererTest : public ClientApp::RenderDelegate {
|
||||
public:
|
||||
TypeRendererTest() :
|
||||
expectations_(false, true) {}
|
||||
|
||||
virtual bool OnBeforeNavigation(CefRefPtr<ClientApp> app,
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
cef_navigation_type_t navigation_type,
|
||||
bool is_redirect) OVERRIDE {
|
||||
if (expectations_.GotRequest(request) && expectations_.IsDone(false))
|
||||
SendTestResults(browser);
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
// Send the test results.
|
||||
void SendTestResults(CefRefPtr<CefBrowser> browser) {
|
||||
// Check if the test has failed.
|
||||
bool result = !TestFailed();
|
||||
|
||||
// Return the result to the browser process.
|
||||
CefRefPtr<CefProcessMessage> return_msg =
|
||||
CefProcessMessage::Create(kTypeTestCompleteMsg);
|
||||
CefRefPtr<CefListValue> args = return_msg->GetArgumentList();
|
||||
EXPECT_TRUE(args.get());
|
||||
EXPECT_TRUE(args->SetBool(0, result));
|
||||
EXPECT_TRUE(browser->SendProcessMessage(PID_BROWSER, return_msg));
|
||||
}
|
||||
|
||||
TypeExpectations expectations_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(TypeRendererTest);
|
||||
};
|
||||
|
||||
// Browser side.
|
||||
class TypeTestHandler : public TestHandler {
|
||||
public:
|
||||
TypeTestHandler() :
|
||||
browse_expectations_(true, true),
|
||||
load_expectations_(true, false),
|
||||
get_expectations_(true, false),
|
||||
browse_expectations_(true),
|
||||
load_expectations_(false),
|
||||
get_expectations_(false),
|
||||
completed_browser_side_(false),
|
||||
completed_render_side_(false),
|
||||
destroyed_(false) {}
|
||||
|
||||
virtual void RunTest() OVERRIDE {
|
||||
|
@ -456,41 +406,13 @@ class TypeTestHandler : public TestHandler {
|
|||
completed_browser_side_ = true;
|
||||
// Destroy the test on the UI thread.
|
||||
CefPostTask(TID_UI,
|
||||
NewCefRunnableMethod(this, &TypeTestHandler::DestroyTestIfComplete));
|
||||
NewCefRunnableMethod(this, &TypeTestHandler::DestroyTest));
|
||||
}
|
||||
|
||||
return TestHandler::GetResourceHandler(browser, frame, request);
|
||||
}
|
||||
|
||||
virtual bool OnProcessMessageReceived(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefProcessId source_process,
|
||||
CefRefPtr<CefProcessMessage> message) OVERRIDE {
|
||||
const std::string& msg_name = message->GetName();
|
||||
if (msg_name == kTypeTestCompleteMsg) {
|
||||
// Test that the renderer side succeeded.
|
||||
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
||||
EXPECT_TRUE(args.get());
|
||||
EXPECT_TRUE(args->GetBool(0));
|
||||
|
||||
completed_render_side_ = true;
|
||||
DestroyTestIfComplete();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Message not handled.
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
void DestroyTestIfComplete() {
|
||||
if (destroyed_)
|
||||
return;
|
||||
|
||||
if (completed_browser_side_ && completed_render_side_)
|
||||
DestroyTest();
|
||||
}
|
||||
|
||||
virtual void DestroyTest() OVERRIDE {
|
||||
if (destroyed_)
|
||||
return;
|
||||
|
@ -498,7 +420,6 @@ class TypeTestHandler : public TestHandler {
|
|||
|
||||
// Verify test expectations.
|
||||
EXPECT_TRUE(completed_browser_side_);
|
||||
EXPECT_TRUE(completed_render_side_);
|
||||
EXPECT_TRUE(browse_expectations_.IsDone(true));
|
||||
EXPECT_TRUE(load_expectations_.IsDone(true));
|
||||
EXPECT_TRUE(get_expectations_.IsDone(true));
|
||||
|
@ -511,7 +432,6 @@ class TypeTestHandler : public TestHandler {
|
|||
TypeExpectations get_expectations_;
|
||||
|
||||
bool completed_browser_side_;
|
||||
bool completed_render_side_;
|
||||
bool destroyed_;
|
||||
};
|
||||
|
||||
|
@ -523,10 +443,3 @@ TEST(RequestTest, ResourceAndTransitionType) {
|
|||
new TypeTestHandler();
|
||||
handler->ExecuteTest();
|
||||
}
|
||||
|
||||
|
||||
// Entry point for creating request renderer test objects.
|
||||
// Called from client_app_delegates.cc.
|
||||
void CreateRequestRendererTests(ClientApp::RenderDelegateSet& delegates) {
|
||||
delegates.insert(new TypeRendererTest);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue