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

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_view_browsertest.cc

Issue 1943683002: Refactor OmniboxEditModel::user_text_ to not include keyword (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test coverage & refactor Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/views/accessibility/navigation_accessibility_uitest_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); 879 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
880 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 880 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
881 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword()); 881 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
882 ASSERT_EQ(search_keyword, omnibox_view->GetText()); 882 ASSERT_EQ(search_keyword, omnibox_view->GetText());
883 883
884 // Trigger keyword mode by space. 884 // Trigger keyword mode by space.
885 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0)); 885 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
886 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 886 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
887 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword()); 887 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
888 ASSERT_TRUE(omnibox_view->GetText().empty()); 888 ASSERT_TRUE(omnibox_view->GetText().empty());
889 size_t start, end;
890 omnibox_view->GetSelectionBounds(&start, &end);
891 EXPECT_EQ(0U, start);
892 EXPECT_EQ(0U, end);
889 893
890 // Revert to keyword hint mode. 894 // Revert to keyword hint mode.
891 omnibox_view->model()->ClearKeyword(); 895 omnibox_view->model()->ClearKeyword();
892 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 896 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
893 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword()); 897 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
894 ASSERT_EQ(search_keyword + base::char16(' '), omnibox_view->GetText()); 898 ASSERT_EQ(search_keyword + base::char16(' '), omnibox_view->GetText());
899 omnibox_view->GetSelectionBounds(&start, &end);
900 EXPECT_EQ(search_keyword.length() + 1, start);
901 EXPECT_EQ(search_keyword.length() + 1, end);
895 902
896 // Keyword should also be accepted by typing an ideographic space. 903 // Keyword should also be accepted by typing an ideographic space.
897 omnibox_view->OnBeforePossibleChange(); 904 omnibox_view->OnBeforePossibleChange();
898 omnibox_view->SetWindowTextAndCaretPos(search_keyword + 905 omnibox_view->SetWindowTextAndCaretPos(search_keyword +
899 base::WideToUTF16(L"\x3000"), search_keyword.length() + 1, false, false); 906 base::WideToUTF16(L"\x3000"), search_keyword.length() + 1, false, false);
900 omnibox_view->OnAfterPossibleChange(true); 907 omnibox_view->OnAfterPossibleChange(true);
901 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 908 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
902 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword()); 909 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
903 ASSERT_TRUE(omnibox_view->GetText().empty()); 910 ASSERT_TRUE(omnibox_view->GetText().empty());
904 911
(...skipping 27 matching lines...) Expand all
932 939
933 // Keyword should be accepted by pressing space in the middle of context and 940 // Keyword should be accepted by pressing space in the middle of context and
934 // just after the keyword. 941 // just after the keyword.
935 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0)); 942 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
936 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, 0)); 943 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, 0));
937 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0)); 944 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
938 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0)); 945 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
939 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 946 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
940 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword()); 947 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
941 ASSERT_EQ(ASCIIToUTF16("a "), omnibox_view->GetText()); 948 ASSERT_EQ(ASCIIToUTF16("a "), omnibox_view->GetText());
942 size_t start, end;
943 omnibox_view->GetSelectionBounds(&start, &end); 949 omnibox_view->GetSelectionBounds(&start, &end);
944 EXPECT_EQ(0U, start); 950 EXPECT_EQ(0U, start);
945 EXPECT_EQ(0U, end); 951 EXPECT_EQ(0U, end);
946 952
947 // Keyword shouldn't be accepted by pasting "foo bar". 953 // Keyword shouldn't be accepted by pasting "foo bar".
948 omnibox_view->SetUserText(base::string16()); 954 omnibox_view->SetUserText(base::string16());
949 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 955 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
950 ASSERT_TRUE(omnibox_view->model()->keyword().empty()); 956 ASSERT_TRUE(omnibox_view->model()->keyword().empty());
951 957
952 omnibox_view->OnBeforePossibleChange(); 958 omnibox_view->OnBeforePossibleChange();
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 // Trigger keyword hint mode. 1389 // Trigger keyword hint mode.
1384 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); 1390 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
1385 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 1391 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1386 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword())); 1392 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
1387 1393
1388 // Trigger keyword mode. 1394 // Trigger keyword mode.
1389 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); 1395 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1390 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 1396 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1391 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword())); 1397 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
1392 1398
1393 // Input something as search text.
1394 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
1395
1396 // Create a new tab. 1399 // Create a new tab.
1397 chrome::NewTab(browser()); 1400 chrome::NewTab(browser());
1398 1401
1399 // Switch back to the first tab. 1402 // Switch back to the first tab.
1400 browser()->tab_strip_model()->ActivateTabAt(0, true); 1403 browser()->tab_strip_model()->ActivateTabAt(0, true);
1401 1404
1402 // Make sure we're still in keyword mode. 1405 // Make sure we're still in keyword mode.
1406 ASSERT_TRUE(omnibox_view->model()->is_keyword_selected());
1403 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword())); 1407 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
1408 ASSERT_EQ(omnibox_view->GetText(), base::string16());
1409
1410 // Input something as search text.
1411 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
1412
1413 // Switch to the second tab and back to the first.
1414 browser()->tab_strip_model()->ActivateTabAt(1, true);
1415 browser()->tab_strip_model()->ActivateTabAt(0, true);
1416
1417 // Make sure we're still in keyword mode.
1418 ASSERT_TRUE(omnibox_view->model()->is_keyword_selected());
1419 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
1420 ASSERT_EQ(omnibox_view->GetText(), base::ASCIIToUTF16(kSearchText));
1404 } 1421 }
1405 1422
1406 // http://crbug.com/133355 1423 // http://crbug.com/133355
1407 #if defined(OS_LINUX) 1424 #if defined(OS_LINUX)
1408 #define MAYBE_CtrlKeyPressedWithInlineAutocompleteTest \ 1425 #define MAYBE_CtrlKeyPressedWithInlineAutocompleteTest \
1409 DISABLED_CtrlKeyPressedWithInlineAutocompleteTest 1426 DISABLED_CtrlKeyPressedWithInlineAutocompleteTest
1410 #else 1427 #else
1411 #define MAYBE_CtrlKeyPressedWithInlineAutocompleteTest \ 1428 #define MAYBE_CtrlKeyPressedWithInlineAutocompleteTest \
1412 CtrlKeyPressedWithInlineAutocompleteTest 1429 CtrlKeyPressedWithInlineAutocompleteTest
1413 #endif 1430 #endif
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 1966
1950 // Now Shift+Right should do nothing, and Shift+Left should reduce. 1967 // Now Shift+Right should do nothing, and Shift+Left should reduce.
1951 // At the end, so Shift+Right should do nothing. 1968 // At the end, so Shift+Right should do nothing.
1952 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, ui::EF_SHIFT_DOWN)); 1969 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, ui::EF_SHIFT_DOWN));
1953 EXPECT_EQ(2u, GetSelectionSize(omnibox_view)); 1970 EXPECT_EQ(2u, GetSelectionSize(omnibox_view));
1954 1971
1955 // And Left should reduce by one character. 1972 // And Left should reduce by one character.
1956 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, ui::EF_SHIFT_DOWN)); 1973 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, ui::EF_SHIFT_DOWN));
1957 EXPECT_EQ(1u, GetSelectionSize(omnibox_view)); 1974 EXPECT_EQ(1u, GetSelectionSize(omnibox_view));
1958 } 1975 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/accessibility/navigation_accessibility_uitest_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698