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

Side by Side Diff: chrome/renderer/translate/translate_script_browsertest.cc

Issue 378253002: Fix translate namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/strings/stringprintf.h" 5 #include "base/strings/stringprintf.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/test/base/chrome_render_view_test.h" 7 #include "chrome/test/base/chrome_render_view_test.h"
8 #include "components/translate/core/common/translate_errors.h" 8 #include "components/translate/core/common/translate_errors.h"
9 #include "grit/component_resources.h" 9 #include "grit/component_resources.h"
10 #include "third_party/WebKit/public/web/WebLocalFrame.h" 10 #include "third_party/WebKit/public/web/WebLocalFrame.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 137 }
138 138
139 DISALLOW_COPY_AND_ASSIGN(TranslateScriptBrowserTest); 139 DISALLOW_COPY_AND_ASSIGN(TranslateScriptBrowserTest);
140 }; 140 };
141 141
142 // Test if onTranslateElementLoad() succeeds to initialize the element library. 142 // Test if onTranslateElementLoad() succeeds to initialize the element library.
143 TEST_F(TranslateScriptBrowserTest, ElementLoadSuccess) { 143 TEST_F(TranslateScriptBrowserTest, ElementLoadSuccess) {
144 InjectElementLibrary(); 144 InjectElementLibrary();
145 EXPECT_TRUE(IsLibReady()); 145 EXPECT_TRUE(IsLibReady());
146 EXPECT_FALSE(GetError()); 146 EXPECT_FALSE(GetError());
147 EXPECT_EQ(TranslateErrors::NONE, GetErrorCode()); 147 EXPECT_EQ(translate::TranslateErrors::NONE, GetErrorCode());
148 } 148 }
149 149
150 // Test if onTranslateElementLoad() fails to initialize the element library and 150 // Test if onTranslateElementLoad() fails to initialize the element library and
151 // report the right error code. 151 // report the right error code.
152 TEST_F(TranslateScriptBrowserTest, ElementLoadFailure) { 152 TEST_F(TranslateScriptBrowserTest, ElementLoadFailure) {
153 ExecuteScript(kThrowInitializationError); 153 ExecuteScript(kThrowInitializationError);
154 154
155 InjectElementLibrary(); 155 InjectElementLibrary();
156 EXPECT_FALSE(IsLibReady()); 156 EXPECT_FALSE(IsLibReady());
157 EXPECT_TRUE(GetError()); 157 EXPECT_TRUE(GetError());
158 EXPECT_EQ(TranslateErrors::INITIALIZATION_ERROR, GetErrorCode()); 158 EXPECT_EQ(translate::TranslateErrors::INITIALIZATION_ERROR, GetErrorCode());
159 } 159 }
160 160
161 // Test if cr.googleTranslate.translate() works. 161 // Test if cr.googleTranslate.translate() works.
162 TEST_F(TranslateScriptBrowserTest, TranslateSuccess) { 162 TEST_F(TranslateScriptBrowserTest, TranslateSuccess) {
163 InjectElementLibrary(); 163 InjectElementLibrary();
164 EXPECT_TRUE(IsLibReady()); 164 EXPECT_TRUE(IsLibReady());
165 EXPECT_FALSE(GetError()); 165 EXPECT_FALSE(GetError());
166 EXPECT_EQ(TranslateErrors::NONE, GetErrorCode()); 166 EXPECT_EQ(translate::TranslateErrors::NONE, GetErrorCode());
167 167
168 ExecuteScript(kTranslate); 168 ExecuteScript(kTranslate);
169 169
170 EXPECT_FALSE(GetError()); 170 EXPECT_FALSE(GetError());
171 EXPECT_EQ(TranslateErrors::NONE, GetErrorCode()); 171 EXPECT_EQ(translate::TranslateErrors::NONE, GetErrorCode());
172 } 172 }
173 173
174 // Test if cr.googleTranslate.translate() handles library exception correctly. 174 // Test if cr.googleTranslate.translate() handles library exception correctly.
175 TEST_F(TranslateScriptBrowserTest, TranslateFail) { 175 TEST_F(TranslateScriptBrowserTest, TranslateFail) {
176 ExecuteScript(kThrowUnexpectedScriptError); 176 ExecuteScript(kThrowUnexpectedScriptError);
177 177
178 InjectElementLibrary(); 178 InjectElementLibrary();
179 EXPECT_TRUE(IsLibReady()); 179 EXPECT_TRUE(IsLibReady());
180 EXPECT_FALSE(GetError()); 180 EXPECT_FALSE(GetError());
181 EXPECT_EQ(TranslateErrors::NONE, GetErrorCode()); 181 EXPECT_EQ(translate::TranslateErrors::NONE, GetErrorCode());
182 182
183 ExecuteScript(kTranslate); 183 ExecuteScript(kTranslate);
184 184
185 EXPECT_TRUE(GetError()); 185 EXPECT_TRUE(GetError());
186 EXPECT_EQ(TranslateErrors::UNEXPECTED_SCRIPT_ERROR, GetErrorCode()); 186 EXPECT_EQ(translate::TranslateErrors::UNEXPECTED_SCRIPT_ERROR,
187 GetErrorCode());
187 } 188 }
188 189
189 // Test if onTranslateProgress callback handles boolean type error correctly. 190 // Test if onTranslateProgress callback handles boolean type error correctly.
190 // Remove this test once server side changes the API to return a number. 191 // Remove this test once server side changes the API to return a number.
191 TEST_F(TranslateScriptBrowserTest, CallbackGetBooleanError) { 192 TEST_F(TranslateScriptBrowserTest, CallbackGetBooleanError) {
192 ExecuteScript(kCallbackReturnBooleanError); 193 ExecuteScript(kCallbackReturnBooleanError);
193 194
194 InjectElementLibrary(); 195 InjectElementLibrary();
195 EXPECT_TRUE(IsLibReady()); 196 EXPECT_TRUE(IsLibReady());
196 EXPECT_FALSE(GetError()); 197 EXPECT_FALSE(GetError());
197 EXPECT_EQ(TranslateErrors::NONE, GetErrorCode()); 198 EXPECT_EQ(translate::TranslateErrors::NONE, GetErrorCode());
198 199
199 ExecuteScript(kTranslate); 200 ExecuteScript(kTranslate);
200 201
201 EXPECT_TRUE(GetError()); 202 EXPECT_TRUE(GetError());
202 EXPECT_EQ(TranslateErrors::TRANSLATION_ERROR, GetErrorCode()); 203 EXPECT_EQ(translate::TranslateErrors::TRANSLATION_ERROR, GetErrorCode());
203 } 204 }
204 205
205 // Test if onTranslateProgress callback handles number type error correctly and 206 // Test if onTranslateProgress callback handles number type error correctly and
206 // converts it to the proper error code. 207 // converts it to the proper error code.
207 TEST_F(TranslateScriptBrowserTest, CallbackGetNumberError1) { 208 TEST_F(TranslateScriptBrowserTest, CallbackGetNumberError1) {
208 ExecuteScript(kCallbackReturnNumberError); 209 ExecuteScript(kCallbackReturnNumberError);
209 ExecuteScript(GenerateSetCallbackErrorCodeScript(1)); 210 ExecuteScript(GenerateSetCallbackErrorCodeScript(1));
210 211
211 InjectElementLibrary(); 212 InjectElementLibrary();
212 EXPECT_TRUE(IsLibReady()); 213 EXPECT_TRUE(IsLibReady());
213 EXPECT_FALSE(GetError()); 214 EXPECT_FALSE(GetError());
214 EXPECT_EQ(TranslateErrors::NONE, GetErrorCode()); 215 EXPECT_EQ(translate::TranslateErrors::NONE, GetErrorCode());
215 216
216 ExecuteScript(kTranslate); 217 ExecuteScript(kTranslate);
217 218
218 EXPECT_TRUE(GetError()); 219 EXPECT_TRUE(GetError());
219 EXPECT_EQ(TranslateErrors::TRANSLATION_ERROR, GetErrorCode()); 220 EXPECT_EQ(translate::TranslateErrors::TRANSLATION_ERROR, GetErrorCode());
220 } 221 }
221 222
222 // Test if onTranslateProgress callback handles number type error correctly and 223 // Test if onTranslateProgress callback handles number type error correctly and
223 // converts it to the proper error code. 224 // converts it to the proper error code.
224 TEST_F(TranslateScriptBrowserTest, CallbackGetNumberError2) { 225 TEST_F(TranslateScriptBrowserTest, CallbackGetNumberError2) {
225 ExecuteScript(kCallbackReturnNumberError); 226 ExecuteScript(kCallbackReturnNumberError);
226 ExecuteScript(GenerateSetCallbackErrorCodeScript(2)); 227 ExecuteScript(GenerateSetCallbackErrorCodeScript(2));
227 228
228 InjectElementLibrary(); 229 InjectElementLibrary();
229 EXPECT_TRUE(IsLibReady()); 230 EXPECT_TRUE(IsLibReady());
230 EXPECT_FALSE(GetError()); 231 EXPECT_FALSE(GetError());
231 EXPECT_EQ(TranslateErrors::NONE, GetErrorCode()); 232 EXPECT_EQ(translate::TranslateErrors::NONE, GetErrorCode());
232 233
233 ExecuteScript(kTranslate); 234 ExecuteScript(kTranslate);
234 235
235 EXPECT_TRUE(GetError()); 236 EXPECT_TRUE(GetError());
236 EXPECT_EQ(TranslateErrors::UNSUPPORTED_LANGUAGE, GetErrorCode()); 237 EXPECT_EQ(translate::TranslateErrors::UNSUPPORTED_LANGUAGE, GetErrorCode());
237 } 238 }
238 239
239 // TODO(toyoshim): Add test for onLoadJavaScript. 240 // TODO(toyoshim): Add test for onLoadJavaScript.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698