diff options
author | finnur@google.com <finnur@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-04 19:32:49 +0000 |
---|---|---|
committer | finnur@google.com <finnur@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-04 19:32:49 +0000 |
commit | aedd85af7d7d0c90ed343ece4c66660db00841ec (patch) | |
tree | 8ba798b3932fbf2c1b5db69f39175326fd8745ab /chrome/browser/views/find_bar_win_uitest.cc | |
parent | d5a94281a8df5b47a341e2dd71b4d5f8dafd5878 (diff) | |
download | chromium_src-aedd85af7d7d0c90ed343ece4c66660db00841ec.zip chromium_src-aedd85af7d7d0c90ed343ece4c66660db00841ec.tar.gz chromium_src-aedd85af7d7d0c90ed343ece4c66660db00841ec.tar.bz2 |
Fix issue 5079: Incorrect "Active match ordinal" count during Find-in-page
I introduced a regression in my reimplemenation of Find-in-page. The active match ordinal in Find-in-page (also known as "the 7" in "7 of 9") would be just a little off on pages with frames.
Problem A: When you search for something in gmail, for example, the ordinal could start off slightly negative or be 0. I wasn't checking the last_match_count_ of a frame for negative numbers before adding it to the total (it starts off as -1 and remains that way if the frame is not deemed to be worthy of being scoped, i.e. if it is hidden).
Problem B: On pages with multiple matches spread across multiple frames the ordinal would not be subtracted correctly after pressing F3 and Shift-F3 to go back to the frame you were on. We shouldn't be increasing/decreasing the active_match_index for a given frame when FindNext/FindPrevious causes us to jump between frames. We should instead reset it.
I added two tests to catch this in the future. They test ordinal values as you use Find in page (including combinations of frames/no-frames & FindNext/FindPrevious).
Oh, and I also removed some traces that were supposed to expose why a test was flaky, but it turns out to have been something unrelated to the test.
Review URL: http://codereview.chromium.org/13130
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6369 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/find_bar_win_uitest.cc')
-rw-r--r-- | chrome/browser/views/find_bar_win_uitest.cc | 155 |
1 files changed, 108 insertions, 47 deletions
diff --git a/chrome/browser/views/find_bar_win_uitest.cc b/chrome/browser/views/find_bar_win_uitest.cc index 7844a55..1ce49f5 100644 --- a/chrome/browser/views/find_bar_win_uitest.cc +++ b/chrome/browser/views/find_bar_win_uitest.cc @@ -18,6 +18,7 @@ class FindInPageControllerTest : public UITest { }; const std::wstring kFramePage = L"files/find_in_page/frames.html"; +const std::wstring kFrameData = L"files/find_in_page/framedata_general.html"; const std::wstring kUserSelectPage = L"files/find_in_page/user-select.html"; const std::wstring kCrashPage = L"files/find_in_page/crash_1341577.html"; const std::wstring kTooFewMatchesPage = L"files/find_in_page/bug_1155639.html"; @@ -33,40 +34,123 @@ TEST_F(FindInPageControllerTest, FindInPageFrames) { WaitUntilTabCount(1); // Try incremental search (mimicking user typing in). - EXPECT_EQ(18, tab->FindInPage(L"g", FWD, IGNORE_CASE, false)); - EXPECT_EQ(11, tab->FindInPage(L"go", FWD, IGNORE_CASE, false)); - EXPECT_EQ(04, tab->FindInPage(L"goo", FWD, IGNORE_CASE, false)); - EXPECT_EQ(03, tab->FindInPage(L"goog", FWD, IGNORE_CASE, false)); - EXPECT_EQ(02, tab->FindInPage(L"googl", FWD, IGNORE_CASE, false)); - EXPECT_EQ(01, tab->FindInPage(L"google", FWD, IGNORE_CASE, false)); - EXPECT_EQ(00, tab->FindInPage(L"google!", FWD, IGNORE_CASE, false)); + EXPECT_EQ(18, tab->FindInPage(L"g", FWD, IGNORE_CASE, false, NULL)); + EXPECT_EQ(11, tab->FindInPage(L"go", FWD, IGNORE_CASE, false, NULL)); + EXPECT_EQ(04, tab->FindInPage(L"goo", FWD, IGNORE_CASE, false, NULL)); + EXPECT_EQ(03, tab->FindInPage(L"goog", FWD, IGNORE_CASE, false, NULL)); + EXPECT_EQ(02, tab->FindInPage(L"googl", FWD, IGNORE_CASE, false, NULL)); + EXPECT_EQ(01, tab->FindInPage(L"google", FWD, IGNORE_CASE, false, NULL)); + EXPECT_EQ(00, tab->FindInPage(L"google!", FWD, IGNORE_CASE, false, NULL)); // Negative test (no matches should be found). EXPECT_EQ(0, tab->FindInPage(L"Non-existing string", FWD, IGNORE_CASE, - false)); + false, NULL)); // 'horse' only exists in the three right frames. - EXPECT_EQ(3, tab->FindInPage(L"horse", FWD, IGNORE_CASE, false)); + EXPECT_EQ(3, tab->FindInPage(L"horse", FWD, IGNORE_CASE, false, NULL)); // 'cat' only exists in the first frame. - EXPECT_EQ(1, tab->FindInPage(L"cat", FWD, IGNORE_CASE, false)); + EXPECT_EQ(1, tab->FindInPage(L"cat", FWD, IGNORE_CASE, false, NULL)); // Try searching again, should still come up with 1 match. - EXPECT_EQ(1, tab->FindInPage(L"cat", FWD, IGNORE_CASE, false)); + EXPECT_EQ(1, tab->FindInPage(L"cat", FWD, IGNORE_CASE, false, NULL)); // Try searching backwards, ignoring case, should still come up with 1 match. - EXPECT_EQ(1, tab->FindInPage(L"CAT", BACK, IGNORE_CASE, false)); + EXPECT_EQ(1, tab->FindInPage(L"CAT", BACK, IGNORE_CASE, false, NULL)); // Try case sensitive, should NOT find it. - EXPECT_EQ(0, tab->FindInPage(L"CAT", FWD, CASE_SENSITIVE, false)); + EXPECT_EQ(0, tab->FindInPage(L"CAT", FWD, CASE_SENSITIVE, false, NULL)); // Try again case sensitive, but this time with right case. - EXPECT_EQ(1, tab->FindInPage(L"dog", FWD, CASE_SENSITIVE, false)); + EXPECT_EQ(1, tab->FindInPage(L"dog", FWD, CASE_SENSITIVE, false, NULL)); // Try non-Latin characters ('Hreggvidur' with 'eth' for 'd' in left frame). - EXPECT_EQ(1, tab->FindInPage(L"Hreggvi\u00F0ur", FWD, IGNORE_CASE, false)); - EXPECT_EQ(1, tab->FindInPage(L"Hreggvi\u00F0ur", FWD, CASE_SENSITIVE, false)); - EXPECT_EQ(0, tab->FindInPage(L"hreggvi\u00F0ur", FWD, CASE_SENSITIVE, false)); + EXPECT_EQ(1, tab->FindInPage(L"Hreggvi\u00F0ur", FWD, IGNORE_CASE, + false, NULL)); + EXPECT_EQ(1, tab->FindInPage(L"Hreggvi\u00F0ur", FWD, CASE_SENSITIVE, + false, NULL)); + EXPECT_EQ(0, tab->FindInPage(L"hreggvi\u00F0ur", FWD, CASE_SENSITIVE, + false, NULL)); +} + +// This test loads a single-frame page and makes sure the ordinal returned makes +// sense as we FindNext over all the items. +TEST_F(FindInPageControllerTest, FindInPageOrdinal) { + TestServer server(L"chrome/test/data"); + + // First we navigate to our frames page. + GURL url = server.TestServerPageW(kFrameData); + scoped_ptr<TabProxy> tab(GetActiveTab()); + ASSERT_TRUE(tab->NavigateToURL(url)); + WaitUntilTabCount(1); + + // Search for 'o', which should make the first item active and return + // '1 in 3' (1st ordinal of a total of 3 matches). + int ordinal = 0; + EXPECT_EQ(3, tab->FindInPage(L"o", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(1, ordinal); + // FindNext returns -1 for match count because it doesn't bother with + // recounting the number of matches. We don't care about the match count + // anyway in this case, we just want to check the ordinal. + EXPECT_EQ(-1, tab->FindInPage(L"o", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(2, ordinal); + EXPECT_EQ(-1, tab->FindInPage(L"o", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(3, ordinal); + // Go back one match. + EXPECT_EQ(-1, tab->FindInPage(L"o", BACK, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(2, ordinal); + EXPECT_EQ(-1, tab->FindInPage(L"o", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(3, ordinal); + // This should wrap to the top. + EXPECT_EQ(-1, tab->FindInPage(L"o", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(1, ordinal); + // This should go back to the end. + EXPECT_EQ(-1, tab->FindInPage(L"o", BACK, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(3, ordinal); +} + +// This test loads a page with frames and makes sure the ordinal returned makes +// sense. +TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { + TestServer server(L"chrome/test/data"); + + // First we navigate to our frames page. + GURL url = server.TestServerPageW(kFramePage); + scoped_ptr<TabProxy> tab(GetActiveTab()); + ASSERT_TRUE(tab->NavigateToURL(url)); + WaitUntilTabCount(1); + + // Search for 'a', which should make the first item active and return + // '1 in 7' (1st ordinal of a total of 7 matches). + int ordinal = 0; + EXPECT_EQ(7, tab->FindInPage(L"a", FWD, IGNORE_CASE, false, &ordinal)); + EXPECT_EQ(1, ordinal); + // FindNext returns -1 for match count because it doesn't bother with + // recounting the number of matches. We don't care about the match count + // anyway in this case, we just want to check the ordinal. + EXPECT_EQ(-1, tab->FindInPage(L"a", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(2, ordinal); + EXPECT_EQ(-1, tab->FindInPage(L"a", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(3, ordinal); + EXPECT_EQ(-1, tab->FindInPage(L"a", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(4, ordinal); + // Go back one, which should go back one frame. + EXPECT_EQ(-1, tab->FindInPage(L"a", BACK, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(3, ordinal); + EXPECT_EQ(-1, tab->FindInPage(L"a", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(4, ordinal); + EXPECT_EQ(-1, tab->FindInPage(L"a", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(5, ordinal); + EXPECT_EQ(-1, tab->FindInPage(L"a", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(6, ordinal); + EXPECT_EQ(-1, tab->FindInPage(L"a", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(7, ordinal); + // Now we should wrap back to frame 1. + EXPECT_EQ(-1, tab->FindInPage(L"a", FWD, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(1, ordinal); + // Now we should wrap back to frame last frame. + EXPECT_EQ(-1, tab->FindInPage(L"a", BACK, IGNORE_CASE, true, &ordinal)); + EXPECT_EQ(7, ordinal); } // Load a page with no selectable text and make sure we don't crash. @@ -78,9 +162,9 @@ TEST_F(FindInPageControllerTest, FindUnSelectableText) { ASSERT_TRUE(tab->NavigateToURL(url)); WaitUntilTabCount(1); - EXPECT_EQ(0, tab->FindInPage(L"text", FWD, IGNORE_CASE, false)); + EXPECT_EQ(0, tab->FindInPage(L"text", FWD, IGNORE_CASE, false, NULL)); EXPECT_EQ(0, tab->FindInPage(L"Non-existing string", FWD, IGNORE_CASE, - false)); + false, NULL)); } // Try to reproduce the crash seen in issue 1341577. @@ -95,15 +179,15 @@ TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) { // This would crash the tab. These must be the first two find requests issued // against the frame, otherwise an active frame pointer is set and it wont // produce the crash. - EXPECT_EQ(1, tab->FindInPage(L"\u0D4C", FWD, IGNORE_CASE, false)); + EXPECT_EQ(1, tab->FindInPage(L"\u0D4C", FWD, IGNORE_CASE, false, NULL)); // FindNext returns -1 for match count because it doesn't bother with // recounting the number of matches. We don't care about the match count // anyway in this case, we just want to make sure it doesn't crash. - EXPECT_EQ(-1, tab->FindInPage(L"\u0D4C", FWD, IGNORE_CASE, true)); + EXPECT_EQ(-1, tab->FindInPage(L"\u0D4C", FWD, IGNORE_CASE, true, NULL)); // This should work fine. - EXPECT_EQ(1, tab->FindInPage(L"\u0D24\u0D46", FWD, IGNORE_CASE, false)); - EXPECT_EQ(0, tab->FindInPage(L"nostring", FWD, IGNORE_CASE, false)); + EXPECT_EQ(1, tab->FindInPage(L"\u0D24\u0D46", FWD, IGNORE_CASE, false, NULL)); + EXPECT_EQ(0, tab->FindInPage(L"nostring", FWD, IGNORE_CASE, false, NULL)); } // Test to make sure Find does the right thing when restarting from a timeout. @@ -124,88 +208,65 @@ TEST_F(FindInPageControllerTest, FindEnoughMatches_Issue1155639) { // This string appears 5 times at the bottom of a long page. If Find restarts // properly after a timeout, it will find 5 matches, not just 1. - EXPECT_EQ(5, tab->FindInPage(L"008.xml", FWD, IGNORE_CASE, false)); + EXPECT_EQ(5, tab->FindInPage(L"008.xml", FWD, IGNORE_CASE, false, NULL)); } // The find window should not change its location just because we open and close // a new tab. TEST_F(FindInPageControllerTest, FindMovesOnTabClose_Issue1343052) { - fprintf(stderr, "Starting FindMovesOnTabClose_Issue1343052\n"); TestServer server(L"chrome/test/data"); - fprintf(stderr, "TestServerPageW\n"); GURL url = server.TestServerPageW(kFramePage); - fprintf(stderr, "GetActiveTab A\n"); scoped_ptr<TabProxy> tabA(GetActiveTab()); - fprintf(stderr, "Navigate A\n"); ASSERT_TRUE(tabA->NavigateToURL(url)); - fprintf(stderr, "WaitUntilTabCount(1) for A\n"); WaitUntilTabCount(1); - fprintf(stderr, "GetBrowserWindow(0)\n"); scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get() != NULL); // Toggle the bookmark bar state. - fprintf(stderr, "ApplyAccelerator bookmark bar\n"); browser->ApplyAccelerator(IDC_SHOW_BOOKMARKS_BAR); - fprintf(stderr, "WaitForBookmarkVisibility\n"); EXPECT_TRUE(WaitForBookmarkBarVisibilityChange(browser.get(), true)); // Open the Find window and wait for it to animate. - fprintf(stderr, "OpenFindInPage in A\n"); EXPECT_TRUE(tabA->OpenFindInPage()); - fprintf(stderr, "WaitForWindowFullyVisible in A\n"); EXPECT_TRUE(WaitForFindWindowFullyVisible(tabA.get())); // Find its location. int x = -1, y = -1; - fprintf(stderr, "GetFindWindowLocation in A\n"); EXPECT_TRUE(tabA->GetFindWindowLocation(&x, &y)); // Open another tab (tab B). - fprintf(stderr, "AppendTab B\n"); EXPECT_TRUE(browser->AppendTab(url)); - fprintf(stderr, "GetActiveTab B\n"); scoped_ptr<TabProxy> tabB(GetActiveTab()); // Close tab B. - fprintf(stderr, "Tab Close B\n"); EXPECT_TRUE(tabB->Close(true)); // See if the Find window has moved. int new_x = -1, new_y = -1; - fprintf(stderr, "GetFindWindowLocation in A\n"); EXPECT_TRUE(tabA->GetFindWindowLocation(&new_x, &new_y)); EXPECT_EQ(x, new_x); EXPECT_EQ(y, new_y); // Now reset the bookmarks bar state and try the same again. - fprintf(stderr, "ApplyAccelerator BookmarksBar\n"); browser->ApplyAccelerator(IDC_SHOW_BOOKMARKS_BAR); - fprintf(stderr, "WaitForBookmarkBarVisibilityChange\n"); EXPECT_TRUE(WaitForBookmarkBarVisibilityChange(browser.get(), false)); // Bookmark bar has moved, reset our coordinates. - fprintf(stderr, "GetFindWindowLocation again\n"); EXPECT_TRUE(tabA->GetFindWindowLocation(&x, &y)); // Open another tab (tab C). - fprintf(stderr, "Append tab C\n"); EXPECT_TRUE(browser->AppendTab(url)); - fprintf(stderr, "GetActiveTab C\n"); scoped_ptr<TabProxy> tabC(GetActiveTab()); // Close it. - fprintf(stderr, "Close tab C\n"); EXPECT_TRUE(tabC->Close(true)); // See if the Find window has moved. - fprintf(stderr, "GetFindWindowLocation yet again\n"); EXPECT_TRUE(tabA->GetFindWindowLocation(&new_x, &new_y)); EXPECT_EQ(x, new_x); EXPECT_EQ(y, new_y); - fprintf(stderr, "Done!\n"); } |