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:
Marshall Greenblatt
2013-09-16 15:26:08 +00:00
parent 71125f76d8
commit 8adb86e7e6
15 changed files with 170 additions and 414 deletions

View File

@@ -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);
}