Commit ea0b89ea authored by siggi's avatar siggi Committed by Commit bot

Test FindBar audible alerts.

BUG=682299

Review-Url: https://codereview.chromium.org/2848883005
Cr-Commit-Position: refs/heads/master@{#469344}
parent 808626a9
......@@ -76,6 +76,7 @@ class FindBarBridge : public FindBar,
base::string16 GetFindSelectedText() override;
base::string16 GetMatchCountText() override;
int GetWidth() override;
size_t GetAudibleAlertCount() override;
// Used to disable find bar animations when testing.
static bool disable_animations_during_testing_;
......@@ -88,6 +89,9 @@ class FindBarBridge : public FindBar,
// Pointer back to the owning controller.
FindBarController* find_bar_controller_; // weak, owns us
// Number of audible alerts generated, for testing.
size_t audible_alerts_;
DISALLOW_COPY_AND_ASSIGN(FindBarBridge);
};
......
......@@ -13,7 +13,7 @@
bool FindBarBridge::disable_animations_during_testing_ = false;
FindBarBridge::FindBarBridge(Browser* browser)
: find_bar_controller_(NULL) {
: find_bar_controller_(NULL), audible_alerts_(0) {
cocoa_controller_ = [[FindBarCocoaController alloc] initWithBrowser:browser];
[cocoa_controller_ setFindBarBridge:this];
}
......@@ -75,6 +75,7 @@ void FindBarBridge::UpdateUIForFindResult(const FindNotificationDetails& result,
void FindBarBridge::AudibleAlert() {
// Beep beep, beep beep, Yeah!
++audible_alerts_;
NSBeep();
}
......@@ -133,3 +134,7 @@ base::string16 FindBarBridge::GetMatchCountText() {
int FindBarBridge::GetWidth() {
return [cocoa_controller_ findBarWidth];
}
size_t FindBarBridge::GetAudibleAlertCount() {
return audible_alerts_;
}
......@@ -111,6 +111,9 @@ class FindBarTesting {
// Gets the pixel width of the FindBar.
virtual int GetWidth() = 0;
// Gets the number of audible alerts that have been issued by this bar.
virtual size_t GetAudibleAlertCount() = 0;
};
#endif // CHROME_BROWSER_UI_FIND_BAR_FIND_BAR_H_
......@@ -128,6 +128,12 @@ class FindInPageControllerTest : public InProcessBrowserTest {
return find_bar->GetWidth();
}
size_t GetFindBarAudibleAlertsForBrowser(Browser* browser) {
FindBarTesting* find_bar =
browser->GetFindBarController()->find_bar()->GetFindBarTesting();
return find_bar->GetAudibleAlertCount();
}
void EnsureFindBoxOpenForBrowser(Browser* browser) {
chrome::ShowFindBar(browser);
gfx::Point position;
......@@ -214,6 +220,8 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) {
int ordinal = 0;
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_EQ(0u, GetFindBarAudibleAlertsForBrowser(browser()));
EXPECT_EQ(18, FindInPageASCII(web_contents, "g",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
......@@ -232,9 +240,24 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) {
EXPECT_EQ(1, FindInPageASCII(web_contents, "google",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(0u, GetFindBarAudibleAlertsForBrowser(browser()));
EXPECT_EQ(
0, FindInPageASCII(web_contents, "google!", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(0, ordinal);
EXPECT_EQ(1u, GetFindBarAudibleAlertsForBrowser(browser()));
// Extend the search string one more.
EXPECT_EQ(0, FindInPageASCII(web_contents, "google!!", kFwd, kIgnoreCase,
&ordinal));
EXPECT_EQ(0, ordinal);
EXPECT_EQ(2u, GetFindBarAudibleAlertsForBrowser(browser()));
// "Backspace" one, make sure there's no audible alert while backspacing.
EXPECT_EQ(0, FindInPageASCII(web_contents, "google!",
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(0, ordinal);
EXPECT_EQ(2u, GetFindBarAudibleAlertsForBrowser(browser()));
// Negative test (no matches should be found).
EXPECT_EQ(0, FindInPageASCII(web_contents, "Non-existing string",
......@@ -301,6 +324,35 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFormsTextAreas) {
}
}
// This test removes a frame after a search comes up empty, then navigates to
// a different page and verifies this doesn't cause any extraneous dings.
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, NoAudibleAlertOnFrameChange) {
// First we navigate to our frames page.
GURL url = GetURL(kFramePage);
ui_test_utils::NavigateToURL(browser(), url);
int ordinal = 0;
WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_EQ(0u, GetFindBarAudibleAlertsForBrowser(browser()));
// Search for a non-existant string.
EXPECT_EQ(
0, FindInPageASCII(web_contents, "google!", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(0, ordinal);
EXPECT_EQ(1u, GetFindBarAudibleAlertsForBrowser(browser()));
// Remove the first frame of the page.
constexpr char kRemoveFrameScript[] =
"frame = document.getElementsByTagName(\"FRAME\")[0];\n"
"frame.parentElement.removeChild(frame);\n";
ASSERT_TRUE(content::ExecuteScript(web_contents, kRemoveFrameScript));
ui_test_utils::NavigateToURL(browser(), GetURL("specialchar.html"));
EXPECT_EQ(1u, GetFindBarAudibleAlertsForBrowser(browser()));
}
// Verify search for text within special URLs such as chrome:history,
// chrome://downloads, data directory
#if defined(OS_MACOSX) || defined(OS_WIN)
......
......@@ -29,7 +29,8 @@ using content::NativeWebKeyboardEvent;
FindBarHost::FindBarHost(BrowserView* browser_view)
: DropdownBarHost(browser_view),
find_bar_controller_(NULL) {
find_bar_controller_(NULL),
audible_alerts_(0) {
FindBarView* find_bar_view = new FindBarView(this);
Init(browser_view->find_bar_host_view(), find_bar_view, find_bar_view);
}
......@@ -145,6 +146,7 @@ void FindBarHost::UpdateUIForFindResult(const FindNotificationDetails& result,
}
void FindBarHost::AudibleAlert() {
++audible_alerts_;
#if defined(OS_WIN)
MessageBeep(MB_OK);
#endif
......@@ -245,6 +247,10 @@ int FindBarHost::GetWidth() {
return view()->width();
}
size_t FindBarHost::GetAudibleAlertCount() {
return audible_alerts_;
}
////////////////////////////////////////////////////////////////////////////////
// Overridden from DropdownBarHost:
......
......@@ -77,6 +77,7 @@ class FindBarHost : public DropdownBarHost,
base::string16 GetFindSelectedText() override;
base::string16 GetMatchCountText() override;
int GetWidth() override;
size_t GetAudibleAlertCount() override;
// Overridden from DropdownBarHost:
// Returns the rectangle representing where to position the find bar. It uses
......@@ -130,6 +131,9 @@ class FindBarHost : public DropdownBarHost,
// A pointer back to the owning controller.
FindBarController* find_bar_controller_;
// The number of audible alerts issued.
size_t audible_alerts_;
DISALLOW_COPY_AND_ASSIGN(FindBarHost);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment