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

Side by Side Diff: chrome/renderer/translate_helper.h

Issue 12209114: Translate: introduce unittest for TranslateHelper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 10 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
« no previous file with comments | « chrome/chrome_tests_unit.gypi ('k') | chrome/renderer/translate_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef CHROME_RENDERER_TRANSLATE_HELPER_H_ 5 #ifndef CHROME_RENDERER_TRANSLATE_HELPER_H_
6 #define CHROME_RENDERER_TRANSLATE_HELPER_H_ 6 #define CHROME_RENDERER_TRANSLATE_HELPER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/gtest_prod_util.h"
10 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
11 #include "chrome/common/translate_errors.h" 12 #include "chrome/common/translate_errors.h"
12 #include "content/public/renderer/render_view_observer.h" 13 #include "content/public/renderer/render_view_observer.h"
13 14
14 namespace WebKit { 15 namespace WebKit {
15 class WebDocument; 16 class WebDocument;
16 class WebFrame; 17 class WebFrame;
17 } 18 }
18 19
19 // This class deals with page translation. 20 // This class deals with page translation.
20 // There is one TranslateHelper per RenderView. 21 // There is one TranslateHelper per RenderView.
21 22
22 class TranslateHelper : public content::RenderViewObserver { 23 class TranslateHelper : public content::RenderViewObserver {
23 public: 24 public:
24 explicit TranslateHelper(content::RenderView* render_view); 25 explicit TranslateHelper(content::RenderView* render_view);
25 virtual ~TranslateHelper(); 26 virtual ~TranslateHelper();
26 27
27 // Informs us that the page's text has been extracted. 28 // Informs us that the page's text has been extracted.
28 void PageCaptured(const string16& contents); 29 void PageCaptured(const string16& contents);
29 30
30 protected: 31 protected:
31 // Convert language code to the one used in server supporting list.
32 static void ConvertLanguageCodeSynonym(std::string* code);
33
34 // The following methods are protected so they can be overridden in 32 // The following methods are protected so they can be overridden in
35 // unit-tests. 33 // unit-tests.
36 void OnTranslatePage(int page_id, 34 void OnTranslatePage(int page_id,
37 const std::string& translate_script, 35 const std::string& translate_script,
38 const std::string& source_lang, 36 const std::string& source_lang,
39 const std::string& target_lang); 37 const std::string& target_lang);
40 void OnRevertTranslation(int page_id); 38 void OnRevertTranslation(int page_id);
41 39
42 // Returns true if the translate library is available, meaning the JavaScript 40 // Returns true if the translate library is available, meaning the JavaScript
43 // has already been injected in that page. 41 // has already been injected in that page.
(...skipping 17 matching lines...) Expand all
61 // Asks the Translate element in the page what the language of the page is. 59 // Asks the Translate element in the page what the language of the page is.
62 // Can only be called if a translation has happened and was successful. 60 // Can only be called if a translation has happened and was successful.
63 // Returns the language code on success, an empty string on failure. 61 // Returns the language code on success, an empty string on failure.
64 virtual std::string GetOriginalPageLanguage(); 62 virtual std::string GetOriginalPageLanguage();
65 63
66 // Used in unit-tests. Makes the various tasks be posted immediately so that 64 // Used in unit-tests. Makes the various tasks be posted immediately so that
67 // the tests don't have to wait before checking states. 65 // the tests don't have to wait before checking states.
68 virtual bool DontDelayTasks(); 66 virtual bool DontDelayTasks();
69 67
70 private: 68 private:
69 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, LanguageCodeSynonyms);
70
71 // Convert language code to the one used in server supporting list.
72 static void ConvertLanguageCodeSynonym(std::string* code);
73
71 // Returns whether the page associated with |document| is a candidate for 74 // Returns whether the page associated with |document| is a candidate for
72 // translation. Some pages can explictly specify (via a meta-tag) that they 75 // translation. Some pages can explictly specify (via a meta-tag) that they
73 // should not be translated. 76 // should not be translated.
74 static bool IsPageTranslatable(WebKit::WebDocument* document); 77 static bool IsPageTranslatable(WebKit::WebDocument* document);
75 78
76 #if defined(ENABLE_LANGUAGE_DETECTION) 79 #if defined(ENABLE_LANGUAGE_DETECTION)
77 // Returns the ISO 639_1 language code of the specified |text|, or 'unknown' 80 // Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
78 // if it failed. 81 // if it failed.
79 static std::string DetermineTextLanguage(const string16& text); 82 static std::string DetermineTextLanguage(const string16& text);
80 #endif 83 #endif
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 std::string source_lang_; 130 std::string source_lang_;
128 std::string target_lang_; 131 std::string target_lang_;
129 132
130 // Method factory used to make calls to TranslatePageImpl. 133 // Method factory used to make calls to TranslatePageImpl.
131 base::WeakPtrFactory<TranslateHelper> weak_method_factory_; 134 base::WeakPtrFactory<TranslateHelper> weak_method_factory_;
132 135
133 DISALLOW_COPY_AND_ASSIGN(TranslateHelper); 136 DISALLOW_COPY_AND_ASSIGN(TranslateHelper);
134 }; 137 };
135 138
136 #endif // CHROME_RENDERER_TRANSLATE_HELPER_H_ 139 #endif // CHROME_RENDERER_TRANSLATE_HELPER_H_
OLDNEW
« no previous file with comments | « chrome/chrome_tests_unit.gypi ('k') | chrome/renderer/translate_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698