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

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: 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 WaitFor(NOTHING);
104 } 131 }
105 } 132 }
106 133
134 // Uses |message_loop_runner_| to wait for various things.
135 void WaitFor(WaitingFor wait_for) {
136 waiting_for_ = wait_for;
137
138 if (message_loop_runner_.get())
139 message_loop_runner_->Quit();
140
141 if (wait_for == NOTHING)
142 return;
143
144 message_loop_runner_ = new content::MessageLoopRunner;
lfg 2016/08/10 03:19:16 This is a bit strange. You just called Quit() on t
paulmeyer 2016/08/10 15:43:12 You're right, it is strange. Based on how the func
145 message_loop_runner_->Run();
146 }
147
107 #if defined(OS_ANDROID) 148 #if defined(OS_ANDROID)
149 // WebContentsDelegate override.
108 void FindMatchRectsReply(WebContents* web_contents, 150 void FindMatchRectsReply(WebContents* web_contents,
109 int version, 151 int version,
110 const std::vector<gfx::RectF>& rects, 152 const std::vector<gfx::RectF>& rects,
111 const gfx::RectF& active_rect) override { 153 const gfx::RectF& active_rect) override {
112 // Update the current rects. 154 // Update the current rects.
113 find_match_rects_ = rects; 155 find_match_rects_ = rects;
114 active_match_rect_ = active_rect; 156 active_match_rect_ = active_rect;
115 157
116 // If we are waiting for match rects, stop waiting. 158 // If we are waiting for match rects, stop waiting.
117 if (match_rects_message_loop_runner_.get()) 159 if (waiting_for_ == MATCH_RECTS)
118 match_rects_message_loop_runner_->Quit(); 160 WaitFor(NOTHING);
119 } 161 }
120 162
121 std::vector<gfx::RectF> find_match_rects_; 163 std::vector<gfx::RectF> find_match_rects_;
122 164
123 gfx::RectF active_match_rect_; 165 gfx::RectF active_match_rect_;
124 #endif 166 #endif
125 167
126 // The latest known results from the current find request. 168 // The latest known results from the current find request.
127 FindResults current_results_; 169 FindResults current_results_;
128 170
171 // The ID of the last find request issued.
172 int last_request_id_;
173
129 // The ID of the last find request to finish (all replies received). 174 // The ID of the last find request to finish (all replies received).
130 int last_finished_request_id_; 175 int last_finished_request_id_;
131 176
132 // If waiting using |find_message_loop_runner_|, this is the ID of the find 177 // Indicates whether the next reply after MarkNextReply() has been received.
133 // request being waited for. 178 bool next_reply_received_;
134 int waiting_request_id_;
135 179
136 scoped_refptr<content::MessageLoopRunner> find_message_loop_runner_; 180 // Indicates what |message_loop_runner_| is waiting for, if anything.
137 scoped_refptr<content::MessageLoopRunner> match_rects_message_loop_runner_; 181 WaitingFor waiting_for_;
182
183 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
138 184
139 DISALLOW_COPY_AND_ASSIGN(TestWebContentsDelegate); 185 DISALLOW_COPY_AND_ASSIGN(TestWebContentsDelegate);
140 }; 186 };
141 187
142 class FindRequestManagerTest : public ContentBrowserTest, 188 class FindRequestManagerTest : public ContentBrowserTest,
143 public testing::WithParamInterface<bool> { 189 public testing::WithParamInterface<bool> {
144 public: 190 public:
145 FindRequestManagerTest() 191 FindRequestManagerTest()
146 : normal_delegate_(nullptr), 192 : normal_delegate_(nullptr),
147 last_request_id_(0) {} 193 last_request_id_(0) {}
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 FrameTreeNode* child = root->child_at(0); 245 FrameTreeNode* child = root->child_at(0);
200 GURL url(embedded_test_server()->GetURL("b.com", 246 GURL url(embedded_test_server()->GetURL("b.com",
201 child->current_url().path())); 247 child->current_url().path()));
202 NavigateFrameToURL(child, url); 248 NavigateFrameToURL(child, url);
203 EXPECT_EQ(url, observer.last_navigation_url()); 249 EXPECT_EQ(url, observer.last_navigation_url());
204 EXPECT_TRUE(observer.last_navigation_succeeded()); 250 EXPECT_TRUE(observer.last_navigation_succeeded());
205 } 251 }
206 252
207 void Find(const std::string& search_text, 253 void Find(const std::string& search_text,
208 const blink::WebFindOptions& options) { 254 const blink::WebFindOptions& options) {
209 contents()->Find(++last_request_id_, 255 delegate()->UpdateLastRequest(++last_request_id_);
256 contents()->Find(last_request_id_,
210 base::UTF8ToUTF16(search_text), 257 base::UTF8ToUTF16(search_text),
211 options); 258 options);
212 } 259 }
213 260
214 void WaitForFinalReply() const {
215 delegate()->WaitForFinalReply(last_request_id_);
216 }
217
218 WebContents* contents() const { 261 WebContents* contents() const {
219 return shell()->web_contents(); 262 return shell()->web_contents();
220 } 263 }
221 264
222 TestWebContentsDelegate* delegate() const { 265 TestWebContentsDelegate* delegate() const {
223 return static_cast<TestWebContentsDelegate*>(contents()->GetDelegate()); 266 return static_cast<TestWebContentsDelegate*>(contents()->GetDelegate());
224 } 267 }
225 268
226 int last_request_id() const { 269 int last_request_id() const {
227 return last_request_id_; 270 return last_request_id_;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 328
286 // Tests basic find-in-page functionality (such as searching forward and 329 // Tests basic find-in-page functionality (such as searching forward and
287 // backward) and check for correct results at each step. 330 // backward) and check for correct results at each step.
288 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(Basic)) { 331 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(Basic)) {
289 LoadAndWait("/find_in_page.html"); 332 LoadAndWait("/find_in_page.html");
290 if (GetParam()) 333 if (GetParam())
291 MakeChildFrameCrossProcess(); 334 MakeChildFrameCrossProcess();
292 335
293 blink::WebFindOptions options; 336 blink::WebFindOptions options;
294 Find("result", options); 337 Find("result", options);
295 WaitForFinalReply(); 338 delegate()->WaitForFinalReply();
296 339
297 FindResults results = delegate()->GetFindResults(); 340 FindResults results = delegate()->GetFindResults();
298 EXPECT_EQ(last_request_id(), results.request_id); 341 EXPECT_EQ(last_request_id(), results.request_id);
299 EXPECT_EQ(19, results.number_of_matches); 342 EXPECT_EQ(19, results.number_of_matches);
300 EXPECT_EQ(1, results.active_match_ordinal); 343 EXPECT_EQ(1, results.active_match_ordinal);
301 344
302 options.findNext = true; 345 options.findNext = true;
303 for (int i = 2; i <= 10; ++i) { 346 for (int i = 2; i <= 10; ++i) {
304 Find("result", options); 347 Find("result", options);
305 WaitForFinalReply(); 348 delegate()->WaitForFinalReply();
306 349
307 results = delegate()->GetFindResults(); 350 results = delegate()->GetFindResults();
308 EXPECT_EQ(last_request_id(), results.request_id); 351 EXPECT_EQ(last_request_id(), results.request_id);
309 EXPECT_EQ(19, results.number_of_matches); 352 EXPECT_EQ(19, results.number_of_matches);
310 EXPECT_EQ(i, results.active_match_ordinal); 353 EXPECT_EQ(i, results.active_match_ordinal);
311 } 354 }
312 355
313 options.forward = false; 356 options.forward = false;
314 for (int i = 9; i >= 5; --i) { 357 for (int i = 9; i >= 5; --i) {
315 Find("result", options); 358 Find("result", options);
316 WaitForFinalReply(); 359 delegate()->WaitForFinalReply();
317 360
318 results = delegate()->GetFindResults(); 361 results = delegate()->GetFindResults();
319 EXPECT_EQ(last_request_id(), results.request_id); 362 EXPECT_EQ(last_request_id(), results.request_id);
320 EXPECT_EQ(19, results.number_of_matches); 363 EXPECT_EQ(19, results.number_of_matches);
321 EXPECT_EQ(i, results.active_match_ordinal); 364 EXPECT_EQ(i, results.active_match_ordinal);
322 } 365 }
323 } 366 }
324 367
325 // Tests searching for a word character-by-character, as would typically be done 368 // Tests searching for a word character-by-character, as would typically be done
326 // by a user typing into the find bar. 369 // by a user typing into the find bar.
327 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(CharacterByCharacter)) { 370 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(CharacterByCharacter)) {
328 LoadAndWait("/find_in_page.html"); 371 LoadAndWait("/find_in_page.html");
329 if (GetParam()) 372 if (GetParam())
330 MakeChildFrameCrossProcess(); 373 MakeChildFrameCrossProcess();
331 374
332 blink::WebFindOptions default_options; 375 blink::WebFindOptions default_options;
333 Find("r", default_options); 376 Find("r", default_options);
334 Find("re", default_options); 377 Find("re", default_options);
335 Find("res", default_options); 378 Find("res", default_options);
336 Find("resu", default_options); 379 Find("resu", default_options);
337 Find("resul", default_options); 380 Find("resul", default_options);
338 Find("result", default_options); 381 Find("result", default_options);
339 WaitForFinalReply(); 382 delegate()->WaitForFinalReply();
340 383
341 FindResults results = delegate()->GetFindResults(); 384 FindResults results = delegate()->GetFindResults();
342 EXPECT_EQ(last_request_id(), results.request_id); 385 EXPECT_EQ(last_request_id(), results.request_id);
343 EXPECT_EQ(19, results.number_of_matches); 386 EXPECT_EQ(19, results.number_of_matches);
344 EXPECT_EQ(1, results.active_match_ordinal); 387 EXPECT_EQ(1, results.active_match_ordinal);
345 } 388 }
346 389
347 // Tests sending a large number of find requests subsequently. 390 // Tests sending a large number of find requests subsequently.
348 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(RapidFire)) { 391 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(RapidFire)) {
349 LoadAndWait("/find_in_page.html"); 392 LoadAndWait("/find_in_page.html");
350 if (GetParam()) 393 if (GetParam())
351 MakeChildFrameCrossProcess(); 394 MakeChildFrameCrossProcess();
352 395
353 blink::WebFindOptions options; 396 blink::WebFindOptions options;
354 Find("result", options); 397 Find("result", options);
355 398
356 options.findNext = true; 399 options.findNext = true;
357 for (int i = 2; i <= 1000; ++i) 400 for (int i = 2; i <= 1000; ++i)
358 Find("result", options); 401 Find("result", options);
359 WaitForFinalReply(); 402 delegate()->WaitForFinalReply();
360 403
361 FindResults results = delegate()->GetFindResults(); 404 FindResults results = delegate()->GetFindResults();
362 EXPECT_EQ(last_request_id(), results.request_id); 405 EXPECT_EQ(last_request_id(), results.request_id);
363 EXPECT_EQ(19, results.number_of_matches); 406 EXPECT_EQ(19, results.number_of_matches);
364 EXPECT_EQ(last_request_id() % results.number_of_matches, 407 EXPECT_EQ(last_request_id() % results.number_of_matches,
365 results.active_match_ordinal); 408 results.active_match_ordinal);
366 } 409 }
367 410
368 // Tests removing a frame during a find session. 411 // Tests removing a frame during a find session.
369 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(RemoveFrame)) { 412 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(RemoveFrame)) {
370 LoadMultiFramePage(2 /* height */, GetParam() /* cross_process */); 413 LoadMultiFramePage(2 /* height */, GetParam() /* cross_process */);
371 414
372 blink::WebFindOptions options; 415 blink::WebFindOptions options;
373 Find("result", options); 416 Find("result", options);
374 options.findNext = true; 417 options.findNext = true;
375 options.forward = false; 418 options.forward = false;
376 Find("result", options); 419 Find("result", options);
377 Find("result", options); 420 Find("result", options);
378 Find("result", options); 421 Find("result", options);
379 Find("result", options); 422 Find("result", options);
380 Find("result", options); 423 Find("result", options);
381 WaitForFinalReply(); 424 delegate()->WaitForFinalReply();
382 425
383 FindResults results = delegate()->GetFindResults(); 426 FindResults results = delegate()->GetFindResults();
384 EXPECT_EQ(last_request_id(), results.request_id); 427 EXPECT_EQ(last_request_id(), results.request_id);
385 EXPECT_EQ(21, results.number_of_matches); 428 EXPECT_EQ(21, results.number_of_matches);
386 EXPECT_EQ(17, results.active_match_ordinal); 429 EXPECT_EQ(17, results.active_match_ordinal);
387 430
388 // Remove a frame. 431 // Remove a frame.
389 FrameTreeNode* root = 432 FrameTreeNode* root =
390 static_cast<WebContentsImpl*>(shell()->web_contents())-> 433 static_cast<WebContentsImpl*>(shell()->web_contents())->
391 GetFrameTree()->root(); 434 GetFrameTree()->root();
392 root->RemoveChild(root->child_at(0)); 435 root->RemoveChild(root->child_at(0));
393 436
394 // The number of matches and active match ordinal should update automatically 437 // The number of matches and active match ordinal should update automatically
395 // to exclude the matches from the removed frame. 438 // to exclude the matches from the removed frame.
396 results = delegate()->GetFindResults(); 439 results = delegate()->GetFindResults();
397 EXPECT_EQ(last_request_id(), results.request_id);
398 EXPECT_EQ(12, results.number_of_matches); 440 EXPECT_EQ(12, results.number_of_matches);
399 EXPECT_EQ(8, results.active_match_ordinal); 441 EXPECT_EQ(8, results.active_match_ordinal);
400 442
401 // TODO(paulemeyer): Once adding frames mid-session is handled, test that too. 443 // TODO(paulemeyer): Once adding frames mid-session is handled, test that too.
402 } 444 }
403 445
404 // Tests Searching in a hidden frame. Matches in the hidden frame should be 446 // Tests Searching in a hidden frame. Matches in the hidden frame should be
405 // ignored. 447 // ignored.
406 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(HiddenFrame)) { 448 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(HiddenFrame)) {
407 LoadAndWait("/find_in_hidden_frame.html"); 449 LoadAndWait("/find_in_hidden_frame.html");
408 450
409 blink::WebFindOptions default_options; 451 blink::WebFindOptions default_options;
410 Find("hello", default_options); 452 Find("hello", default_options);
411 WaitForFinalReply(); 453 delegate()->WaitForFinalReply();
412 FindResults results = delegate()->GetFindResults(); 454 FindResults results = delegate()->GetFindResults();
413 455
414 EXPECT_EQ(last_request_id(), results.request_id); 456 EXPECT_EQ(last_request_id(), results.request_id);
415 EXPECT_EQ(1, results.number_of_matches); 457 EXPECT_EQ(1, results.number_of_matches);
416 EXPECT_EQ(1, results.active_match_ordinal); 458 EXPECT_EQ(1, results.active_match_ordinal);
417 } 459 }
418 460
419 #if defined(OS_ANDROID) 461 #if defined(OS_ANDROID)
420 // Tests requesting find match rects. 462 // Tests requesting find match rects.
421 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(FindMatchRects)) { 463 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(FindMatchRects)) {
422 LoadAndWait("/find_in_page.html"); 464 LoadAndWait("/find_in_page.html");
423 465
424 blink::WebFindOptions default_options; 466 blink::WebFindOptions default_options;
425 Find("result", default_options); 467 Find("result", default_options);
426 WaitForFinalReply(); 468 delegate()->WaitForFinalReply();
427 EXPECT_EQ(19, delegate()->GetFindResults().number_of_matches); 469 EXPECT_EQ(19, delegate()->GetFindResults().number_of_matches);
428 470
429 // Request the find match rects. 471 // Request the find match rects.
430 contents()->RequestFindMatchRects(-1); 472 contents()->RequestFindMatchRects(-1);
431 delegate()->WaitForMatchRects(); 473 delegate()->WaitForMatchRects();
432 const std::vector<gfx::RectF>& rects = delegate()->find_match_rects(); 474 const std::vector<gfx::RectF>& rects = delegate()->find_match_rects();
433 475
434 // The first match should be active. 476 // The first match should be active.
435 EXPECT_EQ(rects[0], delegate()->active_match_rect()); 477 EXPECT_EQ(rects[0], delegate()->active_match_rect());
436 478
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 EXPECT_GT(rects[17].y(), rects[18].y()); 540 EXPECT_GT(rects[17].y(), rects[18].y());
499 } 541 }
500 542
501 // Tests activating the find match nearest to a given point. 543 // Tests activating the find match nearest to a given point.
502 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, 544 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest,
503 MAYBE(ActivateNearestFindMatch)) { 545 MAYBE(ActivateNearestFindMatch)) {
504 LoadAndWait("/find_in_page.html"); 546 LoadAndWait("/find_in_page.html");
505 547
506 blink::WebFindOptions default_options; 548 blink::WebFindOptions default_options;
507 Find("result", default_options); 549 Find("result", default_options);
508 WaitForFinalReply(); 550 delegate()->WaitForFinalReply();
509 EXPECT_EQ(19, delegate()->GetFindResults().number_of_matches); 551 EXPECT_EQ(19, delegate()->GetFindResults().number_of_matches);
510 552
511 // Get the find match rects. 553 // Get the find match rects.
512 contents()->RequestFindMatchRects(-1); 554 contents()->RequestFindMatchRects(-1);
513 delegate()->WaitForMatchRects(); 555 delegate()->WaitForMatchRects();
514 const std::vector<gfx::RectF>& rects = delegate()->find_match_rects(); 556 const std::vector<gfx::RectF>& rects = delegate()->find_match_rects();
515 557
516 // Activate matches via points inside each of the find match rects, in an 558 // 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 559 // arbitrary order. Check that the correct match becomes active after each
518 // activation. 560 // activation.
519 int order[19] = 561 int order[19] =
520 {11, 13, 2, 0, 16, 5, 7, 10, 6, 1, 15, 14, 9, 17, 18, 3, 8, 12, 4}; 562 {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) { 563 for (int i = 0; i < 19; ++i) {
564 delegate()->MarkNextReply();
522 contents()->ActivateNearestFindResult( 565 contents()->ActivateNearestFindResult(
523 rects[order[i]].CenterPoint().x(), rects[order[i]].CenterPoint().y()); 566 rects[order[i]].CenterPoint().x(), rects[order[i]].CenterPoint().y());
524 delegate()->WaitForNextReply(); 567 delegate()->WaitForNextReply();
525 EXPECT_EQ(order[i] + 1, delegate()->GetFindResults().active_match_ordinal); 568 EXPECT_EQ(order[i] + 1, delegate()->GetFindResults().active_match_ordinal);
526 } 569 }
527 } 570 }
528 #endif // defined(OS_ANDROID) 571 #endif // defined(OS_ANDROID)
529 572
530 } // namespace content 573 } // 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