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

Side by Side Diff: chrome/browser/extensions/extension_omnibox_apitest.cc

Issue 6306011: Remove wstring from autocomplete. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 | Annotate | Revision Log
Property Changes:
Deleted: svn:mergeinfo
OLDNEW
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/format_macros.h"
5 #include "base/string_util.h" 6 #include "base/string_util.h"
6 #include "base/stringprintf.h" 7 #include "base/stringprintf.h"
7 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/autocomplete/autocomplete.h" 9 #include "chrome/browser/autocomplete/autocomplete.h"
9 #include "chrome/browser/autocomplete/autocomplete_edit.h" 10 #include "chrome/browser/autocomplete/autocomplete_edit.h"
10 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" 11 #include "chrome/browser/autocomplete/autocomplete_edit_view.h"
11 #include "chrome/browser/autocomplete/autocomplete_match.h" 12 #include "chrome/browser/autocomplete/autocomplete_match.h"
12 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" 13 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
13 #include "chrome/browser/browser_window.h" 14 #include "chrome/browser/browser_window.h"
14 #include "chrome/browser/extensions/extension_apitest.h" 15 #include "chrome/browser/extensions/extension_apitest.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/search_engines/template_url.h" 17 #include "chrome/browser/search_engines/template_url.h"
17 #include "chrome/browser/search_engines/template_url_model.h" 18 #include "chrome/browser/search_engines/template_url_model.h"
18 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/omnibox/location_bar.h" 20 #include "chrome/browser/ui/omnibox/location_bar.h"
20 #include "chrome/common/notification_type.h" 21 #include "chrome/common/notification_type.h"
21 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
22 #include "chrome/test/ui_test_utils.h" 23 #include "chrome/test/ui_test_utils.h"
23 24
24 // Basic test is flaky on ChromeOS. 25 // Basic test is flaky on ChromeOS.
25 // http://crbug.com/52929 26 // http://crbug.com/52929
26 #if defined(OS_CHROMEOS) 27 #if defined(OS_CHROMEOS)
27 #define MAYBE_Basic FLAKY_Basic 28 #define MAYBE_Basic FLAKY_Basic
28 #else 29 #else
29 #define MAYBE_Basic Basic 30 #define MAYBE_Basic Basic
30 #endif 31 #endif
31 32
32 namespace { 33 namespace {
33 34
34 std::wstring AutocompleteResultAsString(const AutocompleteResult& result) { 35 string16 AutocompleteResultAsString(const AutocompleteResult& result) {
35 std::wstring output(base::StringPrintf(L"{%d} ", result.size())); 36 std::string output(base::StringPrintf("{%" PRIuS "} ", result.size()));
evanm 2011/01/24 22:10:25 whaaa, the old code used to work? hate computers.
Avi (use Gerrit) 2011/01/24 22:12:56 Yeah, dunno why. Too bad for me doing the Right Th
36 for (size_t i = 0; i < result.size(); ++i) { 37 for (size_t i = 0; i < result.size(); ++i) {
37 AutocompleteMatch match = result.match_at(i); 38 AutocompleteMatch match = result.match_at(i);
38 std::wstring provider_name(ASCIIToWide(match.provider->name())); 39 std::string provider_name = match.provider->name();
39 output.append(base::StringPrintf(L"[\"%ls\" by \"%ls\"] ", 40 output.append(base::StringPrintf("[\"%s\" by \"%s\"] ",
40 match.contents.c_str(), 41 UTF16ToUTF8(match.contents).c_str(),
41 provider_name.c_str())); 42 provider_name.c_str()));
42 } 43 }
43 return output; 44 return UTF8ToUTF16(output);
44 } 45 }
45 46
46 } // namespace 47 } // namespace
47 48
48 class OmniboxApiTest : public ExtensionApiTest { 49 class OmniboxApiTest : public ExtensionApiTest {
49 protected: 50 protected:
50 LocationBar* GetLocationBar() const { 51 LocationBar* GetLocationBar() const {
51 return browser()->window()->GetLocationBar(); 52 return browser()->window()->GetLocationBar();
52 } 53 }
53 54
(...skipping 27 matching lines...) Expand all
81 // The results depend on the TemplateURLModel being loaded. Make sure it is 82 // The results depend on the TemplateURLModel being loaded. Make sure it is
82 // loaded so that the autocomplete results are consistent. 83 // loaded so that the autocomplete results are consistent.
83 WaitForTemplateURLModelToLoad(); 84 WaitForTemplateURLModelToLoad();
84 85
85 LocationBar* location_bar = GetLocationBar(); 86 LocationBar* location_bar = GetLocationBar();
86 AutocompleteController* autocomplete_controller = GetAutocompleteController(); 87 AutocompleteController* autocomplete_controller = GetAutocompleteController();
87 88
88 // Test that our extension's keyword is suggested to us when we partially type 89 // Test that our extension's keyword is suggested to us when we partially type
89 // it. 90 // it.
90 { 91 {
91 autocomplete_controller->Start(L"keywor", std::wstring(), 92 autocomplete_controller->Start(ASCIIToUTF16("keywor"), string16(),
92 true, false, true, false); 93 true, false, true, false);
93 94
94 WaitForAutocompleteDone(autocomplete_controller); 95 WaitForAutocompleteDone(autocomplete_controller);
95 EXPECT_TRUE(autocomplete_controller->done()); 96 EXPECT_TRUE(autocomplete_controller->done());
96 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); 97 EXPECT_EQ(std::wstring(), location_bar->GetInputString());
97 EXPECT_EQ(std::wstring(), location_bar->location_entry()->GetText()); 98 EXPECT_EQ(string16(), location_bar->location_entry()->GetText());
98 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll()); 99 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll());
99 100
100 // First result should be to search for what was typed, second should be to 101 // First result should be to search for what was typed, second should be to
101 // enter "extension keyword" mode. 102 // enter "extension keyword" mode.
102 const AutocompleteResult& result = autocomplete_controller->result(); 103 const AutocompleteResult& result = autocomplete_controller->result();
103 ASSERT_EQ(2U, result.size()) << AutocompleteResultAsString(result); 104 ASSERT_EQ(2U, result.size()) << AutocompleteResultAsString(result);
104 AutocompleteMatch match = result.match_at(0); 105 AutocompleteMatch match = result.match_at(0);
105 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type); 106 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type);
106 EXPECT_FALSE(match.deletable); 107 EXPECT_FALSE(match.deletable);
107 108
108 match = result.match_at(1); 109 match = result.match_at(1);
109 ASSERT_TRUE(match.template_url); 110 ASSERT_TRUE(match.template_url);
110 EXPECT_TRUE(match.template_url->IsExtensionKeyword()); 111 EXPECT_TRUE(match.template_url->IsExtensionKeyword());
111 EXPECT_EQ(ASCIIToUTF16("keyword"), match.template_url->keyword()); 112 EXPECT_EQ(ASCIIToUTF16("keyword"), match.template_url->keyword());
112 } 113 }
113 114
114 // Test that our extension can send suggestions back to us. 115 // Test that our extension can send suggestions back to us.
115 { 116 {
116 autocomplete_controller->Start(L"keyword suggestio", std::wstring(), 117 autocomplete_controller->Start(ASCIIToUTF16("keyword suggestio"),
117 true, false, true, false); 118 string16(), true, false, true, false);
118 119
119 WaitForAutocompleteDone(autocomplete_controller); 120 WaitForAutocompleteDone(autocomplete_controller);
120 EXPECT_TRUE(autocomplete_controller->done()); 121 EXPECT_TRUE(autocomplete_controller->done());
121 122
122 // First result should be to invoke the keyword with what we typed, 2-4 123 // 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 124 // should be to invoke with suggestions from the extension, and the last
124 // should be to search for what we typed. 125 // should be to search for what we typed.
125 const AutocompleteResult& result = autocomplete_controller->result(); 126 const AutocompleteResult& result = autocomplete_controller->result();
126 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); 127 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result);
127 128
128 ASSERT_TRUE(result.match_at(0).template_url); 129 ASSERT_TRUE(result.match_at(0).template_url);
129 EXPECT_EQ(L"keyword suggestio", result.match_at(0).fill_into_edit); 130 EXPECT_EQ(ASCIIToUTF16("keyword suggestio"),
130 EXPECT_EQ(L"keyword suggestion1", result.match_at(1).fill_into_edit); 131 result.match_at(0).fill_into_edit);
131 EXPECT_EQ(L"keyword suggestion2", result.match_at(2).fill_into_edit); 132 EXPECT_EQ(ASCIIToUTF16("keyword suggestion1"),
132 EXPECT_EQ(L"keyword suggestion3", result.match_at(3).fill_into_edit); 133 result.match_at(1).fill_into_edit);
134 EXPECT_EQ(ASCIIToUTF16("keyword suggestion2"),
135 result.match_at(2).fill_into_edit);
136 EXPECT_EQ(ASCIIToUTF16("keyword suggestion3"),
137 result.match_at(3).fill_into_edit);
133 138
134 std::wstring description = 139 string16 description =
135 L"Description with style: <match>, [dim], (url till end)"; 140 ASCIIToUTF16("Description with style: <match>, [dim], (url till end)");
136 EXPECT_EQ(description, result.match_at(1).contents); 141 EXPECT_EQ(description, result.match_at(1).contents);
137 ASSERT_EQ(6u, result.match_at(1).contents_class.size()); 142 ASSERT_EQ(6u, result.match_at(1).contents_class.size());
138 143
139 EXPECT_EQ(0u, 144 EXPECT_EQ(0u,
140 result.match_at(1).contents_class[0].offset); 145 result.match_at(1).contents_class[0].offset);
141 EXPECT_EQ(ACMatchClassification::NONE, 146 EXPECT_EQ(ACMatchClassification::NONE,
142 result.match_at(1).contents_class[0].style); 147 result.match_at(1).contents_class[0].style);
143 148
144 EXPECT_EQ(description.find('<'), 149 EXPECT_EQ(description.find('<'),
145 result.match_at(1).contents_class[1].offset); 150 result.match_at(1).contents_class[1].offset);
(...skipping 20 matching lines...) Expand all
166 EXPECT_EQ(ACMatchClassification::URL, 171 EXPECT_EQ(ACMatchClassification::URL,
167 result.match_at(1).contents_class[5].style); 172 result.match_at(1).contents_class[5].style);
168 173
169 AutocompleteMatch match = result.match_at(4); 174 AutocompleteMatch match = result.match_at(4);
170 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type); 175 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type);
171 EXPECT_FALSE(match.deletable); 176 EXPECT_FALSE(match.deletable);
172 } 177 }
173 178
174 { 179 {
175 ResultCatcher catcher; 180 ResultCatcher catcher;
176 autocomplete_controller->Start(L"keyword command", std::wstring(), 181 autocomplete_controller->Start(ASCIIToUTF16("keyword command"), string16(),
177 true, false, true, false); 182 true, false, true, false);
178 location_bar->AcceptInput(); 183 location_bar->AcceptInput();
179 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 184 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
180 } 185 }
181 } 186 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_omnibox_api.cc ('k') | chrome/browser/instant/instant_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698