OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
16 #include "chrome/browser/api/prefs/pref_change_registrar.h" | 16 #include "chrome/browser/api/prefs/pref_change_registrar.h" |
17 #include "chrome/browser/extensions/test_extension_system.h" | 17 #include "chrome/browser/extensions/test_extension_system.h" |
18 #include "chrome/browser/infobars/infobar.h" | 18 #include "chrome/browser/infobars/infobar.h" |
19 #include "chrome/browser/infobars/infobar_tab_helper.h" | 19 #include "chrome/browser/infobars/infobar_tab_helper.h" |
20 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
21 #include "chrome/browser/prefs/session_startup_pref.h" | 21 #include "chrome/browser/prefs/session_startup_pref.h" |
22 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 22 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
23 #include "chrome/browser/translate/translate_infobar_delegate.h" | 23 #include "chrome/browser/translate/translate_infobar_delegate.h" |
24 #include "chrome/browser/translate/translate_manager.h" | 24 #include "chrome/browser/translate/translate_manager.h" |
25 #include "chrome/browser/translate/translate_prefs.h" | 25 #include "chrome/browser/translate/translate_prefs.h" |
26 #include "chrome/browser/translate/translate_tab_helper.h" | 26 #include "chrome/browser/translate/translate_tab_helper.h" |
27 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
28 #include "chrome/browser/ui/browser_tabstrip.h" | 28 #include "chrome/browser/ui/browser_tabstrip.h" |
29 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
30 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" | |
31 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
32 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
33 #include "chrome/common/render_messages.h" | 31 #include "chrome/common/render_messages.h" |
34 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 33 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
35 #include "chrome/test/base/in_process_browser_test.h" | 34 #include "chrome/test/base/in_process_browser_test.h" |
36 #include "chrome/test/base/testing_browser_process.h" | 35 #include "chrome/test/base/testing_browser_process.h" |
37 #include "chrome/test/base/testing_profile.h" | 36 #include "chrome/test/base/testing_profile.h" |
38 #include "chrome/test/base/ui_test_utils.h" | 37 #include "chrome/test/base/ui_test_utils.h" |
39 #include "content/public/browser/navigation_details.h" | 38 #include "content/public/browser/navigation_details.h" |
40 #include "content/public/browser/navigation_entry.h" | 39 #include "content/public/browser/navigation_entry.h" |
41 #include "content/public/browser/notification_details.h" | 40 #include "content/public/browser/notification_details.h" |
42 #include "content/public/browser/notification_registrar.h" | 41 #include "content/public/browser/notification_registrar.h" |
43 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
44 #include "content/public/test/mock_notification_observer.h" | 43 #include "content/public/test/mock_notification_observer.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 return details_; | 84 return details_; |
86 } | 85 } |
87 | 86 |
88 private: | 87 private: |
89 content::LoadCommittedDetails details_; | 88 content::LoadCommittedDetails details_; |
90 content::NotificationRegistrar registrar_; | 89 content::NotificationRegistrar registrar_; |
91 | 90 |
92 DISALLOW_COPY_AND_ASSIGN(NavEntryCommittedObserver); | 91 DISALLOW_COPY_AND_ASSIGN(NavEntryCommittedObserver); |
93 }; | 92 }; |
94 | 93 |
95 class TranslateManagerTest : public TabContentsTestHarness, | 94 class TranslateManagerTest : public ChromeRenderViewHostTestHarness, |
96 public content::NotificationObserver { | 95 public content::NotificationObserver { |
97 public: | 96 public: |
98 TranslateManagerTest() | 97 TranslateManagerTest() |
99 : ui_thread_(BrowserThread::UI, &message_loop_) { | 98 : ui_thread_(BrowserThread::UI, &message_loop_) { |
100 } | 99 } |
101 | 100 |
102 // Simulates navigating to a page and getting the page contents and language | 101 // Simulates navigating to a page and getting the page contents and language |
103 // for that navigation. | 102 // for that navigation. |
104 void SimulateNavigation(const GURL& url, | 103 void SimulateNavigation(const GURL& url, |
105 const std::string& lang, | 104 const std::string& lang, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 const content::NotificationDetails& details) { | 211 const content::NotificationDetails& details) { |
213 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); | 212 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); |
214 removed_infobars_.insert( | 213 removed_infobars_.insert( |
215 content::Details<InfoBarRemovedDetails>(details)->first); | 214 content::Details<InfoBarRemovedDetails>(details)->first); |
216 } | 215 } |
217 | 216 |
218 protected: | 217 protected: |
219 virtual void SetUp() { | 218 virtual void SetUp() { |
220 WebKit::initialize(webkit_platform_support_.Get()); | 219 WebKit::initialize(webkit_platform_support_.Get()); |
221 // Access the TranslateManager singleton so it is created before we call | 220 // Access the TranslateManager singleton so it is created before we call |
222 // TabContentsTestHarness::SetUp() to match what's done in Chrome, | 221 // ChromeRenderViewHostTestHarness::SetUp() to match what's done in Chrome, |
223 // where the TranslateManager is created before the WebContents. This | 222 // where the TranslateManager is created before the WebContents. This |
224 // matters as they both register for similar events and we want the | 223 // matters as they both register for similar events and we want the |
225 // notifications to happen in the same sequence (TranslateManager first, | 224 // notifications to happen in the same sequence (TranslateManager first, |
226 // WebContents second). Also clears the translate script so it is fetched | 225 // WebContents second). Also clears the translate script so it is fetched |
227 // everytime and sets the expiration delay to a large value by default (in | 226 // everytime and sets the expiration delay to a large value by default (in |
228 // case it was zeroed in a previous test). | 227 // case it was zeroed in a previous test). |
229 TranslateManager::GetInstance()->ClearTranslateScript(); | 228 TranslateManager::GetInstance()->ClearTranslateScript(); |
230 TranslateManager::GetInstance()-> | 229 TranslateManager::GetInstance()-> |
231 set_translate_script_expiration_delay(60 * 60 * 1000); | 230 set_translate_script_expiration_delay(60 * 60 * 1000); |
232 | 231 |
233 TabContentsTestHarness::SetUp(); | 232 ChromeRenderViewHostTestHarness::SetUp(); |
| 233 InfoBarTabHelper::CreateForWebContents(web_contents()); |
| 234 TranslateTabHelper::CreateForWebContents(web_contents()); |
234 | 235 |
235 notification_registrar_.Add(this, | 236 notification_registrar_.Add(this, |
236 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 237 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
237 content::Source<InfoBarTabHelper>(infobar_tab_helper())); | 238 content::Source<InfoBarTabHelper>(infobar_tab_helper())); |
238 } | 239 } |
239 | 240 |
240 virtual void TearDown() { | 241 virtual void TearDown() { |
241 process()->sink().ClearMessages(); | 242 process()->sink().ClearMessages(); |
242 | 243 |
243 notification_registrar_.Remove(this, | 244 notification_registrar_.Remove(this, |
244 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 245 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
245 content::Source<InfoBarTabHelper>(infobar_tab_helper())); | 246 content::Source<InfoBarTabHelper>(infobar_tab_helper())); |
246 | 247 |
247 TabContentsTestHarness::TearDown(); | 248 ChromeRenderViewHostTestHarness::TearDown(); |
248 WebKit::shutdown(); | 249 WebKit::shutdown(); |
249 } | 250 } |
250 | 251 |
251 void SimulateTranslateScriptURLFetch(bool success) { | 252 void SimulateTranslateScriptURLFetch(bool success) { |
252 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 253 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
253 ASSERT_TRUE(fetcher); | 254 ASSERT_TRUE(fetcher); |
254 net::URLRequestStatus status; | 255 net::URLRequestStatus status; |
255 status.set_status(success ? net::URLRequestStatus::SUCCESS : | 256 status.set_status(success ? net::URLRequestStatus::SUCCESS : |
256 net::URLRequestStatus::FAILED); | 257 net::URLRequestStatus::FAILED); |
257 fetcher->set_url(fetcher->GetOriginalURL()); | 258 fetcher->set_url(fetcher->GetOriginalURL()); |
(...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1517 | 1518 |
1518 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, TranslateSessionRestore) { | 1519 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, TranslateSessionRestore) { |
1519 WebContents* current_web_contents = chrome::GetActiveWebContents(browser()); | 1520 WebContents* current_web_contents = chrome::GetActiveWebContents(browser()); |
1520 content::Source<WebContents> source(current_web_contents); | 1521 content::Source<WebContents> source(current_web_contents); |
1521 | 1522 |
1522 ui_test_utils::WindowedNotificationObserverWithDetails<std::string> | 1523 ui_test_utils::WindowedNotificationObserverWithDetails<std::string> |
1523 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, | 1524 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, |
1524 source); | 1525 source); |
1525 fr_language_detected_signal.Wait(); | 1526 fr_language_detected_signal.Wait(); |
1526 } | 1527 } |
OLD | NEW |