diff options
Diffstat (limited to 'Source/WebKit/chromium/tests/WebFrameTest.cpp')
-rw-r--r-- | Source/WebKit/chromium/tests/WebFrameTest.cpp | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/Source/WebKit/chromium/tests/WebFrameTest.cpp b/Source/WebKit/chromium/tests/WebFrameTest.cpp index b8bc2e3c4..2fe01bf16 100644 --- a/Source/WebKit/chromium/tests/WebFrameTest.cpp +++ b/Source/WebKit/chromium/tests/WebFrameTest.cpp @@ -40,6 +40,7 @@ #include "WebRange.h" #include "WebScriptSource.h" #include "WebSearchableFormData.h" +#include "WebSecurityOrigin.h" #include "WebSecurityPolicy.h" #include "WebSettings.h" #include "WebViewClient.h" @@ -136,22 +137,71 @@ TEST_F(WebFrameTest, FormWithNullFrame) WebSearchableFormData searchableDataForm(forms[0]); } +TEST_F(WebFrameTest, ChromePageJavascript) +{ + registerMockedChromeURLLoad("history.html"); + + // Pass true to enable JavaScript. + WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_chromeURL + "history.html", true); + + // Try to run JS against the chrome-style URL. + FrameTestHelpers::loadFrame(webView->mainFrame(), "javascript:document.body.appendChild(document.createTextNode('Clobbered'))"); + + // Required to see any updates in contentAsText. + webView->layout(); + + // Now retrieve the frame's text and ensure it was modified by running javascript. + std::string content = webView->mainFrame()->contentAsText(1024).utf8(); + EXPECT_NE(std::string::npos, content.find("Clobbered")); +} + TEST_F(WebFrameTest, ChromePageNoJavascript) { registerMockedChromeURLLoad("history.html"); + /// Pass true to enable JavaScript. WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_chromeURL + "history.html", true); - // Try to run JS against the chrome-style URL. + // Try to run JS against the chrome-style URL after prohibiting it. WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs("chrome"); FrameTestHelpers::loadFrame(webView->mainFrame(), "javascript:document.body.appendChild(document.createTextNode('Clobbered'))"); - // Now retrieve the frames text and see if it was clobbered. + // Required to see any updates in contentAsText. + webView->layout(); + + // Now retrieve the frame's text and ensure it wasn't modified by running javascript. std::string content = webView->mainFrame()->contentAsText(1024).utf8(); - EXPECT_NE(std::string::npos, content.find("Simulated Chromium History Page")); EXPECT_EQ(std::string::npos, content.find("Clobbered")); } +TEST_F(WebFrameTest, DispatchMessageEventWithOriginCheck) +{ + registerMockedHttpURLLoad("postmessage_test.html"); + + // Pass true to enable JavaScript. + WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "postmessage_test.html", true); + + // Send a message with the correct origin. + WebSecurityOrigin correctOrigin(WebSecurityOrigin::create(GURL(m_baseURL))); + WebDOMEvent event = webView->mainFrame()->document().createEvent("MessageEvent"); + WebDOMMessageEvent message = event.to<WebDOMMessageEvent>(); + WebSerializedScriptValue data(WebSerializedScriptValue::fromString("foo")); + message.initMessageEvent("message", false, false, data, "http://origin.com", 0, ""); + webView->mainFrame()->dispatchMessageEventWithOriginCheck(correctOrigin, message); + + // Send another message with incorrect origin. + WebSecurityOrigin incorrectOrigin(WebSecurityOrigin::create(GURL(m_chromeURL))); + webView->mainFrame()->dispatchMessageEventWithOriginCheck(incorrectOrigin, message); + + // Required to see any updates in contentAsText. + webView->layout(); + + // Verify that only the first addition is in the body of the page. + std::string content = webView->mainFrame()->contentAsText(1024).utf8(); + EXPECT_NE(std::string::npos, content.find("Message 1.")); + EXPECT_EQ(std::string::npos, content.find("Message 2.")); +} + #if ENABLE(VIEWPORT) class FixedLayoutTestWebViewClient : public WebViewClient { |