| Index: chrome/browser/ui/toolbar/toolbar_model_unittest.cc
|
| diff --git a/chrome/browser/ui/toolbar/toolbar_model_unittest.cc b/chrome/browser/ui/toolbar/toolbar_model_unittest.cc
|
| index ac9ea80a515ba420fbf5eab4f64a53aae2c80aca..f1d6f1d1442afdd5ec1f93c74f11a9d722a093fa 100644
|
| --- a/chrome/browser/ui/toolbar/toolbar_model_unittest.cc
|
| +++ b/chrome/browser/ui/toolbar/toolbar_model_unittest.cc
|
| @@ -38,7 +38,7 @@ struct TestItem {
|
| string16 expected_replace_text_inactive;
|
| // The expected text to display when query extraction is active.
|
| string16 expected_replace_text_active;
|
| - bool would_replace;
|
| + ToolbarModel::SearchTermType search_term_type;
|
| bool should_display;
|
| } test_items[] = {
|
| {
|
| @@ -46,7 +46,7 @@ struct TestItem {
|
| ASCIIToUTF16("view-source:www.google.com"),
|
| ASCIIToUTF16("view-source:www.google.com"),
|
| ASCIIToUTF16("view-source:www.google.com"),
|
| - false,
|
| + ToolbarModel::SEARCH_TERM_NONE,
|
| true
|
| },
|
| {
|
| @@ -54,7 +54,7 @@ struct TestItem {
|
| ASCIIToUTF16("view-source:chrome://newtab"),
|
| ASCIIToUTF16("view-source:chrome://newtab"),
|
| ASCIIToUTF16("view-source:chrome://newtab"),
|
| - false,
|
| + ToolbarModel::SEARCH_TERM_NONE,
|
| true
|
| },
|
| {
|
| @@ -62,7 +62,7 @@ struct TestItem {
|
| ASCIIToUTF16("chrome-extension://monkey/balls.html"),
|
| ASCIIToUTF16("chrome-extension://monkey/balls.html"),
|
| ASCIIToUTF16("chrome-extension://monkey/balls.html"),
|
| - false,
|
| + ToolbarModel::SEARCH_TERM_NONE,
|
| true
|
| },
|
| {
|
| @@ -70,7 +70,7 @@ struct TestItem {
|
| string16(),
|
| string16(),
|
| string16(),
|
| - false,
|
| + ToolbarModel::SEARCH_TERM_NONE,
|
| false
|
| },
|
| {
|
| @@ -78,7 +78,7 @@ struct TestItem {
|
| ASCIIToUTF16(chrome::kAboutBlankURL),
|
| ASCIIToUTF16(chrome::kAboutBlankURL),
|
| ASCIIToUTF16(chrome::kAboutBlankURL),
|
| - false,
|
| + ToolbarModel::SEARCH_TERM_NONE,
|
| true
|
| },
|
| {
|
| @@ -86,7 +86,7 @@ struct TestItem {
|
| ASCIIToUTF16("searchurl/?q=tractor+supply"),
|
| ASCIIToUTF16("searchurl/?q=tractor+supply"),
|
| ASCIIToUTF16("searchurl/?q=tractor+supply"),
|
| - false,
|
| + ToolbarModel::SEARCH_TERM_NONE,
|
| true
|
| },
|
| {
|
| @@ -94,7 +94,7 @@ struct TestItem {
|
| ASCIIToUTF16("https://google.ca/search?q=tractor+supply"),
|
| ASCIIToUTF16("https://google.ca/search?q=tractor+supply"),
|
| ASCIIToUTF16("https://google.ca/search?q=tractor+supply"),
|
| - false,
|
| + ToolbarModel::SEARCH_TERM_NONE,
|
| true
|
| },
|
| {
|
| @@ -102,7 +102,7 @@ struct TestItem {
|
| ASCIIToUTF16("https://google.com/search?q=tractor+supply"),
|
| ASCIIToUTF16("https://google.com/search?q=tractor+supply"),
|
| ASCIIToUTF16("https://google.com/search?q=tractor+supply"),
|
| - false,
|
| + ToolbarModel::SEARCH_TERM_NONE,
|
| true
|
| },
|
| {
|
| @@ -110,7 +110,7 @@ struct TestItem {
|
| ASCIIToUTF16("https://google.com/search?q=tractor+supply&espv=1"),
|
| ASCIIToUTF16("https://google.com/search?q=tractor+supply&espv=1"),
|
| ASCIIToUTF16("tractor supply"),
|
| - true,
|
| + ToolbarModel::SEARCH_TERM_NORMAL,
|
| true
|
| },
|
| {
|
| @@ -118,7 +118,7 @@ struct TestItem {
|
| ASCIIToUTF16("https://google.com/search?q=tractorsupply.com&espv=1"),
|
| ASCIIToUTF16("https://google.com/search?q=tractorsupply.com&espv=1"),
|
| ASCIIToUTF16("https://google.com/search?q=tractorsupply.com&espv=1"),
|
| - false,
|
| + ToolbarModel::SEARCH_TERM_NONE,
|
| true
|
| },
|
| {
|
| @@ -126,7 +126,7 @@ struct TestItem {
|
| ASCIIToUTF16("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"),
|
| ASCIIToUTF16("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"),
|
| ASCIIToUTF16("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"),
|
| - false,
|
| + ToolbarModel::SEARCH_TERM_NONE,
|
| true
|
| },
|
| };
|
| @@ -165,16 +165,16 @@ class ToolbarModelTest : public BrowserWithTestWindowTest {
|
| void NavigateAndCheckText(const GURL& url,
|
| const string16& expected_text,
|
| const string16& expected_replace_text,
|
| - bool would_replace,
|
| + ToolbarModel::SearchTermType search_term_type,
|
| bool should_display) {
|
| - NavigateAndCheckTextImpl(url, false, expected_text, would_replace,
|
| + NavigateAndCheckTextImpl(url, false, expected_text, search_term_type,
|
| should_display);
|
| - NavigateAndCheckTextImpl(url, true, expected_replace_text, would_replace,
|
| + NavigateAndCheckTextImpl(url, true, expected_replace_text, search_term_type,
|
| should_display);
|
| }
|
|
|
| void NavigateAndCheckQueries(const std::vector<const char*>& queries,
|
| - bool would_replace) {
|
| + ToolbarModel::SearchTermType search_term_type) {
|
| const std::string kInstantExtendedPrefix(
|
| "https://google.com/search?espv=1&q=");
|
|
|
| @@ -185,11 +185,14 @@ class ToolbarModelTest : public BrowserWithTestWindowTest {
|
| for (size_t i = 0; i < queries.size(); ++i) {
|
| std::string url_string = kInstantExtendedPrefix +
|
| net::EscapeQueryParamValue(queries[i], true);
|
| + std::string expected_text;
|
| + if (search_term_type == ToolbarModel::SEARCH_TERM_NONE)
|
| + expected_text = url_string;
|
| + else
|
| + expected_text = std::string(queries[i]);
|
| NavigateAndCheckTextImpl(GURL(url_string), true,
|
| - ASCIIToUTF16(would_replace ?
|
| - std::string(queries[i]) :
|
| - url_string),
|
| - would_replace, true);
|
| + ASCIIToUTF16(expected_text),
|
| + search_term_type, true);
|
| }
|
| }
|
|
|
| @@ -197,7 +200,7 @@ class ToolbarModelTest : public BrowserWithTestWindowTest {
|
| void NavigateAndCheckTextImpl(const GURL& url,
|
| bool can_replace,
|
| const string16 expected_text,
|
| - bool would_replace,
|
| + ToolbarModel::SearchTermType search_term_type,
|
| bool should_display) {
|
| WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0);
|
| browser()->OpenURL(OpenURLParams(
|
| @@ -216,15 +219,13 @@ class ToolbarModelTest : public BrowserWithTestWindowTest {
|
| // Check while loading.
|
| EXPECT_EQ(should_display, toolbar_model->ShouldDisplayURL());
|
| EXPECT_EQ(expected_text, toolbar_model->GetText(can_replace));
|
| - EXPECT_EQ(would_replace,
|
| - toolbar_model->WouldReplaceSearchURLWithSearchTerms());
|
| + EXPECT_EQ(search_term_type, toolbar_model->GetSearchTermType());
|
|
|
| // Check after commit.
|
| CommitPendingLoad(&contents->GetController());
|
| EXPECT_EQ(should_display, toolbar_model->ShouldDisplayURL());
|
| EXPECT_EQ(expected_text, toolbar_model->GetText(can_replace));
|
| - EXPECT_EQ(would_replace,
|
| - toolbar_model->WouldReplaceSearchURLWithSearchTerms());
|
| + EXPECT_EQ(search_term_type, toolbar_model->GetSearchTermType());
|
| }
|
| };
|
|
|
| @@ -240,7 +241,7 @@ TEST_F(ToolbarModelTest, ShouldDisplayURLQueryExtractionDisabled) {
|
| NavigateAndCheckText(test_item.url,
|
| test_item.expected_text,
|
| test_item.expected_replace_text_inactive,
|
| - false,
|
| + ToolbarModel::SEARCH_TERM_NONE,
|
| test_item.should_display);
|
| }
|
| }
|
| @@ -256,7 +257,7 @@ TEST_F(ToolbarModelTest, ShouldDisplayURLQueryExtractionEnabled) {
|
| NavigateAndCheckText(test_item.url,
|
| test_item.expected_text,
|
| test_item.expected_replace_text_active,
|
| - test_item.would_replace,
|
| + test_item.search_term_type,
|
| test_item.should_display);
|
| }
|
| }
|
| @@ -283,8 +284,8 @@ TEST_F(ToolbarModelTest, DoNotExtractUrls) {
|
| };
|
|
|
| NavigateAndCheckQueries(
|
| - std::vector<const char*>(&kQueries[0],
|
| - &kQueries[arraysize(kQueries)]), false);
|
| + std::vector<const char*>(&kQueries[0], &kQueries[arraysize(kQueries)]),
|
| + ToolbarModel::SEARCH_TERM_NONE);
|
| }
|
|
|
| // Test that replacement does happen for non-URLs.
|
| @@ -302,6 +303,17 @@ TEST_F(ToolbarModelTest, ExtractNonUrls) {
|
| };
|
|
|
| NavigateAndCheckQueries(
|
| - std::vector<const char*>(&kQueries[0],
|
| - &kQueries[arraysize(kQueries)]), true);
|
| + std::vector<const char*>(&kQueries[0], &kQueries[arraysize(kQueries)]),
|
| + ToolbarModel::SEARCH_TERM_NORMAL);
|
| +}
|
| +
|
| +// Verify that URL search terms are correctly identified.
|
| +TEST_F(ToolbarModelTest, ProminentSearchTerm) {
|
| + static const char* const kQueries[] = {
|
| + "example.com"
|
| + };
|
| + browser()->toolbar_model()->SetIsProminentSearchTermUISupported(true);
|
| + NavigateAndCheckQueries(
|
| + std::vector<const char*>(&kQueries[0], &kQueries[arraysize(kQueries)]),
|
| + ToolbarModel::SEARCH_TERM_PROMINENT);
|
| }
|
|
|