This source file includes following definitions.
- GetFindBarWindowInfoForBrowser
- GetFindBarWindowInfo
- GetFindBarTextForBrowser
- GetFindBarText
- GetFindBarMatchCountTextForBrowser
- GetMatchCountText
- GetFindBarWidthForBrowser
- EnsureFindBoxOpenForBrowser
- EnsureFindBoxOpen
- FindInPageWchar
- FindInPageTillBoxMoves
- GetURL
- FlushHistoryService
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- EnumerateChildren
- IN_PROC_BROWSER_TEST_F
#include "base/file_util.h"
#include "base/message_loop/message_loop.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/common/cancelable_request.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/find_bar/find_bar.h"
#include "chrome/browser/ui/find_bar/find_bar_controller.h"
#include "chrome/browser/ui/find_bar/find_bar_host_unittest_util.h"
#include "chrome/browser/ui/find_bar/find_notification_details.h"
#include "chrome/browser/ui/find_bar/find_tab_helper.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/find_in_page_observer.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "content/public/test/browser_test_utils.h"
#include "net/base/net_util.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/events/keycodes/keyboard_codes.h"
#if defined(OS_WIN)
#include "content/public/browser/web_contents_view.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#endif
using base::ASCIIToUTF16;
using base::WideToUTF16;
using content::NavigationController;
using content::WebContents;
namespace {
const char kAnchorPage[] = "anchor.html";
const char kAnchor[] = "#chapter2";
const char kFramePage[] = "frames.html";
const char kFrameData[] = "framedata_general.html";
const char kUserSelectPage[] = "user-select.html";
const char kCrashPage[] = "crash_1341577.html";
const char kTooFewMatchesPage[] = "bug_1155639.html";
const char kLongTextareaPage[] = "large_textarea.html";
const char kPrematureEnd[] = "premature_end.html";
const char kMoveIfOver[] = "move_if_obscuring.html";
const char kBitstackCrash[] = "crash_14491.html";
const char kSelectChangesOrdinal[] = "select_changes_ordinal.html";
const char kStartAfterSelection[] = "start_after_selection.html";
const char kSimple[] = "simple.html";
const char kLinkPage[] = "link.html";
const bool kBack = false;
const bool kFwd = true;
const bool kIgnoreCase = false;
const bool kCaseSensitive = true;
const int kMoveIterations = 30;
}
class FindInPageControllerTest : public InProcessBrowserTest {
public:
FindInPageControllerTest() {
chrome::DisableFindBarAnimationsDuringTesting(true);
}
protected:
bool GetFindBarWindowInfoForBrowser(
Browser* browser, gfx::Point* position, bool* fully_visible) {
FindBarTesting* find_bar =
browser->GetFindBarController()->find_bar()->GetFindBarTesting();
return find_bar->GetFindBarWindowInfo(position, fully_visible);
}
bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) {
return GetFindBarWindowInfoForBrowser(browser(), position, fully_visible);
}
base::string16 GetFindBarTextForBrowser(Browser* browser) {
FindBar* find_bar = browser->GetFindBarController()->find_bar();
return find_bar->GetFindText();
}
base::string16 GetFindBarText() {
return GetFindBarTextForBrowser(browser());
}
base::string16 GetFindBarMatchCountTextForBrowser(Browser* browser) {
FindBarTesting* find_bar =
browser->GetFindBarController()->find_bar()->GetFindBarTesting();
return find_bar->GetMatchCountText();
}
base::string16 GetMatchCountText() {
return GetFindBarMatchCountTextForBrowser(browser());
}
int GetFindBarWidthForBrowser(Browser* browser) {
FindBarTesting* find_bar =
browser->GetFindBarController()->find_bar()->GetFindBarTesting();
return find_bar->GetWidth();
}
void EnsureFindBoxOpenForBrowser(Browser* browser) {
chrome::ShowFindBar(browser);
gfx::Point position;
bool fully_visible = false;
EXPECT_TRUE(GetFindBarWindowInfoForBrowser(
browser, &position, &fully_visible));
EXPECT_TRUE(fully_visible);
}
void EnsureFindBoxOpen() {
EnsureFindBoxOpenForBrowser(browser());
}
int FindInPageWchar(WebContents* web_contents,
const wchar_t* search_str,
bool forward,
bool case_sensitive,
int* ordinal) {
base::string16 search_str16(WideToUTF16(std::wstring(search_str)));
Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
browser->GetFindBarController()->find_bar()->SetFindTextAndSelectedRange(
search_str16, gfx::Range());
return ui_test_utils::FindInPage(
web_contents, search_str16, forward, case_sensitive, ordinal, NULL);
}
int FindInPageTillBoxMoves(WebContents* web_contents,
int start_x_position,
const wchar_t* search_str,
int expected_matches) {
for (int index = 0; index < expected_matches; ++index) {
int ordinal = 0;
EXPECT_EQ(expected_matches, FindInPageWchar(web_contents, search_str,
kFwd, kIgnoreCase, &ordinal));
bool fully_visible;
gfx::Point position;
EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
EXPECT_TRUE(fully_visible);
if (position.x() != start_x_position)
return position.x();
}
return start_x_position;
}
GURL GetURL(const std::string& filename) {
return ui_test_utils::GetTestUrl(
base::FilePath().AppendASCII("find_in_page"),
base::FilePath().AppendASCII(filename));
}
void FlushHistoryService() {
HistoryServiceFactory::GetForProfile(
browser()->profile(), Profile::IMPLICIT_ACCESS)->FlushForTest(
base::Bind(&base::MessageLoop::Quit,
base::Unretained(base::MessageLoop::current()->current())));
content::RunMessageLoop();
}
};
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) {
GURL url = GetURL(kFramePage);
ui_test_utils::NavigateToURL(browser(), url);
int ordinal = 0;
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_EQ(18, FindInPageWchar(web_contents, L"g",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(11, FindInPageWchar(web_contents, L"go",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(4, FindInPageWchar(web_contents, L"goo",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(3, FindInPageWchar(web_contents, L"goog",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(2, FindInPageWchar(web_contents, L"googl",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(1, FindInPageWchar(web_contents, L"google",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(0, FindInPageWchar(web_contents, L"google!",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(0, ordinal);
EXPECT_EQ(0, FindInPageWchar(web_contents, L"Non-existing string",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(0, ordinal);
EXPECT_EQ(3, FindInPageWchar(web_contents, L"horse",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(1, FindInPageWchar(web_contents, L"cat",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(1, FindInPageWchar(web_contents, L"cat",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(1, FindInPageWchar(web_contents, L"CAT",
kBack, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(0, FindInPageWchar(web_contents, L"CAT",
kFwd, kCaseSensitive, &ordinal));
EXPECT_EQ(0, ordinal);
EXPECT_EQ(1, FindInPageWchar(web_contents, L"dog",
kFwd, kCaseSensitive, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(1, FindInPageWchar(web_contents, L"Hreggvi\u00F0ur",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(1, FindInPageWchar(web_contents, L"Hreggvi\u00F0ur",
kFwd, kCaseSensitive, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(0, FindInPageWchar(web_contents, L"hreggvi\u00F0ur",
kFwd, kCaseSensitive, &ordinal));
EXPECT_EQ(0, ordinal);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFormsTextAreas) {
std::vector<GURL> urls;
urls.push_back(GetURL("textintextarea.html"));
urls.push_back(GetURL("smalltextarea.html"));
urls.push_back(GetURL("populatedform.html"));
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
for (size_t i = 0; i < urls.size(); ++i) {
ui_test_utils::NavigateToURL(browser(), urls[i]);
EXPECT_EQ(1, FindInPageWchar(web_contents, L"cat",
kFwd, kIgnoreCase, NULL));
EXPECT_EQ(0, FindInPageWchar(web_contents, L"bat",
kFwd, kIgnoreCase, NULL));
}
}
#if defined(OS_WIN)
#define MAYBE_SearchWithinSpecialURL \
DISABLED_SearchWithinSpecialURL
#else
#define MAYBE_SearchWithinSpecialURL \
SearchWithinSpecialURL
#endif
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_SearchWithinSpecialURL) {
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
base::FilePath data_dir =
ui_test_utils::GetTestFilePath(base::FilePath(), base::FilePath());
ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(data_dir));
EXPECT_EQ(1, FindInPageWchar(web_contents, L"downloads",
kFwd, kIgnoreCase, NULL));
ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIHistoryURL));
FlushHistoryService();
base::string16 query(data_dir.LossyDisplayName());
EXPECT_EQ(1,
ui_test_utils::FindInPage(web_contents, query,
kFwd, kIgnoreCase, NULL, NULL));
GURL download_url = ui_test_utils::GetTestUrl(
base::FilePath().AppendASCII("downloads"),
base::FilePath().AppendASCII("a_zip_file.zip"));
ui_test_utils::DownloadURL(browser(), download_url);
ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL));
FlushHistoryService();
EXPECT_EQ(1,
FindInPageWchar(web_contents,
base::ASCIIToWide(download_url.spec()).c_str(),
kFwd, kIgnoreCase, NULL));
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageSpecialURLs) {
std::wstring search_string(L"\u5728\u897f\u660c\u536b\u661f\u53d1");
gfx::Rect first, second, first_reverse;
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html"));
ui_test_utils::FindInPage(web_contents, WideToUTF16(search_string),
kFwd, kIgnoreCase, NULL, &first);
ui_test_utils::FindInPage(web_contents, WideToUTF16(search_string),
kFwd, kIgnoreCase, NULL, &second);
ASSERT_EQ(first.y(), second.y());
ASSERT_EQ(first.bottom(), second.bottom());
ASSERT_LT(first.x(), second.x());
ASSERT_LT(first.right(), second.right());
ui_test_utils::FindInPage(
web_contents, WideToUTF16(search_string), kBack, kIgnoreCase, NULL,
&first_reverse);
ASSERT_EQ(first, first_reverse);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
CommentsAndMetaDataNotSearchable) {
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html"));
std::wstring search_string =
L"\u4e2d\u65b0\u793e\u8bb0\u8005\u5b8b\u5409\u6cb3\u6444\u4e2d\u65b0\u7f51";
EXPECT_EQ(0, ui_test_utils::FindInPage(
web_contents, WideToUTF16(search_string), kFwd, kIgnoreCase, NULL, NULL));
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, SpanAndListsSearchable) {
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(browser(), GetURL("FindRandomTests.html"));
std::wstring search_string = L"has light blue eyes and my father has dark";
EXPECT_EQ(1, ui_test_utils::FindInPage(
web_contents, WideToUTF16(search_string), kFwd, kIgnoreCase, NULL, NULL));
search_string = L"Google\nApple\nandroid";
EXPECT_EQ(1, ui_test_utils::FindInPage(
web_contents, WideToUTF16(search_string), kFwd, kIgnoreCase, NULL, NULL));
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, LargePage) {
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(browser(), GetURL("largepage.html"));
std::wstring search_string = L"daughter of Prince";
EXPECT_EQ(373,
FindInPageWchar(web_contents, search_string.c_str(),
kFwd, kIgnoreCase, NULL));
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindLongString) {
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(browser(), GetURL("largepage.html"));
base::FilePath path = ui_test_utils::GetTestFilePath(
base::FilePath().AppendASCII("find_in_page"),
base::FilePath().AppendASCII("LongFind.txt"));
std::string query;
base::ReadFileToString(path, &query);
std::wstring search_string = base::UTF8ToWide(query);
EXPECT_EQ(1,
FindInPageWchar(web_contents, search_string.c_str(),
kFwd, kIgnoreCase, NULL));
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, BigString) {
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(browser(), GetURL("BigText.html"));
EXPECT_EQ(1,
FindInPageWchar(web_contents, L"SomeLargeString",
kFwd, kIgnoreCase, NULL));
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, SingleOccurrence) {
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(browser(), GetURL("FindRandomTests.html"));
gfx::Rect first_rect;
EXPECT_EQ(1,
ui_test_utils::FindInPage(web_contents,
ASCIIToUTF16("2010 Pro Bowl"), kFwd,
kIgnoreCase, NULL, &first_rect));
gfx::Rect second_rect;
EXPECT_EQ(1,
ui_test_utils::FindInPage(web_contents,
ASCIIToUTF16("2010 Pro Bowl"), kFwd,
kIgnoreCase, NULL, &second_rect));
ui_test_utils::FindInPage(web_contents, ASCIIToUTF16("ghgfjgfh201232rere"),
kFwd, kIgnoreCase, NULL, NULL);
ASSERT_EQ(first_rect, second_rect);
EXPECT_EQ(1,
ui_test_utils::FindInPage(web_contents,
ASCIIToUTF16("2010 Pro Bowl"), kFwd,
kIgnoreCase, NULL, &first_rect));
EXPECT_EQ(1,
ui_test_utils::FindInPage(web_contents,
ASCIIToUTF16("2010 Pro Bowl"), kBack,
kIgnoreCase, NULL, &second_rect));
ASSERT_EQ(first_rect, second_rect);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindWholeFileContent) {
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
base::FilePath path = ui_test_utils::GetTestFilePath(
base::FilePath().AppendASCII("find_in_page"),
base::FilePath().AppendASCII("find_test.txt"));
ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(path));
std::string query;
base::ReadFileToString(path, &query);
std::wstring search_string = base::UTF8ToWide(query);
EXPECT_EQ(1,
FindInPageWchar(web_contents, search_string.c_str(),
false, false, NULL));
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) {
GURL url = GetURL(kFrameData);
ui_test_utils::NavigateToURL(browser(), url);
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
int ordinal = 0;
EXPECT_EQ(3, FindInPageWchar(web_contents, L"o",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(3, FindInPageWchar(web_contents, L"o",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(2, ordinal);
EXPECT_EQ(3, FindInPageWchar(web_contents, L"o",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(3, ordinal);
EXPECT_EQ(3, FindInPageWchar(web_contents, L"o",
kBack, kIgnoreCase, &ordinal));
EXPECT_EQ(2, ordinal);
EXPECT_EQ(3, FindInPageWchar(web_contents, L"o",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(3, ordinal);
EXPECT_EQ(3, FindInPageWchar(web_contents, L"o",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(3, FindInPageWchar(web_contents, L"o",
kBack, kIgnoreCase, &ordinal));
EXPECT_EQ(3, ordinal);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
SelectChangesOrdinal_Issue20883) {
GURL url = GetURL(kSelectChangesOrdinal);
ui_test_utils::NavigateToURL(browser(), url);
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(NULL != web_contents);
FindTabHelper* find_tab_helper =
FindTabHelper::FromWebContents(web_contents);
int ordinal = 0;
EXPECT_EQ(4, FindInPageWchar(web_contents,
L"google",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
std::string result;
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
web_contents,
"window.domAutomationController.send(selectLink1());",
&result));
EXPECT_EQ(4, FindInPageWchar(web_contents,
L"google",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(3, ordinal);
find_tab_helper->StopFinding(FindBarController::kKeepSelectionOnPage);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
StartSearchAfterSelection) {
ui_test_utils::NavigateToURL(browser(), GetURL(kStartAfterSelection));
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(web_contents != NULL);
int ordinal = 0;
std::string result;
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
web_contents,
"window.domAutomationController.send(selectSpan());",
&result));
EXPECT_EQ(4, FindInPageWchar(web_contents,
L"fi",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(2, ordinal);
EXPECT_EQ(4, FindInPageWchar(web_contents,
L"find",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(2, ordinal);
EXPECT_EQ(2, FindInPageWchar(web_contents,
L"findMe",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(2, ordinal);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) {
GURL url = GetURL(kFramePage);
ui_test_utils::NavigateToURL(browser(), url);
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
int ordinal = 0;
EXPECT_EQ(7,
FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(7,
FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(2, ordinal);
EXPECT_EQ(7,
FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(3, ordinal);
EXPECT_EQ(7,
FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(4, ordinal);
EXPECT_EQ(7,
FindInPageWchar(web_contents, L"a", kBack, kIgnoreCase, &ordinal));
EXPECT_EQ(3, ordinal);
EXPECT_EQ(7,
FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(4, ordinal);
EXPECT_EQ(7,
FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(5, ordinal);
EXPECT_EQ(7,
FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(6, ordinal);
EXPECT_EQ(7,
FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(7, ordinal);
EXPECT_EQ(7,
FindInPageWchar(web_contents, L"a", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(7,
FindInPageWchar(web_contents, L"a", kBack, kIgnoreCase, &ordinal));
EXPECT_EQ(7, ordinal);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) {
GURL url = GetURL(kFramePage);
ui_test_utils::NavigateToURL(browser(), url);
int ordinal = 0;
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_EQ(6, FindInPageWchar(web_contents, L"goa",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(6, FindInPageWchar(web_contents, L"goa",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(2, ordinal);
EXPECT_EQ(6, FindInPageWchar(web_contents, L"goa",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(3, ordinal);
EXPECT_EQ(0, FindInPageWchar(web_contents, L"goa ",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(0, ordinal);
EXPECT_EQ(6, FindInPageWchar(web_contents, L"goa",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(3, ordinal);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, NavigateClearsOrdinal) {
GURL url = GetURL(kSimple);
ui_test_utils::NavigateToURL(browser(), url);
EnsureFindBoxOpen();
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(NULL != web_contents);
int ordinal = 0;
EXPECT_EQ(8, FindInPageWchar(web_contents,
L"e",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
url = GetURL(kLinkPage);
ui_test_utils::NavigateToURL(browser(), url);
EnsureFindBoxOpen();
EXPECT_EQ(ASCIIToUTF16("e"), GetFindBarText());
EXPECT_EQ(ASCIIToUTF16(""), GetMatchCountText());
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindUnselectableText) {
GURL url = GetURL(kUserSelectPage);
ui_test_utils::NavigateToURL(browser(), url);
int ordinal = 0;
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_EQ(1, FindInPageWchar(web_contents,
L"text",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) {
GURL url = GetURL(kCrashPage);
ui_test_utils::NavigateToURL(browser(), url);
int ordinal = 0;
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
FindInPageWchar(web_contents, L"\u0D4C", kFwd, kIgnoreCase, &ordinal);
FindInPageWchar(web_contents, L"\u0D4C", kFwd, kIgnoreCase, &ordinal);
EXPECT_EQ(1, FindInPageWchar(web_contents, L"\u0D24\u0D46",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(0, FindInPageWchar(web_contents, L"nostring",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(0, ordinal);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue14491) {
GURL url = GetURL(kBitstackCrash);
ui_test_utils::NavigateToURL(browser(), url);
int ordinal = 0;
EXPECT_EQ(0, FindInPageWchar(browser()->tab_strip_model()->
GetActiveWebContents(),
L"s", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(0, ordinal);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue1155639) {
GURL url = GetURL(kTooFewMatchesPage);
ui_test_utils::NavigateToURL(browser(), url);
int ordinal = 0;
EXPECT_EQ(5, FindInPageWchar(browser()->tab_strip_model()->
GetActiveWebContents(),
L"008.xml",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue70505) {
GURL url = GetURL(kLongTextareaPage);
ui_test_utils::NavigateToURL(browser(), url);
int ordinal = 0;
FindInPageWchar(browser()->tab_strip_model()->GetActiveWebContents(),
L"a", kFwd, kIgnoreCase, &ordinal);
EXPECT_EQ(1, ordinal);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
DISABLED_FindInPagePrematureEnd) {
GURL url = GetURL(kPrematureEnd);
ui_test_utils::NavigateToURL(browser(), url);
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(NULL != web_contents);
int ordinal = 0;
EXPECT_EQ(2, FindInPageWchar(web_contents, L"html ",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) {
GURL url = GetURL(kSimple);
GURL url2 = GetURL(kFramePage);
ui_test_utils::NavigateToURL(browser(), url);
chrome::ShowFindBar(browser());
gfx::Point position;
bool fully_visible = false;
EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
EXPECT_TRUE(fully_visible);
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(
&browser()->tab_strip_model()->GetActiveWebContents()->
GetController()));
chrome::Reload(browser(), CURRENT_TAB);
observer.Wait();
EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
EXPECT_TRUE(fully_visible);
ui_test_utils::NavigateToURL(browser(), url2);
EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
EXPECT_FALSE(fully_visible);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindStayVisibleOnAnchorLoad) {
GURL url = GetURL(kAnchorPage);
ui_test_utils::NavigateToURL(browser(), url);
chrome::ShowFindBar(browser());
gfx::Point position;
bool fully_visible = false;
EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
EXPECT_TRUE(fully_visible);
GURL url_with_anchor = url.Resolve(kAnchor);
ui_test_utils::NavigateToURL(browser(), url_with_anchor);
EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
EXPECT_TRUE(fully_visible);
}
#if defined(OS_MACOSX)
#define MAYBE_FindDisappearOnNewTabAndHistory DISABLED_FindDisappearOnNewTabAndHistory
#else
#define MAYBE_FindDisappearOnNewTabAndHistory FindDisappearOnNewTabAndHistory
#endif
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
MAYBE_FindDisappearOnNewTabAndHistory) {
GURL url = GetURL(kSimple);
ui_test_utils::NavigateToURL(browser(), url);
chrome::ShowFindBar(browser());
gfx::Point position;
bool fully_visible = false;
EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
EXPECT_TRUE(fully_visible);
chrome::NewTab(browser());
ui_test_utils::NavigateToURL(browser(), url);
EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
EXPECT_FALSE(fully_visible);
chrome::CloseTab(browser());
EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
EXPECT_TRUE(fully_visible);
chrome::ShowHistory(browser());
EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
EXPECT_FALSE(fully_visible);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindMovesWhenObscuring) {
GURL url = GetURL(kMoveIfOver);
ui_test_utils::NavigateToURL(browser(), url);
chrome::ShowFindBar(browser());
base::MessageLoop::current()->RunUntilIdle();
gfx::Point start_position;
gfx::Point position;
bool fully_visible = false;
int ordinal = 0;
EXPECT_TRUE(GetFindBarWindowInfo(&start_position, &fully_visible));
EXPECT_TRUE(fully_visible);
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
int moved_x_coord = FindInPageTillBoxMoves(web_contents, start_position.x(),
L"Chromium", kMoveIterations);
EXPECT_TRUE(moved_x_coord != start_position.x());
EXPECT_EQ(1, FindInPageWchar(web_contents, L"Done",
kFwd, kIgnoreCase, &ordinal));
EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
EXPECT_TRUE(fully_visible);
EXPECT_EQ(position.x(), start_position.x());
moved_x_coord = FindInPageTillBoxMoves(web_contents, start_position.x(),
L"Chromium", kMoveIterations);
EXPECT_TRUE(moved_x_coord != start_position.x());
EXPECT_EQ(0, FindInPageWchar(web_contents, L"WeirdSearchString",
kFwd, kIgnoreCase, &ordinal));
EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible));
EXPECT_TRUE(fully_visible);
EXPECT_EQ(position.x(), start_position.x());
}
#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
#define MAYBE_FindNextInNewTabUsesPrepopulate \
DISABLED_FindNextInNewTabUsesPrepopulate
#else
#define MAYBE_FindNextInNewTabUsesPrepopulate FindNextInNewTabUsesPrepopulate
#endif
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
MAYBE_FindNextInNewTabUsesPrepopulate) {
GURL url = GetURL(kSimple);
ui_test_utils::NavigateToURL(browser(), url);
int ordinal = 0;
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_EQ(0, FindInPageWchar(web_contents, L"no_match",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(0, ordinal);
chrome::NewTab(browser());
ui_test_utils::NavigateToURL(browser(), url);
EXPECT_EQ(0, ui_test_utils::FindInPage(web_contents, base::string16(),
kFwd, kIgnoreCase, &ordinal, NULL));
EXPECT_EQ(0, ordinal);
chrome::NewTab(browser());
ui_test_utils::NavigateToURL(browser(), url);
EXPECT_EQ(0, ui_test_utils::FindInPage(web_contents, base::string16(),
kFwd, kIgnoreCase, &ordinal, NULL));
EXPECT_EQ(0, ordinal);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, StayActive) {
GURL url = GetURL(kSimple);
ui_test_utils::NavigateToURL(browser(), url);
chrome::ShowFindBar(browser());
FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(
browser()->tab_strip_model()->GetActiveWebContents());
find_tab_helper->StopFinding(FindBarController::kClearSelectionOnPage);
ASSERT_TRUE(find_tab_helper->find_ui_active());
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) {
GURL url = GetURL(kSimple);
ui_test_utils::NavigateToURL(browser(), url);
int ordinal = 0;
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_EQ(1, FindInPageWchar(web_contents, L"page",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(1, ui_test_utils::FindInPage(web_contents, base::string16(),
kFwd, kIgnoreCase, &ordinal, NULL));
EXPECT_EQ(1, ordinal);
browser()->GetFindBarController()->EndFindSession(
FindBarController::kKeepSelectionOnPage,
FindBarController::kKeepResultsInFindBox);
EXPECT_EQ(1, FindInPageWchar(web_contents, L"", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) {
GURL url = GetURL(kSimple);
ui_test_utils::NavigateToURL(browser(), url);
int ordinal = 0;
WebContents* web_contents_1 =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"text",
kFwd, kIgnoreCase, &ordinal));
chrome::AddTabAt(browser(), GURL(), -1, true);
ui_test_utils::NavigateToURL(browser(), url);
WebContents* web_contents_2 =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_NE(web_contents_1, web_contents_2);
FindInPageWchar(web_contents_2, L"given", kFwd, kIgnoreCase, &ordinal);
browser()->tab_strip_model()->ActivateTabAt(0, false);
browser()->GetFindBarController()->EndFindSession(
FindBarController::kKeepSelectionOnPage,
FindBarController::kKeepResultsInFindBox);
ui_test_utils::FindInPage(web_contents_1, base::string16(),
kFwd, kIgnoreCase, &ordinal, NULL);
FindBar* find_bar = browser()->GetFindBarController()->find_bar();
if (find_bar->HasGlobalFindPasteboard()) {
EXPECT_EQ(FindTabHelper::FromWebContents(web_contents_1)->find_text(),
WideToUTF16(L"given"));
} else {
EXPECT_EQ(FindTabHelper::FromWebContents(web_contents_1)->find_text(),
WideToUTF16(L"text"));
}
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateSameTab) {
GURL url = GetURL(kSimple);
ui_test_utils::NavigateToURL(browser(), url);
int ordinal = 0;
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_EQ(1, FindInPageWchar(web_contents, L"page",
kFwd, kIgnoreCase, &ordinal));
EnsureFindBoxOpen();
EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
browser()->GetFindBarController()->EndFindSession(
FindBarController::kKeepSelectionOnPage,
FindBarController::kKeepResultsInFindBox);
EnsureFindBoxOpen();
EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateInNewTab) {
GURL url = GetURL(kSimple);
ui_test_utils::NavigateToURL(browser(), url);
int ordinal = 0;
WebContents* web_contents_1 =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"page",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED);
WebContents* web_contents_2 =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_NE(web_contents_1, web_contents_2);
EnsureFindBoxOpen();
EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
EXPECT_EQ(base::string16(), GetMatchCountText());
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulatePreserveLast) {
FindBar* find_bar = browser()->GetFindBarController()->find_bar();
if (find_bar->HasGlobalFindPasteboard())
return;
GURL url = GetURL(kSimple);
ui_test_utils::NavigateToURL(browser(), url);
int ordinal = 0;
WebContents* web_contents_1 =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"page",
kFwd, kIgnoreCase, &ordinal));
EnsureFindBoxOpen();
EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
browser()->GetFindBarController()->EndFindSession(
FindBarController::kKeepSelectionOnPage,
FindBarController::kKeepResultsInFindBox);
chrome::AddTabAt(browser(), GURL(), -1, true);
ui_test_utils::NavigateToURL(browser(), url);
WebContents* web_contents_2 =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_NE(web_contents_1, web_contents_2);
FindInPageWchar(web_contents_2, L"text", kFwd, kIgnoreCase, &ordinal);
browser()->tab_strip_model()->ActivateTabAt(0, false);
EnsureFindBoxOpen();
EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
browser()->GetFindBarController()->EndFindSession(
FindBarController::kKeepSelectionOnPage,
FindBarController::kKeepResultsInFindBox);
EnsureFindBoxOpen();
EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
}
#if defined(OS_LINUX) && defined(TOOLKIT_VIEWS)
#define MAYBE_NoIncognitoPrepopulate DISABLED_NoIncognitoPrepopulate
#else
#define MAYBE_NoIncognitoPrepopulate NoIncognitoPrepopulate
#endif
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_NoIncognitoPrepopulate) {
FindBar* find_bar = browser()->GetFindBarController()->find_bar();
if (find_bar->HasGlobalFindPasteboard())
return;
GURL url = GetURL(kSimple);
ui_test_utils::NavigateToURL(browser(), url);
int ordinal = 0;
WebContents* web_contents_1 =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"page",
kFwd, kIgnoreCase, &ordinal));
EnsureFindBoxOpenForBrowser(browser());
EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser()));
browser()->GetFindBarController()->EndFindSession(
FindBarController::kKeepSelectionOnPage,
FindBarController::kKeepResultsInFindBox);
Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile();
Browser* incognito_browser =
new Browser(Browser::CreateParams(incognito_profile,
browser()->host_desktop_type()));
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
chrome::AddSelectedTabWithURL(incognito_browser, url,
content::PAGE_TRANSITION_AUTO_TOPLEVEL);
observer.Wait();
incognito_browser->window()->Show();
EnsureFindBoxOpenForBrowser(incognito_browser);
EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(incognito_browser));
WebContents* incognito_tab =
incognito_browser->tab_strip_model()->GetActiveWebContents();
EXPECT_EQ(1, FindInPageWchar(incognito_tab, L"text",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(ASCIIToUTF16("text"), GetFindBarTextForBrowser(incognito_browser));
incognito_browser->GetFindBarController()->EndFindSession(
FindBarController::kKeepSelectionOnPage,
FindBarController::kKeepResultsInFindBox);
chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED);
WebContents* web_contents_2 =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_NE(web_contents_1, web_contents_2);
EnsureFindBoxOpenForBrowser(browser());
EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser()));
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, ActivateLinkNavigatesPage) {
GURL url = GetURL(kLinkPage);
ui_test_utils::NavigateToURL(browser(), url);
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
FindTabHelper* find_tab_helper =
FindTabHelper::FromWebContents(web_contents);
int ordinal = 0;
FindInPageWchar(web_contents, L"link", kFwd, kIgnoreCase, &ordinal);
EXPECT_EQ(ordinal, 1);
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&web_contents->GetController()));
find_tab_helper->StopFinding(FindBarController::kActivateSelectionOnPage);
observer.Wait();
}
#if defined(TOOLKIT_GTK)
#define MAYBE_FitWindow DISABLED_FitWindow
#else
#define MAYBE_FitWindow FitWindow
#endif
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_FitWindow) {
Browser::CreateParams params(Browser::TYPE_POPUP, browser()->profile(),
browser()->host_desktop_type());
params.initial_bounds = gfx::Rect(0, 0, 250, 500);
Browser* popup = new Browser(params);
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
chrome::AddSelectedTabWithURL(popup, GURL(content::kAboutBlankURL),
content::PAGE_TRANSITION_LINK);
observer.Wait();
popup->window()->Show();
base::MessageLoop::current()->RunUntilIdle();
EnsureFindBoxOpenForBrowser(popup);
base::MessageLoop::current()->RunUntilIdle();
ASSERT_LE(GetFindBarWidthForBrowser(popup),
popup->window()->GetBounds().width());
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
FindMovesOnTabClose_Issue1343052) {
EnsureFindBoxOpen();
content::RunAllPendingInMessageLoop();
gfx::Point position;
EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL));
GURL url = GetURL(kSimple);
ui_test_utils::NavigateToURLWithDisposition(
browser(), url, NEW_FOREGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
chrome::CloseTab(browser());
gfx::Point position2;
EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL));
EXPECT_EQ(position, position2);
chrome::ToggleBookmarkBar(browser());
ui_test_utils::NavigateToURLWithDisposition(
browser(), url, NEW_FOREGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
EnsureFindBoxOpen();
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL));
ui_test_utils::NavigateToURLWithDisposition(
browser(), url, NEW_FOREGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
chrome::CloseTab(browser());
EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL));
EXPECT_EQ(position, position2);
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
GlobalPasteBoardClearMatches) {
FindBar* find_bar = browser()->GetFindBarController()->find_bar();
if (!find_bar->HasGlobalFindPasteboard())
return;
GURL url = GetURL(kSimple);
ui_test_utils::NavigateToURL(browser(), url);
int ordinal = 0;
WebContents* web_contents_1 =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_EQ(1, FindInPageWchar(web_contents_1, L"page",
kFwd, kIgnoreCase, &ordinal));
EnsureFindBoxOpen();
EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
chrome::AddTabAt(browser(), GURL(), -1, true);
ui_test_utils::NavigateToURL(browser(), url);
WebContents* web_contents_2 =
browser()->tab_strip_model()->GetActiveWebContents();
FindInPageWchar(web_contents_2, L"text", kFwd, kIgnoreCase, &ordinal);
EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText());
browser()->tab_strip_model()->ActivateTabAt(0, false);
EXPECT_EQ(ASCIIToUTF16(""), GetMatchCountText());
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, GlobalPasteboardIncognito) {
Browser* browser_incognito = CreateIncognitoBrowser();
WebContents* web_contents_1 =
browser()->tab_strip_model()->GetActiveWebContents();
FindInPageWchar(web_contents_1, L"page", kFwd, kIgnoreCase, NULL);
EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
WebContents* web_contents_2 =
browser_incognito->tab_strip_model()->GetActiveWebContents();
FindInPageWchar(web_contents_2, L"Incognito", kFwd, kIgnoreCase, NULL);
EXPECT_EQ(ASCIIToUTF16("Incognito"),
GetFindBarTextForBrowser(browser_incognito));
EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarText());
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, IncognitoFindNextSecret) {
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
FindInPageWchar(web_contents, L"bar", kFwd, kIgnoreCase, NULL);
Browser* browser_incognito = CreateIncognitoBrowser();
ui_test_utils::NavigateToURL(browser_incognito,
GURL("data:text/plain,barfoofoo"));
WebContents* web_contents_incognito =
browser_incognito->tab_strip_model()->GetActiveWebContents();
FindInPageWchar(web_contents_incognito, L"foo", true, kIgnoreCase, NULL);
EXPECT_EQ(ASCIIToUTF16("foo"),
GetFindBarTextForBrowser(browser_incognito));
EXPECT_EQ(ASCIIToUTF16("1 of 2"),
GetFindBarMatchCountTextForBrowser(browser_incognito));
FindTabHelper* find_tab_helper =
FindTabHelper::FromWebContents(web_contents_incognito);
find_tab_helper->StopFinding(FindBarController::kActivateSelectionOnPage);
EXPECT_TRUE(chrome::ExecuteCommand(browser_incognito, IDC_FIND_NEXT));
ui_test_utils::FindInPageNotificationObserver observer(
web_contents_incognito);
observer.Wait();
EXPECT_EQ(ASCIIToUTF16("foo"),
GetFindBarTextForBrowser(browser_incognito));
EXPECT_EQ(ASCIIToUTF16("2 of 2"),
GetFindBarMatchCountTextForBrowser(browser_incognito));
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, IncognitoFindNextShared) {
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
FindInPageWchar(web_contents, L"bar", kFwd, kIgnoreCase, NULL);
Browser* browser_incognito = CreateIncognitoBrowser();
ui_test_utils::NavigateToURL(browser_incognito,
GURL("data:text/plain,bar"));
EXPECT_TRUE(chrome::ExecuteCommand(browser_incognito, IDC_FIND_NEXT));
WebContents* web_contents_incognito =
browser_incognito->tab_strip_model()->GetActiveWebContents();
ui_test_utils::FindInPageNotificationObserver observer(
web_contents_incognito);
observer.Wait();
EXPECT_EQ(ASCIIToUTF16("bar"),
GetFindBarTextForBrowser(browser_incognito));
}
#if defined(OS_WIN)
BOOL CALLBACK EnumerateChildren(HWND hwnd, LPARAM l_param) {
HWND* child = reinterpret_cast<HWND*>(l_param);
*child = hwnd;
return FALSE;
}
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, WindowedNPAPIPluginHidden) {
browser()->profile()->GetPrefs()->SetBoolean(prefs::kPluginsAlwaysAuthorize,
true);
base::string16 expected_title(ASCIIToUTF16("ready"));
content::WebContents* tab =
browser()->tab_strip_model()->GetActiveWebContents();
content::TitleWatcher title_watcher(tab, expected_title);
GURL url = ui_test_utils::GetTestUrl(
base::FilePath().AppendASCII("printing"),
base::FilePath().AppendASCII("npapi_plugin.html"));
ui_test_utils::NavigateToURL(browser(), url);
EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
HWND hwnd =
tab->GetView()->GetNativeView()->GetHost()->GetAcceleratedWidget();
HWND child = NULL;
EnumChildWindows(hwnd, EnumerateChildren,reinterpret_cast<LPARAM>(&child));
RECT region_before, region_after;
int result = GetWindowRgnBox(child, ®ion_before);
ASSERT_EQ(result, SIMPLEREGION);
chrome::NewTab(browser());
browser()->tab_strip_model()->ActivateTabAt(1, true);
ui_test_utils::NavigateToURL(browser(), GURL(content::kAboutBlankURL));
EnsureFindBoxOpen();
browser()->tab_strip_model()->ActivateTabAt(0, true);
EnsureFindBoxOpen();
result = GetWindowRgnBox(child, ®ion_after);
if (result == NULLREGION) {
return;
}
if (result == COMPLEXREGION) {
return;
}
ASSERT_EQ(result, SIMPLEREGION);
bool rects_equal =
region_before.left == region_after.left &&
region_before.top == region_after.top &&
region_before.right == region_after.right &&
region_before.bottom == region_after.bottom;
ASSERT_FALSE(rects_equal);
}
#endif