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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_unittest.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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/utf_string_conversions.h"
5 #include "chrome/browser/autocomplete/autocomplete_edit.h" 6 #include "chrome/browser/autocomplete/autocomplete_edit.h"
6 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" 7 #include "chrome/browser/autocomplete/autocomplete_edit_view.h"
7 #include "chrome/test/testing_profile.h" 8 #include "chrome/test/testing_profile.h"
8 #include "third_party/skia/include/core/SkBitmap.h" 9 #include "third_party/skia/include/core/SkBitmap.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 namespace { 12 namespace {
12 13
13 class TestingAutocompleteEditView : public AutocompleteEditView { 14 class TestingAutocompleteEditView : public AutocompleteEditView {
14 public: 15 public:
15 TestingAutocompleteEditView() {} 16 TestingAutocompleteEditView() {}
16 17
17 virtual AutocompleteEditModel* model() { return NULL; } 18 virtual AutocompleteEditModel* model() { return NULL; }
18 virtual const AutocompleteEditModel* model() const { return NULL; } 19 virtual const AutocompleteEditModel* model() const { return NULL; }
19 virtual void SaveStateToTab(TabContents* tab) {} 20 virtual void SaveStateToTab(TabContents* tab) {}
20 virtual void Update(const TabContents* tab_for_state_restoring) {} 21 virtual void Update(const TabContents* tab_for_state_restoring) {}
21 virtual void OpenURL(const GURL& url, 22 virtual void OpenURL(const GURL& url,
22 WindowOpenDisposition disposition, 23 WindowOpenDisposition disposition,
23 PageTransition::Type transition, 24 PageTransition::Type transition,
24 const GURL& alternate_nav_url, 25 const GURL& alternate_nav_url,
25 size_t selected_line, 26 size_t selected_line,
26 const std::wstring& keyword) {} 27 const string16& keyword) {}
27 virtual std::wstring GetText() const { return std::wstring(); } 28 virtual string16 GetText() const { return string16(); }
28 virtual bool IsEditingOrEmpty() const { return true; } 29 virtual bool IsEditingOrEmpty() const { return true; }
29 virtual int GetIcon() const { return 0; } 30 virtual int GetIcon() const { return 0; }
30 virtual void SetUserText(const std::wstring& text) {} 31 virtual void SetUserText(const string16& text) {}
31 virtual void SetUserText(const std::wstring& text, 32 virtual void SetUserText(const string16& text,
32 const std::wstring& display_text, 33 const string16& display_text,
33 bool update_popup) {} 34 bool update_popup) {}
34 virtual void SetWindowTextAndCaretPos(const std::wstring& text, 35 virtual void SetWindowTextAndCaretPos(const string16& text,
35 size_t caret_pos) {} 36 size_t caret_pos) {}
36 virtual void SetForcedQuery() {} 37 virtual void SetForcedQuery() {}
37 virtual bool IsSelectAll() { return false; } 38 virtual bool IsSelectAll() { return false; }
38 virtual bool DeleteAtEndPressed() { return false; } 39 virtual bool DeleteAtEndPressed() { return false; }
39 virtual void GetSelectionBounds(std::wstring::size_type* start, 40 virtual void GetSelectionBounds(string16::size_type* start,
40 std::wstring::size_type* end) {} 41 string16::size_type* end) {}
41 virtual void SelectAll(bool reversed) {} 42 virtual void SelectAll(bool reversed) {}
42 virtual void RevertAll() {} 43 virtual void RevertAll() {}
43 virtual void UpdatePopup() {} 44 virtual void UpdatePopup() {}
44 virtual void ClosePopup() {} 45 virtual void ClosePopup() {}
45 virtual void SetFocus() {} 46 virtual void SetFocus() {}
46 virtual void OnTemporaryTextMaybeChanged(const std::wstring& display_text, 47 virtual void OnTemporaryTextMaybeChanged(const string16& display_text,
47 bool save_original_selection) {} 48 bool save_original_selection) {}
48 virtual bool OnInlineAutocompleteTextMaybeChanged( 49 virtual bool OnInlineAutocompleteTextMaybeChanged(
49 const std::wstring& display_text, size_t user_text_length) { 50 const string16& display_text, size_t user_text_length) {
50 return false; 51 return false;
51 } 52 }
52 virtual void OnRevertTemporaryText() {} 53 virtual void OnRevertTemporaryText() {}
53 virtual void OnBeforePossibleChange() {} 54 virtual void OnBeforePossibleChange() {}
54 virtual bool OnAfterPossibleChange() { return false; } 55 virtual bool OnAfterPossibleChange() { return false; }
55 virtual gfx::NativeView GetNativeView() const { return 0; } 56 virtual gfx::NativeView GetNativeView() const { return 0; }
56 virtual CommandUpdater* GetCommandUpdater() { return NULL; } 57 virtual CommandUpdater* GetCommandUpdater() { return NULL; }
57 virtual void SetInstantSuggestion(const string16& input) {} 58 virtual void SetInstantSuggestion(const string16& input) {}
58 virtual int TextWidth() const { return 0; } 59 virtual int TextWidth() const { return 0; }
59 virtual bool IsImeComposing() const { return false; } 60 virtual bool IsImeComposing() const { return false; }
60 61
61 #if defined(TOOLKIT_VIEWS) 62 #if defined(TOOLKIT_VIEWS)
62 virtual views::View* AddToView(views::View* parent) { return NULL; } 63 virtual views::View* AddToView(views::View* parent) { return NULL; }
63 virtual bool CommitInstantSuggestion( 64 virtual bool CommitInstantSuggestion(
64 const std::wstring& typed_text, 65 const string16& typed_text,
65 const std::wstring& suggested_text) { return false;} 66 const string16& suggested_text) { return false; }
66 #endif 67 #endif
67 68
68 private: 69 private:
69 DISALLOW_COPY_AND_ASSIGN(TestingAutocompleteEditView); 70 DISALLOW_COPY_AND_ASSIGN(TestingAutocompleteEditView);
70 }; 71 };
71 72
72 class TestingAutocompleteEditController : public AutocompleteEditController { 73 class TestingAutocompleteEditController : public AutocompleteEditController {
73 public: 74 public:
74 TestingAutocompleteEditController() {} 75 TestingAutocompleteEditController() {}
75 virtual void OnAutocompleteWillClosePopup() {} 76 virtual void OnAutocompleteWillClosePopup() {}
76 virtual void OnAutocompleteLosingFocus(gfx::NativeView view_gaining_focus) {} 77 virtual void OnAutocompleteLosingFocus(gfx::NativeView view_gaining_focus) {}
77 virtual void OnAutocompleteWillAccept() {} 78 virtual void OnAutocompleteWillAccept() {}
78 virtual bool OnCommitSuggestedText(const std::wstring& typed_text) { 79 virtual bool OnCommitSuggestedText(const string16& typed_text) {
79 return false; 80 return false;
80 } 81 }
81 virtual bool AcceptCurrentInstantPreview() { 82 virtual bool AcceptCurrentInstantPreview() {
82 return false; 83 return false;
83 } 84 }
84 virtual void OnPopupBoundsChanged(const gfx::Rect& bounds) {} 85 virtual void OnPopupBoundsChanged(const gfx::Rect& bounds) {}
85 virtual void OnAutocompleteAccept(const GURL& url, 86 virtual void OnAutocompleteAccept(const GURL& url,
86 WindowOpenDisposition disposition, 87 WindowOpenDisposition disposition,
87 PageTransition::Type transition, 88 PageTransition::Type transition,
88 const GURL& alternate_nav_url) {} 89 const GURL& alternate_nav_url) {}
89 virtual void OnChanged() {} 90 virtual void OnChanged() {}
90 virtual void OnSelectionBoundsChanged() {} 91 virtual void OnSelectionBoundsChanged() {}
91 virtual void OnInputInProgress(bool in_progress) {} 92 virtual void OnInputInProgress(bool in_progress) {}
92 virtual void OnKillFocus() {} 93 virtual void OnKillFocus() {}
93 virtual void OnSetFocus() {} 94 virtual void OnSetFocus() {}
94 virtual SkBitmap GetFavIcon() const { return SkBitmap(); } 95 virtual SkBitmap GetFavIcon() const { return SkBitmap(); }
95 virtual std::wstring GetTitle() const { return std::wstring(); } 96 virtual string16 GetTitle() const { return string16(); }
96 97
97 private: 98 private:
98 DISALLOW_COPY_AND_ASSIGN(TestingAutocompleteEditController); 99 DISALLOW_COPY_AND_ASSIGN(TestingAutocompleteEditController);
99 }; 100 };
100 101
101 } 102 }
102 103
103 typedef testing::Test AutocompleteEditTest; 104 typedef testing::Test AutocompleteEditTest;
104 105
105 // Tests various permutations of AutocompleteModel::AdjustTextForCopy. 106 // Tests various permutations of AutocompleteModel::AdjustTextForCopy.
106 TEST(AutocompleteEditTest, AdjustTextForCopy) { 107 TEST(AutocompleteEditTest, AdjustTextForCopy) {
107 struct Data { 108 struct Data {
108 const wchar_t* perm_text; 109 const char* perm_text;
109 const int sel_start; 110 const int sel_start;
110 const bool is_all_selected; 111 const bool is_all_selected;
111 const wchar_t* input; 112 const char* input;
112 const wchar_t* expected_output; 113 const char* expected_output;
113 const bool write_url; 114 const bool write_url;
114 const char* expected_url; 115 const char* expected_url;
115 } input[] = { 116 } input[] = {
116 // Test that http:// is inserted if all text is selected. 117 // Test that http:// is inserted if all text is selected.
117 { L"a.b/c", 0, true, L"a.b/c", L"http://a.b/c", true, "http://a.b/c" }, 118 { "a.b/c", 0, true, "a.b/c", "http://a.b/c", true, "http://a.b/c" },
118 119
119 // Test that http:// is inserted if the host is selected. 120 // Test that http:// is inserted if the host is selected.
120 { L"a.b/c", 0, false, L"a.b/", L"http://a.b/", true, "http://a.b/" }, 121 { "a.b/c", 0, false, "a.b/", "http://a.b/", true, "http://a.b/" },
121 122
122 // Tests that http:// is inserted if the path is modified. 123 // Tests that http:// is inserted if the path is modified.
123 { L"a.b/c", 0, false, L"a.b/d", L"http://a.b/d", true, "http://a.b/d" }, 124 { "a.b/c", 0, false, "a.b/d", "http://a.b/d", true, "http://a.b/d" },
124 125
125 // Tests that http:// isn't inserted if the host is modified. 126 // Tests that http:// isn't inserted if the host is modified.
126 { L"a.b/c", 0, false, L"a.c/", L"a.c/", false, "" }, 127 { "a.b/c", 0, false, "a.c/", "a.c/", false, "" },
127 128
128 // Tests that http:// isn't inserted if the start of the selection is 1. 129 // Tests that http:// isn't inserted if the start of the selection is 1.
129 { L"a.b/c", 1, false, L"a.b/", L"a.b/", false, "" }, 130 { "a.b/c", 1, false, "a.b/", "a.b/", false, "" },
130 131
131 // Tests that http:// isn't inserted if a portion of the host is selected. 132 // Tests that http:// isn't inserted if a portion of the host is selected.
132 { L"a.com/", 0, false, L"a.co", L"a.co", false, "" }, 133 { "a.com/", 0, false, "a.co", "a.co", false, "" },
133 134
134 // Tests that http:// isn't inserted for an https url after the user nukes 135 // Tests that http:// isn't inserted for an https url after the user nukes
135 // https. 136 // https.
136 { L"https://a.com/", 0, false, L"a.com/", L"a.com/", false, "" }, 137 { "https://a.com/", 0, false, "a.com/", "a.com/", false, "" },
137 138
138 // Tests that http:// isn't inserted if the user adds to the host. 139 // Tests that http:// isn't inserted if the user adds to the host.
139 { L"a.b/", 0, false, L"a.bc/", L"a.bc/", false, "" }, 140 { "a.b/", 0, false, "a.bc/", "a.bc/", false, "" },
140 141
141 // Tests that we don't get double http if the user manually inserts http. 142 // Tests that we don't get double http if the user manually inserts http.
142 { L"a.b/", 0, false, L"http://a.b/", L"http://a.b/", true, "http://a.b/" }, 143 { "a.b/", 0, false, "http://a.b/", "http://a.b/", true, "http://a.b/" },
143 }; 144 };
144 TestingAutocompleteEditView view; 145 TestingAutocompleteEditView view;
145 TestingAutocompleteEditController controller; 146 TestingAutocompleteEditController controller;
146 TestingProfile profile; 147 TestingProfile profile;
147 AutocompleteEditModel model(&view, &controller, &profile); 148 AutocompleteEditModel model(&view, &controller, &profile);
148 149
149 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input); ++i) { 150 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input); ++i) {
150 model.UpdatePermanentText(input[i].perm_text); 151 model.UpdatePermanentText(ASCIIToUTF16(input[i].perm_text));
151 152
152 std::wstring result(input[i].input); 153 string16 result = ASCIIToUTF16(input[i].input);
153 GURL url; 154 GURL url;
154 bool write_url; 155 bool write_url;
155 model.AdjustTextForCopy(input[i].sel_start, input[i].is_all_selected, 156 model.AdjustTextForCopy(input[i].sel_start, input[i].is_all_selected,
156 &result, &url, &write_url); 157 &result, &url, &write_url);
157 EXPECT_EQ(input[i].expected_output, result) << "@: " << i; 158 EXPECT_EQ(ASCIIToUTF16(input[i].expected_output), result) << "@: " << i;
158 EXPECT_EQ(input[i].write_url, write_url) << " @" << i; 159 EXPECT_EQ(input[i].write_url, write_url) << " @" << i;
159 if (write_url) 160 if (write_url)
160 EXPECT_EQ(input[i].expected_url, url.spec()) << " @" << i; 161 EXPECT_EQ(input[i].expected_url, url.spec()) << " @" << i;
161 } 162 }
162 } 163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698