| OLD | NEW |
| 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 | 5 |
| 6 #include <algorithm> | 6 #include <algorithm> |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
| 13 #include "chrome/browser/infobars/infobar_tab_helper.h" | 13 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 14 #include "chrome/browser/prefs/pref_change_registrar.h" | 14 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/tab_contents/infobar.h" | 16 #include "chrome/browser/tab_contents/infobar.h" |
| 17 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 17 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 18 #include "chrome/browser/translate/translate_infobar_delegate.h" | 18 #include "chrome/browser/translate/translate_infobar_delegate.h" |
| 19 #include "chrome/browser/translate/translate_manager.h" | 19 #include "chrome/browser/translate/translate_manager.h" |
| 20 #include "chrome/browser/translate/translate_prefs.h" | 20 #include "chrome/browser/translate/translate_prefs.h" |
| 21 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 21 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" |
| 22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 23 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
| 24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/common/render_messages.h" | 25 #include "chrome/common/render_messages.h" |
| 26 #include "chrome/test/base/testing_browser_process.h" | 26 #include "chrome/test/base/testing_browser_process.h" |
| 27 #include "chrome/test/base/testing_profile.h" | 27 #include "chrome/test/base/testing_profile.h" |
| 28 #include "content/browser/browser_thread.h" | 28 #include "content/browser/browser_thread.h" |
| 29 #include "content/browser/renderer_host/mock_render_process_host.h" | 29 #include "content/browser/renderer_host/mock_render_process_host.h" |
| 30 #include "content/browser/renderer_host/test_render_view_host.h" | |
| 31 #include "content/browser/tab_contents/navigation_details.h" | 30 #include "content/browser/tab_contents/navigation_details.h" |
| 32 #include "content/browser/tab_contents/test_tab_contents.h" | 31 #include "content/browser/tab_contents/test_tab_contents.h" |
| 33 #include "content/common/notification_details.h" | 32 #include "content/common/notification_details.h" |
| 34 #include "content/common/notification_observer_mock.h" | 33 #include "content/common/notification_observer_mock.h" |
| 35 #include "content/common/notification_registrar.h" | 34 #include "content/common/notification_registrar.h" |
| 36 #include "content/common/view_messages.h" | 35 #include "content/common/view_messages.h" |
| 37 #include "content/test/test_url_fetcher_factory.h" | 36 #include "content/test/test_url_fetcher_factory.h" |
| 38 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
| 39 #include "ipc/ipc_test_sink.h" | 38 #include "ipc/ipc_test_sink.h" |
| 40 #include "testing/gmock/include/gmock/gmock.h" | 39 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 virtual void Observe(int type, | 146 virtual void Observe(int type, |
| 148 const NotificationSource& source, | 147 const NotificationSource& source, |
| 149 const NotificationDetails& details) { | 148 const NotificationDetails& details) { |
| 150 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); | 149 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); |
| 151 removed_infobars_.insert(Details<InfoBarRemovedDetails>(details)->first); | 150 removed_infobars_.insert(Details<InfoBarRemovedDetails>(details)->first); |
| 152 } | 151 } |
| 153 | 152 |
| 154 protected: | 153 protected: |
| 155 virtual void SetUp() { | 154 virtual void SetUp() { |
| 156 // Access the TranslateManager singleton so it is created before we call | 155 // Access the TranslateManager singleton so it is created before we call |
| 157 // RenderViewHostTestHarness::SetUp() to match what's done in Chrome, where | 156 // TabContentsWrapperTestHarness::SetUp() to match what's done in Chrome, |
| 158 // the TranslateManager is created before the TabContents. This matters as | 157 // where the TranslateManager is created before the TabContents. This |
| 159 // they both register for similar events and we want the notifications to | 158 // matters as they both register for similar events and we want the |
| 160 // happen in the same sequence (TranslateManager first, TabContents second). | 159 // notifications to happen in the same sequence (TranslateManager first, |
| 161 // Also clears the translate script so it is fetched everytime and sets the | 160 // TabContents second). Also clears the translate script so it is fetched |
| 162 // expiration delay to a large value by default (in case it was zeroed in | 161 // everytime and sets the expiration delay to a large value by default (in |
| 163 // a previous test). | 162 // case it was zeroed in a previous test). |
| 164 TranslateManager::GetInstance()->ClearTranslateScript(); | 163 TranslateManager::GetInstance()->ClearTranslateScript(); |
| 165 TranslateManager::GetInstance()-> | 164 TranslateManager::GetInstance()-> |
| 166 set_translate_script_expiration_delay(60 * 60 * 1000); | 165 set_translate_script_expiration_delay(60 * 60 * 1000); |
| 167 | 166 |
| 168 TabContentsWrapperTestHarness::SetUp(); | 167 TabContentsWrapperTestHarness::SetUp(); |
| 169 | 168 |
| 170 notification_registrar_.Add(this, | 169 notification_registrar_.Add(this, |
| 171 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 170 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 172 Source<TabContentsWrapper>(contents_wrapper())); | 171 Source<TabContentsWrapper>(contents_wrapper())); |
| 173 } | 172 } |
| (...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1334 NULL); | 1333 NULL); |
| 1335 // Now simulate the URL fetch. | 1334 // Now simulate the URL fetch. |
| 1336 SimulateTranslateScriptURLFetch(true); | 1335 SimulateTranslateScriptURLFetch(true); |
| 1337 // Now the message should have been sent. | 1336 // Now the message should have been sent. |
| 1338 int page_id = 0; | 1337 int page_id = 0; |
| 1339 std::string original_lang, target_lang; | 1338 std::string original_lang, target_lang; |
| 1340 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1339 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 1341 EXPECT_EQ("es", original_lang); | 1340 EXPECT_EQ("es", original_lang); |
| 1342 EXPECT_EQ("en", target_lang); | 1341 EXPECT_EQ("en", target_lang); |
| 1343 } | 1342 } |
| OLD | NEW |