Chromium Code Reviews| 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 14 matching lines...) Expand all Loading... | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 | 32 |
| 33 #include "WebFrame.h" | 33 #include "WebFrame.h" |
| 34 | 34 |
| 35 #include <gmock/gmock.h> | |
|
abarth-chromium
2013/07/12 23:44:11
I remember someone was telling us to avoid gmock..
Jeffrey Yasskin
2013/07/16 00:38:51
Actual mocks are often a mistake. Here I'm just us
| |
| 35 #include <gtest/gtest.h> | 36 #include <gtest/gtest.h> |
| 36 #include "FrameTestHelpers.h" | 37 #include "FrameTestHelpers.h" |
| 37 #include "SkBitmap.h" | 38 #include "SkBitmap.h" |
| 38 #include "SkCanvas.h" | 39 #include "SkCanvas.h" |
| 39 #include "URLTestHelpers.h" | 40 #include "URLTestHelpers.h" |
| 40 #include "WebDataSource.h" | 41 #include "WebDataSource.h" |
| 41 #include "WebDocument.h" | 42 #include "WebDocument.h" |
| 42 #include "WebFindOptions.h" | 43 #include "WebFindOptions.h" |
| 43 #include "WebFormElement.h" | 44 #include "WebFormElement.h" |
| 44 #include "WebFrameClient.h" | 45 #include "WebFrameClient.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 68 #include "core/page/Settings.h" | 69 #include "core/page/Settings.h" |
| 69 #include "core/platform/ScrollbarTheme.h" | 70 #include "core/platform/ScrollbarTheme.h" |
| 70 #include "core/platform/graphics/FloatRect.h" | 71 #include "core/platform/graphics/FloatRect.h" |
| 71 #include "core/platform/network/ResourceError.h" | 72 #include "core/platform/network/ResourceError.h" |
| 72 #include "core/rendering/HitTestResult.h" | 73 #include "core/rendering/HitTestResult.h" |
| 73 #include "core/rendering/RenderLayerCompositor.h" | 74 #include "core/rendering/RenderLayerCompositor.h" |
| 74 #include "core/rendering/RenderView.h" | 75 #include "core/rendering/RenderView.h" |
| 75 #include "core/rendering/TextAutosizer.h" | 76 #include "core/rendering/TextAutosizer.h" |
| 76 #include "v8.h" | 77 #include "v8.h" |
| 77 #include "public/platform/Platform.h" | 78 #include "public/platform/Platform.h" |
| 79 #include "public/platform/WebCString.h" | |
| 78 #include "public/platform/WebFloatRect.h" | 80 #include "public/platform/WebFloatRect.h" |
| 79 #include "public/platform/WebThread.h" | 81 #include "public/platform/WebThread.h" |
| 80 #include "public/platform/WebUnitTestSupport.h" | 82 #include "public/platform/WebUnitTestSupport.h" |
| 81 #include "public/platform/WebURLResponse.h" | 83 #include "public/platform/WebURLResponse.h" |
| 82 #include "wtf/dtoa/utils.h" | 84 #include "wtf/dtoa/utils.h" |
| 83 #include "wtf/Forward.h" | 85 #include "wtf/Forward.h" |
| 86 #include <map> | |
| 84 | 87 |
| 85 using namespace WebKit; | 88 using namespace WebKit; |
| 86 using WebCore::Document; | 89 using WebCore::Document; |
| 87 using WebCore::DocumentMarker; | 90 using WebCore::DocumentMarker; |
| 88 using WebCore::Element; | 91 using WebCore::Element; |
| 89 using WebCore::FloatRect; | 92 using WebCore::FloatRect; |
| 90 using WebCore::HitTestRequest; | 93 using WebCore::HitTestRequest; |
| 91 using WebCore::Range; | 94 using WebCore::Range; |
| 92 using WebKit::URLTestHelpers::toKURL; | 95 using WebKit::URLTestHelpers::toKURL; |
| 93 using WebKit::FrameTestHelpers::runPendingTasks; | 96 using WebKit::FrameTestHelpers::runPendingTasks; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 FrameTestHelpers::loadFrame(m_webView->mainFrame(), "javascript:document.bod y.appendChild(document.createTextNode('Clobbered'))"); | 266 FrameTestHelpers::loadFrame(m_webView->mainFrame(), "javascript:document.bod y.appendChild(document.createTextNode('Clobbered'))"); |
| 264 | 267 |
| 265 // Required to see any updates in contentAsText. | 268 // Required to see any updates in contentAsText. |
| 266 m_webView->layout(); | 269 m_webView->layout(); |
| 267 | 270 |
| 268 // Now retrieve the frame's text and ensure it wasn't modified by running ja vascript. | 271 // Now retrieve the frame's text and ensure it wasn't modified by running ja vascript. |
| 269 std::string content = std::string(m_webView->mainFrame()->contentAsText(1024 ).utf8().data()); | 272 std::string content = std::string(m_webView->mainFrame()->contentAsText(1024 ).utf8().data()); |
| 270 EXPECT_EQ(std::string::npos, content.find("Clobbered")); | 273 EXPECT_EQ(std::string::npos, content.find("Clobbered")); |
| 271 } | 274 } |
| 272 | 275 |
| 276 #if ENABLE(CSS_CALLBACKS) | |
| 277 struct CssCallbackWebFrameClient : public WebFrameClient { | |
|
abarth-chromium
2013/07/12 23:44:11
CssCallbackWebFrameClient -> CSSCallbackWebFrameCl
Jeffrey Yasskin
2013/07/16 00:38:51
Done.
| |
| 278 CssCallbackWebFrameClient() : m_updateCount(0) { } | |
| 279 virtual void didMatchCss(WebFrame* frame, const WebVector<WebString>& newlyM atchingSelectors, const WebVector<WebString>& stoppedMatchingSelectors) OVERRIDE | |
|
abarth-chromium
2013/07/12 23:44:11
didMatchCss -> didMatchCSS
Basically, we use CSS
Jeffrey Yasskin
2013/07/16 00:38:51
Done everywhere.
| |
| 280 { | |
| 281 ++m_updateCount; | |
| 282 std::set<std::string>& frameSelectors = m_matchedSelectors[frame]; | |
| 283 for (size_t i = 0; i < newlyMatchingSelectors.size(); ++i) { | |
| 284 std::string selector = newlyMatchingSelectors[i].utf8(); | |
| 285 EXPECT_EQ(0U, frameSelectors.count(selector)) << selector; | |
| 286 frameSelectors.insert(selector); | |
| 287 } | |
| 288 for (size_t i = 0; i < stoppedMatchingSelectors.size(); ++i) { | |
| 289 std::string selector = stoppedMatchingSelectors[i].utf8(); | |
| 290 EXPECT_EQ(1U, frameSelectors.count(selector)) << selector; | |
| 291 frameSelectors.erase(selector); | |
| 292 } | |
| 293 } | |
| 294 | |
| 295 std::map<WebFrame*, std::set<std::string> > m_matchedSelectors; | |
| 296 int m_updateCount; | |
| 297 }; | |
| 298 | |
| 299 TEST_F(WebFrameTest, CssCallbackAuthorStyleSheet) | |
| 300 { | |
| 301 CssCallbackWebFrameClient client; | |
| 302 WebView* webView = FrameTestHelpers::createWebViewAndLoad("about:blank", tru e, &client); | |
| 303 WebFrame* frame = webView->mainFrame(); | |
| 304 | |
| 305 frame->loadHTMLString( | |
| 306 "<style>" | |
| 307 // This stylesheet checks that the internal property and value can't be | |
| 308 // set by a stylesheet, only WebDocument::watchCssSelectors(). | |
| 309 "div.initial_on { -internal-callback: none; }" | |
| 310 "div.initial_off { -internal-callback: -internal-presence; }" | |
| 311 "</style>" | |
| 312 "<div class=\"initial_on\"></div>" | |
| 313 "<div class=\"initial_off\"></div>", | |
| 314 toKURL("about:blank")); | |
| 315 runPendingTasks(); | |
| 316 | |
| 317 std::vector<WebString> selectors; | |
| 318 selectors.push_back(WebString::fromUTF8("div.initial_on")); | |
| 319 frame->document().watchCssSelectors(WebVector<WebString>(selectors)); | |
| 320 runPendingTasks(); | |
| 321 EXPECT_EQ(1, client.m_updateCount); | |
| 322 EXPECT_THAT(client.m_matchedSelectors[frame], | |
| 323 testing::ElementsAre("div.initial_on")); | |
| 324 | |
| 325 WebDocument doc = frame->document(); | |
| 326 // Check that adding a watched selector calls back for already-present nodes . | |
| 327 selectors.push_back(WebString::fromUTF8("div.initial_off")); | |
| 328 frame->document().watchCssSelectors(WebVector<WebString>(selectors)); | |
| 329 runPendingTasks(); | |
| 330 EXPECT_EQ(2, client.m_updateCount); | |
| 331 EXPECT_THAT(client.m_matchedSelectors[frame], | |
| 332 testing::ElementsAre("div.initial_off", "div.initial_on")); | |
| 333 | |
| 334 // Check that we can turn off callbacks for certain selectors. | |
| 335 frame->document().watchCssSelectors(WebVector<WebString>()); | |
| 336 runPendingTasks(); | |
| 337 EXPECT_EQ(3, client.m_updateCount); | |
| 338 EXPECT_THAT(client.m_matchedSelectors[frame], | |
| 339 testing::ElementsAre()); | |
| 340 | |
| 341 EXPECT_EQ(1U, client.m_matchedSelectors.size()); | |
| 342 webView->close(); | |
| 343 } | |
| 344 | |
| 345 TEST_F(WebFrameTest, CssCallbackSharedRenderStyle) | |
| 346 { | |
| 347 CssCallbackWebFrameClient client; | |
| 348 WebView* webView = FrameTestHelpers::createWebViewAndLoad("about:blank", tru e, &client); | |
| 349 WebFrame* frame = webView->mainFrame(); | |
| 350 WebDocument doc = frame->document(); | |
| 351 | |
| 352 // Check that adding an element calls back when it matches an existing rule. | |
| 353 std::vector<WebString> selectors; | |
| 354 selectors.push_back(WebString::fromUTF8("span")); | |
| 355 doc.watchCssSelectors(WebVector<WebString>(selectors)); | |
| 356 | |
| 357 frame->executeScript(WebScriptSource( | |
| 358 "i1 = document.createElement('span');" | |
| 359 "i1.id = 'first_span';" | |
| 360 "document.body.appendChild(i1)")); | |
| 361 runPendingTasks(); | |
| 362 EXPECT_EQ(1, client.m_updateCount); | |
| 363 EXPECT_THAT(client.m_matchedSelectors[frame], | |
| 364 testing::ElementsAre("span")); | |
| 365 | |
| 366 // Adding a second element that shares a RenderStyle shouldn't call back. | |
| 367 // We use <span>s to avoid default style rules that can set | |
| 368 // RenderStyle::unique(). | |
| 369 frame->executeScript(WebScriptSource( | |
| 370 "i2 = document.createElement('span');" | |
| 371 "i2.id = 'second_span';" | |
| 372 "i1 = document.getElementById('first_span');" | |
| 373 "i1.parentNode.insertBefore(i2, i1.nextSibling);")); | |
| 374 runPendingTasks(); | |
| 375 EXPECT_EQ(1, client.m_updateCount); | |
| 376 EXPECT_THAT(client.m_matchedSelectors[frame], | |
| 377 testing::ElementsAre("span")); | |
| 378 | |
| 379 // Removing the first element shouldn't call back. | |
| 380 frame->executeScript(WebScriptSource( | |
| 381 "i1 = document.getElementById('first_span');" | |
| 382 "i1.parentNode.removeChild(i1);")); | |
| 383 runPendingTasks(); | |
| 384 EXPECT_EQ(1, client.m_updateCount); | |
| 385 EXPECT_THAT(client.m_matchedSelectors[frame], | |
| 386 testing::ElementsAre("span")); | |
| 387 | |
| 388 // But removing the second element *should* call back. | |
| 389 frame->executeScript(WebScriptSource( | |
| 390 "i2 = document.getElementById('second_span');" | |
| 391 "i2.parentNode.removeChild(i2);")); | |
| 392 runPendingTasks(); | |
| 393 EXPECT_EQ(2, client.m_updateCount); | |
| 394 EXPECT_THAT(client.m_matchedSelectors[frame], | |
| 395 testing::ElementsAre()); | |
| 396 | |
| 397 EXPECT_EQ(1U, client.m_matchedSelectors.size()); | |
| 398 webView->close(); | |
| 399 } | |
| 400 | |
| 401 TEST_F(WebFrameTest, CssCallbackMultiSelector) | |
| 402 { | |
| 403 CssCallbackWebFrameClient client; | |
| 404 WebView* webView = FrameTestHelpers::createWebViewAndLoad("about:blank", tru e, &client); | |
| 405 WebFrame* frame = webView->mainFrame(); | |
| 406 frame->loadHTMLString("<span></span>", toKURL("about:blank")); | |
| 407 runPendingTasks(); | |
| 408 WebDocument doc = frame->document(); | |
| 409 | |
| 410 // Check that selector lists match as the whole list, not as each element | |
| 411 // independently. | |
| 412 std::vector<WebString> selectors; | |
| 413 selectors.push_back(WebString::fromUTF8("span")); | |
| 414 selectors.push_back(WebString::fromUTF8("span,p")); | |
| 415 frame->document().watchCssSelectors(WebVector<WebString>(selectors)); | |
| 416 | |
| 417 runPendingTasks(); | |
| 418 EXPECT_EQ(1, client.m_updateCount); | |
| 419 EXPECT_THAT(client.m_matchedSelectors[frame], | |
| 420 testing::ElementsAre("span", "span, p")); | |
| 421 | |
| 422 EXPECT_EQ(1U, client.m_matchedSelectors.size()); | |
| 423 webView->close(); | |
| 424 } | |
| 425 #endif | |
| 426 | |
| 273 TEST_F(WebFrameTest, DispatchMessageEventWithOriginCheck) | 427 TEST_F(WebFrameTest, DispatchMessageEventWithOriginCheck) |
| 274 { | 428 { |
| 275 registerMockedHttpURLLoad("postmessage_test.html"); | 429 registerMockedHttpURLLoad("postmessage_test.html"); |
| 276 | 430 |
| 277 // Pass true to enable JavaScript. | 431 // Pass true to enable JavaScript. |
| 278 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "postmessage_ test.html", true); | 432 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "postmessage_ test.html", true); |
| 279 | 433 |
| 280 // Send a message with the correct origin. | 434 // Send a message with the correct origin. |
| 281 WebSecurityOrigin correctOrigin(WebSecurityOrigin::create(toKURL(m_baseURL)) ); | 435 WebSecurityOrigin correctOrigin(WebSecurityOrigin::create(toKURL(m_baseURL)) ); |
| 282 WebDOMEvent event = m_webView->mainFrame()->document().createEvent("MessageE vent"); | 436 WebDOMEvent event = m_webView->mainFrame()->document().createEvent("MessageE vent"); |
| (...skipping 3125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3408 frame->reload(); | 3562 frame->reload(); |
| 3409 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 3563 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 3410 EXPECT_EQ(WebURLRequest::ReloadIgnoringCacheData, frame->dataSource()->reque st().cachePolicy()); | 3564 EXPECT_EQ(WebURLRequest::ReloadIgnoringCacheData, frame->dataSource()->reque st().cachePolicy()); |
| 3411 | 3565 |
| 3412 m_webView->close(); | 3566 m_webView->close(); |
| 3413 m_webView = 0; | 3567 m_webView = 0; |
| 3414 } | 3568 } |
| 3415 | 3569 |
| 3416 | 3570 |
| 3417 } // namespace | 3571 } // namespace |
| OLD | NEW |