Chromium Code Reviews| 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 4986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4997 EXPECT_TRUE( | 4997 EXPECT_TRUE( |
| 4998 frame->find(findIdentifier, searchText, options, false, &activeNow)); | 4998 frame->find(findIdentifier, searchText, options, false, &activeNow)); |
| 4999 frame->stopFinding(WebLocalFrame::StopFindActionKeepSelection); | 4999 frame->stopFinding(WebLocalFrame::StopFindActionKeepSelection); |
| 5000 WebRange range = frame->selectionRange(); | 5000 WebRange range = frame->selectionRange(); |
| 5001 EXPECT_EQ(5, range.startOffset()); | 5001 EXPECT_EQ(5, range.startOffset()); |
| 5002 EXPECT_EQ(8, range.endOffset()); | 5002 EXPECT_EQ(8, range.endOffset()); |
| 5003 EXPECT_TRUE(frame->document().focusedElement().isNull()); | 5003 EXPECT_TRUE(frame->document().focusedElement().isNull()); |
| 5004 EXPECT_FALSE(activeNow); | 5004 EXPECT_FALSE(activeNow); |
| 5005 } | 5005 } |
| 5006 | 5006 |
| 5007 struct FakeTimerSetter { | |
|
kotenkov
2016/12/07 11:22:34
There are a couple of places containing similar co
| |
| 5008 FakeTimerSetter() { | |
| 5009 s_timeElapsed = 0.0; | |
| 5010 m_originalTimeFunction = setTimeFunctionsForTesting(returnMockTime); | |
| 5011 } | |
| 5012 | |
| 5013 ~FakeTimerSetter() { setTimeFunctionsForTesting(m_originalTimeFunction); } | |
| 5014 static double returnMockTime() { | |
| 5015 s_timeElapsed += 1.0; | |
| 5016 return s_timeElapsed; | |
| 5017 } | |
| 5018 | |
| 5019 private: | |
| 5020 TimeFunction m_originalTimeFunction; | |
| 5021 static double s_timeElapsed; | |
| 5022 }; | |
| 5023 double FakeTimerSetter::s_timeElapsed = 0.; | |
| 5024 | |
| 5025 TEST_P(ParameterizedWebFrameTest, FindInPageJavaScriptUpdatesDOMProperOrdinal) { | |
| 5026 FakeTimerSetter fakeTimer; | |
| 5027 | |
| 5028 const WebString searchPattern = WebString::fromUTF8("abc"); | |
| 5029 // We have 2 occurrences of the pattern in our text. | |
| 5030 const char* html = | |
| 5031 "foo bar foo bar foo abc bar foo bar foo bar foo bar foo bar foo bar foo " | |
| 5032 "bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo " | |
| 5033 "bar foo bar foo abc bar <div id='new_text'></div>"; | |
| 5034 | |
| 5035 FindUpdateWebFrameClient client; | |
| 5036 FrameTestHelpers::WebViewHelper webViewHelper; | |
| 5037 webViewHelper.initialize(true, &client); | |
| 5038 | |
| 5039 WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl(); | |
| 5040 FrameTestHelpers::loadHTMLString(frame, html, | |
| 5041 URLTestHelpers::toKURL(m_baseURL)); | |
| 5042 webViewHelper.resize(WebSize(640, 480)); | |
| 5043 webViewHelper.webView()->setFocus(true); | |
| 5044 runPendingTasks(); | |
| 5045 | |
| 5046 const int findIdentifier = 12345; | |
| 5047 WebFindOptions options; | |
| 5048 | |
| 5049 // The first search that will start the scoping process. | |
| 5050 frame->requestFind(findIdentifier, searchPattern, options); | |
| 5051 EXPECT_FALSE(client.findResultsAreReady()); | |
| 5052 EXPECT_EQ(1, client.count()); | |
| 5053 EXPECT_TRUE(frame->ensureTextFinder().scopingInProgress()); | |
| 5054 | |
| 5055 // The scoping won't find all the entries on the first run due to the fake | |
| 5056 // timer. | |
| 5057 while (frame->ensureTextFinder().scopingInProgress()) | |
| 5058 runPendingTasks(); | |
| 5059 | |
| 5060 EXPECT_EQ(2, client.count()); | |
| 5061 EXPECT_EQ(1, client.activeIndex()); | |
| 5062 | |
| 5063 options.findNext = true; | |
| 5064 | |
| 5065 // The second search will jump to the next match without any scoping. | |
| 5066 frame->requestFind(findIdentifier, searchPattern, options); | |
| 5067 | |
| 5068 EXPECT_EQ(2, client.count()); | |
| 5069 EXPECT_EQ(2, client.activeIndex()); | |
| 5070 EXPECT_FALSE(frame->ensureTextFinder().scopingInProgress()); | |
| 5071 | |
| 5072 // Insert new text, which contains occurence of |searchText|. | |
| 5073 frame->executeScript( | |
| 5074 WebScriptSource("var textDiv = document.getElementById('new_text');" | |
| 5075 "textDiv.innerHTML = 'foo abc';")); | |
| 5076 | |
| 5077 // The third search will find a new match and initiate a new scoping. | |
| 5078 frame->requestFind(findIdentifier, searchPattern, options); | |
| 5079 | |
| 5080 EXPECT_TRUE(frame->ensureTextFinder().scopingInProgress()); | |
| 5081 | |
| 5082 while (frame->ensureTextFinder().scopingInProgress()) | |
| 5083 runPendingTasks(); | |
| 5084 | |
| 5085 EXPECT_EQ(3, client.count()); | |
| 5086 EXPECT_EQ(3, client.activeIndex()); | |
| 5087 } | |
| 5088 | |
| 5007 static WebPoint topLeft(const WebRect& rect) { | 5089 static WebPoint topLeft(const WebRect& rect) { |
| 5008 return WebPoint(rect.x, rect.y); | 5090 return WebPoint(rect.x, rect.y); |
| 5009 } | 5091 } |
| 5010 | 5092 |
| 5011 static WebPoint bottomRightMinusOne(const WebRect& rect) { | 5093 static WebPoint bottomRightMinusOne(const WebRect& rect) { |
| 5012 // FIXME: If we don't subtract 1 from the x- and y-coordinates of the | 5094 // FIXME: If we don't subtract 1 from the x- and y-coordinates of the |
| 5013 // selection bounds, selectRange() will select the *next* element. That's | 5095 // selection bounds, selectRange() will select the *next* element. That's |
| 5014 // strictly correct, as hit-testing checks the pixel to the lower-right of | 5096 // strictly correct, as hit-testing checks the pixel to the lower-right of |
| 5015 // the input coordinate, but it's a wart on the API. | 5097 // the input coordinate, but it's a wart on the API. |
| 5016 return WebPoint(rect.x + rect.width - 1, rect.y + rect.height - 1); | 5098 return WebPoint(rect.x + rect.width - 1, rect.y + rect.height - 1); |
| (...skipping 5988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11005 | 11087 |
| 11006 EXPECT_TRUE(mainFrameClient.childClient().didCallFrameDetached()); | 11088 EXPECT_TRUE(mainFrameClient.childClient().didCallFrameDetached()); |
| 11007 EXPECT_TRUE(mainFrameClient.childClient().didCallDidStopLoading()); | 11089 EXPECT_TRUE(mainFrameClient.childClient().didCallDidStopLoading()); |
| 11008 EXPECT_TRUE(mainFrameClient.childClient().didCallDidFinishDocumentLoad()); | 11090 EXPECT_TRUE(mainFrameClient.childClient().didCallDidFinishDocumentLoad()); |
| 11009 EXPECT_TRUE(mainFrameClient.childClient().didCallDidHandleOnloadEvents()); | 11091 EXPECT_TRUE(mainFrameClient.childClient().didCallDidHandleOnloadEvents()); |
| 11010 | 11092 |
| 11011 webViewHelper.reset(); | 11093 webViewHelper.reset(); |
| 11012 } | 11094 } |
| 11013 | 11095 |
| 11014 } // namespace blink | 11096 } // namespace blink |
| OLD | NEW |