OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/string_util.h" | 5 #include "base/string_util.h" |
6 #include "base/stringprintf.h" | 6 #include "base/stringprintf.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/autocomplete/autocomplete.h" | 8 #include "chrome/browser/autocomplete/autocomplete.h" |
9 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 9 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
10 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" | 10 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 // Basic test is flaky on ChromeOS. | 24 // Basic test is flaky on ChromeOS. |
25 // http://crbug.com/52929 | 25 // http://crbug.com/52929 |
26 #if defined(OS_CHROMEOS) | 26 #if defined(OS_CHROMEOS) |
27 #define MAYBE_Basic FLAKY_Basic | 27 #define MAYBE_Basic FLAKY_Basic |
28 #else | 28 #else |
29 #define MAYBE_Basic Basic | 29 #define MAYBE_Basic Basic |
30 #endif | 30 #endif |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 std::wstring AutocompleteResultAsString(const AutocompleteResult& result) { | 34 string16 AutocompleteResultAsString(const AutocompleteResult& result) { |
35 std::wstring output(base::StringPrintf(L"{%d} ", result.size())); | 35 std::string output(base::StringPrintf("{%lu} ", result.size())); |
36 for (size_t i = 0; i < result.size(); ++i) { | 36 for (size_t i = 0; i < result.size(); ++i) { |
37 AutocompleteMatch match = result.match_at(i); | 37 AutocompleteMatch match = result.match_at(i); |
38 std::wstring provider_name(ASCIIToWide(match.provider->name())); | 38 std::string provider_name = match.provider->name(); |
39 output.append(base::StringPrintf(L"[\"%ls\" by \"%ls\"] ", | 39 output.append(base::StringPrintf("[\"%s\" by \"%s\"] ", |
40 match.contents.c_str(), | 40 UTF16ToUTF8(match.contents).c_str(), |
41 provider_name.c_str())); | 41 provider_name.c_str())); |
42 } | 42 } |
43 return output; | 43 return UTF8ToUTF16(output); |
44 } | 44 } |
45 | 45 |
46 } // namespace | 46 } // namespace |
47 | 47 |
48 class OmniboxApiTest : public ExtensionApiTest { | 48 class OmniboxApiTest : public ExtensionApiTest { |
49 protected: | 49 protected: |
50 LocationBar* GetLocationBar() const { | 50 LocationBar* GetLocationBar() const { |
51 return browser()->window()->GetLocationBar(); | 51 return browser()->window()->GetLocationBar(); |
52 } | 52 } |
53 | 53 |
(...skipping 27 matching lines...) Expand all Loading... |
81 // The results depend on the TemplateURLModel being loaded. Make sure it is | 81 // The results depend on the TemplateURLModel being loaded. Make sure it is |
82 // loaded so that the autocomplete results are consistent. | 82 // loaded so that the autocomplete results are consistent. |
83 WaitForTemplateURLModelToLoad(); | 83 WaitForTemplateURLModelToLoad(); |
84 | 84 |
85 LocationBar* location_bar = GetLocationBar(); | 85 LocationBar* location_bar = GetLocationBar(); |
86 AutocompleteController* autocomplete_controller = GetAutocompleteController(); | 86 AutocompleteController* autocomplete_controller = GetAutocompleteController(); |
87 | 87 |
88 // Test that our extension's keyword is suggested to us when we partially type | 88 // Test that our extension's keyword is suggested to us when we partially type |
89 // it. | 89 // it. |
90 { | 90 { |
91 autocomplete_controller->Start(L"keywor", std::wstring(), | 91 autocomplete_controller->Start(ASCIIToUTF16("keywor"), string16(), |
92 true, false, true, false); | 92 true, false, true, false); |
93 | 93 |
94 WaitForAutocompleteDone(autocomplete_controller); | 94 WaitForAutocompleteDone(autocomplete_controller); |
95 EXPECT_TRUE(autocomplete_controller->done()); | 95 EXPECT_TRUE(autocomplete_controller->done()); |
96 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); | 96 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); |
97 EXPECT_EQ(std::wstring(), location_bar->location_entry()->GetText()); | 97 EXPECT_EQ(string16(), location_bar->location_entry()->GetText()); |
98 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll()); | 98 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll()); |
99 | 99 |
100 // First result should be to search for what was typed, second should be to | 100 // First result should be to search for what was typed, second should be to |
101 // enter "extension keyword" mode. | 101 // enter "extension keyword" mode. |
102 const AutocompleteResult& result = autocomplete_controller->result(); | 102 const AutocompleteResult& result = autocomplete_controller->result(); |
103 ASSERT_EQ(2U, result.size()) << AutocompleteResultAsString(result); | 103 ASSERT_EQ(2U, result.size()) << AutocompleteResultAsString(result); |
104 AutocompleteMatch match = result.match_at(0); | 104 AutocompleteMatch match = result.match_at(0); |
105 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type); | 105 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type); |
106 EXPECT_FALSE(match.deletable); | 106 EXPECT_FALSE(match.deletable); |
107 | 107 |
108 match = result.match_at(1); | 108 match = result.match_at(1); |
109 ASSERT_TRUE(match.template_url); | 109 ASSERT_TRUE(match.template_url); |
110 EXPECT_TRUE(match.template_url->IsExtensionKeyword()); | 110 EXPECT_TRUE(match.template_url->IsExtensionKeyword()); |
111 EXPECT_EQ(ASCIIToUTF16("keyword"), match.template_url->keyword()); | 111 EXPECT_EQ(ASCIIToUTF16("keyword"), match.template_url->keyword()); |
112 } | 112 } |
113 | 113 |
114 // Test that our extension can send suggestions back to us. | 114 // Test that our extension can send suggestions back to us. |
115 { | 115 { |
116 autocomplete_controller->Start(L"keyword suggestio", std::wstring(), | 116 autocomplete_controller->Start(ASCIIToUTF16("keyword suggestio"), |
117 true, false, true, false); | 117 string16(), true, false, true, false); |
118 | 118 |
119 WaitForAutocompleteDone(autocomplete_controller); | 119 WaitForAutocompleteDone(autocomplete_controller); |
120 EXPECT_TRUE(autocomplete_controller->done()); | 120 EXPECT_TRUE(autocomplete_controller->done()); |
121 | 121 |
122 // First result should be to invoke the keyword with what we typed, 2-4 | 122 // First result should be to invoke the keyword with what we typed, 2-4 |
123 // should be to invoke with suggestions from the extension, and the last | 123 // should be to invoke with suggestions from the extension, and the last |
124 // should be to search for what we typed. | 124 // should be to search for what we typed. |
125 const AutocompleteResult& result = autocomplete_controller->result(); | 125 const AutocompleteResult& result = autocomplete_controller->result(); |
126 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); | 126 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); |
127 | 127 |
128 ASSERT_TRUE(result.match_at(0).template_url); | 128 ASSERT_TRUE(result.match_at(0).template_url); |
129 EXPECT_EQ(L"keyword suggestio", result.match_at(0).fill_into_edit); | 129 EXPECT_EQ(ASCIIToUTF16("keyword suggestio"), |
130 EXPECT_EQ(L"keyword suggestion1", result.match_at(1).fill_into_edit); | 130 result.match_at(0).fill_into_edit); |
131 EXPECT_EQ(L"keyword suggestion2", result.match_at(2).fill_into_edit); | 131 EXPECT_EQ(ASCIIToUTF16("keyword suggestion1"), |
132 EXPECT_EQ(L"keyword suggestion3", result.match_at(3).fill_into_edit); | 132 result.match_at(1).fill_into_edit); |
| 133 EXPECT_EQ(ASCIIToUTF16("keyword suggestion2"), |
| 134 result.match_at(2).fill_into_edit); |
| 135 EXPECT_EQ(ASCIIToUTF16("keyword suggestion3"), |
| 136 result.match_at(3).fill_into_edit); |
133 | 137 |
134 std::wstring description = | 138 string16 description = |
135 L"Description with style: <match>, [dim], (url till end)"; | 139 ASCIIToUTF16("Description with style: <match>, [dim], (url till end)"); |
136 EXPECT_EQ(description, result.match_at(1).contents); | 140 EXPECT_EQ(description, result.match_at(1).contents); |
137 ASSERT_EQ(6u, result.match_at(1).contents_class.size()); | 141 ASSERT_EQ(6u, result.match_at(1).contents_class.size()); |
138 | 142 |
139 EXPECT_EQ(0u, | 143 EXPECT_EQ(0u, |
140 result.match_at(1).contents_class[0].offset); | 144 result.match_at(1).contents_class[0].offset); |
141 EXPECT_EQ(ACMatchClassification::NONE, | 145 EXPECT_EQ(ACMatchClassification::NONE, |
142 result.match_at(1).contents_class[0].style); | 146 result.match_at(1).contents_class[0].style); |
143 | 147 |
144 EXPECT_EQ(description.find('<'), | 148 EXPECT_EQ(description.find('<'), |
145 result.match_at(1).contents_class[1].offset); | 149 result.match_at(1).contents_class[1].offset); |
(...skipping 20 matching lines...) Expand all Loading... |
166 EXPECT_EQ(ACMatchClassification::URL, | 170 EXPECT_EQ(ACMatchClassification::URL, |
167 result.match_at(1).contents_class[5].style); | 171 result.match_at(1).contents_class[5].style); |
168 | 172 |
169 AutocompleteMatch match = result.match_at(4); | 173 AutocompleteMatch match = result.match_at(4); |
170 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type); | 174 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type); |
171 EXPECT_FALSE(match.deletable); | 175 EXPECT_FALSE(match.deletable); |
172 } | 176 } |
173 | 177 |
174 { | 178 { |
175 ResultCatcher catcher; | 179 ResultCatcher catcher; |
176 autocomplete_controller->Start(L"keyword command", std::wstring(), | 180 autocomplete_controller->Start(ASCIIToUTF16("keyword command"), string16(), |
177 true, false, true, false); | 181 true, false, true, false); |
178 location_bar->AcceptInput(); | 182 location_bar->AcceptInput(); |
179 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 183 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
180 } | 184 } |
181 } | 185 } |
OLD | NEW |