Commit afe1a67b authored by aa@chromium.org's avatar aa@chromium.org

2011-04-05 Aaron Boodman <aa@chromium.org>

        Reviewed by Adam Barth.

        Add ability to get frame from v8 context to chromium WebKit API
        https://bugs.webkit.org/show_bug.cgi?id=57516

        * public/WebFrame.h:
        * src/WebFrameImpl.cpp:
        (WebKit::WebFrame::frameForV8Context):

git-svn-id: svn://svn.chromium.org/blink/trunk@83007 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 57336756
2011-04-05 Aaron Boodman <aa@chromium.org>
Reviewed by Adam Barth.
Add ability to get frame from v8 context to chromium WebKit API
https://bugs.webkit.org/show_bug.cgi?id=57516
* public/WebFrame.h:
* src/WebFrameImpl.cpp:
(WebKit::WebFrame::frameForV8Context):
2011-04-05 Nico Weber <thakis@chromium.org> 2011-04-05 Nico Weber <thakis@chromium.org>
Reviewed by Dimitri Glazkov. Reviewed by Dimitri Glazkov.
......
...@@ -815,11 +815,10 @@ ...@@ -815,11 +815,10 @@
'conditions': [ 'conditions': [
['OS=="win"', { ['OS=="win"', {
'sources': [ 'sources': [
# FIXME: Port PopupMenuTest and WebFrameTest to Linux and Mac. # FIXME: Port PopupMenuTest to Linux and Mac.
'tests/PopupMenuTest.cpp', 'tests/PopupMenuTest.cpp',
'tests/TransparencyWinTest.cpp', 'tests/TransparencyWinTest.cpp',
'tests/UniscribeHelperTest.cpp', 'tests/UniscribeHelperTest.cpp',
'tests/WebFrameTest.cpp',
'tests/WebPageSerializerTest.cpp', 'tests/WebPageSerializerTest.cpp',
], ],
}], }],
......
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
'tests/TilingDataTest.cpp', 'tests/TilingDataTest.cpp',
'tests/TreeTestHelpers.cpp', 'tests/TreeTestHelpers.cpp',
'tests/TreeTestHelpers.h', 'tests/TreeTestHelpers.h',
'tests/WebFrameTest.cpp',
], ],
}, },
} }
......
...@@ -97,6 +97,13 @@ public: ...@@ -97,6 +97,13 @@ public:
WEBKIT_API static WebFrame* frameForEnteredContext(); WEBKIT_API static WebFrame* frameForEnteredContext();
WEBKIT_API static WebFrame* frameForCurrentContext(); WEBKIT_API static WebFrame* frameForCurrentContext();
#if WEBKIT_USING_V8
// Returns the frame corresponding to the given context. This can return 0
// if the context is detached from the frame, or if the context doesn't
// correspond to a frame (e.g., workers).
WEBKIT_API static WebFrame* frameForContext(v8::Handle<v8::Context>);
#endif
// Returns the frame inside a given frame or iframe element. Returns 0 if // Returns the frame inside a given frame or iframe element. Returns 0 if
// the given element is not a frame, iframe or if the frame is empty. // the given element is not a frame, iframe or if the frame is empty.
WEBKIT_API static WebFrame* fromFrameOwnerElement(const WebElement&); WEBKIT_API static WebFrame* fromFrameOwnerElement(const WebElement&);
......
...@@ -473,6 +473,13 @@ WebFrame* WebFrame::frameForCurrentContext() ...@@ -473,6 +473,13 @@ WebFrame* WebFrame::frameForCurrentContext()
return WebFrameImpl::fromFrame(frame); return WebFrameImpl::fromFrame(frame);
} }
#if WEBKIT_USING_V8
WebFrame* WebFrame::frameForContext(v8::Handle<v8::Context> context)
{
return WebFrameImpl::fromFrame(V8Proxy::retrieveFrame(context));
}
#endif
WebFrame* WebFrame::fromFrameOwnerElement(const WebElement& element) WebFrame* WebFrame::fromFrameOwnerElement(const WebElement& element)
{ {
return WebFrameImpl::fromFrameOwnerElement( return WebFrameImpl::fromFrameOwnerElement(
......
...@@ -35,11 +35,13 @@ ...@@ -35,11 +35,13 @@
#include <webkit/support/webkit_support.h> #include <webkit/support/webkit_support.h>
#include "WebFrame.h" #include "WebFrame.h"
#include "WebFrameClient.h" #include "WebFrameClient.h"
#include "WebSettings.h"
#include "WebString.h" #include "WebString.h"
#include "WebURL.h" #include "WebURL.h"
#include "WebURLRequest.h" #include "WebURLRequest.h"
#include "WebURLResponse.h" #include "WebURLResponse.h"
#include "WebView.h" #include "WebView.h"
#include "v8.h"
using namespace WebKit; using namespace WebKit;
...@@ -47,25 +49,44 @@ namespace { ...@@ -47,25 +49,44 @@ namespace {
class WebFrameTest : public testing::Test { class WebFrameTest : public testing::Test {
public: public:
WebFrameTest() {} WebFrameTest()
: baseURL("http://www.test.com/")
{
}
virtual void TearDown() virtual void TearDown()
{ {
webkit_support::UnregisterAllMockedURLs(); webkit_support::UnregisterAllMockedURLs();
} }
void registerMockedURLLoad(const WebURL& url, const WebURLResponse& response, const WebString& fileName) void registerMockedURLLoad(const std::string& fileName)
{ {
WebURLResponse response;
response.initialize();
response.setMIMEType("text/html");
std::string filePath = webkit_support::GetWebKitRootDir().utf8(); std::string filePath = webkit_support::GetWebKitRootDir().utf8();
filePath.append("/Source/WebKit/chromium/tests/data/"); filePath += "/Source/WebKit/chromium/tests/data/";
filePath.append(fileName.utf8()); filePath += fileName;
webkit_support::RegisterMockedURL(url, response, WebString::fromUTF8(filePath));
webkit_support::RegisterMockedURL(WebURL(GURL(baseURL + fileName)), response, WebString::fromUTF8(filePath));
} }
void serveRequests() void serveRequests()
{ {
webkit_support::ServeAsynchronousMockedRequests(); webkit_support::ServeAsynchronousMockedRequests();
} }
void loadFrame(WebFrame* frame, const std::string& fileName)
{
WebURLRequest urlRequest;
urlRequest.initialize();
urlRequest.setURL(WebURL(GURL(baseURL + fileName)));
frame->loadRequest(urlRequest);
}
protected:
std::string baseURL;
}; };
class TestWebFrameClient : public WebFrameClient { class TestWebFrameClient : public WebFrameClient {
...@@ -73,31 +94,17 @@ class TestWebFrameClient : public WebFrameClient { ...@@ -73,31 +94,17 @@ class TestWebFrameClient : public WebFrameClient {
TEST_F(WebFrameTest, ContentText) TEST_F(WebFrameTest, ContentText)
{ {
// Register our resources. registerMockedURLLoad("iframes_test.html");
WebURLResponse response; registerMockedURLLoad("visible_iframe.html");
response.initialize(); registerMockedURLLoad("invisible_iframe.html");
response.setMIMEType("text/html"); registerMockedURLLoad("zero_sized_iframe.html");
std::string rootURL = "http://www.test.com/";
const char* files[] = { "iframes_test.html", "visible_iframe.html",
"invisible_iframe.html", "zero_sized_iframe.html" };
for (int i = 0; i < (sizeof(files) / sizeof(char*)); ++i) {
WebURL webURL = GURL(rootURL + files[i]);
registerMockedURLLoad(webURL, response, WebString::fromUTF8(files[i]));
}
// Create and initialize the WebView. // Create and initialize the WebView.
TestWebFrameClient webFrameClient; TestWebFrameClient webFrameClient;
WebView* webView = WebView::create(0); WebView* webView = WebView::create(0);
webView->initializeMainFrame(&webFrameClient); webView->initializeMainFrame(&webFrameClient);
// Load the main frame URL. loadFrame(webView->mainFrame(), "iframes_test.html");
WebURL testURL(GURL(rootURL + files[0]));
WebURLRequest urlRequest;
urlRequest.initialize();
urlRequest.setURL(testURL);
webView->mainFrame()->loadRequest(urlRequest);
// Load all pending asynchronous requests.
serveRequests(); serveRequests();
// Now retrieve the frames text and test it only includes visible elements. // Now retrieve the frames text and test it only includes visible elements.
...@@ -111,4 +118,31 @@ TEST_F(WebFrameTest, ContentText) ...@@ -111,4 +118,31 @@ TEST_F(WebFrameTest, ContentText)
webView->close(); webView->close();
} }
TEST_F(WebFrameTest, FrameForEnteredContext)
{
registerMockedURLLoad("iframes_test.html");
registerMockedURLLoad("visible_iframe.html");
registerMockedURLLoad("invisible_iframe.html");
registerMockedURLLoad("zero_sized_iframe.html");
// Create and initialize the WebView.
TestWebFrameClient webFrameClient;
WebView* webView = WebView::create(0);
webView->settings()->setJavaScriptEnabled(true);
webView->initializeMainFrame(&webFrameClient);
loadFrame(webView->mainFrame(), "iframes_test.html");
serveRequests();
v8::HandleScope scope;
EXPECT_EQ(webView->mainFrame(),
WebFrame::frameForContext(
webView->mainFrame()->mainWorldScriptContext()));
EXPECT_EQ(webView->mainFrame()->firstChild(),
WebFrame::frameForContext(
webView->mainFrame()->firstChild()->mainWorldScriptContext()));
webView->close();
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment