Add direct DOM access (issue #511).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@610 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2012-04-27 21:19:06 +00:00
parent 4fe0ddf640
commit db3a9817ed
58 changed files with 5089 additions and 7 deletions

View File

@@ -34,6 +34,7 @@ IDS_LOGO BINARY "res\\logo.png"
IDS_LOGOBALL BINARY "res\\logoball.png"
IDS_LOCALSTORAGE BINARY "res\\localstorage.html"
IDS_XMLHTTPREQUEST BINARY "res\\xmlhttprequest.html"
IDS_DOMACCESS BINARY "res\\domaccess.html"
/////////////////////////////////////////////////////////////////////////////
//
@@ -70,6 +71,7 @@ BEGIN
MENUITEM "JavaScript Binding", ID_TESTS_BINDING
MENUITEM "JavaScript Dialogs", ID_TESTS_DIALOGS
MENUITEM "Plugin Info", ID_TESTS_PLUGIN_INFO
MENUITEM "DOM Access", ID_TESTS_DOM_ACCESS
MENUITEM "Local Storage", ID_TESTS_LOCALSTORAGE
MENUITEM "XMLHttpRequest", ID_TESTS_XMLHTTPREQUEST
MENUITEM "Accelerated 2D Canvas", ID_TESTS_ACCELERATED2DCANVAS

View File

@@ -13,6 +13,7 @@
#include "include/cef_runnable.h"
#include "cefclient/binding_test.h"
#include "cefclient/client_handler.h"
#include "cefclient/dom_test.h"
#include "cefclient/scheme_test.h"
#include "cefclient/string_util.h"
@@ -93,6 +94,14 @@ gboolean PluginInfoActivated(GtkWidget* widget) {
return FALSE; // Don't stop this message.
}
// Callback for Debug > DOM Access... menu item.
gboolean DOMAccessActivated(GtkWidget* widget) {
if (g_handler.get() && g_handler->GetBrowserId())
dom_test::RunTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
}
// Callback for Debug > Popup Window... menu item.
gboolean PopupWindowActivated(GtkWidget* widget) {
if (g_handler.get() && g_handler->GetBrowserId())
@@ -212,6 +221,8 @@ GtkWidget* CreateMenuBar() {
G_CALLBACK(BindingActivated));
AddMenuEntry(debug_menu, "Plugin Info",
G_CALLBACK(PluginInfoActivated));
AddMenuEntry(debug_menu, "DOM Access",
G_CALLBACK(DOMAccessActivated));
AddMenuEntry(debug_menu, "Popup Window",
G_CALLBACK(PopupWindowActivated));
AddMenuEntry(debug_menu, "Accelerated 2D Canvas",

View File

@@ -13,6 +13,7 @@
#include "include/cef_runnable.h"
#include "cefclient/binding_test.h"
#include "cefclient/client_handler.h"
#include "cefclient/dom_test.h"
#include "cefclient/resource_util.h"
#include "cefclient/scheme_test.h"
#include "cefclient/string_util.h"
@@ -195,6 +196,7 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
- (IBAction)testBinding:(id)sender;
- (IBAction)testDialogs:(id)sender;
- (IBAction)testPluginInfo:(id)sender;
- (IBAction)testDOMAccess:(id)sender;
- (IBAction)testPopupWindow:(id)sender;
- (IBAction)testAccelerated2DCanvas:(id)sender;
- (IBAction)testAcceleratedLayers:(id)sender;
@@ -243,6 +245,9 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
[testMenu addItemWithTitle:@"Plugin Info"
action:@selector(testPluginInfo:)
keyEquivalent:@""];
[testMenu addItemWithTitle:@"DOM Access"
action:@selector(testDOMAccess:)
keyEquivalent:@""];
[testMenu addItemWithTitle:@"Local Storage"
action:@selector(testLocalStorage:)
keyEquivalent:@""];
@@ -400,6 +405,11 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
RunPluginInfoTest(g_handler->GetBrowser());
}
- (IBAction)testDOMAccess:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
dom_test::RunTest(g_handler->GetBrowser());
}
- (IBAction)testPopupWindow:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
RunPopupTest(g_handler->GetBrowser());

View File

@@ -15,6 +15,7 @@
#include "include/cef_runnable.h"
#include "cefclient/binding_test.h"
#include "cefclient/client_handler.h"
#include "cefclient/dom_test.h"
#include "cefclient/resource.h"
#include "cefclient/scheme_test.h"
#include "cefclient/string_util.h"
@@ -385,6 +386,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
if (browser.get())
RunPluginInfoTest(browser);
return 0;
case ID_TESTS_DOM_ACCESS: // Test DOM access
if (browser.get())
dom_test::RunTest(browser);
return 0;
case ID_TESTS_LOCALSTORAGE: // Test localStorage
if (browser.get())
RunLocalStorageTest(browser);

View File

@@ -3,10 +3,12 @@
// can be found in the LICENSE file.
#include "cefclient/client_app.h"
#include "cefclient/dom_test.h"
#include "cefclient/scheme_test.h"
// static
void ClientApp::CreateRenderDelegates(RenderDelegateSet& delegates) {
dom_test::CreateRenderDelegates(delegates);
}
// static

View File

@@ -11,6 +11,7 @@
#include "include/wrapper/cef_stream_resource_handler.h"
#include "cefclient/binding_test.h"
#include "cefclient/cefclient.h"
#include "cefclient/dom_test.h"
#include "cefclient/resource_util.h"
#include "cefclient/string_util.h"
@@ -114,6 +115,10 @@ void ClientHandler::OnLoadEnd(CefRefPtr<CefBrowser> browser,
if (m_BrowserId == browser->GetIdentifier() && frame->IsMain()) {
// We've just finished loading a page
SetLoading(false);
// Continue the DOM test.
if (frame->GetURL() == dom_test::kTestUrl)
dom_test::OnLoadEnd(browser);
}
}
@@ -153,6 +158,12 @@ CefRefPtr<CefResourceHandler> ClientHandler::GetResourceHandler(
GetBinaryResourceReader("dialogs.html");
ASSERT(stream.get());
return new CefStreamResourceHandler("text/html", stream);
} else if (url == dom_test::kTestUrl) {
// Show the domaccess contents
CefRefPtr<CefStreamReader> stream =
GetBinaryResourceReader("domaccess.html");
ASSERT(stream.get());
return new CefStreamResourceHandler("text/html", stream);
} else if (url == "http://tests/localstorage") {
// Show the localstorage contents
CefRefPtr<CefStreamReader> stream =
@@ -247,7 +258,7 @@ void ClientHandler::OnBeforeContextMenu(
// Add a separator if the menu already has items.
if (model->GetCount() > 0)
model->AddSeparator();
// Add a "Show DevTools" item to all context menus.
model->AddItem(CLIENT_ID_SHOW_DEVTOOLS, "&Show DevTools");

View File

@@ -0,0 +1,139 @@
// Copyright (c) 2012 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 "cefclient/dom_test.h"
#include <sstream>
#include <string>
#include "include/cef_dom.h"
#include "cefclient/util.h"
namespace dom_test {
const char kTestUrl[] = "http://tests/domaccess";
namespace {
const char* kMessageName = "DOMTest.Message";
class ClientDOMEventListener : public CefDOMEventListener {
public:
ClientDOMEventListener() {
}
virtual void HandleEvent(CefRefPtr<CefDOMEvent> event) OVERRIDE {
CefRefPtr<CefDOMDocument> document = event->GetDocument();
ASSERT(document.get());
std::stringstream ss;
CefRefPtr<CefDOMNode> button = event->GetTarget();
ASSERT(button.get());
std::string buttonValue = button->GetElementAttribute("value");
ss << "You clicked the " << buttonValue.c_str() << " button. ";
if (document->HasSelection()) {
std::string startName, endName;
// Determine the start name by first trying to locate the "id" attribute
// and then defaulting to the tag name.
{
CefRefPtr<CefDOMNode> node = document->GetSelectionStartNode();
if (!node->IsElement())
node = node->GetParent();
if (node->IsElement() && node->HasElementAttribute("id"))
startName = node->GetElementAttribute("id");
else
startName = node->GetName();
}
// Determine the end name by first trying to locate the "id" attribute
// and then defaulting to the tag name.
{
CefRefPtr<CefDOMNode> node = document->GetSelectionEndNode();
if (!node->IsElement())
node = node->GetParent();
if (node->IsElement() && node->HasElementAttribute("id"))
endName = node->GetElementAttribute("id");
else
endName = node->GetName();
}
ss << "The selection is from " <<
startName.c_str() << ":" << document->GetSelectionStartOffset() <<
" to " <<
endName.c_str() << ":" << document->GetSelectionEndOffset();
} else {
ss << "Nothing is selected.";
}
// Update the description.
CefRefPtr<CefDOMNode> desc = document->GetElementById("description");
ASSERT(desc.get());
CefRefPtr<CefDOMNode> text = desc->GetFirstChild();
ASSERT(text.get());
ASSERT(text->IsText());
text->SetValue(ss.str());
}
IMPLEMENT_REFCOUNTING(ClientDOMEventListener);
};
class ClientDOMVisitor : public CefDOMVisitor {
public:
ClientDOMVisitor() {
}
virtual void Visit(CefRefPtr<CefDOMDocument> document) OVERRIDE {
// Register a click listener for the button.
CefRefPtr<CefDOMNode> button = document->GetElementById("button");
ASSERT(button.get());
button->AddEventListener("click", new ClientDOMEventListener(), false);
}
IMPLEMENT_REFCOUNTING(ClientDOMVisitor);
};
class DOMRenderDelegate : public ClientApp::RenderDelegate {
public:
DOMRenderDelegate() {
}
virtual bool OnProcessMessageRecieved(
CefRefPtr<ClientApp> app,
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) OVERRIDE {
if (message->GetName() == kMessageName) {
// Visit the DOM to attach the event listener.
browser->GetMainFrame()->VisitDOM(new ClientDOMVisitor);
return true;
}
return false;
}
private:
IMPLEMENT_REFCOUNTING(DOMRenderDelegate);
};
} // namespace
void CreateRenderDelegates(ClientApp::RenderDelegateSet& delegates) {
delegates.insert(new DOMRenderDelegate);
}
void RunTest(CefRefPtr<CefBrowser> browser) {
// Load the test URL.
browser->GetMainFrame()->LoadURL(kTestUrl);
}
void OnLoadEnd(CefRefPtr<CefBrowser> browser) {
// Send a message to the render process to continue the test setup.
browser->SendProcessMessage(PID_RENDERER,
CefProcessMessage::Create(kMessageName));
}
} // namespace dom_test

View File

@@ -0,0 +1,28 @@
// Copyright (c) 2012 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.
#ifndef CEF_TESTS_CEFCLIENT_DOM_TEST_H_
#define CEF_TESTS_CEFCLIENT_DOM_TEST_H_
#pragma once
#include "include/cef_base.h"
#include "cefclient/client_app.h"
namespace dom_test {
// The DOM test URL.
extern const char kTestUrl[];
// Create the render delegate.
void CreateRenderDelegates(ClientApp::RenderDelegateSet& delegates);
// Run the test.
void RunTest(CefRefPtr<CefBrowser> browser);
// Continue the test after the page has loaded.
void OnLoadEnd(CefRefPtr<CefBrowser> browser);
} // namespace dom_test
#endif // CEF_TESTS_CEFCLIENT_DOM_TEST_H_

View File

@@ -0,0 +1,13 @@
<html>
<body>
<p id="instructions">Select some portion of the below page content and click the "Describe Selection" button. The selected region will then be described below.</p>
<p id="p1">This is p1</p>
<p id="p2">This is p2</p>
<p id="p3">This is p3</p>
<p id="p4">This is p4</p>
<form>
<input type="button" id="button" value="Describe Selection">
<p id="description">The description will appear here.</p>
</form>
</body>
</html>

View File

@@ -40,6 +40,7 @@
#define ID_TESTS_BINDING 32773
#define ID_TESTS_DIALOGS 32774
#define ID_TESTS_PLUGIN_INFO 32775
#define ID_TESTS_DOM_ACCESS 32776
#define IDC_STATIC -1
#define IDS_BINDING 1000
#define IDS_DIALOGS 1001
@@ -47,6 +48,7 @@
#define IDS_LOGOBALL 1003
#define IDS_LOCALSTORAGE 1004
#define IDS_XMLHTTPREQUEST 1005
#define IDS_DOMACCESS 1006
// Avoid files associated with MacOS
#define _X86_

View File

@@ -47,6 +47,7 @@ CefRefPtr<CefStreamReader> GetBinaryResourceReader(const char* resource_name) {
} resource_map[] = {
{"binding.html", IDS_BINDING},
{"dialogs.html", IDS_DIALOGS},
{"domaccess.html", IDS_DOMACCESS},
{"localstorage.html", IDS_LOCALSTORAGE},
{"xmlhttprequest.html", IDS_XMLHTTPREQUEST},
};

View File

@@ -12,8 +12,12 @@ void ClientApp::CreateRenderDelegates(RenderDelegateSet& delegates) {
CreateProcessMessageRendererTests(delegates);
// Bring in the V8 tests.
extern void CreateV8RendererTests(ClientApp::RenderDelegateSet& delegates);
extern void CreateV8RendererTests(RenderDelegateSet& delegates);
CreateV8RendererTests(delegates);
// Bring in the DOM tests.
extern void CreateDOMRendererTests(RenderDelegateSet& delegates);
CreateDOMRendererTests(delegates);
}
// static

View File

@@ -0,0 +1,332 @@
// Copyright (c) 2012 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 "include/cef_dom.h"
#include "tests/cefclient/client_app.h"
#include "tests/unittests/test_handler.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const char* kTestUrl = "http://tests/DOMTest.Test";
const char* kTestMessage = "DOMTest.Message";
enum DOMTestType {
DOM_TEST_STRUCTURE,
DOM_TEST_MODIFY,
};
class TestDOMVisitor : public CefDOMVisitor {
public:
explicit TestDOMVisitor(CefRefPtr<CefBrowser> browser, DOMTestType test_type)
: browser_(browser),
test_type_(test_type) {
}
void TestHeadNodeStructure(CefRefPtr<CefDOMNode> headNode) {
EXPECT_TRUE(headNode.get());
EXPECT_TRUE(headNode->IsElement());
EXPECT_FALSE(headNode->IsText());
EXPECT_EQ(headNode->GetName(), "HEAD");
EXPECT_EQ(headNode->GetElementTagName(), "HEAD");
EXPECT_TRUE(headNode->HasChildren());
EXPECT_FALSE(headNode->HasElementAttributes());
CefRefPtr<CefDOMNode> titleNode = headNode->GetFirstChild();
EXPECT_TRUE(titleNode.get());
EXPECT_TRUE(titleNode->IsElement());
EXPECT_FALSE(titleNode->IsText());
EXPECT_EQ(titleNode->GetName(), "TITLE");
EXPECT_EQ(titleNode->GetElementTagName(), "TITLE");
EXPECT_TRUE(titleNode->GetParent()->IsSame(headNode));
EXPECT_FALSE(titleNode->GetNextSibling().get());
EXPECT_FALSE(titleNode->GetPreviousSibling().get());
EXPECT_TRUE(titleNode->HasChildren());
EXPECT_FALSE(titleNode->HasElementAttributes());
CefRefPtr<CefDOMNode> textNode = titleNode->GetFirstChild();
EXPECT_TRUE(textNode.get());
EXPECT_FALSE(textNode->IsElement());
EXPECT_TRUE(textNode->IsText());
EXPECT_EQ(textNode->GetValue(), "The Title");
EXPECT_TRUE(textNode->GetParent()->IsSame(titleNode));
EXPECT_FALSE(textNode->GetNextSibling().get());
EXPECT_FALSE(textNode->GetPreviousSibling().get());
EXPECT_FALSE(textNode->HasChildren());
}
void TestBodyNodeStructure(CefRefPtr<CefDOMNode> bodyNode) {
EXPECT_TRUE(bodyNode.get());
EXPECT_TRUE(bodyNode->IsElement());
EXPECT_FALSE(bodyNode->IsText());
EXPECT_EQ(bodyNode->GetName(), "BODY");
EXPECT_EQ(bodyNode->GetElementTagName(), "BODY");
EXPECT_TRUE(bodyNode->HasChildren());
EXPECT_FALSE(bodyNode->HasElementAttributes());
CefRefPtr<CefDOMNode> h1Node = bodyNode->GetFirstChild();
EXPECT_TRUE(h1Node.get());
EXPECT_TRUE(h1Node->IsElement());
EXPECT_FALSE(h1Node->IsText());
EXPECT_EQ(h1Node->GetName(), "H1");
EXPECT_EQ(h1Node->GetElementTagName(), "H1");
EXPECT_FALSE(h1Node->GetNextSibling().get());
EXPECT_FALSE(h1Node->GetPreviousSibling().get());
EXPECT_TRUE(h1Node->HasChildren());
EXPECT_FALSE(h1Node->HasElementAttributes());
CefRefPtr<CefDOMNode> textNode = h1Node->GetFirstChild();
EXPECT_TRUE(textNode.get());
EXPECT_FALSE(textNode->IsElement());
EXPECT_TRUE(textNode->IsText());
EXPECT_EQ(textNode->GetValue(), "Hello From");
EXPECT_FALSE(textNode->GetPreviousSibling().get());
EXPECT_FALSE(textNode->HasChildren());
CefRefPtr<CefDOMNode> brNode = textNode->GetNextSibling();
EXPECT_TRUE(brNode.get());
EXPECT_TRUE(brNode->IsElement());
EXPECT_FALSE(brNode->IsText());
EXPECT_EQ(brNode->GetName(), "BR");
EXPECT_EQ(brNode->GetElementTagName(), "BR");
EXPECT_FALSE(brNode->HasChildren());
EXPECT_TRUE(brNode->HasElementAttributes());
EXPECT_TRUE(brNode->HasElementAttribute("class"));
EXPECT_EQ(brNode->GetElementAttribute("class"), "some_class");
EXPECT_TRUE(brNode->HasElementAttribute("id"));
EXPECT_EQ(brNode->GetElementAttribute("id"), "some_id");
EXPECT_FALSE(brNode->HasElementAttribute("no_existing"));
CefDOMNode::AttributeMap map;
brNode->GetElementAttributes(map);
ASSERT_EQ(map.size(), (size_t)2);
EXPECT_EQ(map["class"], "some_class");
EXPECT_EQ(map["id"], "some_id");
// Can also retrieve by ID.
brNode = bodyNode->GetDocument()->GetElementById("some_id");
EXPECT_TRUE(brNode.get());
EXPECT_TRUE(brNode->IsElement());
EXPECT_FALSE(brNode->IsText());
EXPECT_EQ(brNode->GetName(), "BR");
EXPECT_EQ(brNode->GetElementTagName(), "BR");
textNode = brNode->GetNextSibling();
EXPECT_TRUE(textNode.get());
EXPECT_FALSE(textNode->IsElement());
EXPECT_TRUE(textNode->IsText());
EXPECT_EQ(textNode->GetValue(), "Main Frame");
EXPECT_FALSE(textNode->GetNextSibling().get());
EXPECT_FALSE(textNode->HasChildren());
}
// Test document structure by iterating through the DOM tree.
void TestStructure(CefRefPtr<CefDOMDocument> document) {
EXPECT_EQ(document->GetTitle(), "The Title");
EXPECT_EQ(document->GetBaseURL(), kTestUrl);
EXPECT_EQ(document->GetCompleteURL("foo.html"), "http://tests/foo.html");
// Navigate the complete document structure.
CefRefPtr<CefDOMNode> docNode = document->GetDocument();
EXPECT_TRUE(docNode.get());
EXPECT_FALSE(docNode->IsElement());
EXPECT_FALSE(docNode->IsText());
CefRefPtr<CefDOMNode> htmlNode = docNode->GetFirstChild();
EXPECT_TRUE(htmlNode.get());
EXPECT_TRUE(htmlNode->IsElement());
EXPECT_FALSE(htmlNode->IsText());
EXPECT_EQ(htmlNode->GetName(), "HTML");
EXPECT_EQ(htmlNode->GetElementTagName(), "HTML");
EXPECT_TRUE(htmlNode->HasChildren());
EXPECT_FALSE(htmlNode->HasElementAttributes());
CefRefPtr<CefDOMNode> headNode = htmlNode->GetFirstChild();
TestHeadNodeStructure(headNode);
CefRefPtr<CefDOMNode> bodyNode = headNode->GetNextSibling();
TestBodyNodeStructure(bodyNode);
// Retrieve the head node directly.
headNode = document->GetHead();
TestHeadNodeStructure(headNode);
// Retrieve the body node directly.
bodyNode = document->GetBody();
TestBodyNodeStructure(bodyNode);
}
// Test document modification by changing the H1 tag.
void TestModify(CefRefPtr<CefDOMDocument> document) {
CefRefPtr<CefDOMNode> bodyNode = document->GetBody();
CefRefPtr<CefDOMNode> h1Node = bodyNode->GetFirstChild();
ASSERT_EQ(h1Node->GetAsMarkup(),
"<h1>Hello From<br class=\"some_class\" id=\"some_id\">"
"Main Frame</h1>");
CefRefPtr<CefDOMNode> textNode = h1Node->GetFirstChild();
ASSERT_EQ(textNode->GetValue(), "Hello From");
ASSERT_TRUE(textNode->SetValue("A Different Message From"));
ASSERT_EQ(textNode->GetValue(), "A Different Message From");
CefRefPtr<CefDOMNode> brNode = textNode->GetNextSibling();
EXPECT_EQ(brNode->GetElementAttribute("class"), "some_class");
EXPECT_TRUE(brNode->SetElementAttribute("class", "a_different_class"));
EXPECT_EQ(brNode->GetElementAttribute("class"), "a_different_class");
ASSERT_EQ(h1Node->GetAsMarkup(),
"<h1>A Different Message From<br class=\"a_different_class\" "
"id=\"some_id\">Main Frame</h1>");
ASSERT_FALSE(h1Node->SetValue("Something Different"));
}
virtual void Visit(CefRefPtr<CefDOMDocument> document) OVERRIDE {
if (test_type_ == DOM_TEST_STRUCTURE)
TestStructure(document);
else if (test_type_ == DOM_TEST_MODIFY)
TestModify(document);
DestroyTest();
}
protected:
// Return from the test.
void DestroyTest() {
// Check if the test has failed.
bool result = !TestFailed();
// Return the result to the browser process.
CefRefPtr<CefProcessMessage> return_msg =
CefProcessMessage::Create(kTestMessage);
EXPECT_TRUE(return_msg->GetArgumentList()->SetBool(0, result));
EXPECT_TRUE(browser_->SendProcessMessage(PID_BROWSER, return_msg));
}
CefRefPtr<CefBrowser> browser_;
DOMTestType test_type_;
IMPLEMENT_REFCOUNTING(TestDOMVisitor);
};
// Used in the render process.
class DOMRendererTest : public ClientApp::RenderDelegate {
public:
DOMRendererTest() {
}
virtual bool OnProcessMessageRecieved(
CefRefPtr<ClientApp> app,
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) OVERRIDE {
if (message->GetName() == kTestMessage) {
EXPECT_EQ(message->GetArgumentList()->GetSize(), (size_t)1);
int test_type = message->GetArgumentList()->GetInt(0);
browser->GetMainFrame()->VisitDOM(
new TestDOMVisitor(browser, static_cast<DOMTestType>(test_type)));
return true;
}
return false;
}
private:
IMPLEMENT_REFCOUNTING(DOMRendererTest);
};
// Used in the browser process.
class TestDOMHandler : public TestHandler {
public:
explicit TestDOMHandler(DOMTestType test)
: test_type_(test) {
}
virtual void RunTest() OVERRIDE {
std::stringstream mainHtml;
mainHtml <<
"<html>"
"<head><title>The Title</title></head>"
"<body>"
"<h1>Hello From<br class=\"some_class\"/ id=\"some_id\"/>"
"Main Frame</h1>"
"</body>"
"</html>";
AddResource(kTestUrl, mainHtml.str(), "text/html");
CreateBrowser(kTestUrl);
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE {
if (frame->IsMain()) {
// Start the test in the render process.
CefRefPtr<CefProcessMessage> message(
CefProcessMessage::Create(kTestMessage));
message->GetArgumentList()->SetInt(0, test_type_);
EXPECT_TRUE(browser->SendProcessMessage(PID_RENDERER, message));
}
}
virtual bool OnProcessMessageRecieved(
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) OVERRIDE {
EXPECT_STREQ(message->GetName().ToString().c_str(), kTestMessage);
got_message_.yes();
if (message->GetArgumentList()->GetBool(0))
got_success_.yes();
// Test is complete.
DestroyTest();
return true;
}
DOMTestType test_type_;
TrackCallback got_message_;
TrackCallback got_success_;
};
} // namespace
// Test DOM structure reading.
TEST(DOMTest, Read) {
CefRefPtr<TestDOMHandler> handler =
new TestDOMHandler(DOM_TEST_STRUCTURE);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_message_);
EXPECT_TRUE(handler->got_success_);
}
// Test DOM modifications.
TEST(DOMTest, Modify) {
CefRefPtr<TestDOMHandler> handler =
new TestDOMHandler(DOM_TEST_MODIFY);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_message_);
EXPECT_TRUE(handler->got_success_);
}
// Entry point for creating DOM renderer test objects.
// Called from client_app_delegates.cc.
void CreateDOMRendererTests(ClientApp::RenderDelegateSet& delegates) {
delegates.insert(new DOMRendererTest);
}