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

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

Issue 1707083002: Fix find in page behavior (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix android_webview test Created 4 years, 10 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) 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 3698 matching lines...) Expand 10 before | Expand all | Expand 10 after
3709 webViewHelper.initializeAndLoad(m_baseURL + "hello_world.html", true, &webFr ameClient); 3709 webViewHelper.initializeAndLoad(m_baseURL + "hello_world.html", true, &webFr ameClient);
3710 3710
3711 FrameTestHelpers::reloadFrame(webViewHelper.webView()->mainFrame()); 3711 FrameTestHelpers::reloadFrame(webViewHelper.webView()->mainFrame());
3712 } 3712 }
3713 3713
3714 class FindUpdateWebFrameClient : public FrameTestHelpers::TestWebFrameClient { 3714 class FindUpdateWebFrameClient : public FrameTestHelpers::TestWebFrameClient {
3715 public: 3715 public:
3716 FindUpdateWebFrameClient() 3716 FindUpdateWebFrameClient()
3717 : m_findResultsAreReady(false) 3717 : m_findResultsAreReady(false)
3718 , m_count(-1) 3718 , m_count(-1)
3719 , m_activeIndex(-1)
3719 { 3720 {
3720 } 3721 }
3721 3722
3722 void reportFindInPageMatchCount(int, int count, bool finalUpdate) override 3723 void reportFindInPageMatchCount(int, int count, bool finalUpdate) override
3723 { 3724 {
3724 m_count = count; 3725 m_count = count;
3725 if (finalUpdate) 3726 if (finalUpdate)
3726 m_findResultsAreReady = true; 3727 m_findResultsAreReady = true;
3727 } 3728 }
3728 3729
3730 void reportFindInPageSelection(int, int activeMatchOrdinal, const WebRect&) override
3731 {
3732 m_activeIndex = activeMatchOrdinal;
3733 }
3734
3729 bool findResultsAreReady() const { return m_findResultsAreReady; } 3735 bool findResultsAreReady() const { return m_findResultsAreReady; }
3730 int count() const { return m_count; } 3736 int count() const { return m_count; }
3737 int activeIndex() const { return m_activeIndex; }
3731 3738
3732 private: 3739 private:
3733 bool m_findResultsAreReady; 3740 bool m_findResultsAreReady;
3734 int m_count; 3741 int m_count;
3742 int m_activeIndex;
3735 }; 3743 };
3736 3744
3737 TEST_P(ParameterizedWebFrameTest, FindInPageMatchRects) 3745 TEST_P(ParameterizedWebFrameTest, FindInPageMatchRects)
3738 { 3746 {
3739 registerMockedHttpURLLoad("find_in_page.html"); 3747 registerMockedHttpURLLoad("find_in_page.html");
3740 registerMockedHttpURLLoad("find_in_page_frame.html"); 3748 registerMockedHttpURLLoad("find_in_page_frame.html");
3741 3749
3742 FindUpdateWebFrameClient client; 3750 FindUpdateWebFrameClient client;
3743 FrameTestHelpers::WebViewHelper webViewHelper(this); 3751 FrameTestHelpers::WebViewHelper webViewHelper(this);
3744 webViewHelper.initializeAndLoad(m_baseURL + "find_in_page.html", true, &clie nt); 3752 webViewHelper.initializeAndLoad(m_baseURL + "find_in_page.html", true, &clie nt);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
3847 // Result 18 should be normalized with respect to the position:relative div, and not it's 3855 // Result 18 should be normalized with respect to the position:relative div, and not it's
3848 // immediate containing div. Consequently, result 18 should be above result 17. 3856 // immediate containing div. Consequently, result 18 should be above result 17.
3849 EXPECT_TRUE(webMatchRects[17].y > webMatchRects[18].y); 3857 EXPECT_TRUE(webMatchRects[17].y > webMatchRects[18].y);
3850 3858
3851 // Resizing should update the rects version. 3859 // Resizing should update the rects version.
3852 webViewHelper.resize(WebSize(800, 600)); 3860 webViewHelper.resize(WebSize(800, 600));
3853 runPendingTasks(); 3861 runPendingTasks();
3854 EXPECT_TRUE(mainFrame->findMatchMarkersVersion() != rectsVersion); 3862 EXPECT_TRUE(mainFrame->findMatchMarkersVersion() != rectsVersion);
3855 } 3863 }
3856 3864
3865 TEST_F(WebFrameTest, FindInPageActiveIndex)
3866 {
3867 registerMockedHttpURLLoad("find_match_count.html");
3868
3869 FindUpdateWebFrameClient client;
3870 FrameTestHelpers::WebViewHelper webViewHelper;
3871 webViewHelper.initializeAndLoad(m_baseURL + "find_match_count.html", true, & client);
3872 webViewHelper.webView()->resize(WebSize(640, 480));
3873 runPendingTasks();
3874
3875 const char* kFindString = "a";
3876 const int kFindIdentifier = 7777;
3877 const int kActiveIndex = 1;
3878
3879 WebFindOptions options;
3880 WebString searchText = WebString::fromUTF8(kFindString);
3881 WebLocalFrameImpl* mainFrame = toWebLocalFrameImpl(webViewHelper.webView()-> mainFrame());
3882 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchText, options, false, 0)) ;
3883 mainFrame->resetMatchCount();
3884
3885 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false))
3886 frame->toWebLocalFrame()->scopeStringMatches(kFindIdentifier, searchText , options, true);
3887
3888 runPendingTasks();
3889 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchText, options, false, 0)) ;
3890 mainFrame->stopFinding(true);
3891
3892 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false))
3893 frame->toWebLocalFrame()->scopeStringMatches(kFindIdentifier, searchText , options, true);
3894
3895 runPendingTasks();
3896 EXPECT_TRUE(client.findResultsAreReady());
3897 EXPECT_EQ(kActiveIndex, client.activeIndex());
3898
3899 const char* kFindStringNew = "e";
3900 WebString searchTextNew = WebString::fromUTF8(kFindStringNew);
3901
3902 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchTextNew, options, false, 0));
3903 mainFrame->resetMatchCount();
3904
3905 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false))
3906 frame->toWebLocalFrame()->scopeStringMatches(kFindIdentifier, searchText New, options, true);
3907
3908 runPendingTasks();
3909 EXPECT_TRUE(client.findResultsAreReady());
3910 EXPECT_EQ(kActiveIndex, client.activeIndex());
3911 }
3912
3857 TEST_P(ParameterizedWebFrameTest, FindInPageSkipsHiddenFrames) 3913 TEST_P(ParameterizedWebFrameTest, FindInPageSkipsHiddenFrames)
3858 { 3914 {
3859 registerMockedHttpURLLoad("find_in_hidden_frame.html"); 3915 registerMockedHttpURLLoad("find_in_hidden_frame.html");
3860 3916
3861 FindUpdateWebFrameClient client; 3917 FindUpdateWebFrameClient client;
3862 FrameTestHelpers::WebViewHelper webViewHelper(this); 3918 FrameTestHelpers::WebViewHelper webViewHelper(this);
3863 webViewHelper.initializeAndLoad(m_baseURL + "find_in_hidden_frame.html", tru e, &client); 3919 webViewHelper.initializeAndLoad(m_baseURL + "find_in_hidden_frame.html", tru e, &client);
3864 webViewHelper.resize(WebSize(640, 480)); 3920 webViewHelper.resize(WebSize(640, 480));
3865 runPendingTasks(); 3921 runPendingTasks();
3866 3922
(...skipping 4540 matching lines...) Expand 10 before | Expand all | Expand 10 after
8407 } 8463 }
8408 8464
8409 TEST_F(WebFrameVisibilityChangeTest, RemoteFrameParentVisibilityChange) 8465 TEST_F(WebFrameVisibilityChangeTest, RemoteFrameParentVisibilityChange)
8410 { 8466 {
8411 swapLocalFrameToRemoteFrame(); 8467 swapLocalFrameToRemoteFrame();
8412 executeScriptOnMainFrame(WebScriptSource("document.querySelector('iframe').p arentElement.style.display = 'none';")); 8468 executeScriptOnMainFrame(WebScriptSource("document.querySelector('iframe').p arentElement.style.display = 'none';"));
8413 EXPECT_FALSE(remoteFrameClient()->isVisible()); 8469 EXPECT_FALSE(remoteFrameClient()->isVisible());
8414 } 8470 }
8415 8471
8416 } // namespace blink 8472 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/TextFinder.cpp ('k') | third_party/WebKit/Source/web/tests/data/find_match_count.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698