OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/translate/core/browser/language_state.h" | 5 #include "components/translate/core/browser/language_state.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "components/translate/core/browser/language_state.h" | 8 #include "components/translate/core/browser/language_state.h" |
9 #include "components/translate/core/browser/translate_driver.h" | 9 #include "components/translate/core/browser/translate_driver.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "url/gurl.h" |
11 | 12 |
12 namespace { | 13 namespace { |
13 | 14 |
| 15 const std::string kHtmlMimeType = "text/html"; |
| 16 |
14 class MockTranslateDriver : public TranslateDriver { | 17 class MockTranslateDriver : public TranslateDriver { |
15 public: | 18 public: |
16 MockTranslateDriver() | 19 MockTranslateDriver() |
17 : on_is_page_translated_changed_called_(false), | 20 : on_is_page_translated_changed_called_(false), |
18 on_translate_enabled_changed_called_(false), | 21 on_translate_enabled_changed_called_(false), |
19 language_state_(this) { | 22 language_state_(this) { |
20 } | 23 } |
21 | 24 |
22 void Reset() { | 25 void Reset() { |
23 on_is_page_translated_changed_called_ = false; | 26 on_is_page_translated_changed_called_ = false; |
(...skipping 19 matching lines...) Expand all Loading... |
43 } | 46 } |
44 | 47 |
45 virtual void TranslatePage(const std::string& translate_script, | 48 virtual void TranslatePage(const std::string& translate_script, |
46 const std::string& source_lang, | 49 const std::string& source_lang, |
47 const std::string& target_lang) OVERRIDE {} | 50 const std::string& target_lang) OVERRIDE {} |
48 | 51 |
49 virtual void RevertTranslation() OVERRIDE {} | 52 virtual void RevertTranslation() OVERRIDE {} |
50 | 53 |
51 virtual bool IsOffTheRecord() OVERRIDE { return false; } | 54 virtual bool IsOffTheRecord() OVERRIDE { return false; } |
52 | 55 |
| 56 virtual const std::string& GetContentsMimeType() OVERRIDE { |
| 57 return kHtmlMimeType; |
| 58 } |
| 59 |
| 60 virtual const GURL& GetLastCommittedURL() OVERRIDE { |
| 61 return GURL::EmptyGURL(); |
| 62 } |
| 63 |
| 64 virtual const GURL& GetActiveURL() OVERRIDE { return GURL::EmptyGURL(); } |
| 65 |
| 66 virtual const GURL& GetVisibleURL() OVERRIDE { return GURL::EmptyGURL(); } |
| 67 |
| 68 virtual bool HasCurrentPage() OVERRIDE { return true; } |
| 69 |
| 70 virtual int GetCurrentPageID() OVERRIDE { return 0; } |
| 71 |
53 bool on_is_page_translated_changed_called() const { | 72 bool on_is_page_translated_changed_called() const { |
54 return on_is_page_translated_changed_called_; | 73 return on_is_page_translated_changed_called_; |
55 } | 74 } |
56 | 75 |
57 bool on_translate_enabled_changed_called() const { | 76 bool on_translate_enabled_changed_called() const { |
58 return on_translate_enabled_changed_called_; | 77 return on_translate_enabled_changed_called_; |
59 } | 78 } |
60 | 79 |
61 private: | 80 private: |
62 bool on_is_page_translated_changed_called_; | 81 bool on_is_page_translated_changed_called_; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 139 |
121 // Translate. | 140 // Translate. |
122 language_state.SetCurrentLanguage("en"); | 141 language_state.SetCurrentLanguage("en"); |
123 EXPECT_TRUE(language_state.IsPageTranslated()); | 142 EXPECT_TRUE(language_state.IsPageTranslated()); |
124 EXPECT_TRUE(driver->on_is_page_translated_changed_called()); | 143 EXPECT_TRUE(driver->on_is_page_translated_changed_called()); |
125 | 144 |
126 // Translate feature must be enabled after an actual translation. | 145 // Translate feature must be enabled after an actual translation. |
127 EXPECT_TRUE(language_state.translate_enabled()); | 146 EXPECT_TRUE(language_state.translate_enabled()); |
128 EXPECT_TRUE(driver->on_translate_enabled_changed_called()); | 147 EXPECT_TRUE(driver->on_translate_enabled_changed_called()); |
129 } | 148 } |
OLD | NEW |