OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 #include "platform/weborigin/SchemeRegistry.h" | 86 #include "platform/weborigin/SchemeRegistry.h" |
87 #include "platform/weborigin/SecurityOrigin.h" | 87 #include "platform/weborigin/SecurityOrigin.h" |
88 #include "public/platform/Platform.h" | 88 #include "public/platform/Platform.h" |
89 #include "public/platform/WebFloatRect.h" | 89 #include "public/platform/WebFloatRect.h" |
90 #include "public/platform/WebSecurityOrigin.h" | 90 #include "public/platform/WebSecurityOrigin.h" |
91 #include "public/platform/WebThread.h" | 91 #include "public/platform/WebThread.h" |
92 #include "public/platform/WebURL.h" | 92 #include "public/platform/WebURL.h" |
93 #include "public/platform/WebURLResponse.h" | 93 #include "public/platform/WebURLResponse.h" |
94 #include "public/platform/WebUnitTestSupport.h" | 94 #include "public/platform/WebUnitTestSupport.h" |
95 #include "public/web/WebCache.h" | 95 #include "public/web/WebCache.h" |
| 96 #include "public/web/WebConsoleMessage.h" |
96 #include "public/web/WebDataSource.h" | 97 #include "public/web/WebDataSource.h" |
97 #include "public/web/WebDocument.h" | 98 #include "public/web/WebDocument.h" |
98 #include "public/web/WebFindOptions.h" | 99 #include "public/web/WebFindOptions.h" |
99 #include "public/web/WebFormElement.h" | 100 #include "public/web/WebFormElement.h" |
100 #include "public/web/WebFrameClient.h" | 101 #include "public/web/WebFrameClient.h" |
101 #include "public/web/WebHistoryItem.h" | 102 #include "public/web/WebHistoryItem.h" |
102 #include "public/web/WebPrintParams.h" | 103 #include "public/web/WebPrintParams.h" |
103 #include "public/web/WebRange.h" | 104 #include "public/web/WebRange.h" |
104 #include "public/web/WebRemoteFrame.h" | 105 #include "public/web/WebRemoteFrame.h" |
105 #include "public/web/WebScriptSource.h" | 106 #include "public/web/WebScriptSource.h" |
(...skipping 7073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7179 FrameTestHelpers::TestWebViewClient viewClient; | 7180 FrameTestHelpers::TestWebViewClient viewClient; |
7180 FrameTestHelpers::TestWebRemoteFrameClient remoteClient; | 7181 FrameTestHelpers::TestWebRemoteFrameClient remoteClient; |
7181 WebView* view = WebView::create(&viewClient); | 7182 WebView* view = WebView::create(&viewClient); |
7182 view->setMainFrame(remoteClient.frame()); | 7183 view->setMainFrame(remoteClient.frame()); |
7183 FrameTestHelpers::TestWebRemoteFrameClient childFrameClient; | 7184 FrameTestHelpers::TestWebRemoteFrameClient childFrameClient; |
7184 WebRemoteFrame* childFrame = view->mainFrame()->toWebRemoteFrame()->createRe
moteChild("", WebSandboxFlags::None, &childFrameClient); | 7185 WebRemoteFrame* childFrame = view->mainFrame()->toWebRemoteFrame()->createRe
moteChild("", WebSandboxFlags::None, &childFrameClient); |
7185 childFrame->detach(); | 7186 childFrame->detach(); |
7186 view->close(); | 7187 view->close(); |
7187 } | 7188 } |
7188 | 7189 |
| 7190 class TestConsoleMessageWebFrameClient : public FrameTestHelpers::TestWebFrameCl
ient { |
| 7191 public: |
| 7192 virtual void didAddMessageToConsole(const WebConsoleMessage& message, const
WebString& sourceName, unsigned sourceLine, const WebString& stackTrace) |
| 7193 { |
| 7194 messages.push_back(message); |
| 7195 } |
| 7196 |
| 7197 std::vector<WebConsoleMessage> messages; |
| 7198 }; |
| 7199 |
| 7200 TEST_F(WebFrameTest, CrossDomainAccessErrorsUseCallingWindow) |
| 7201 { |
| 7202 registerMockedHttpURLLoad("hidden_frames.html"); |
| 7203 registerMockedChromeURLLoad("hello_world.html"); |
| 7204 |
| 7205 FrameTestHelpers::WebViewHelper webViewHelper; |
| 7206 TestConsoleMessageWebFrameClient webFrameClient; |
| 7207 FrameTestHelpers::TestWebViewClient webViewClient; |
| 7208 webViewHelper.initializeAndLoad(m_baseURL + "hidden_frames.html", true, &web
FrameClient, &webViewClient); |
| 7209 |
| 7210 // Create another window with a cross-origin page, and point its opener to |
| 7211 // first window. |
| 7212 FrameTestHelpers::WebViewHelper popupWebViewHelper; |
| 7213 TestConsoleMessageWebFrameClient popupWebFrameClient; |
| 7214 WebView* popupView = popupWebViewHelper.initializeAndLoad(m_chromeURL + "hel
lo_world.html", true, &popupWebFrameClient); |
| 7215 popupView->mainFrame()->setOpener(webViewHelper.webView()->mainFrame()); |
| 7216 |
| 7217 // Attempt a blocked navigation of an opener's subframe, and ensure that |
| 7218 // the error shows up on the popup (calling) window's console, rather than |
| 7219 // the target window. |
| 7220 popupView->mainFrame()->executeScript(WebScriptSource("opener.frames[1].loca
tion.href='data:text/html,foo'")); |
| 7221 EXPECT_TRUE(webFrameClient.messages.empty()); |
| 7222 ASSERT_EQ(1u, popupWebFrameClient.messages.size()); |
| 7223 EXPECT_TRUE(std::string::npos != popupWebFrameClient.messages[0].text.utf8()
.find("Unsafe JavaScript attempt to initiate navigation")); |
| 7224 |
| 7225 // Try setting a cross-origin iframe element's source to a javascript: URL, |
| 7226 // and check that this error is also printed on the calling window. |
| 7227 popupView->mainFrame()->executeScript(WebScriptSource("opener.document.query
SelectorAll('iframe')[1].src='javascript:alert()'")); |
| 7228 EXPECT_TRUE(webFrameClient.messages.empty()); |
| 7229 ASSERT_EQ(2u, popupWebFrameClient.messages.size()); |
| 7230 EXPECT_TRUE(std::string::npos != popupWebFrameClient.messages[1].text.utf8()
.find("Blocked a frame")); |
| 7231 |
| 7232 // Manually reset to break WebViewHelpers' dependencies on the stack |
| 7233 // allocated WebFrameClients. |
| 7234 webViewHelper.reset(); |
| 7235 popupWebViewHelper.reset(); |
| 7236 } |
| 7237 |
7189 } // namespace blink | 7238 } // namespace blink |
OLD | NEW |