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

Unified Diff: chrome/browser/autocomplete/in_memory_url_index_unittest.cc

Issue 1163963004: [Omnibox] Changing scheme from https:// to http:// results in DCHECK (Always). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed breakages on mac trybot. Created 5 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/autocomplete/url_index_private_data.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autocomplete/in_memory_url_index_unittest.cc
diff --git a/chrome/browser/autocomplete/in_memory_url_index_unittest.cc b/chrome/browser/autocomplete/in_memory_url_index_unittest.cc
index 5c68b4074e9bad4427cd9b4c86c10ffc85a2b8dc..d133754609e00ad568cbf8734e41636af65e4132 100644
--- a/chrome/browser/autocomplete/in_memory_url_index_unittest.cc
+++ b/chrome/browser/autocomplete/in_memory_url_index_unittest.cc
@@ -9,6 +9,7 @@
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
+#include "base/i18n/case_conversion.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/string16.h"
@@ -46,6 +47,26 @@ using base::ASCIIToUTF16;
namespace {
const size_t kMaxMatches = 3;
const char kTestLanguages[] = "en,ja,hi,zh";
+
+// Helper function to set lower case |lower_string| and |lower_terms| (words
+// list) based on supplied |search_string| and |cursor_position|. If
+// |cursor_position| is set and useful (not at either end of the string), allow
+// the |search_string| to be broken at |cursor_position|. We do this by
+// pretending there's a space where the cursor is. |lower_terms| are obtained by
+// splitting the |lower_string| on whitespace into tokens.
+void StringToTerms(const char* search_string,
+ size_t cursor_position,
+ base::string16* lower_string,
+ String16Vector* lower_terms) {
+ *lower_string = base::i18n::ToLower(ASCIIToUTF16(search_string));
+ if ((cursor_position != base::string16::npos) &&
+ (cursor_position < lower_string->length()) && (cursor_position > 0)) {
+ lower_string->insert(cursor_position, base::ASCIIToUTF16(" "));
+ }
+
+ Tokenize(*lower_string, base::kWhitespaceUTF16, lower_terms);
+}
+
} // namespace
// -----------------------------------------------------------------------------
@@ -1193,6 +1214,86 @@ TEST_F(InMemoryURLIndexTest, MAYBE_RebuildFromHistoryIfCacheOld) {
ExpectPrivateDataEqual(*old_data.get(), new_data);
}
+#if defined(OS_MACOSX)
+// FIXME(pritam.nikam): Flaky on mac trybots: C++11 error about initializing
+// explicit constructor with {}.
+#define MAX_TERMS 2
+typedef size_t SizeVector[MAX_TERMS];
+#else
+typedef std::vector<size_t> SizeVector;
+#endif
+
+TEST_F(InMemoryURLIndexTest, AddHistoryMatch) {
+ const struct {
+ const char* search_string;
+ size_t cursor_position;
+ const SizeVector expected_word_starts_offsets;
Mark P 2015/06/10 16:53:01 Instead of this approach, just use a fixed size ar
Pritam Nikam 2015/06/11 03:06:09 Done.
+ } test_cases[] = {
+ /* No punctuations, only cursor position change. */
+ { "ABCD", base::string16::npos, {0} },
+ { "abcd", 0, {0} },
+ { "AbcD", 1, {0, 0} },
+ { "abcd", 4, {0} },
+
+ /* Starting with punctuation. */
+ { ".abcd", base::string16::npos, {1} },
+ { ".abcd", 0, {1} },
+ { "!abcd", 1, {1, 0} },
+ { "::abcd", 1, {1, 1} },
+ { ":abcd", 5, {1} },
+
+ /* Ending with punctuation. */
+ { "abcd://", base::string16::npos, {0} },
+ { "ABCD://", 0, {0} },
+ { "abcd://", 1, {0, 0} },
+ { "abcd://", 4, {0, 3} },
+ { "abcd://", 7, {0} },
+
+ /* Punctuation in the middle. */
+ { "ab.cd", base::string16::npos, {0} },
+ { "ab.cd", 0, {0} },
+ { "ab!cd", 1, {0, 0} },
+ { "AB.cd", 2, {0, 1} },
+ { "AB.cd", 3, {0, 0} },
+ { "ab:cd", 5, {0} },
+
+ /* Hyphenation */
+ { "Ab-cd", base::string16::npos, {0} },
+ { "ab-cd", 0, {0} },
+ { "-abcd", 0, {1} },
+ { "-abcd", 1, {1, 0} },
+ { "abcd-", 2, {0, 0} },
+ { "abcd-", 4, {0, 1} },
+ { "ab-cd", 5, {0} }
+ };
+
+ for (size_t i = 0; i < arraysize(test_cases); ++i) {
+ SCOPED_TRACE(testing::Message()
+ << "search_string = " << test_cases[i].search_string
+ << ", cursor_position = " << test_cases[i].cursor_position);
+
+ base::string16 lower_string;
+ String16Vector lower_terms;
+ StringToTerms(test_cases[i].search_string, test_cases[i].cursor_position,
+ &lower_string, &lower_terms);
+ URLIndexPrivateData::AddHistoryMatch match(nullptr, *GetPrivateData(),
+ kTestLanguages, lower_string,
+ lower_terms, base::Time::Now());
+
+// Verify against expectations.
+#if defined(OS_MACOSX)
+ for (size_t j = 0; j < match.lower_terms_to_word_starts_offsets_.size();
+ ++j) {
+ EXPECT_EQ(test_cases[i].expected_word_starts_offsets[j],
+ match.lower_terms_to_word_starts_offsets_[j]);
+ }
+#else
+ EXPECT_EQ(test_cases[i].expected_word_starts_offsets,
+ match.lower_terms_to_word_starts_offsets_);
+#endif
+ }
+}
+
class InMemoryURLIndexCacheTest : public testing::Test {
public:
InMemoryURLIndexCacheTest() {}
« no previous file with comments | « no previous file | chrome/browser/autocomplete/url_index_private_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698