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

Side by Side Diff: content/browser/find_request_manager_browsertest.cc

Issue 1891773002: Implement the basic testing infrastructure for FindRequestManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added comment to describe TestFindRequestManager. Created 4 years, 8 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/command_line.h"
6 #include "base/strings/utf_string_conversions.h"
7 #include "content/browser/web_contents/web_contents_impl.h"
8 #include "content/public/browser/notification_types.h"
9 #include "content/public/common/content_switches.h"
10 #include "content/public/test/content_browser_test.h"
11 #include "content/public/test/content_browser_test_utils.h"
12 #include "content/public/test/test_navigation_observer.h"
13 #include "content/shell/browser/shell.h"
14 #include "content/test/test_find_request_manager.h"
15 #include "net/dns/mock_host_resolver.h"
16 #include "third_party/WebKit/public/web/WebFindOptions.h"
17
18 namespace content {
19
20 using FindResults = TestFindRequestManager::FindResults;
21
22 class FindRequestManagerTest : public ContentBrowserTest {
23 public:
24 FindRequestManagerTest()
25 : find_request_manager_(nullptr) {}
26
27 protected:
nasko 2016/04/15 19:26:50 What is the goal of the protected section here? Th
paulmeyer 2016/04/18 19:11:22 All of the individual tests themselves inherit fro
28 void LoadAndWait(const std::string& url) {
29 WindowedNotificationObserver load_observer(
nasko 2016/04/15 19:26:50 Use TestNavigationObserver whenever possible. It d
paulmeyer 2016/04/18 19:11:22 Done.
30 NOTIFICATION_LOAD_STOP, Source<NavigationController>(
31 &shell()->web_contents()->GetController()));
32 NavigateToURL(shell(), embedded_test_server()->GetURL("a.com", url));
33 load_observer.Wait();
34 }
35
36 TestFindRequestManager* find_request_manager() {
37 return find_request_manager_;
38 }
39
40 private:
41 void SetUpOnMainThread() override {
nasko 2016/04/15 19:26:50 No need for publicly inherited methods to be priva
paulmeyer 2016/04/18 19:11:22 I've always believed in giving the most limited ac
nasko 2016/04/18 21:02:39 However, you still can call those methods through
42 host_resolver()->AddRule("*", "127.0.0.1");
43 ASSERT_TRUE(embedded_test_server()->Start());
44
45 WebContentsImpl* contents =
46 static_cast<WebContentsImpl*>(shell()->web_contents());
47 find_request_manager_ = new TestFindRequestManager(contents);
48 contents->find_request_manager_.reset(find_request_manager_);
49 }
50
51 void SetUpCommandLine(base::CommandLine* command_line) override {
52 command_line->AppendSwitch(switches::kSitePerProcess);
nasko 2016/04/15 19:26:50 IsolateAllSitesForTesting(command_line); which doe
paulmeyer 2016/04/18 19:11:22 Done.
53 }
54
55 TestFindRequestManager* find_request_manager_;
56
57 DISALLOW_COPY_AND_ASSIGN(FindRequestManagerTest);
58 };
59
60 // Test basic find-in-page functionality (such as searching forward and
61 // backward) and check for correct results at each step.
62 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, Basic) {
63 LoadAndWait("/find_in_page.html");
64
65 blink::WebFindOptions options;
66 find_request_manager()->Find(1, base::UTF8ToUTF16("result"), options);
nasko 2016/04/15 19:26:50 I know this file is trying to target the FindReque
paulmeyer 2016/04/18 19:11:22 The tests now access WebContents::Find() and check
nasko 2016/04/18 21:02:39 Awesome! Thanks!
67 find_request_manager()->WaitForFinalReply();
68
69 FindResults results = find_request_manager()->GetFindResults();
70 EXPECT_EQ(1, results.request_id);
71 EXPECT_EQ(19, results.number_of_matches);
72 EXPECT_EQ(1, results.active_match_ordinal);
73
74 options.findNext = true;
75 for (int i = 2; i <= 10; ++i) {
76 find_request_manager()->Find(i, base::UTF8ToUTF16("result"), options);
nasko 2016/04/15 19:26:50 Would using |L"result"| work instead of |base::UTF
paulmeyer 2016/04/18 19:11:22 I tried it and it actually doesn't work.
77 find_request_manager()->WaitForFinalReply();
78 results = find_request_manager()->GetFindResults();
79
80 EXPECT_EQ(i, results.request_id);
81 EXPECT_EQ(19, results.number_of_matches);
82 EXPECT_EQ(i, results.active_match_ordinal);
83 }
84
85 options.forward = false;
86 for (int i = 11; i <= 15; ++i) {
87 find_request_manager()->Find(i, base::UTF8ToUTF16("result"), options);
88 find_request_manager()->WaitForFinalReply();
89 results = find_request_manager()->GetFindResults();
90
91 EXPECT_EQ(i, results.request_id);
92 EXPECT_EQ(19, results.number_of_matches);
93 EXPECT_EQ(20 - i, results.active_match_ordinal);
94 }
95 }
96
97 // Tests searching for a word character-by-character, as would typically be done
98 // by a user typing into the find bar.
99 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, CharacterByCharacter) {
100 LoadAndWait("/find_in_page.html");
101
102 blink::WebFindOptions default_options;
103 find_request_manager()->Find(1, base::UTF8ToUTF16("r"), default_options);
104 find_request_manager()->Find(2, base::UTF8ToUTF16("re"), default_options);
105 find_request_manager()->Find(3, base::UTF8ToUTF16("res"), default_options);
106 find_request_manager()->Find(4, base::UTF8ToUTF16("resu"), default_options);
107 find_request_manager()->Find(5, base::UTF8ToUTF16("resul"), default_options);
108 find_request_manager()->Find(6, base::UTF8ToUTF16("result"), default_options);
109 find_request_manager()->WaitForFinalReply();
110
111 FindResults results = find_request_manager()->GetFindResults();
112 EXPECT_EQ(6, results.request_id);
113 EXPECT_EQ(19, results.number_of_matches);
114 EXPECT_EQ(1, results.active_match_ordinal);
115 }
116
117 // Test sending a large number of find requests subsequently.
118 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, RapidFire) {
119 LoadAndWait("/find_in_page.html");
120
121 blink::WebFindOptions options;
122 find_request_manager()->Find(1, base::UTF8ToUTF16("result"), options);
123
124 options.findNext = true;
125 for (int i = 2; i <= 1000; ++i)
126 find_request_manager()->Find(i, base::UTF8ToUTF16("result"), options);
127 find_request_manager()->WaitForFinalReply();
128 FindResults results = find_request_manager()->GetFindResults();
129
130 EXPECT_EQ(1000, results.request_id);
131 EXPECT_EQ(19, results.number_of_matches);
132 EXPECT_EQ(1000 % results.number_of_matches, results.active_match_ordinal);
133 }
134
135 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698