Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Unified Diff: chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc

Issue 23494016: views: Move views specific portions out of omnibox_view_browsertest.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_view_browsertest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc
index 6fa4a4e3fb1e033e0eaa44e3302bc2c45ace5654..3536b015a4fa1ec953f7e79bc899bf43a8d928ab 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc
@@ -4,24 +4,85 @@
#include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
-#include "chrome/app/chrome_command_ids.h"
-#include "chrome/browser/command_updater.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
#include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
#include "chrome/browser/ui/view_ids.h"
+#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/omnibox/omnibox_views.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 "grit/generated_resources.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
+#include "ui/base/test/ui_controls.h"
#include "ui/views/controls/textfield/native_textfield_wrapper.h"
-typedef InProcessBrowserTest OmniboxViewViewsTest;
+class OmniboxViewViewsTest : public InProcessBrowserTest,
+ public content::NotificationObserver {
+ protected:
+ static void GetOmniboxViewForBrowser(const Browser* browser,
+ OmniboxView** omnibox_view) {
+ BrowserWindow* window = browser->window();
+ ASSERT_TRUE(window);
+ LocationBar* location_bar = window->GetLocationBar();
+ ASSERT_TRUE(location_bar);
+ *omnibox_view = location_bar->GetLocationEntry();
+ ASSERT_TRUE(*omnibox_view);
+ }
+
+ // InProcessBrowserTest:
+ virtual void SetUpOnMainThread() OVERRIDE {
+ ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
+ chrome::FocusLocationBar(browser());
+ ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
+ }
+
+ // content::NotificationObserver:
Peter Kasting 2013/09/03 21:10:26 Why is this necessary?
tfarina 2013/09/03 22:16:22 I was sure you were going to notice. Yes, it was
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE {
+ base::MessageLoop::current()->Quit();
+ }
+
+ void GetOmniboxView(OmniboxView** omnibox_view) {
+ GetOmniboxViewForBrowser(browser(), omnibox_view);
+ }
+
+ const BrowserView* GetBrowserView() const {
+ return BrowserView::GetBrowserViewForBrowser(browser());
+ }
+
+ // Move the mouse to the center of the browser window and left-click.
+ void ClickBrowserWindowCenter() {
+ ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
+ GetBrowserView()->GetBoundsInScreen().CenterPoint()));
+ ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(ui_controls::LEFT,
+ ui_controls::DOWN));
+ ASSERT_TRUE(
+ ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::UP));
+ }
+
+ // Press and release the mouse in the omnibox at an offset from its origin.
+ // If |release_offset| differs from |press_offset|, the mouse will be moved
+ // between the press and release.
+ void ClickOmnibox(ui_controls::MouseButton button,
+ const gfx::Vector2d& press_offset,
+ const gfx::Vector2d& release_offset) {
+ const views::View* omnibox = GetBrowserView()->GetViewByID(VIEW_ID_OMNIBOX);
+ gfx::Point omnibox_origin = omnibox->GetBoundsInScreen().origin();
+ gfx::Point press_point = omnibox_origin + press_offset;
+ ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(press_point));
+ ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::DOWN));
+
+ gfx::Point release_point = omnibox_origin + release_offset;
+ if (release_point != press_point)
+ ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(release_point));
+ ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::UP));
+ }
+};
IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, PasteAndGoDoesNotLeavePopupOpen) {
OmniboxView* view = browser()->window()->GetLocationBar()->GetLocationEntry();
@@ -49,3 +110,51 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, PasteAndGoDoesNotLeavePopupOpen) {
// The popup should not be open.
EXPECT_FALSE(view->model()->popup_model()->IsOpen());
}
+
+IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, SelectAllOnClick) {
+ OmniboxView* omnibox_view = NULL;
+ ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
+ omnibox_view->SetUserText(ASCIIToUTF16("http://www.google.com/"));
+ const gfx::Vector2d click(40, 10);
+
+ // Take the focus away from the omnibox.
+ ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter());
+ EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
+ EXPECT_FALSE(omnibox_view->IsSelectAll());
+
+ // Clicking in the omnibox should take focus and select all text.
+ ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click, click));
+ EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
+ EXPECT_TRUE(omnibox_view->IsSelectAll());
+
+ // Clicking in another view should clear focus and the selection.
+ ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter());
+ EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
+ EXPECT_FALSE(omnibox_view->IsSelectAll());
+
+ // Clicking in the omnibox again should take focus and select all text again.
+ ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click, click));
+ EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
+ EXPECT_TRUE(omnibox_view->IsSelectAll());
+
+ // Clicking another omnibox spot should keep focus but clear the selection.
+ omnibox_view->SelectAll(false);
+ const gfx::Vector2d click_2(click.x() + 10, click.y());
+ ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click_2, click_2));
+ EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
+ EXPECT_FALSE(omnibox_view->IsSelectAll());
+
+ // Take the focus away and click in the omnibox again, but drag a bit before
+ // releasing. We should focus the omnibox but not select all of its text.
+ ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter());
+ const gfx::Vector2d release(click.x() + 10, click.y());
+ ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click, release));
+ EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
+ EXPECT_FALSE(omnibox_view->IsSelectAll());
+
+ // Middle-clicking should not be handled by the omnibox.
+ ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter());
+ ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::MIDDLE, click, click));
+ EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
+ EXPECT_FALSE(omnibox_view->IsSelectAll());
+}
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_view_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698