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/scoped_observer.h" | 10 #include "base/scoped_observer.h" |
(...skipping 1832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1843 // Mac uses alt-left/right to select a word. | 1843 // Mac uses alt-left/right to select a word. |
1844 const int modifiers = ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN; | 1844 const int modifiers = ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN; |
1845 #else | 1845 #else |
1846 const int modifiers = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN; | 1846 const int modifiers = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN; |
1847 #endif | 1847 #endif |
1848 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, modifiers)); | 1848 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, modifiers)); |
1849 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, modifiers)); | 1849 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, modifiers)); |
1850 ASSERT_EQ(ASCIIToUTF16("www.bar.com/2"), omnibox_view->GetText()); | 1850 ASSERT_EQ(ASCIIToUTF16("www.bar.com/2"), omnibox_view->GetText()); |
1851 } | 1851 } |
1852 | 1852 |
1853 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, | |
1854 PersistSearchReplacementAcrossTabSwitch) { | |
1855 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled()); | |
1856 browser()->toolbar_model()->set_url_replacement_enabled(false); | |
1857 | |
1858 // Create a new tab. | |
1859 chrome::NewTab(browser()); | |
1860 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled()); | |
1861 | |
1862 // Switch back to the first tab. | |
1863 browser()->tab_strip_model()->ActivateTabAt(0, true); | |
1864 EXPECT_FALSE(browser()->toolbar_model()->url_replacement_enabled()); | |
1865 } | |
1866 | |
1867 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, | |
1868 DontUpdateURLWhileSearchTermReplacementIsDisabled) { | |
1869 OmniboxView* omnibox_view = NULL; | |
1870 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | |
1871 TestToolbarModel* test_toolbar_model = new TestToolbarModel; | |
1872 std::unique_ptr<ToolbarModel> toolbar_model(test_toolbar_model); | |
1873 browser()->swap_toolbar_models(&toolbar_model); | |
1874 | |
1875 base::string16 url_a(ASCIIToUTF16("http://www.a.com/")); | |
1876 base::string16 url_b(ASCIIToUTF16("http://www.b.com/")); | |
1877 base::string16 url_c(ASCIIToUTF16("http://www.c.com/")); | |
1878 chrome::FocusLocationBar(browser()); | |
1879 test_toolbar_model->set_text(url_a); | |
1880 omnibox_view->Update(); | |
1881 EXPECT_EQ(url_a, omnibox_view->GetText()); | |
1882 | |
1883 // Disable URL replacement and update. Because the omnibox has focus, the | |
1884 // visible text shouldn't change; see comments in | |
1885 // OmniboxEditModel::UpdatePermanentText(). | |
1886 browser()->toolbar_model()->set_url_replacement_enabled(false); | |
1887 test_toolbar_model->set_text(url_b); | |
1888 omnibox_view->Update(); | |
1889 EXPECT_EQ(url_a, omnibox_view->GetText()); | |
1890 | |
1891 // Re-enable URL replacement and ensure updating changes the text. | |
1892 browser()->toolbar_model()->set_url_replacement_enabled(true); | |
1893 // We have to change the toolbar model text here, or Update() will do nothing. | |
1894 // This is because the previous update already updated the permanent text. | |
1895 test_toolbar_model->set_text(url_c); | |
1896 omnibox_view->Update(); | |
1897 EXPECT_EQ(url_c, omnibox_view->GetText()); | |
1898 | |
1899 // The same test, but using RevertAll() to reset search term replacement. | |
1900 test_toolbar_model->set_text(url_a); | |
1901 omnibox_view->Update(); | |
1902 EXPECT_EQ(url_a, omnibox_view->GetText()); | |
1903 browser()->toolbar_model()->set_url_replacement_enabled(false); | |
1904 test_toolbar_model->set_text(url_b); | |
1905 omnibox_view->Update(); | |
1906 EXPECT_EQ(url_a, omnibox_view->GetText()); | |
1907 omnibox_view->RevertAll(); | |
1908 EXPECT_EQ(url_b, omnibox_view->GetText()); | |
1909 test_toolbar_model->set_text(url_c); | |
1910 omnibox_view->Update(); | |
1911 EXPECT_EQ(url_c, omnibox_view->GetText()); | |
1912 } | |
1913 | |
1914 namespace { | 1853 namespace { |
1915 | 1854 |
1916 // Returns the number of characters currently selected in |omnibox_view|. | 1855 // Returns the number of characters currently selected in |omnibox_view|. |
1917 size_t GetSelectionSize(OmniboxView* omnibox_view) { | 1856 size_t GetSelectionSize(OmniboxView* omnibox_view) { |
1918 size_t start, end; | 1857 size_t start, end; |
1919 omnibox_view->GetSelectionBounds(&start, &end); | 1858 omnibox_view->GetSelectionBounds(&start, &end); |
1920 if (end >= start) | 1859 if (end >= start) |
1921 return end - start; | 1860 return end - start; |
1922 return start - end; | 1861 return start - end; |
1923 } | 1862 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1988 | 1927 |
1989 // Now Shift+Right should do nothing, and Shift+Left should reduce. | 1928 // Now Shift+Right should do nothing, and Shift+Left should reduce. |
1990 // At the end, so Shift+Right should do nothing. | 1929 // At the end, so Shift+Right should do nothing. |
1991 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, ui::EF_SHIFT_DOWN)); | 1930 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, ui::EF_SHIFT_DOWN)); |
1992 EXPECT_EQ(2u, GetSelectionSize(omnibox_view)); | 1931 EXPECT_EQ(2u, GetSelectionSize(omnibox_view)); |
1993 | 1932 |
1994 // And Left should reduce by one character. | 1933 // And Left should reduce by one character. |
1995 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, ui::EF_SHIFT_DOWN)); | 1934 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, ui::EF_SHIFT_DOWN)); |
1996 EXPECT_EQ(1u, GetSelectionSize(omnibox_view)); | 1935 EXPECT_EQ(1u, GetSelectionSize(omnibox_view)); |
1997 } | 1936 } |
OLD | NEW |