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

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

Issue 2223063005: Some changes to the testing infrastructure in find_request_manager_browsertest.cc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Created 4 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "content/browser/web_contents/web_contents_impl.h" 7 #include "content/browser/web_contents/web_contents_impl.h"
8 #include "content/public/browser/notification_types.h" 8 #include "content/public/browser/notification_types.h"
9 #include "content/public/common/content_switches.h" 9 #include "content/public/common/content_switches.h"
10 #include "content/public/test/content_browser_test.h" 10 #include "content/public/test/content_browser_test.h"
(...skipping 16 matching lines...) Expand all
27 int request_id = kInvalidId; 27 int request_id = kInvalidId;
28 int number_of_matches = 0; 28 int number_of_matches = 0;
29 int active_match_ordinal = 0; 29 int active_match_ordinal = 0;
30 }; 30 };
31 31
32 } // namespace 32 } // namespace
33 33
34 class TestWebContentsDelegate : public WebContentsDelegate { 34 class TestWebContentsDelegate : public WebContentsDelegate {
35 public: 35 public:
36 TestWebContentsDelegate() 36 TestWebContentsDelegate()
37 : last_finished_request_id_(kInvalidId), 37 : last_request_id_(kInvalidId),
38 waiting_request_id_(kInvalidId) {} 38 last_finished_request_id_(kInvalidId),
39 next_reply_received_(false),
40 waiting_for_(NOTHING) {}
39 ~TestWebContentsDelegate() override {} 41 ~TestWebContentsDelegate() override {}
40 42
41 // Waits for the final reply to the find request with ID |request_id|.
42 void WaitForFinalReply(int request_id) {
43 if (last_finished_request_id_ >= request_id)
44 return;
45
46 waiting_request_id_ = request_id;
47 find_message_loop_runner_ = new content::MessageLoopRunner;
48 find_message_loop_runner_->Run();
49 }
50
51 // Returns the current find results. 43 // Returns the current find results.
52 FindResults GetFindResults() { 44 FindResults GetFindResults() {
53 return current_results_; 45 return current_results_;
54 } 46 }
55 47
56 #if defined(OS_ANDROID) 48 // Waits for all pending replies to be received.
57 // Waits for the next find reply. This is useful for waiting for a single 49 void WaitForFinalReply() {
58 // match to be activated, which results in a single find reply (without a 50 if (last_finished_request_id_ >= last_request_id_)
59 // unique request ID). 51 return;
60 void WaitForNextReply() { 52
61 waiting_request_id_ = 0; 53 WaitFor(FINAL_REPLY);
62 find_message_loop_runner_ = new content::MessageLoopRunner;
63 find_message_loop_runner_->Run();
64 } 54 }
65 55
56 // Waits for the next find reply. This is useful for waiting for a single
57 // match to be activated, or for a new frame to be searched.
58 void WaitForNextReply() {
59 if (next_reply_received_)
60 return;
61
62 WaitFor(NEXT_REPLY);
63 }
64
65 // Indicates that the next find reply from this point will be the one to wait
66 // for when WaitForNextReply() is called. It may be the case that the reply
67 // comes before the call to WaitForNextReply(), in which case it will return
68 // immediately.
69 void MarkNextReply() {
70 next_reply_received_ = false;
71 }
72
73 // Called when a new find request is issued, so the delegate knows the last
74 // request ID.
75 void UpdateLastRequest(int request_id) {
76 last_request_id_ = request_id;
77 }
78
79 #if defined(OS_ANDROID)
66 // Waits for all of the find match rects to be received. 80 // Waits for all of the find match rects to be received.
67 void WaitForMatchRects() { 81 void WaitForMatchRects() {
68 match_rects_message_loop_runner_ = new content::MessageLoopRunner; 82 WaitFor(MATCH_RECTS);
69 match_rects_message_loop_runner_->Run();
70 } 83 }
71 84
72 const std::vector<gfx::RectF>& find_match_rects() const { 85 const std::vector<gfx::RectF>& find_match_rects() const {
73 return find_match_rects_; 86 return find_match_rects_;
74 } 87 }
75 88
76 const gfx::RectF& active_match_rect() const { 89 const gfx::RectF& active_match_rect() const {
77 return active_match_rect_; 90 return active_match_rect_;
78 } 91 }
79 #endif 92 #endif
80 93
81 private: 94 private:
95 enum WaitingFor {
96 NOTHING,
97 FINAL_REPLY,
98 NEXT_REPLY,
99 #if defined(OS_ANDROID)
100 MATCH_RECTS
101 #endif
102 };
103
82 // WebContentsDelegate override. 104 // WebContentsDelegate override.
83 void FindReply(WebContents* web_contents, 105 void FindReply(WebContents* web_contents,
84 int request_id, 106 int request_id,
85 int number_of_matches, 107 int number_of_matches,
86 const gfx::Rect& selection_rect, 108 const gfx::Rect& selection_rect,
87 int active_match_ordinal, 109 int active_match_ordinal,
88 bool final_update) override { 110 bool final_update) override {
89 // Update the current results. 111 // Update the current results.
90 if (request_id > current_results_.request_id) 112 if (request_id > current_results_.request_id)
91 current_results_.request_id = request_id; 113 current_results_.request_id = request_id;
92 if (number_of_matches != -1) 114 if (number_of_matches != -1)
93 current_results_.number_of_matches = number_of_matches; 115 current_results_.number_of_matches = number_of_matches;
94 if (active_match_ordinal != -1) 116 if (active_match_ordinal != -1)
95 current_results_.active_match_ordinal = active_match_ordinal; 117 current_results_.active_match_ordinal = active_match_ordinal;
96 118
97 if (final_update) 119 if (!final_update)
120 return;
121
122 if (request_id > last_finished_request_id_)
98 last_finished_request_id_ = request_id; 123 last_finished_request_id_ = request_id;
124 next_reply_received_ = true;
99 125
100 // If we are waiting for a final reply and this is it, stop waiting. 126 // If we are waiting for this find reply, stop waiting.
101 if (find_message_loop_runner_.get() && 127 if (waiting_for_ == NEXT_REPLY ||
102 last_finished_request_id_ >= waiting_request_id_) { 128 (waiting_for_ == FINAL_REPLY &&
103 find_message_loop_runner_->Quit(); 129 last_finished_request_id_ >= last_request_id_)) {
130 StopWaiting();
104 } 131 }
105 } 132 }
106 133
134 // Uses |message_loop_runner_| to wait for various things.
135 void WaitFor(WaitingFor wait_for) {
136 ASSERT_EQ(NOTHING, waiting_for_);
137 ASSERT_NE(NOTHING, wait_for);
138
139 // Wait for |wait_for|.
140 waiting_for_ = wait_for;
141 message_loop_runner_ = new content::MessageLoopRunner;
142 message_loop_runner_->Run();
143
144 // Done waiting.
145 waiting_for_ = NOTHING;
146 message_loop_runner_ = nullptr;
147 }
148
149 // Stop waiting for |waiting_for_|.
150 void StopWaiting() {
151 if (!message_loop_runner_.get())
152 return;
153
154 ASSERT_NE(NOTHING, waiting_for_);
155 message_loop_runner_->Quit();
156 }
157
107 #if defined(OS_ANDROID) 158 #if defined(OS_ANDROID)
159 // WebContentsDelegate override.
108 void FindMatchRectsReply(WebContents* web_contents, 160 void FindMatchRectsReply(WebContents* web_contents,
109 int version, 161 int version,
110 const std::vector<gfx::RectF>& rects, 162 const std::vector<gfx::RectF>& rects,
111 const gfx::RectF& active_rect) override { 163 const gfx::RectF& active_rect) override {
112 // Update the current rects. 164 // Update the current rects.
113 find_match_rects_ = rects; 165 find_match_rects_ = rects;
114 active_match_rect_ = active_rect; 166 active_match_rect_ = active_rect;
115 167
116 // If we are waiting for match rects, stop waiting. 168 // If we are waiting for match rects, stop waiting.
117 if (match_rects_message_loop_runner_.get()) 169 if (waiting_for_ == MATCH_RECTS)
118 match_rects_message_loop_runner_->Quit(); 170 StopWaiting();
119 } 171 }
120 172
121 std::vector<gfx::RectF> find_match_rects_; 173 std::vector<gfx::RectF> find_match_rects_;
122 174
123 gfx::RectF active_match_rect_; 175 gfx::RectF active_match_rect_;
124 #endif 176 #endif
125 177
126 // The latest known results from the current find request. 178 // The latest known results from the current find request.
127 FindResults current_results_; 179 FindResults current_results_;
128 180
181 // The ID of the last find request issued.
182 int last_request_id_;
183
129 // The ID of the last find request to finish (all replies received). 184 // The ID of the last find request to finish (all replies received).
130 int last_finished_request_id_; 185 int last_finished_request_id_;
131 186
132 // If waiting using |find_message_loop_runner_|, this is the ID of the find 187 // Indicates whether the next reply after MarkNextReply() has been received.
133 // request being waited for. 188 bool next_reply_received_;
134 int waiting_request_id_;
135 189
136 scoped_refptr<content::MessageLoopRunner> find_message_loop_runner_; 190 // Indicates what |message_loop_runner_| is waiting for, if anything.
137 scoped_refptr<content::MessageLoopRunner> match_rects_message_loop_runner_; 191 WaitingFor waiting_for_;
192
193 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
138 194
139 DISALLOW_COPY_AND_ASSIGN(TestWebContentsDelegate); 195 DISALLOW_COPY_AND_ASSIGN(TestWebContentsDelegate);
140 }; 196 };
141 197
142 class FindRequestManagerTest : public ContentBrowserTest, 198 class FindRequestManagerTest : public ContentBrowserTest,
143 public testing::WithParamInterface<bool> { 199 public testing::WithParamInterface<bool> {
144 public: 200 public:
145 FindRequestManagerTest() 201 FindRequestManagerTest()
146 : normal_delegate_(nullptr), 202 : normal_delegate_(nullptr),
147 last_request_id_(0) {} 203 last_request_id_(0) {}
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 FrameTreeNode* child = root->child_at(0); 255 FrameTreeNode* child = root->child_at(0);
200 GURL url(embedded_test_server()->GetURL("b.com", 256 GURL url(embedded_test_server()->GetURL("b.com",
201 child->current_url().path())); 257 child->current_url().path()));
202 NavigateFrameToURL(child, url); 258 NavigateFrameToURL(child, url);
203 EXPECT_EQ(url, observer.last_navigation_url()); 259 EXPECT_EQ(url, observer.last_navigation_url());
204 EXPECT_TRUE(observer.last_navigation_succeeded()); 260 EXPECT_TRUE(observer.last_navigation_succeeded());
205 } 261 }
206 262
207 void Find(const std::string& search_text, 263 void Find(const std::string& search_text,
208 const blink::WebFindOptions& options) { 264 const blink::WebFindOptions& options) {
209 contents()->Find(++last_request_id_, 265 delegate()->UpdateLastRequest(++last_request_id_);
266 contents()->Find(last_request_id_,
210 base::UTF8ToUTF16(search_text), 267 base::UTF8ToUTF16(search_text),
211 options); 268 options);
212 } 269 }
213 270
214 void WaitForFinalReply() const {
215 delegate()->WaitForFinalReply(last_request_id_);
216 }
217
218 WebContents* contents() const { 271 WebContents* contents() const {
219 return shell()->web_contents(); 272 return shell()->web_contents();
220 } 273 }
221 274
222 TestWebContentsDelegate* delegate() const { 275 TestWebContentsDelegate* delegate() const {
223 return static_cast<TestWebContentsDelegate*>(contents()->GetDelegate()); 276 return static_cast<TestWebContentsDelegate*>(contents()->GetDelegate());
224 } 277 }
225 278
226 int last_request_id() const { 279 int last_request_id() const {
227 return last_request_id_; 280 return last_request_id_;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 338
286 // Tests basic find-in-page functionality (such as searching forward and 339 // Tests basic find-in-page functionality (such as searching forward and
287 // backward) and check for correct results at each step. 340 // backward) and check for correct results at each step.
288 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(Basic)) { 341 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(Basic)) {
289 LoadAndWait("/find_in_page.html"); 342 LoadAndWait("/find_in_page.html");
290 if (GetParam()) 343 if (GetParam())
291 MakeChildFrameCrossProcess(); 344 MakeChildFrameCrossProcess();
292 345
293 blink::WebFindOptions options; 346 blink::WebFindOptions options;
294 Find("result", options); 347 Find("result", options);
295 WaitForFinalReply(); 348 delegate()->WaitForFinalReply();
296 349
297 FindResults results = delegate()->GetFindResults(); 350 FindResults results = delegate()->GetFindResults();
298 EXPECT_EQ(last_request_id(), results.request_id); 351 EXPECT_EQ(last_request_id(), results.request_id);
299 EXPECT_EQ(19, results.number_of_matches); 352 EXPECT_EQ(19, results.number_of_matches);
300 EXPECT_EQ(1, results.active_match_ordinal); 353 EXPECT_EQ(1, results.active_match_ordinal);
301 354
302 options.findNext = true; 355 options.findNext = true;
303 for (int i = 2; i <= 10; ++i) { 356 for (int i = 2; i <= 10; ++i) {
304 Find("result", options); 357 Find("result", options);
305 WaitForFinalReply(); 358 delegate()->WaitForFinalReply();
306 359
307 results = delegate()->GetFindResults(); 360 results = delegate()->GetFindResults();
308 EXPECT_EQ(last_request_id(), results.request_id); 361 EXPECT_EQ(last_request_id(), results.request_id);
309 EXPECT_EQ(19, results.number_of_matches); 362 EXPECT_EQ(19, results.number_of_matches);
310 EXPECT_EQ(i, results.active_match_ordinal); 363 EXPECT_EQ(i, results.active_match_ordinal);
311 } 364 }
312 365
313 options.forward = false; 366 options.forward = false;
314 for (int i = 9; i >= 5; --i) { 367 for (int i = 9; i >= 5; --i) {
315 Find("result", options); 368 Find("result", options);
316 WaitForFinalReply(); 369 delegate()->WaitForFinalReply();
317 370
318 results = delegate()->GetFindResults(); 371 results = delegate()->GetFindResults();
319 EXPECT_EQ(last_request_id(), results.request_id); 372 EXPECT_EQ(last_request_id(), results.request_id);
320 EXPECT_EQ(19, results.number_of_matches); 373 EXPECT_EQ(19, results.number_of_matches);
321 EXPECT_EQ(i, results.active_match_ordinal); 374 EXPECT_EQ(i, results.active_match_ordinal);
322 } 375 }
323 } 376 }
324 377
325 // Tests searching for a word character-by-character, as would typically be done 378 // Tests searching for a word character-by-character, as would typically be done
326 // by a user typing into the find bar. 379 // by a user typing into the find bar.
327 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(CharacterByCharacter)) { 380 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(CharacterByCharacter)) {
328 LoadAndWait("/find_in_page.html"); 381 LoadAndWait("/find_in_page.html");
329 if (GetParam()) 382 if (GetParam())
330 MakeChildFrameCrossProcess(); 383 MakeChildFrameCrossProcess();
331 384
332 blink::WebFindOptions default_options; 385 blink::WebFindOptions default_options;
333 Find("r", default_options); 386 Find("r", default_options);
334 Find("re", default_options); 387 Find("re", default_options);
335 Find("res", default_options); 388 Find("res", default_options);
336 Find("resu", default_options); 389 Find("resu", default_options);
337 Find("resul", default_options); 390 Find("resul", default_options);
338 Find("result", default_options); 391 Find("result", default_options);
339 WaitForFinalReply(); 392 delegate()->WaitForFinalReply();
340 393
341 FindResults results = delegate()->GetFindResults(); 394 FindResults results = delegate()->GetFindResults();
342 EXPECT_EQ(last_request_id(), results.request_id); 395 EXPECT_EQ(last_request_id(), results.request_id);
343 EXPECT_EQ(19, results.number_of_matches); 396 EXPECT_EQ(19, results.number_of_matches);
344 EXPECT_EQ(1, results.active_match_ordinal); 397 EXPECT_EQ(1, results.active_match_ordinal);
345 } 398 }
346 399
347 // Tests sending a large number of find requests subsequently. 400 // Tests sending a large number of find requests subsequently.
348 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(RapidFire)) { 401 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(RapidFire)) {
349 LoadAndWait("/find_in_page.html"); 402 LoadAndWait("/find_in_page.html");
350 if (GetParam()) 403 if (GetParam())
351 MakeChildFrameCrossProcess(); 404 MakeChildFrameCrossProcess();
352 405
353 blink::WebFindOptions options; 406 blink::WebFindOptions options;
354 Find("result", options); 407 Find("result", options);
355 408
356 options.findNext = true; 409 options.findNext = true;
357 for (int i = 2; i <= 1000; ++i) 410 for (int i = 2; i <= 1000; ++i)
358 Find("result", options); 411 Find("result", options);
359 WaitForFinalReply(); 412 delegate()->WaitForFinalReply();
360 413
361 FindResults results = delegate()->GetFindResults(); 414 FindResults results = delegate()->GetFindResults();
362 EXPECT_EQ(last_request_id(), results.request_id); 415 EXPECT_EQ(last_request_id(), results.request_id);
363 EXPECT_EQ(19, results.number_of_matches); 416 EXPECT_EQ(19, results.number_of_matches);
364 EXPECT_EQ(last_request_id() % results.number_of_matches, 417 EXPECT_EQ(last_request_id() % results.number_of_matches,
365 results.active_match_ordinal); 418 results.active_match_ordinal);
366 } 419 }
367 420
368 // Tests removing a frame during a find session. 421 // Tests removing a frame during a find session.
369 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(RemoveFrame)) { 422 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(RemoveFrame)) {
370 LoadMultiFramePage(2 /* height */, GetParam() /* cross_process */); 423 LoadMultiFramePage(2 /* height */, GetParam() /* cross_process */);
371 424
372 blink::WebFindOptions options; 425 blink::WebFindOptions options;
373 Find("result", options); 426 Find("result", options);
374 options.findNext = true; 427 options.findNext = true;
375 options.forward = false; 428 options.forward = false;
376 Find("result", options); 429 Find("result", options);
377 Find("result", options); 430 Find("result", options);
378 Find("result", options); 431 Find("result", options);
379 Find("result", options); 432 Find("result", options);
380 Find("result", options); 433 Find("result", options);
381 WaitForFinalReply(); 434 delegate()->WaitForFinalReply();
382 435
383 FindResults results = delegate()->GetFindResults(); 436 FindResults results = delegate()->GetFindResults();
384 EXPECT_EQ(last_request_id(), results.request_id); 437 EXPECT_EQ(last_request_id(), results.request_id);
385 EXPECT_EQ(21, results.number_of_matches); 438 EXPECT_EQ(21, results.number_of_matches);
386 EXPECT_EQ(17, results.active_match_ordinal); 439 EXPECT_EQ(17, results.active_match_ordinal);
387 440
388 // Remove a frame. 441 // Remove a frame.
389 FrameTreeNode* root = 442 FrameTreeNode* root =
390 static_cast<WebContentsImpl*>(shell()->web_contents())-> 443 static_cast<WebContentsImpl*>(shell()->web_contents())->
391 GetFrameTree()->root(); 444 GetFrameTree()->root();
392 root->RemoveChild(root->child_at(0)); 445 root->RemoveChild(root->child_at(0));
393 446
394 // The number of matches and active match ordinal should update automatically 447 // The number of matches and active match ordinal should update automatically
395 // to exclude the matches from the removed frame. 448 // to exclude the matches from the removed frame.
396 results = delegate()->GetFindResults(); 449 results = delegate()->GetFindResults();
397 EXPECT_EQ(last_request_id(), results.request_id);
398 EXPECT_EQ(12, results.number_of_matches); 450 EXPECT_EQ(12, results.number_of_matches);
399 EXPECT_EQ(8, results.active_match_ordinal); 451 EXPECT_EQ(8, results.active_match_ordinal);
400 452
401 // TODO(paulemeyer): Once adding frames mid-session is handled, test that too. 453 // TODO(paulemeyer): Once adding frames mid-session is handled, test that too.
402 } 454 }
403 455
404 // Tests Searching in a hidden frame. Matches in the hidden frame should be 456 // Tests Searching in a hidden frame. Matches in the hidden frame should be
405 // ignored. 457 // ignored.
406 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(HiddenFrame)) { 458 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(HiddenFrame)) {
407 LoadAndWait("/find_in_hidden_frame.html"); 459 LoadAndWait("/find_in_hidden_frame.html");
408 460
409 blink::WebFindOptions default_options; 461 blink::WebFindOptions default_options;
410 Find("hello", default_options); 462 Find("hello", default_options);
411 WaitForFinalReply(); 463 delegate()->WaitForFinalReply();
412 FindResults results = delegate()->GetFindResults(); 464 FindResults results = delegate()->GetFindResults();
413 465
414 EXPECT_EQ(last_request_id(), results.request_id); 466 EXPECT_EQ(last_request_id(), results.request_id);
415 EXPECT_EQ(1, results.number_of_matches); 467 EXPECT_EQ(1, results.number_of_matches);
416 EXPECT_EQ(1, results.active_match_ordinal); 468 EXPECT_EQ(1, results.active_match_ordinal);
417 } 469 }
418 470
419 #if defined(OS_ANDROID) 471 #if defined(OS_ANDROID)
420 // Tests requesting find match rects. 472 // Tests requesting find match rects.
421 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(FindMatchRects)) { 473 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(FindMatchRects)) {
422 LoadAndWait("/find_in_page.html"); 474 LoadAndWait("/find_in_page.html");
423 475
424 blink::WebFindOptions default_options; 476 blink::WebFindOptions default_options;
425 Find("result", default_options); 477 Find("result", default_options);
426 WaitForFinalReply(); 478 delegate()->WaitForFinalReply();
427 EXPECT_EQ(19, delegate()->GetFindResults().number_of_matches); 479 EXPECT_EQ(19, delegate()->GetFindResults().number_of_matches);
428 480
429 // Request the find match rects. 481 // Request the find match rects.
430 contents()->RequestFindMatchRects(-1); 482 contents()->RequestFindMatchRects(-1);
431 delegate()->WaitForMatchRects(); 483 delegate()->WaitForMatchRects();
432 const std::vector<gfx::RectF>& rects = delegate()->find_match_rects(); 484 const std::vector<gfx::RectF>& rects = delegate()->find_match_rects();
433 485
434 // The first match should be active. 486 // The first match should be active.
435 EXPECT_EQ(rects[0], delegate()->active_match_rect()); 487 EXPECT_EQ(rects[0], delegate()->active_match_rect());
436 488
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 EXPECT_GT(rects[17].y(), rects[18].y()); 550 EXPECT_GT(rects[17].y(), rects[18].y());
499 } 551 }
500 552
501 // Tests activating the find match nearest to a given point. 553 // Tests activating the find match nearest to a given point.
502 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, 554 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest,
503 MAYBE(ActivateNearestFindMatch)) { 555 MAYBE(ActivateNearestFindMatch)) {
504 LoadAndWait("/find_in_page.html"); 556 LoadAndWait("/find_in_page.html");
505 557
506 blink::WebFindOptions default_options; 558 blink::WebFindOptions default_options;
507 Find("result", default_options); 559 Find("result", default_options);
508 WaitForFinalReply(); 560 delegate()->WaitForFinalReply();
509 EXPECT_EQ(19, delegate()->GetFindResults().number_of_matches); 561 EXPECT_EQ(19, delegate()->GetFindResults().number_of_matches);
510 562
511 // Get the find match rects. 563 // Get the find match rects.
512 contents()->RequestFindMatchRects(-1); 564 contents()->RequestFindMatchRects(-1);
513 delegate()->WaitForMatchRects(); 565 delegate()->WaitForMatchRects();
514 const std::vector<gfx::RectF>& rects = delegate()->find_match_rects(); 566 const std::vector<gfx::RectF>& rects = delegate()->find_match_rects();
515 567
516 // Activate matches via points inside each of the find match rects, in an 568 // Activate matches via points inside each of the find match rects, in an
517 // arbitrary order. Check that the correct match becomes active after each 569 // arbitrary order. Check that the correct match becomes active after each
518 // activation. 570 // activation.
519 int order[19] = 571 int order[19] =
520 {11, 13, 2, 0, 16, 5, 7, 10, 6, 1, 15, 14, 9, 17, 18, 3, 8, 12, 4}; 572 {11, 13, 2, 0, 16, 5, 7, 10, 6, 1, 15, 14, 9, 17, 18, 3, 8, 12, 4};
521 for (int i = 0; i < 19; ++i) { 573 for (int i = 0; i < 19; ++i) {
574 delegate()->MarkNextReply();
522 contents()->ActivateNearestFindResult( 575 contents()->ActivateNearestFindResult(
523 rects[order[i]].CenterPoint().x(), rects[order[i]].CenterPoint().y()); 576 rects[order[i]].CenterPoint().x(), rects[order[i]].CenterPoint().y());
524 delegate()->WaitForNextReply(); 577 delegate()->WaitForNextReply();
525 EXPECT_EQ(order[i] + 1, delegate()->GetFindResults().active_match_ordinal); 578 EXPECT_EQ(order[i] + 1, delegate()->GetFindResults().active_match_ordinal);
526 } 579 }
527 } 580 }
528 #endif // defined(OS_ANDROID) 581 #endif // defined(OS_ANDROID)
529 582
530 } // namespace content 583 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698