| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 EXPECT_EQ(old_text.size(), end); | 854 EXPECT_EQ(old_text.size(), end); |
| 855 | 855 |
| 856 // Delete the content | 856 // Delete the content |
| 857 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DELETE, 0)); | 857 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DELETE, 0)); |
| 858 EXPECT_TRUE(omnibox_view->IsSelectAll()); | 858 EXPECT_TRUE(omnibox_view->IsSelectAll()); |
| 859 omnibox_view->GetSelectionBounds(&start, &end); | 859 omnibox_view->GetSelectionBounds(&start, &end); |
| 860 EXPECT_EQ(0U, start); | 860 EXPECT_EQ(0U, start); |
| 861 EXPECT_EQ(0U, end); | 861 EXPECT_EQ(0U, end); |
| 862 EXPECT_TRUE(omnibox_view->GetText().empty()); | 862 EXPECT_TRUE(omnibox_view->GetText().empty()); |
| 863 | 863 |
| 864 // Check if RevertAll() can set text and cursor correctly. | 864 // Add a small amount of text to move the cursor past offset 0. |
| 865 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, 0)); |
| 866 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_B, 0)); |
| 867 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_C, 0)); |
| 868 |
| 869 // Check if RevertAll() resets the text and preserves the cursor position. |
| 865 omnibox_view->RevertAll(); | 870 omnibox_view->RevertAll(); |
| 866 EXPECT_FALSE(omnibox_view->IsSelectAll()); | 871 EXPECT_FALSE(omnibox_view->IsSelectAll()); |
| 867 EXPECT_EQ(old_text, omnibox_view->GetText()); | 872 EXPECT_EQ(old_text, omnibox_view->GetText()); |
| 868 omnibox_view->GetSelectionBounds(&start, &end); | 873 omnibox_view->GetSelectionBounds(&start, &end); |
| 869 EXPECT_EQ(0U, start); | 874 EXPECT_EQ(3U, start); |
| 870 EXPECT_EQ(0U, end); | 875 EXPECT_EQ(3U, end); |
| 876 |
| 877 // Check that reverting clamps the cursor to the bounds of the new text. |
| 878 // Move the cursor to the end. |
| 879 #if defined(OS_MACOSX) |
| 880 // End doesn't work on Mac trybot. |
| 881 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_E, ui::EF_CONTROL_DOWN)); |
| 882 #else |
| 883 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, 0)); |
| 884 #endif |
| 885 // Add a small amount of text to push the cursor past where the text end |
| 886 // will be once we revert. |
| 887 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, 0)); |
| 888 omnibox_view->RevertAll(); |
| 889 // Cursor should be no further than original text. |
| 890 omnibox_view->GetSelectionBounds(&start, &end); |
| 891 EXPECT_EQ(11U, start); |
| 892 EXPECT_EQ(11U, end); |
| 871 } | 893 } |
| 872 | 894 |
| 873 // Make sure the cursor position doesn't get set past the last character of | 895 // Make sure the cursor position doesn't get set past the last character of |
| 874 // user input text when the URL is longer than the keyword. | 896 // user input text when the URL is longer than the keyword. |
| 875 // (http://crbug.com/656209) | 897 // (http://crbug.com/656209) |
| 876 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, FocusSearchLongUrl) { | 898 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, FocusSearchLongUrl) { |
| 877 OmniboxView* omnibox_view = NULL; | 899 OmniboxView* omnibox_view = NULL; |
| 878 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 900 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
| 879 | 901 |
| 880 ASSERT_GT(strlen(url::kAboutBlankURL), strlen(kSearchKeyword)); | 902 ASSERT_GT(strlen(url::kAboutBlankURL), strlen(kSearchKeyword)); |
| (...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1999 | 2021 |
| 2000 // Now Shift+Right should do nothing, and Shift+Left should reduce. | 2022 // Now Shift+Right should do nothing, and Shift+Left should reduce. |
| 2001 // At the end, so Shift+Right should do nothing. | 2023 // At the end, so Shift+Right should do nothing. |
| 2002 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, ui::EF_SHIFT_DOWN)); | 2024 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, ui::EF_SHIFT_DOWN)); |
| 2003 EXPECT_EQ(2u, GetSelectionSize(omnibox_view)); | 2025 EXPECT_EQ(2u, GetSelectionSize(omnibox_view)); |
| 2004 | 2026 |
| 2005 // And Left should reduce by one character. | 2027 // And Left should reduce by one character. |
| 2006 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, ui::EF_SHIFT_DOWN)); | 2028 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, ui::EF_SHIFT_DOWN)); |
| 2007 EXPECT_EQ(1u, GetSelectionSize(omnibox_view)); | 2029 EXPECT_EQ(1u, GetSelectionSize(omnibox_view)); |
| 2008 } | 2030 } |
| OLD | NEW |