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

Unified Diff: chrome/browser/ui/toolbar/toolbar_model_unittest.cc

Issue 14259008: Instant Extended: Add prominent search term support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix tests Created 7 years, 8 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
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..a4a74d5a83aff6853d009f386ec659bec01ac044 100644
--- a/chrome/browser/ui/toolbar/toolbar_model_unittest.cc
+++ b/chrome/browser/ui/toolbar/toolbar_model_unittest.cc
@@ -20,8 +20,10 @@
#include "chrome/browser/ui/toolbar/toolbar_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/browser_with_test_window_test.h"
+#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/common/ssl_status.h"
#include "content/public/common/url_constants.h"
#include "net/base/escape.h"
@@ -38,7 +40,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::SearchTermsType search_terms_type;
bool should_display;
} test_items[] = {
{
@@ -46,7 +48,7 @@ struct TestItem {
ASCIIToUTF16("view-source:www.google.com"),
ASCIIToUTF16("view-source:www.google.com"),
ASCIIToUTF16("view-source:www.google.com"),
- false,
+ ToolbarModel::NO_SEARCH_TERMS,
true
},
{
@@ -54,7 +56,7 @@ struct TestItem {
ASCIIToUTF16("view-source:chrome://newtab"),
ASCIIToUTF16("view-source:chrome://newtab"),
ASCIIToUTF16("view-source:chrome://newtab"),
- false,
+ ToolbarModel::NO_SEARCH_TERMS,
true
},
{
@@ -62,7 +64,7 @@ struct TestItem {
ASCIIToUTF16("chrome-extension://monkey/balls.html"),
ASCIIToUTF16("chrome-extension://monkey/balls.html"),
ASCIIToUTF16("chrome-extension://monkey/balls.html"),
- false,
+ ToolbarModel::NO_SEARCH_TERMS,
true
},
{
@@ -70,7 +72,7 @@ struct TestItem {
string16(),
string16(),
string16(),
- false,
+ ToolbarModel::NO_SEARCH_TERMS,
false
},
{
@@ -78,7 +80,7 @@ struct TestItem {
ASCIIToUTF16(chrome::kAboutBlankURL),
ASCIIToUTF16(chrome::kAboutBlankURL),
ASCIIToUTF16(chrome::kAboutBlankURL),
- false,
+ ToolbarModel::NO_SEARCH_TERMS,
true
},
{
@@ -86,7 +88,7 @@ struct TestItem {
ASCIIToUTF16("searchurl/?q=tractor+supply"),
ASCIIToUTF16("searchurl/?q=tractor+supply"),
ASCIIToUTF16("searchurl/?q=tractor+supply"),
- false,
+ ToolbarModel::NO_SEARCH_TERMS,
true
},
{
@@ -94,7 +96,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::NO_SEARCH_TERMS,
true
},
{
@@ -102,7 +104,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::NO_SEARCH_TERMS,
true
},
{
@@ -110,7 +112,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::NORMAL_SEARCH_TERMS,
true
},
{
@@ -118,7 +120,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::NO_SEARCH_TERMS,
true
},
{
@@ -126,7 +128,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::NO_SEARCH_TERMS,
true
},
};
@@ -165,16 +167,17 @@ class ToolbarModelTest : public BrowserWithTestWindowTest {
void NavigateAndCheckText(const GURL& url,
const string16& expected_text,
const string16& expected_replace_text,
- bool would_replace,
+ ToolbarModel::SearchTermsType search_terms_type,
bool should_display) {
- NavigateAndCheckTextImpl(url, false, expected_text, would_replace,
- should_display);
- NavigateAndCheckTextImpl(url, true, expected_replace_text, would_replace,
+ NavigateAndCheckTextImpl(url, false, expected_text, search_terms_type,
should_display);
+ NavigateAndCheckTextImpl(url, true, expected_replace_text,
+ search_terms_type, should_display);
}
- void NavigateAndCheckQueries(const std::vector<const char*>& queries,
- bool would_replace) {
+ void NavigateAndCheckQueries(
+ const std::vector<const char*>& queries,
+ ToolbarModel::SearchTermsType search_terms_type) {
const std::string kInstantExtendedPrefix(
"https://google.com/search?espv=1&q=");
@@ -185,11 +188,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_terms_type == ToolbarModel::NO_SEARCH_TERMS)
+ 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_terms_type, true);
}
}
@@ -197,7 +203,7 @@ class ToolbarModelTest : public BrowserWithTestWindowTest {
void NavigateAndCheckTextImpl(const GURL& url,
bool can_replace,
const string16 expected_text,
- bool would_replace,
+ ToolbarModel::SearchTermsType search_terms_type,
bool should_display) {
WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0);
browser()->OpenURL(OpenURLParams(
@@ -214,17 +220,19 @@ class ToolbarModelTest : public BrowserWithTestWindowTest {
ToolbarModel* toolbar_model = browser()->toolbar_model();
// Check while loading.
+ contents->GetController().GetVisibleEntry()->GetSSL().security_style =
+ content::SECURITY_STYLE_AUTHENTICATED;
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_terms_type, toolbar_model->GetSearchTermsType());
// Check after commit.
CommitPendingLoad(&contents->GetController());
+ contents->GetController().GetVisibleEntry()->GetSSL().security_style =
+ content::SECURITY_STYLE_AUTHENTICATED;
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_terms_type, toolbar_model->GetSearchTermsType());
}
};
@@ -240,7 +248,7 @@ TEST_F(ToolbarModelTest, ShouldDisplayURLQueryExtractionDisabled) {
NavigateAndCheckText(test_item.url,
test_item.expected_text,
test_item.expected_replace_text_inactive,
- false,
+ ToolbarModel::NO_SEARCH_TERMS,
test_item.should_display);
}
}
@@ -256,7 +264,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_terms_type,
test_item.should_display);
}
}
@@ -283,8 +291,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::NO_SEARCH_TERMS);
}
// Test that replacement does happen for non-URLs.
@@ -302,6 +310,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::NORMAL_SEARCH_TERMS);
+}
+
+// Verify that URL search terms are correctly identified.
+TEST_F(ToolbarModelTest, ProminentSearchTerm) {
+ static const char* const kQueries[] = {
+ "example.com"
+ };
+ browser()->toolbar_model()->SetSupportsExtractionOfURLLikeSearchTerms(true);
+ NavigateAndCheckQueries(
+ std::vector<const char*>(&kQueries[0], &kQueries[arraysize(kQueries)]),
+ ToolbarModel::URL_LIKE_SEARCH_TERMS);
}
« no previous file with comments | « chrome/browser/ui/toolbar/toolbar_model_impl.cc ('k') | chrome/browser/ui/views/location_bar/location_bar_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698