This source file includes following definitions.
- GetFindBarText
- GetFindBarSelectedText
- 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
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/find_bar/find_bar_controller.h"
#include "chrome/browser/ui/find_bar/find_notification_details.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/find_bar_host.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/view.h"
#include "ui/views/views_delegate.h"
using base::ASCIIToUTF16;
using content::WebContents;
namespace {
static const char kSimplePage[] = "files/find_in_page/simple.html";
class FindInPageTest : public InProcessBrowserTest {
public:
FindInPageTest() {
FindBarHost::disable_animations_during_testing_ = true;
}
base::string16 GetFindBarText() {
FindBar* find_bar = browser()->GetFindBarController()->find_bar();
return find_bar->GetFindText();
}
base::string16 GetFindBarSelectedText() {
FindBarTesting* find_bar =
browser()->GetFindBarController()->find_bar()->GetFindBarTesting();
return find_bar->GetFindSelectedText();
}
private:
DISALLOW_COPY_AND_ASSIGN(FindInPageTest);
};
}
IN_PROC_BROWSER_TEST_F(FindInPageTest, CrashEscHandlers) {
ASSERT_TRUE(test_server()->Start());
GURL url = test_server()->GetURL(kSimplePage);
ui_test_utils::NavigateToURL(browser(), url);
chrome::Find(browser());
chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED);
chrome::Find(browser());
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
browser()->tab_strip_model()->ActivateTabAt(0, true);
browser()->tab_strip_model()->CloseWebContentsAt(1,
TabStripModel::CLOSE_NONE);
ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(),
VIEW_ID_OMNIBOX));
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_ESCAPE, false, false, false, false));
}
#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
#define MAYBE_FocusRestore DISABLED_FocusRestore
#else
#define MAYBE_FocusRestore FocusRestore
#endif
IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_FocusRestore) {
ASSERT_TRUE(test_server()->Start());
GURL url = test_server()->GetURL("title1.html");
ui_test_utils::NavigateToURL(browser(), url);
chrome::FocusLocationBar(browser());
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
browser()->GetFindBarController()->Show();
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
browser()->GetFindBarController()->EndFindSession(
FindBarController::kKeepSelectionOnPage,
FindBarController::kKeepResultsInFindBox);
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
chrome::FocusLocationBar(browser());
chrome::Find(browser());
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
ui_test_utils::FindInPage(
browser()->tab_strip_model()->GetActiveWebContents(),
ASCIIToUTF16("a"), true, false, NULL, NULL);
browser()->GetFindBarController()->EndFindSession(
FindBarController::kKeepSelectionOnPage,
FindBarController::kKeepResultsInFindBox);
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
chrome::FocusLocationBar(browser());
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
browser()->GetFindBarController()->Show();
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
browser()->GetFindBarController()->EndFindSession(
FindBarController::kKeepSelectionOnPage,
FindBarController::kKeepResultsInFindBox);
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
}
IN_PROC_BROWSER_TEST_F(FindInPageTest, DISABLED_SelectionRestoreOnTabSwitch) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
GURL url = test_server()->GetURL(kSimplePage);
ui_test_utils::NavigateToURL(browser(), url);
browser()->GetFindBarController()->Show();
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_A, false, false, false, false));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_B, false, false, false, false));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_C, false, false, false, false));
EXPECT_EQ(ASCIIToUTF16("abc"), GetFindBarText());
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_LEFT, false, true, false, false));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_LEFT, false, true, false, false));
EXPECT_EQ(ASCIIToUTF16("bc"), GetFindBarSelectedText());
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED);
observer.Wait();
browser()->GetFindBarController()->Show();
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_D, false, false, false, false));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_E, false, false, false, false));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_F, false, false, false, false));
EXPECT_EQ(ASCIIToUTF16("def"), GetFindBarText());
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_HOME, false, false, false, false));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_RIGHT, false, true, false, false));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_RIGHT, false, true, false, false));
EXPECT_EQ(ASCIIToUTF16("de"), GetFindBarSelectedText());
browser()->tab_strip_model()->ActivateTabAt(0, true);
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
EXPECT_EQ(ASCIIToUTF16("bc"), GetFindBarSelectedText());
browser()->tab_strip_model()->ActivateTabAt(1, true);
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
EXPECT_EQ(ASCIIToUTF16("de"), GetFindBarSelectedText());
}
#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
#define MAYBE_FocusRestoreOnTabSwitch DISABLED_FocusRestoreOnTabSwitch
#else
#define MAYBE_FocusRestoreOnTabSwitch FocusRestoreOnTabSwitch
#endif
IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_FocusRestoreOnTabSwitch) {
ASSERT_TRUE(test_server()->Start());
GURL url = test_server()->GetURL(kSimplePage);
ui_test_utils::NavigateToURL(browser(), url);
chrome::Find(browser());
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
ui_test_utils::FindInPage(
browser()->tab_strip_model()->GetActiveWebContents(),
ASCIIToUTF16("a"), true, false, NULL, NULL);
EXPECT_EQ(ASCIIToUTF16("a"), GetFindBarSelectedText());
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED);
observer.Wait();
chrome::Find(browser());
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
ui_test_utils::FindInPage(
browser()->tab_strip_model()->GetActiveWebContents(),
ASCIIToUTF16("b"), true, false, NULL, NULL);
EXPECT_EQ(ASCIIToUTF16("b"), GetFindBarSelectedText());
chrome::FocusLocationBar(browser());
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
browser()->tab_strip_model()->ActivateTabAt(0, true);
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
EXPECT_EQ(ASCIIToUTF16("a"), GetFindBarSelectedText());
browser()->tab_strip_model()->ActivateTabAt(1, true);
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
}
#if !defined(OS_MACOSX) && !defined(USE_AURA)
IN_PROC_BROWSER_TEST_F(FindInPageTest, PrepopulateRespectBlank) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
GURL url = test_server()->GetURL(kSimplePage);
ui_test_utils::NavigateToURL(browser(), url);
browser()->GetFindBarController()->Show();
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_A, false, false, false, false));
EXPECT_EQ(ASCIIToUTF16("a"), GetFindBarText());
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_BACK, false, false, false, false));
EXPECT_EQ(base::string16(), GetFindBarText());
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_ESCAPE, false, false, false, false));
browser()->GetFindBarController()->Show();
EXPECT_EQ(base::string16(), GetFindBarText());
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_ESCAPE, false, false, false, false));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_F3, false, false, false, false));
EXPECT_EQ(base::string16(), GetFindBarText());
}
#endif
#if defined(TOOLKIT_VIEWS)
#define MAYBE_PasteWithoutTextChange DISABLED_PasteWithoutTextChange
#else
#define MAYBE_PasteWithoutTextChange PasteWithoutTextChange
#endif
IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_PasteWithoutTextChange) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
GURL url = test_server()->GetURL(kSimplePage);
ui_test_utils::NavigateToURL(browser(), url);
browser()->GetFindBarController()->Show();
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_A, false, false, false, false));
EXPECT_EQ(ASCIIToUTF16("a"), GetFindBarText());
chrome::Reload(browser(), CURRENT_TAB);
browser()->GetFindBarController()->Show();
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
EXPECT_EQ(ASCIIToUTF16("a"), GetFindBarSelectedText());
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_C, true, false, false, false));
base::string16 str;
ui::Clipboard::GetForCurrentThread()->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE,
&str);
EXPECT_EQ(ASCIIToUTF16("a"), str);
content::Source<WebContents> notification_source(
browser()->tab_strip_model()->GetActiveWebContents());
ui_test_utils::WindowedNotificationObserverWithDetails
<FindNotificationDetails> observer(
chrome::NOTIFICATION_FIND_RESULT_AVAILABLE, notification_source);
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_V, true, false, false, false));
ASSERT_NO_FATAL_FAILURE(observer.Wait());
FindNotificationDetails details;
ASSERT_TRUE(observer.GetDetailsFor(notification_source.map_key(), &details));
EXPECT_TRUE(details.number_of_matches() > 0);
}
#if defined(OS_WIN)
IN_PROC_BROWSER_TEST_F(FindInPageTest, DISABLED_CtrlEnter) {
ui_test_utils::NavigateToURL(browser(),
GURL("data:text/html,This is some text with a "
"<a href=\"about:blank\">link</a>."));
browser()->GetFindBarController()->Show();
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_L, false, false, false, false));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_I, false, false, false, false));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_N, false, false, false, false));
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_K, false, false, false, false));
EXPECT_EQ(ASCIIToUTF16("link"), GetFindBarText());
ui_test_utils::UrlLoadObserver observer(
GURL("about:blank"), content::NotificationService::AllSources());
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_RETURN, true, false, false, false));
observer.Wait();
}
#endif