Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: third_party/WebKit/Source/web/tests/WebViewTest.cpp

Issue 1365203002: Make WebNode::to<Type>() (and toConst) casts contain type asserts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add BLINK_IMPLEMENTATION guard. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 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 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 TEST_F(WebViewTest, HitTestResultAtWithPageScale) 591 TEST_F(WebViewTest, HitTestResultAtWithPageScale)
592 { 592 {
593 std::string url = m_baseURL + "specify_size.html?" + "50px" + ":" + "50px"; 593 std::string url = m_baseURL + "specify_size.html?" + "50px" + ":" + "50px";
594 URLTestHelpers::registerMockedURLLoad(toKURL(url), "specify_size.html"); 594 URLTestHelpers::registerMockedURLLoad(toKURL(url), "specify_size.html");
595 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0); 595 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0);
596 webView->resize(WebSize(100, 100)); 596 webView->resize(WebSize(100, 100));
597 WebPoint hitPoint(75, 75); 597 WebPoint hitPoint(75, 75);
598 598
599 // Image is at top left quandrant, so should not hit it. 599 // Image is at top left quandrant, so should not hit it.
600 WebHitTestResult negativeResult = webView->hitTestResultAt(hitPoint); 600 WebHitTestResult negativeResult = webView->hitTestResultAt(hitPoint);
601 ASSERT_EQ(WebNode::ElementNode, negativeResult.node().nodeType());
602 EXPECT_FALSE(negativeResult.node().to<WebElement>().hasHTMLTagName("img")); 601 EXPECT_FALSE(negativeResult.node().to<WebElement>().hasHTMLTagName("img"));
603 negativeResult.reset(); 602 negativeResult.reset();
604 603
605 // Scale page up 2x so image should occupy the whole viewport. 604 // Scale page up 2x so image should occupy the whole viewport.
606 webView->setPageScaleFactor(2.0f); 605 webView->setPageScaleFactor(2.0f);
607 WebHitTestResult positiveResult = webView->hitTestResultAt(hitPoint); 606 WebHitTestResult positiveResult = webView->hitTestResultAt(hitPoint);
608 ASSERT_EQ(WebNode::ElementNode, positiveResult.node().nodeType());
609 EXPECT_TRUE(positiveResult.node().to<WebElement>().hasHTMLTagName("img")); 607 EXPECT_TRUE(positiveResult.node().to<WebElement>().hasHTMLTagName("img"));
610 positiveResult.reset(); 608 positiveResult.reset();
611 } 609 }
612 610
613 TEST_F(WebViewTest, HitTestResultAtWithPageScaleAndPan) 611 TEST_F(WebViewTest, HitTestResultAtWithPageScaleAndPan)
614 { 612 {
615 std::string url = m_baseURL + "specify_size.html?" + "50px" + ":" + "50px"; 613 std::string url = m_baseURL + "specify_size.html?" + "50px" + ":" + "50px";
616 URLTestHelpers::registerMockedURLLoad(toKURL(url), "specify_size.html"); 614 URLTestHelpers::registerMockedURLLoad(toKURL(url), "specify_size.html");
617 WebView* webView = m_webViewHelper.initialize(true); 615 WebView* webView = m_webViewHelper.initialize(true);
618 loadFrame(webView->mainFrame(), url); 616 loadFrame(webView->mainFrame(), url);
619 webView->resize(WebSize(100, 100)); 617 webView->resize(WebSize(100, 100));
620 WebPoint hitPoint(75, 75); 618 WebPoint hitPoint(75, 75);
621 619
622 // Image is at top left quandrant, so should not hit it. 620 // Image is at top left quandrant, so should not hit it.
623 WebHitTestResult negativeResult = webView->hitTestResultAt(hitPoint); 621 WebHitTestResult negativeResult = webView->hitTestResultAt(hitPoint);
624 ASSERT_EQ(WebNode::ElementNode, negativeResult.node().nodeType());
625 EXPECT_FALSE(negativeResult.node().to<WebElement>().hasHTMLTagName("img")); 622 EXPECT_FALSE(negativeResult.node().to<WebElement>().hasHTMLTagName("img"));
626 negativeResult.reset(); 623 negativeResult.reset();
627 624
628 // Scale page up 2x so image should occupy the whole viewport. 625 // Scale page up 2x so image should occupy the whole viewport.
629 webView->setPageScaleFactor(2.0f); 626 webView->setPageScaleFactor(2.0f);
630 WebHitTestResult positiveResult = webView->hitTestResultAt(hitPoint); 627 WebHitTestResult positiveResult = webView->hitTestResultAt(hitPoint);
631 ASSERT_EQ(WebNode::ElementNode, positiveResult.node().nodeType());
632 EXPECT_TRUE(positiveResult.node().to<WebElement>().hasHTMLTagName("img")); 628 EXPECT_TRUE(positiveResult.node().to<WebElement>().hasHTMLTagName("img"));
633 positiveResult.reset(); 629 positiveResult.reset();
634 630
635 // Pan around the zoomed in page so the image is not visible in viewport. 631 // Pan around the zoomed in page so the image is not visible in viewport.
636 webView->setVisualViewportOffset(WebFloatPoint(100, 100)); 632 webView->setVisualViewportOffset(WebFloatPoint(100, 100));
637 WebHitTestResult negativeResult2 = webView->hitTestResultAt(hitPoint); 633 WebHitTestResult negativeResult2 = webView->hitTestResultAt(hitPoint);
638 ASSERT_EQ(WebNode::ElementNode, negativeResult2.node().nodeType());
639 EXPECT_FALSE(negativeResult2.node().to<WebElement>().hasHTMLTagName("img")); 634 EXPECT_FALSE(negativeResult2.node().to<WebElement>().hasHTMLTagName("img"));
640 negativeResult2.reset(); 635 negativeResult2.reset();
641 } 636 }
642 637
643 TEST_F(WebViewTest, HitTestResultForTapWithTapArea) 638 TEST_F(WebViewTest, HitTestResultForTapWithTapArea)
644 { 639 {
645 std::string url = m_baseURL + "hit_test.html"; 640 std::string url = m_baseURL + "hit_test.html";
646 URLTestHelpers::registerMockedURLLoad(toKURL(url), "hit_test.html"); 641 URLTestHelpers::registerMockedURLLoad(toKURL(url), "hit_test.html");
647 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0); 642 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0);
648 webView->resize(WebSize(100, 100)); 643 webView->resize(WebSize(100, 100));
649 WebPoint hitPoint(55, 55); 644 WebPoint hitPoint(55, 55);
650 645
651 // Image is at top left quandrant, so should not hit it. 646 // Image is at top left quandrant, so should not hit it.
652 WebHitTestResult negativeResult = webView->hitTestResultAt(hitPoint); 647 WebHitTestResult negativeResult = webView->hitTestResultAt(hitPoint);
653 ASSERT_EQ(WebNode::ElementNode, negativeResult.node().nodeType());
654 EXPECT_FALSE(negativeResult.node().to<WebElement>().hasHTMLTagName("img")); 648 EXPECT_FALSE(negativeResult.node().to<WebElement>().hasHTMLTagName("img"));
655 negativeResult.reset(); 649 negativeResult.reset();
656 650
657 // The tap area is 20 by 20 square, centered at 55, 55. 651 // The tap area is 20 by 20 square, centered at 55, 55.
658 WebSize tapArea(20, 20); 652 WebSize tapArea(20, 20);
659 WebHitTestResult positiveResult = webView->hitTestResultForTap(hitPoint, tap Area); 653 WebHitTestResult positiveResult = webView->hitTestResultForTap(hitPoint, tap Area);
660 ASSERT_EQ(WebNode::ElementNode, positiveResult.node().nodeType());
661 EXPECT_TRUE(positiveResult.node().to<WebElement>().hasHTMLTagName("img")); 654 EXPECT_TRUE(positiveResult.node().to<WebElement>().hasHTMLTagName("img"));
662 positiveResult.reset(); 655 positiveResult.reset();
663 656
664 // Move the hit point the image is just outside the tapped area now. 657 // Move the hit point the image is just outside the tapped area now.
665 hitPoint = WebPoint(61, 61); 658 hitPoint = WebPoint(61, 61);
666 WebHitTestResult negativeResult2 = webView->hitTestResultForTap(hitPoint, ta pArea); 659 WebHitTestResult negativeResult2 = webView->hitTestResultForTap(hitPoint, ta pArea);
667 ASSERT_EQ(WebNode::ElementNode, negativeResult2.node().nodeType());
668 EXPECT_FALSE(negativeResult2.node().to<WebElement>().hasHTMLTagName("img")); 660 EXPECT_FALSE(negativeResult2.node().to<WebElement>().hasHTMLTagName("img"));
669 negativeResult2.reset(); 661 negativeResult2.reset();
670 } 662 }
671 663
672 TEST_F(WebViewTest, HitTestResultForTapWithTapAreaPageScaleAndPan) 664 TEST_F(WebViewTest, HitTestResultForTapWithTapAreaPageScaleAndPan)
673 { 665 {
674 std::string url = m_baseURL + "hit_test.html"; 666 std::string url = m_baseURL + "hit_test.html";
675 URLTestHelpers::registerMockedURLLoad(toKURL(url), "hit_test.html"); 667 URLTestHelpers::registerMockedURLLoad(toKURL(url), "hit_test.html");
676 WebView* webView = m_webViewHelper.initialize(true); 668 WebView* webView = m_webViewHelper.initialize(true);
677 loadFrame(webView->mainFrame(), url); 669 loadFrame(webView->mainFrame(), url);
678 webView->resize(WebSize(100, 100)); 670 webView->resize(WebSize(100, 100));
679 WebPoint hitPoint(55, 55); 671 WebPoint hitPoint(55, 55);
680 672
681 // Image is at top left quandrant, so should not hit it. 673 // Image is at top left quandrant, so should not hit it.
682 WebHitTestResult negativeResult = webView->hitTestResultAt(hitPoint); 674 WebHitTestResult negativeResult = webView->hitTestResultAt(hitPoint);
683 ASSERT_EQ(WebNode::ElementNode, negativeResult.node().nodeType());
684 EXPECT_FALSE(negativeResult.node().to<WebElement>().hasHTMLTagName("img")); 675 EXPECT_FALSE(negativeResult.node().to<WebElement>().hasHTMLTagName("img"));
685 negativeResult.reset(); 676 negativeResult.reset();
686 677
687 // The tap area is 20 by 20 square, centered at 55, 55. 678 // The tap area is 20 by 20 square, centered at 55, 55.
688 WebSize tapArea(20, 20); 679 WebSize tapArea(20, 20);
689 WebHitTestResult positiveResult = webView->hitTestResultForTap(hitPoint, tap Area); 680 WebHitTestResult positiveResult = webView->hitTestResultForTap(hitPoint, tap Area);
690 ASSERT_EQ(WebNode::ElementNode, positiveResult.node().nodeType());
691 EXPECT_TRUE(positiveResult.node().to<WebElement>().hasHTMLTagName("img")); 681 EXPECT_TRUE(positiveResult.node().to<WebElement>().hasHTMLTagName("img"));
692 positiveResult.reset(); 682 positiveResult.reset();
693 683
694 // Zoom in and pan around the page so the image is not visible in viewport. 684 // Zoom in and pan around the page so the image is not visible in viewport.
695 webView->setPageScaleFactor(2.0f); 685 webView->setPageScaleFactor(2.0f);
696 webView->setVisualViewportOffset(WebFloatPoint(100, 100)); 686 webView->setVisualViewportOffset(WebFloatPoint(100, 100));
697 WebHitTestResult negativeResult2 = webView->hitTestResultForTap(hitPoint, ta pArea); 687 WebHitTestResult negativeResult2 = webView->hitTestResultForTap(hitPoint, ta pArea);
698 ASSERT_EQ(WebNode::ElementNode, negativeResult2.node().nodeType());
699 EXPECT_FALSE(negativeResult2.node().to<WebElement>().hasHTMLTagName("img")); 688 EXPECT_FALSE(negativeResult2.node().to<WebElement>().hasHTMLTagName("img"));
700 negativeResult2.reset(); 689 negativeResult2.reset();
701 } 690 }
702 691
703 void WebViewTest::testAutoResize(const WebSize& minAutoResize, const WebSize& ma xAutoResize, 692 void WebViewTest::testAutoResize(const WebSize& minAutoResize, const WebSize& ma xAutoResize,
704 const std::string& pageWidth, const std::string & pageHeight, 693 const std::string& pageWidth, const std::string & pageHeight,
705 int expectedWidth, int expectedHeight, 694 int expectedWidth, int expectedHeight,
706 HorizontalScrollbarState expectedHorizontalStat e, VerticalScrollbarState expectedVerticalState) 695 HorizontalScrollbarState expectedHorizontalStat e, VerticalScrollbarState expectedVerticalState)
707 { 696 {
708 AutoResizeWebViewClient client; 697 AutoResizeWebViewClient client;
(...skipping 2361 matching lines...) Expand 10 before | Expand all | Expand 10 after
3070 WebFrame* frame = mainWebView.webView()->mainFrame(); 3059 WebFrame* frame = mainWebView.webView()->mainFrame();
3071 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3060 v8::HandleScope scope(v8::Isolate::GetCurrent());
3072 v8::Local<v8::Value> v8Value = frame->executeScriptAndReturnValue(WebScriptS ource("var win = window.open('javascript:false'); win.document")); 3061 v8::Local<v8::Value> v8Value = frame->executeScriptAndReturnValue(WebScriptS ource("var win = window.open('javascript:false'); win.document"));
3073 ASSERT_TRUE(v8Value->IsObject()); 3062 ASSERT_TRUE(v8Value->IsObject());
3074 Document* document = V8Document::toImplWithTypeCheck(v8::Isolate::GetCurrent (), v8Value); 3063 Document* document = V8Document::toImplWithTypeCheck(v8::Isolate::GetCurrent (), v8Value);
3075 ASSERT_TRUE(document); 3064 ASSERT_TRUE(document);
3076 EXPECT_FALSE(document->frame()->isLoading()); 3065 EXPECT_FALSE(document->frame()->isLoading());
3077 } 3066 }
3078 3067
3079 } // namespace blink 3068 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/tests/WebFrameTest.cpp ('k') | third_party/WebKit/public/web/WebDocument.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698