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 3726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3737 int activeIndex() const { return m_activeIndex; } | 3737 int activeIndex() const { return m_activeIndex; } |
3738 | 3738 |
3739 private: | 3739 private: |
3740 bool m_findResultsAreReady; | 3740 bool m_findResultsAreReady; |
3741 int m_count; | 3741 int m_count; |
3742 int m_activeIndex; | 3742 int m_activeIndex; |
3743 }; | 3743 }; |
3744 | 3744 |
3745 TEST_P(ParameterizedWebFrameTest, FindInPageMatchRects) | 3745 TEST_P(ParameterizedWebFrameTest, FindInPageMatchRects) |
3746 { | 3746 { |
3747 registerMockedHttpURLLoad("find_in_page.html"); | |
3748 registerMockedHttpURLLoad("find_in_page_frame.html"); | 3747 registerMockedHttpURLLoad("find_in_page_frame.html"); |
3749 | 3748 |
3750 FindUpdateWebFrameClient client; | 3749 FindUpdateWebFrameClient client; |
3751 FrameTestHelpers::WebViewHelper webViewHelper(this); | 3750 FrameTestHelpers::WebViewHelper webViewHelper(this); |
3752 webViewHelper.initializeAndLoad(m_baseURL + "find_in_page.html", true, &clie nt); | 3751 webViewHelper.initializeAndLoad(m_baseURL + "find_in_page_frame.html", true, &client); |
3753 webViewHelper.resize(WebSize(640, 480)); | 3752 webViewHelper.resize(WebSize(640, 480)); |
3754 webViewHelper.webView()->setMaximumLegibleScale(1.f); | 3753 webViewHelper.webView()->setMaximumLegibleScale(1.f); |
3755 webViewHelper.webView()->updateAllLifecyclePhases(); | 3754 webViewHelper.webView()->updateAllLifecyclePhases(); |
3756 runPendingTasks(); | 3755 runPendingTasks(); |
3757 | 3756 |
3758 // Note that the 'result 19' in the <select> element is not expected to prod uce a match. | 3757 // Note that the 'result 19' in the <select> element is not expected to |
3758 // produce a match. Also, results 00 and 01 are in a different frame that is | |
3759 // not included in this test. | |
3759 const char kFindString[] = "result"; | 3760 const char kFindString[] = "result"; |
3760 const int kFindIdentifier = 12345; | 3761 const int kFindIdentifier = 12345; |
3761 const int kNumResults = 19; | 3762 const int kNumResults = 17; |
3762 | 3763 |
3763 WebFindOptions options; | 3764 WebFindOptions options; |
3764 WebString searchText = WebString::fromUTF8(kFindString); | 3765 WebString searchText = WebString::fromUTF8(kFindString); |
3765 WebLocalFrameImpl* mainFrame = toWebLocalFrameImpl(webViewHelper.webView()-> mainFrame()); | 3766 WebLocalFrameImpl* mainFrame = toWebLocalFrameImpl(webViewHelper.webView()-> mainFrame()); |
3766 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchText, options, false, 0)) ; | 3767 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchText, options, false, 0)) ; |
3767 | 3768 |
3768 mainFrame->resetMatchCount(); | 3769 mainFrame->resetMatchCount(); |
3769 | 3770 |
3770 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) | 3771 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) |
3771 frame->toWebLocalFrame()->scopeStringMatches(kFindIdentifier, searchText , options, true); | 3772 frame->toWebLocalFrame()->scopeStringMatches(kFindIdentifier, searchText , options, true); |
3772 | 3773 |
3773 runPendingTasks(); | 3774 runPendingTasks(); |
3774 EXPECT_TRUE(client.findResultsAreReady()); | 3775 EXPECT_TRUE(client.findResultsAreReady()); |
3775 | 3776 |
3776 WebVector<WebFloatRect> webMatchRects; | 3777 WebVector<WebFloatRect> webMatchRects; |
3777 mainFrame->findMatchRects(webMatchRects); | 3778 mainFrame->findMatchRects(webMatchRects); |
3778 ASSERT_EQ(webMatchRects.size(), static_cast<size_t>(kNumResults)); | 3779 ASSERT_EQ(static_cast<size_t>(kNumResults), webMatchRects.size()); |
3779 int rectsVersion = mainFrame->findMatchMarkersVersion(); | 3780 int rectsVersion = mainFrame->findMatchMarkersVersion(); |
3780 | 3781 |
3781 for (int resultIndex = 0; resultIndex < kNumResults; ++resultIndex) { | 3782 for (int resultIndex = 0; resultIndex < kNumResults; ++resultIndex) { |
3782 FloatRect resultRect = static_cast<FloatRect>(webMatchRects[resultIndex] ); | 3783 FloatRect resultRect = static_cast<FloatRect>(webMatchRects[resultIndex] ); |
3783 | 3784 |
3784 // Select the match by the center of its rect. | 3785 // Select the match by the center of its rect. |
3785 EXPECT_EQ(mainFrame->selectNearestFindMatch(resultRect.center(), 0), res ultIndex + 1); | 3786 EXPECT_EQ(mainFrame->selectNearestFindMatch(resultRect.center(), 0), res ultIndex + 1); |
3786 | 3787 |
3787 // Check that the find result ordering matches with our expectations. | 3788 // Check that the find result ordering matches with our expectations. |
3788 Range* result = mainFrame->textFinder()->activeMatchFrame()->textFinder( )->activeMatch(); | 3789 Range* result = mainFrame->textFinder()->activeMatch(); |
3789 ASSERT_TRUE(result); | 3790 ASSERT_TRUE(result); |
3790 result->setEnd(result->endContainer(), result->endOffset() + 3); | 3791 result->setEnd(result->endContainer(), result->endOffset() + 3); |
3791 EXPECT_EQ(result->text(), String::format("%s %02d", kFindString, resultI ndex)); | 3792 EXPECT_EQ(result->text(), String::format("%s %02d", kFindString, resultI ndex + 2)); |
3792 | 3793 |
3793 // Verify that the expected match rect also matches the currently active match. | 3794 // Verify that the expected match rect also matches the currently active match. |
3794 // Compare the enclosing rects to prevent precision issues caused by CSS transforms. | 3795 // Compare the enclosing rects to prevent precision issues caused by CSS transforms. |
3795 FloatRect activeMatch = mainFrame->activeFindMatchRect(); | 3796 FloatRect activeMatch = mainFrame->activeFindMatchRect(); |
3796 EXPECT_EQ(enclosingIntRect(activeMatch), enclosingIntRect(resultRect)); | 3797 EXPECT_EQ(enclosingIntRect(activeMatch), enclosingIntRect(resultRect)); |
3797 | 3798 |
3798 // The rects version should not have changed. | 3799 // The rects version should not have changed. |
3799 EXPECT_EQ(mainFrame->findMatchMarkersVersion(), rectsVersion); | 3800 EXPECT_EQ(mainFrame->findMatchMarkersVersion(), rectsVersion); |
3800 } | 3801 } |
3801 | 3802 |
lfg
2016/05/13 20:15:40
Any reason we can't assert that the rects are in s
paulmeyer
2016/05/16 15:25:11
We could still assert the positions of the rects i
lfg
2016/05/16 16:03:29
Acknowledged.
| |
3802 // All results after the first two ones should be below between them in find -in-page coordinates. | |
3803 // This is because results 2 to 9 are inside an iframe located between resul ts 0 and 1. This applies to the fixed div too. | |
3804 EXPECT_TRUE(webMatchRects[0].y < webMatchRects[1].y); | |
3805 for (int resultIndex = 2; resultIndex < kNumResults; ++resultIndex) { | |
3806 EXPECT_TRUE(webMatchRects[0].y < webMatchRects[resultIndex].y); | |
3807 EXPECT_TRUE(webMatchRects[1].y > webMatchRects[resultIndex].y); | |
3808 } | |
3809 | |
3810 // Result 3 should be below both 2 and 4. This is caused by the CSS transfor m in the containing div. | |
3811 // If the transform doesn't work then 3 will be between 2 and 4. | |
3812 EXPECT_TRUE(webMatchRects[3].y > webMatchRects[2].y); | |
3813 EXPECT_TRUE(webMatchRects[3].y > webMatchRects[4].y); | |
3814 | |
3815 // Results 6, 7, 8 and 9 should be one below the other in that same order. | |
3816 // If overflow:scroll is not properly handled then result 8 would be below r esult 9 or | |
3817 // result 7 above result 6 depending on the scroll. | |
3818 EXPECT_TRUE(webMatchRects[6].y < webMatchRects[7].y); | |
3819 EXPECT_TRUE(webMatchRects[7].y < webMatchRects[8].y); | |
3820 EXPECT_TRUE(webMatchRects[8].y < webMatchRects[9].y); | |
3821 | |
3822 // Results 11, 12, 13 and 14 should be between results 10 and 15, as they ar e inside the table. | |
3823 EXPECT_TRUE(webMatchRects[11].y > webMatchRects[10].y); | |
3824 EXPECT_TRUE(webMatchRects[12].y > webMatchRects[10].y); | |
3825 EXPECT_TRUE(webMatchRects[13].y > webMatchRects[10].y); | |
3826 EXPECT_TRUE(webMatchRects[14].y > webMatchRects[10].y); | |
3827 EXPECT_TRUE(webMatchRects[11].y < webMatchRects[15].y); | |
3828 EXPECT_TRUE(webMatchRects[12].y < webMatchRects[15].y); | |
3829 EXPECT_TRUE(webMatchRects[13].y < webMatchRects[15].y); | |
3830 EXPECT_TRUE(webMatchRects[14].y < webMatchRects[15].y); | |
3831 | |
3832 // Result 11 should be above 12, 13 and 14 as it's in the table header. | |
3833 EXPECT_TRUE(webMatchRects[11].y < webMatchRects[12].y); | |
3834 EXPECT_TRUE(webMatchRects[11].y < webMatchRects[13].y); | |
3835 EXPECT_TRUE(webMatchRects[11].y < webMatchRects[14].y); | |
3836 | |
3837 // Result 11 should also be right to 12, 13 and 14 because of the colspan. | |
3838 EXPECT_TRUE(webMatchRects[11].x > webMatchRects[12].x); | |
3839 EXPECT_TRUE(webMatchRects[11].x > webMatchRects[13].x); | |
3840 EXPECT_TRUE(webMatchRects[11].x > webMatchRects[14].x); | |
3841 | |
3842 // Result 12 should be left to results 11, 13 and 14 in the table layout. | |
3843 EXPECT_TRUE(webMatchRects[12].x < webMatchRects[11].x); | |
3844 EXPECT_TRUE(webMatchRects[12].x < webMatchRects[13].x); | |
3845 EXPECT_TRUE(webMatchRects[12].x < webMatchRects[14].x); | |
3846 | |
3847 // Results 13, 12 and 14 should be one above the other in that order because of the rowspan | |
3848 // and vertical-align: middle by default. | |
3849 EXPECT_TRUE(webMatchRects[13].y < webMatchRects[12].y); | |
3850 EXPECT_TRUE(webMatchRects[12].y < webMatchRects[14].y); | |
3851 | |
3852 // Result 16 should be below result 15. | |
3853 EXPECT_TRUE(webMatchRects[15].y > webMatchRects[14].y); | |
3854 | |
3855 // Result 18 should be normalized with respect to the position:relative div, and not it's | |
3856 // immediate containing div. Consequently, result 18 should be above result 17. | |
3857 EXPECT_TRUE(webMatchRects[17].y > webMatchRects[18].y); | |
3858 | |
3859 // Resizing should update the rects version. | 3803 // Resizing should update the rects version. |
3860 webViewHelper.resize(WebSize(800, 600)); | 3804 webViewHelper.resize(WebSize(800, 600)); |
3861 runPendingTasks(); | 3805 runPendingTasks(); |
3862 EXPECT_TRUE(mainFrame->findMatchMarkersVersion() != rectsVersion); | 3806 EXPECT_TRUE(mainFrame->findMatchMarkersVersion() != rectsVersion); |
3863 } | 3807 } |
3864 | 3808 |
3865 TEST_F(WebFrameTest, FindInPageActiveIndex) | 3809 TEST_F(WebFrameTest, FindInPageActiveIndex) |
3866 { | 3810 { |
3867 registerMockedHttpURLLoad("find_match_count.html"); | 3811 registerMockedHttpURLLoad("find_match_count.html"); |
3868 | 3812 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3902 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchTextNew, options, false, 0)); | 3846 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchTextNew, options, false, 0)); |
3903 mainFrame->resetMatchCount(); | 3847 mainFrame->resetMatchCount(); |
3904 | 3848 |
3905 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) | 3849 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) |
3906 frame->toWebLocalFrame()->scopeStringMatches(kFindIdentifier, searchText New, options, true); | 3850 frame->toWebLocalFrame()->scopeStringMatches(kFindIdentifier, searchText New, options, true); |
3907 | 3851 |
3908 runPendingTasks(); | 3852 runPendingTasks(); |
3909 EXPECT_TRUE(client.findResultsAreReady()); | 3853 EXPECT_TRUE(client.findResultsAreReady()); |
3910 EXPECT_EQ(kActiveIndex, client.activeIndex()); | 3854 EXPECT_EQ(kActiveIndex, client.activeIndex()); |
3911 } | 3855 } |
3912 | 3856 |
lfg
2016/05/13 20:15:40
Can we remove find_in_hidden_frame.html from Sourc
paulmeyer
2016/05/16 15:25:12
Yes. Done.
| |
3913 TEST_P(ParameterizedWebFrameTest, FindInPageSkipsHiddenFrames) | |
3914 { | |
3915 registerMockedHttpURLLoad("find_in_hidden_frame.html"); | |
3916 | |
3917 FindUpdateWebFrameClient client; | |
3918 FrameTestHelpers::WebViewHelper webViewHelper(this); | |
3919 webViewHelper.initializeAndLoad(m_baseURL + "find_in_hidden_frame.html", tru e, &client); | |
3920 webViewHelper.resize(WebSize(640, 480)); | |
3921 runPendingTasks(); | |
3922 | |
3923 const char kFindString[] = "hello"; | |
3924 const int kFindIdentifier = 12345; | |
3925 const int kNumResults = 1; | |
3926 | |
3927 WebFindOptions options; | |
3928 WebString searchText = WebString::fromUTF8(kFindString); | |
3929 WebLocalFrameImpl* mainFrame = toWebLocalFrameImpl(webViewHelper.webView()-> mainFrame()); | |
3930 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchText, options, false, 0)) ; | |
3931 | |
3932 mainFrame->resetMatchCount(); | |
3933 | |
3934 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) | |
3935 frame->toWebLocalFrame()->scopeStringMatches(kFindIdentifier, searchText , options, true); | |
3936 | |
3937 runPendingTasks(); | |
3938 EXPECT_TRUE(client.findResultsAreReady()); | |
3939 EXPECT_EQ(kNumResults, client.count()); | |
3940 } | |
3941 | |
3942 TEST_P(ParameterizedWebFrameTest, FindOnDetachedFrame) | 3857 TEST_P(ParameterizedWebFrameTest, FindOnDetachedFrame) |
3943 { | 3858 { |
3944 registerMockedHttpURLLoad("find_in_page.html"); | 3859 registerMockedHttpURLLoad("find_in_page.html"); |
3945 registerMockedHttpURLLoad("find_in_page_frame.html"); | 3860 registerMockedHttpURLLoad("find_in_page_frame.html"); |
3946 | 3861 |
3947 FindUpdateWebFrameClient client; | 3862 FindUpdateWebFrameClient client; |
3948 FrameTestHelpers::WebViewHelper webViewHelper(this); | 3863 FrameTestHelpers::WebViewHelper webViewHelper(this); |
3949 webViewHelper.initializeAndLoad(m_baseURL + "find_in_page.html", true, &clie nt); | 3864 webViewHelper.initializeAndLoad(m_baseURL + "find_in_page.html", true, &clie nt); |
3950 webViewHelper.resize(WebSize(640, 480)); | 3865 webViewHelper.resize(WebSize(640, 480)); |
3951 runPendingTasks(); | 3866 runPendingTasks(); |
(...skipping 4730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8682 WebLocalFrame* mainFrame = helper.webView()->mainFrame()->toWebLocalFrame(); | 8597 WebLocalFrame* mainFrame = helper.webView()->mainFrame()->toWebLocalFrame(); |
8683 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 8598 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
8684 mainFrame->executeScript(WebScriptSource("hello = 'world';")); | 8599 mainFrame->executeScript(WebScriptSource("hello = 'world';")); |
8685 FrameTestHelpers::loadFrame(mainFrame, "data:text/html,new page"); | 8600 FrameTestHelpers::loadFrame(mainFrame, "data:text/html,new page"); |
8686 v8::Local<v8::Value> result = mainFrame->executeScriptAndReturnValue(WebScri ptSource("hello")); | 8601 v8::Local<v8::Value> result = mainFrame->executeScriptAndReturnValue(WebScri ptSource("hello")); |
8687 ASSERT_TRUE(result->IsString()); | 8602 ASSERT_TRUE(result->IsString()); |
8688 EXPECT_EQ("world", toCoreString(result->ToString(mainFrame->mainWorldScriptC ontext()).ToLocalChecked())); | 8603 EXPECT_EQ("world", toCoreString(result->ToString(mainFrame->mainWorldScriptC ontext()).ToLocalChecked())); |
8689 } | 8604 } |
8690 | 8605 |
8691 } // namespace blink | 8606 } // namespace blink |
OLD | NEW |