2013-07-15 22:25:59 +02:00
|
|
|
// 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.
|
|
|
|
|
2014-07-15 00:18:51 +02:00
|
|
|
// Include this first to avoid type conflicts with CEF headers.
|
|
|
|
#include "tests/unittests/chromium_includes.h"
|
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
#include "base/strings/stringprintf.h"
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2014-07-15 20:10:40 +02:00
|
|
|
#include "include/base/cef_bind.h"
|
2013-07-15 22:25:59 +02:00
|
|
|
#include "include/cef_cookie.h"
|
2014-07-15 20:10:40 +02:00
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
2013-07-15 22:25:59 +02:00
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
2015-01-31 05:41:36 +01:00
|
|
|
#include "tests/cefclient/browser/client_app_browser.h"
|
|
|
|
#include "tests/cefclient/renderer/client_app_renderer.h"
|
2014-07-15 00:18:51 +02:00
|
|
|
#include "tests/unittests/test_handler.h"
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2015-01-31 05:41:36 +01:00
|
|
|
using client::ClientAppBrowser;
|
|
|
|
using client::ClientAppRenderer;
|
2015-01-23 20:09:34 +01:00
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
enum NetNotifyTestType {
|
|
|
|
NNTT_NONE = 0,
|
|
|
|
NNTT_NORMAL,
|
|
|
|
NNTT_DELAYED_RENDERER,
|
|
|
|
NNTT_DELAYED_BROWSER,
|
|
|
|
};
|
|
|
|
|
|
|
|
const char kNetNotifyOrigin1[] = "http://tests-netnotify1/";
|
|
|
|
const char kNetNotifyOrigin2[] = "http://tests-netnotify2/";
|
|
|
|
const char kNetNotifyMsg[] = "RequestHandlerTest.NetNotify";
|
|
|
|
|
2013-09-16 17:26:08 +02:00
|
|
|
bool g_net_notify_test = false;
|
|
|
|
|
|
|
|
// Browser side.
|
2015-01-31 05:41:36 +01:00
|
|
|
class NetNotifyBrowserTest : public ClientAppBrowser::Delegate {
|
2013-09-16 17:26:08 +02:00
|
|
|
public:
|
|
|
|
NetNotifyBrowserTest() {}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnBeforeChildProcessLaunch(
|
2015-01-31 05:41:36 +01:00
|
|
|
CefRefPtr<ClientAppBrowser> app,
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefCommandLine> command_line) override {
|
2013-09-16 17:26:08 +02:00
|
|
|
if (!g_net_notify_test)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Indicate to the render process that the test should be run.
|
|
|
|
command_line->AppendSwitchWithValue("test", kNetNotifyMsg);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-07-15 00:18:51 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(NetNotifyBrowserTest);
|
2013-09-16 17:26:08 +02:00
|
|
|
};
|
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
// Browser side.
|
|
|
|
class NetNotifyTestHandler : public TestHandler {
|
|
|
|
public:
|
2013-09-03 18:43:31 +02:00
|
|
|
class RequestContextHandler : public CefRequestContextHandler {
|
|
|
|
public:
|
|
|
|
explicit RequestContextHandler(NetNotifyTestHandler* handler)
|
|
|
|
: handler_(handler) {}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefCookieManager> GetCookieManager() override {
|
2013-09-03 18:43:31 +02:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
NetNotifyTestHandler(CompletionState* completion_state,
|
|
|
|
NetNotifyTestType test_type,
|
|
|
|
bool same_origin)
|
|
|
|
: TestHandler(completion_state),
|
|
|
|
test_type_(test_type),
|
|
|
|
same_origin_(same_origin) {}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void SetupTest() override {
|
2013-07-15 22:25:59 +02:00
|
|
|
url1_ = base::StringPrintf("%snav1.html?t=%d",
|
|
|
|
kNetNotifyOrigin1, test_type_);
|
|
|
|
url2_ = base::StringPrintf("%snav2.html?t=%d",
|
|
|
|
same_origin_ ? kNetNotifyOrigin1 : kNetNotifyOrigin2, test_type_);
|
|
|
|
|
|
|
|
cookie_manager_ = CefCookieManager::CreateManager(CefString(), true);
|
|
|
|
|
|
|
|
AddResource(url1_,
|
|
|
|
"<html>"
|
|
|
|
"<head><script>document.cookie='name1=value1';</script></head>"
|
|
|
|
"<body>Nav1</body>"
|
|
|
|
"</html>", "text/html");
|
|
|
|
AddResource(url2_,
|
|
|
|
"<html>"
|
|
|
|
"<head><script>document.cookie='name2=value2';</script></head>"
|
|
|
|
"<body>Nav2</body>"
|
|
|
|
"</html>", "text/html");
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
context_handler_ = new RequestContextHandler(this);
|
|
|
|
context_handler_->SetURL(url1_);
|
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
// Create browser that loads the 1st URL.
|
2013-09-03 18:43:31 +02:00
|
|
|
CreateBrowser(url1_,
|
|
|
|
CefRequestContext::CreateContext(context_handler_.get()));
|
2013-07-15 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void RunTest() override {
|
2013-07-15 22:25:59 +02:00
|
|
|
// Navigate to the 2nd URL.
|
2013-09-03 18:43:31 +02:00
|
|
|
context_handler_->SetURL(url2_);
|
2013-07-15 22:25:59 +02:00
|
|
|
GetBrowser()->GetMainFrame()->LoadURL(url2_);
|
2015-01-10 00:40:26 +01:00
|
|
|
|
|
|
|
// Time out the test after a reasonable period of time.
|
|
|
|
SetTestTimeout();
|
2013-07-15 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request) override {
|
2013-07-15 22:25:59 +02:00
|
|
|
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
|
|
|
|
|
|
|
|
const std::string& url = request->GetURL();
|
|
|
|
if (url.find(url1_) == 0)
|
|
|
|
got_before_resource_load1_.yes();
|
|
|
|
else if (url.find(url2_) == 0)
|
|
|
|
got_before_resource_load2_.yes();
|
|
|
|
else
|
|
|
|
EXPECT_TRUE(false); // Not reached
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefResourceHandler> GetResourceHandler(
|
2013-07-15 22:25:59 +02:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefRequest> request) override {
|
2013-07-15 22:25:59 +02:00
|
|
|
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
|
|
|
|
|
|
|
|
const std::string& url = request->GetURL();
|
|
|
|
if (url.find(url1_) == 0)
|
|
|
|
got_get_resource_handler1_.yes();
|
|
|
|
else if (url.find(url2_) == 0)
|
|
|
|
got_get_resource_handler2_.yes();
|
|
|
|
else
|
|
|
|
EXPECT_TRUE(false); // Not reached
|
|
|
|
|
|
|
|
return TestHandler::GetResourceHandler(browser, frame, request);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
bool is_redirect) override {
|
2013-09-16 17:26:08 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
2013-07-15 22:25:59 +02:00
|
|
|
const std::string& url = frame->GetURL();
|
|
|
|
if (url.find(url1_) == 0) {
|
|
|
|
got_load_end1_.yes();
|
2013-09-16 17:26:08 +02:00
|
|
|
SetupCompleteIfDone();
|
2013-07-15 22:25:59 +02:00
|
|
|
} else if (url.find(url2_) == 0) {
|
|
|
|
got_load_end2_.yes();
|
2013-09-16 17:26:08 +02:00
|
|
|
FinishTestIfDone();
|
2013-07-15 22:25:59 +02:00
|
|
|
} else {
|
|
|
|
EXPECT_TRUE(false); // Not reached
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnProcessMessageReceived(
|
2013-07-15 22:25:59 +02:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefProcessId source_process,
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefProcessMessage> message) override {
|
2013-07-15 22:25:59 +02:00
|
|
|
if (message->GetName().ToString() == kNetNotifyMsg) {
|
|
|
|
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
|
|
|
EXPECT_TRUE(args.get());
|
|
|
|
|
2013-09-16 17:26:08 +02:00
|
|
|
std::string url = args->GetString(0);
|
|
|
|
if (url.find(url1_) == 0) {
|
2013-07-15 22:25:59 +02:00
|
|
|
got_process_message1_.yes();
|
2013-09-16 17:26:08 +02:00
|
|
|
SetupCompleteIfDone();
|
|
|
|
} else if (url.find(url2_) == 0) {
|
2013-07-15 22:25:59 +02:00
|
|
|
got_process_message2_.yes();
|
2013-09-16 17:26:08 +02:00
|
|
|
FinishTestIfDone();
|
2013-07-15 22:25:59 +02:00
|
|
|
} else {
|
2013-09-16 17:26:08 +02:00
|
|
|
EXPECT_TRUE(false); // Not reached
|
2013-07-15 22:25:59 +02:00
|
|
|
}
|
2013-09-16 17:26:08 +02:00
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Message not handled.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2013-09-16 17:26:08 +02:00
|
|
|
void SetupCompleteIfDone() {
|
|
|
|
if (got_load_end1_ && got_process_message1_)
|
|
|
|
SetupComplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FinishTestIfDone() {
|
|
|
|
if (got_load_end2_ && got_process_message2_)
|
|
|
|
FinishTest();
|
|
|
|
}
|
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
void FinishTest() {
|
2013-09-16 17:26:08 +02:00
|
|
|
// Verify that cookies were set correctly.
|
2013-07-15 22:25:59 +02:00
|
|
|
class TestVisitor : public CefCookieVisitor {
|
|
|
|
public:
|
|
|
|
explicit TestVisitor(NetNotifyTestHandler* handler)
|
|
|
|
: handler_(handler) {
|
|
|
|
}
|
2014-11-12 20:25:15 +01:00
|
|
|
~TestVisitor() override {
|
2013-07-15 22:25:59 +02:00
|
|
|
// Destroy the test.
|
|
|
|
CefPostTask(TID_UI,
|
2014-07-15 20:10:40 +02:00
|
|
|
base::Bind(&NetNotifyTestHandler::DestroyTest, handler_));
|
2013-07-15 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool Visit(const CefCookie& cookie, int count, int total,
|
|
|
|
bool& deleteCookie) override {
|
2013-07-15 22:25:59 +02:00
|
|
|
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:
|
|
|
|
NetNotifyTestHandler* handler_;
|
|
|
|
IMPLEMENT_REFCOUNTING(TestVisitor);
|
|
|
|
};
|
|
|
|
|
|
|
|
cookie_manager_->VisitAllCookies(new TestVisitor(this));
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void DestroyTest() override {
|
2013-07-15 22:25:59 +02:00
|
|
|
int browser_id = GetBrowser()->GetIdentifier();
|
|
|
|
|
|
|
|
// Verify test expectations.
|
2013-09-16 17:26:08 +02:00
|
|
|
EXPECT_TRUE(got_before_browse1_) << " browser " << browser_id;
|
2013-07-15 22:25:59 +02:00
|
|
|
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;
|
2013-09-16 17:26:08 +02:00
|
|
|
EXPECT_TRUE(got_process_message1_) << " browser " << browser_id;
|
|
|
|
EXPECT_TRUE(got_before_browse2_) << " browser " << browser_id;
|
2013-07-15 22:25:59 +02:00
|
|
|
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;
|
2013-09-16 17:26:08 +02:00
|
|
|
EXPECT_TRUE(got_process_message2_) << " browser " << browser_id;
|
2013-07-15 22:25:59 +02:00
|
|
|
|
|
|
|
if (test_type_ == NNTT_DELAYED_RENDERER ||
|
|
|
|
test_type_ == NNTT_DELAYED_BROWSER) {
|
2013-09-16 17:26:08 +02:00
|
|
|
EXPECT_TRUE(got_before_browse2_will_delay_) << " browser " << browser_id;
|
|
|
|
EXPECT_TRUE(got_before_browse2_delayed_) << " browser " << browser_id;
|
2013-07-15 22:25:59 +02:00
|
|
|
} else {
|
2013-09-16 17:26:08 +02:00
|
|
|
EXPECT_FALSE(got_before_browse2_will_delay_) << " browser " << browser_id;
|
|
|
|
EXPECT_FALSE(got_before_browse2_delayed_) << " browser " << browser_id;
|
2013-07-15 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
context_handler_->Detach();
|
|
|
|
context_handler_ = NULL;
|
2013-07-15 22:25:59 +02:00
|
|
|
cookie_manager_ = NULL;
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
TestHandler::DestroyTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
NetNotifyTestType test_type_;
|
|
|
|
bool same_origin_;
|
|
|
|
std::string url1_;
|
|
|
|
std::string url2_;
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
CefRefPtr<RequestContextHandler> context_handler_;
|
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
CefRefPtr<CefCookieManager> cookie_manager_;
|
|
|
|
|
2013-09-16 17:26:08 +02:00
|
|
|
TrackCallback got_before_browse1_;
|
2013-07-15 22:25:59 +02:00
|
|
|
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_;
|
2013-09-16 17:26:08 +02:00
|
|
|
TrackCallback got_before_browse2_;
|
2013-07-15 22:25:59 +02:00
|
|
|
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_;
|
2013-09-16 17:26:08 +02:00
|
|
|
TrackCallback got_before_browse2_will_delay_;
|
|
|
|
TrackCallback got_before_browse2_delayed_;
|
2013-07-15 22:25:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Renderer side.
|
2015-01-31 05:41:36 +01:00
|
|
|
class NetNotifyRendererTest : public ClientAppRenderer::Delegate,
|
2013-09-16 17:26:08 +02:00
|
|
|
public CefLoadHandler {
|
2013-07-15 22:25:59 +02:00
|
|
|
public:
|
2013-09-16 17:26:08 +02:00
|
|
|
NetNotifyRendererTest()
|
|
|
|
: run_test_(false) {}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnRenderThreadCreated(
|
2015-01-31 05:41:36 +01:00
|
|
|
CefRefPtr<ClientAppRenderer> app,
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefListValue> extra_info) override {
|
2013-09-16 17:26:08 +02:00
|
|
|
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;
|
2013-07-15 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2013-09-16 17:26:08 +02:00
|
|
|
run_test_ = true;
|
|
|
|
}
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefLoadHandler> GetLoadHandler(
|
2015-01-31 05:41:36 +01:00
|
|
|
CefRefPtr<ClientAppRenderer> app) override {
|
2013-09-16 17:26:08 +02:00
|
|
|
if (run_test_)
|
|
|
|
return this;
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) override {
|
2013-09-16 17:26:08 +02:00
|
|
|
if (!run_test_)
|
|
|
|
return;
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2013-09-16 17:26:08 +02:00
|
|
|
const std::string& url = frame->GetURL();
|
2013-07-15 22:25:59 +02:00
|
|
|
|
2013-09-16 17:26:08 +02:00
|
|
|
// 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));
|
2013-07-15 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool OnProcessMessageReceived(
|
2015-01-31 05:41:36 +01:00
|
|
|
CefRefPtr<ClientAppRenderer> app,
|
2013-07-15 22:25:59 +02:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefProcessId source_process,
|
2014-11-12 20:25:15 +01:00
|
|
|
CefRefPtr<CefProcessMessage> message) override {
|
2013-07-15 22:25:59 +02:00
|
|
|
if (message->GetName().ToString() == kNetNotifyMsg) {
|
|
|
|
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
|
|
|
EXPECT_TRUE(args.get());
|
|
|
|
|
|
|
|
NetNotifyTestType test_type =
|
|
|
|
static_cast<NetNotifyTestType>(args->GetInt(0));
|
|
|
|
EXPECT_EQ(test_type, NNTT_DELAYED_RENDERER);
|
|
|
|
|
|
|
|
const std::string& url = args->GetString(1);
|
|
|
|
|
|
|
|
// Load the URL from the render process.
|
|
|
|
browser->GetMainFrame()->LoadURL(url);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Message not handled.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-16 17:26:08 +02:00
|
|
|
private:
|
|
|
|
bool run_test_;
|
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(NetNotifyRendererTest);
|
|
|
|
};
|
|
|
|
|
|
|
|
void RunNetNotifyTest(NetNotifyTestType test_type, bool same_origin) {
|
2013-09-16 17:26:08 +02:00
|
|
|
g_net_notify_test = true;
|
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
TestHandler::CompletionState completion_state(3);
|
|
|
|
|
|
|
|
CefRefPtr<NetNotifyTestHandler> handler1 =
|
|
|
|
new NetNotifyTestHandler(&completion_state, test_type, same_origin);
|
|
|
|
CefRefPtr<NetNotifyTestHandler> handler2 =
|
|
|
|
new NetNotifyTestHandler(&completion_state, test_type, same_origin);
|
|
|
|
CefRefPtr<NetNotifyTestHandler> handler3 =
|
|
|
|
new NetNotifyTestHandler(&completion_state, test_type, same_origin);
|
|
|
|
|
|
|
|
TestHandler::Collection collection(&completion_state);
|
|
|
|
collection.AddTestHandler(handler1.get());
|
|
|
|
collection.AddTestHandler(handler2.get());
|
|
|
|
collection.AddTestHandler(handler3.get());
|
|
|
|
|
|
|
|
collection.ExecuteTests();
|
2013-09-16 17:26:08 +02:00
|
|
|
|
2015-01-10 00:40:26 +01:00
|
|
|
ReleaseAndWaitForDestructor(handler1);
|
|
|
|
ReleaseAndWaitForDestructor(handler2);
|
|
|
|
ReleaseAndWaitForDestructor(handler3);
|
|
|
|
|
2013-09-16 17:26:08 +02:00
|
|
|
g_net_notify_test = false;
|
2013-07-15 22:25:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Verify network notifications for multiple browsers existing simultaniously.
|
|
|
|
// URL loading is from the same origin and is not delayed.
|
|
|
|
TEST(RequestHandlerTest, NotificationsSameOriginDirect) {
|
|
|
|
RunNetNotifyTest(NNTT_NORMAL, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify network notifications for multiple browsers existing simultaniously.
|
|
|
|
// URL loading is from the same origin and is continued asynchronously from the
|
|
|
|
// render process.
|
|
|
|
TEST(RequestHandlerTest, NotificationsSameOriginDelayedRenderer) {
|
|
|
|
RunNetNotifyTest(NNTT_DELAYED_RENDERER, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify network notifications for multiple browsers existing simultaniously.
|
|
|
|
// URL loading is from the same origin and is continued asynchronously from the
|
|
|
|
// browser process.
|
|
|
|
TEST(RequestHandlerTest, NotificationsSameOriginDelayedBrowser) {
|
|
|
|
RunNetNotifyTest(NNTT_DELAYED_BROWSER, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify network notifications for multiple browsers existing simultaniously.
|
|
|
|
// URL loading is from a different origin and is not delayed.
|
|
|
|
TEST(RequestHandlerTest, NotificationsCrossOriginDirect) {
|
|
|
|
RunNetNotifyTest(NNTT_NORMAL, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify network notifications for multiple browsers existing simultaniously.
|
|
|
|
// URL loading is from a different origin and is continued asynchronously from
|
|
|
|
// the render process.
|
|
|
|
TEST(RequestHandlerTest, NotificationsCrossOriginDelayedRenderer) {
|
|
|
|
RunNetNotifyTest(NNTT_DELAYED_RENDERER, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify network notifications for multiple browsers existing simultaniously.
|
|
|
|
// URL loading is from a different origin and is continued asynchronously from
|
|
|
|
// the browser process.
|
|
|
|
TEST(RequestHandlerTest, NotificationsCrossOriginDelayedBrowser) {
|
|
|
|
RunNetNotifyTest(NNTT_DELAYED_BROWSER, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-16 17:26:08 +02:00
|
|
|
// Entry point for creating request handler browser test objects.
|
|
|
|
// Called from client_app_delegates.cc.
|
|
|
|
void CreateRequestHandlerBrowserTests(
|
2015-01-31 05:41:36 +01:00
|
|
|
ClientAppBrowser::DelegateSet& delegates) {
|
2013-09-16 17:26:08 +02:00
|
|
|
delegates.insert(new NetNotifyBrowserTest);
|
|
|
|
}
|
|
|
|
|
2013-07-15 22:25:59 +02:00
|
|
|
// Entry point for creating request handler renderer test objects.
|
|
|
|
// Called from client_app_delegates.cc.
|
|
|
|
void CreateRequestHandlerRendererTests(
|
2015-01-31 05:41:36 +01:00
|
|
|
ClientAppRenderer::DelegateSet& delegates) {
|
2013-07-15 22:25:59 +02:00
|
|
|
delegates.insert(new NetNotifyRendererTest);
|
|
|
|
}
|