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

Side by Side Diff: chrome/browser/translate/translate_manager_browsertest.cc

Issue 10542010: TabContentsWrapper -> TabContents, part 2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, rename Created 8 years, 6 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
OLDNEW
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/extensions/test_extension_system.h" 16 #include "chrome/browser/extensions/test_extension_system.h"
17 #include "chrome/browser/infobars/infobar.h" 17 #include "chrome/browser/infobars/infobar.h"
18 #include "chrome/browser/infobars/infobar_tab_helper.h" 18 #include "chrome/browser/infobars/infobar_tab_helper.h"
19 #include "chrome/browser/prefs/pref_change_registrar.h" 19 #include "chrome/browser/prefs/pref_change_registrar.h"
20 #include "chrome/browser/prefs/pref_service.h" 20 #include "chrome/browser/prefs/pref_service.h"
21 #include "chrome/browser/tab_contents/render_view_context_menu.h" 21 #include "chrome/browser/tab_contents/render_view_context_menu.h"
22 #include "chrome/browser/translate/translate_infobar_delegate.h" 22 #include "chrome/browser/translate/translate_infobar_delegate.h"
23 #include "chrome/browser/translate/translate_manager.h" 23 #include "chrome/browser/translate/translate_manager.h"
24 #include "chrome/browser/translate/translate_prefs.h" 24 #include "chrome/browser/translate/translate_prefs.h"
25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
26 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" 26 #include "chrome/browser/ui/tab_contents/test_tab_contents.h"
27 #include "chrome/common/chrome_notification_types.h" 27 #include "chrome/common/chrome_notification_types.h"
28 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
29 #include "chrome/common/render_messages.h" 29 #include "chrome/common/render_messages.h"
30 #include "chrome/test/base/testing_browser_process.h" 30 #include "chrome/test/base/testing_browser_process.h"
31 #include "chrome/test/base/testing_profile.h" 31 #include "chrome/test/base/testing_profile.h"
32 #include "content/public/browser/navigation_details.h" 32 #include "content/public/browser/navigation_details.h"
33 #include "content/public/browser/navigation_entry.h" 33 #include "content/public/browser/navigation_entry.h"
34 #include "content/public/browser/notification_details.h" 34 #include "content/public/browser/notification_details.h"
35 #include "content/public/browser/notification_registrar.h" 35 #include "content/public/browser/notification_registrar.h"
36 #include "content/public/browser/web_contents.h" 36 #include "content/public/browser/web_contents.h"
(...skipping 12 matching lines...) Expand all
49 49
50 using content::BrowserThread; 50 using content::BrowserThread;
51 using content::NavigationController; 51 using content::NavigationController;
52 using content::RenderViewHostTester; 52 using content::RenderViewHostTester;
53 using content::WebContents; 53 using content::WebContents;
54 using testing::_; 54 using testing::_;
55 using testing::Pointee; 55 using testing::Pointee;
56 using testing::Property; 56 using testing::Property;
57 using WebKit::WebContextMenuData; 57 using WebKit::WebContextMenuData;
58 58
59 class TranslateManagerTest : public TabContentsWrapperTestHarness, 59 class TranslateManagerTest : public TabContentsTestHarness,
60 public content::NotificationObserver { 60 public content::NotificationObserver {
61 public: 61 public:
62 TranslateManagerTest() 62 TranslateManagerTest()
63 : ui_thread_(BrowserThread::UI, &message_loop_) { 63 : ui_thread_(BrowserThread::UI, &message_loop_) {
64 } 64 }
65 65
66 // Simulates navigating to a page and getting the page contents and language 66 // Simulates navigating to a page and getting the page contents and language
67 // for that navigation. 67 // for that navigation.
68 void SimulateNavigation(const GURL& url, 68 void SimulateNavigation(const GURL& url,
69 const std::string& lang, 69 const std::string& lang,
(...skipping 24 matching lines...) Expand all
94 *page_id = translate_param.a; 94 *page_id = translate_param.a;
95 // Ignore translate_param.b which is the script injected in the page. 95 // Ignore translate_param.b which is the script injected in the page.
96 if (original_lang) 96 if (original_lang)
97 *original_lang = translate_param.c; 97 *original_lang = translate_param.c;
98 if (target_lang) 98 if (target_lang)
99 *target_lang = translate_param.d; 99 *target_lang = translate_param.d;
100 return true; 100 return true;
101 } 101 }
102 102
103 InfoBarTabHelper* infobar_tab_helper() { 103 InfoBarTabHelper* infobar_tab_helper() {
104 return contents_wrapper()->infobar_tab_helper(); 104 return tab_contents()->infobar_tab_helper();
105 } 105 }
106 106
107 // Returns the translate infobar if there is 1 infobar and it is a translate 107 // Returns the translate infobar if there is 1 infobar and it is a translate
108 // infobar. 108 // infobar.
109 TranslateInfoBarDelegate* GetTranslateInfoBar() { 109 TranslateInfoBarDelegate* GetTranslateInfoBar() {
110 return (infobar_tab_helper()->infobar_count() == 1) ? 110 return (infobar_tab_helper()->infobar_count() == 1) ?
111 infobar_tab_helper()->GetInfoBarDelegateAt(0)-> 111 infobar_tab_helper()->GetInfoBarDelegateAt(0)->
112 AsTranslateInfoBarDelegate() : NULL; 112 AsTranslateInfoBarDelegate() : NULL;
113 } 113 }
114 114
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 const content::NotificationDetails& details) { 161 const content::NotificationDetails& details) {
162 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); 162 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type);
163 removed_infobars_.insert( 163 removed_infobars_.insert(
164 content::Details<InfoBarRemovedDetails>(details)->first); 164 content::Details<InfoBarRemovedDetails>(details)->first);
165 } 165 }
166 166
167 protected: 167 protected:
168 virtual void SetUp() { 168 virtual void SetUp() {
169 WebKit::initialize(webkit_platform_support_.Get()); 169 WebKit::initialize(webkit_platform_support_.Get());
170 // Access the TranslateManager singleton so it is created before we call 170 // Access the TranslateManager singleton so it is created before we call
171 // TabContentsWrapperTestHarness::SetUp() to match what's done in Chrome, 171 // TabContentsTestHarness::SetUp() to match what's done in Chrome,
172 // where the TranslateManager is created before the WebContents. This 172 // where the TranslateManager is created before the WebContents. This
173 // matters as they both register for similar events and we want the 173 // matters as they both register for similar events and we want the
174 // notifications to happen in the same sequence (TranslateManager first, 174 // notifications to happen in the same sequence (TranslateManager first,
175 // WebContents second). Also clears the translate script so it is fetched 175 // WebContents second). Also clears the translate script so it is fetched
176 // everytime and sets the expiration delay to a large value by default (in 176 // everytime and sets the expiration delay to a large value by default (in
177 // case it was zeroed in a previous test). 177 // case it was zeroed in a previous test).
178 TranslateManager::GetInstance()->ClearTranslateScript(); 178 TranslateManager::GetInstance()->ClearTranslateScript();
179 TranslateManager::GetInstance()-> 179 TranslateManager::GetInstance()->
180 set_translate_script_expiration_delay(60 * 60 * 1000); 180 set_translate_script_expiration_delay(60 * 60 * 1000);
181 181
182 TabContentsWrapperTestHarness::SetUp(); 182 TabContentsTestHarness::SetUp();
183 183
184 notification_registrar_.Add(this, 184 notification_registrar_.Add(this,
185 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, 185 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
186 content::Source<InfoBarTabHelper>( 186 content::Source<InfoBarTabHelper>(
187 contents_wrapper()->infobar_tab_helper())); 187 tab_contents()->infobar_tab_helper()));
188 } 188 }
189 189
190 virtual void TearDown() { 190 virtual void TearDown() {
191 process()->sink().ClearMessages(); 191 process()->sink().ClearMessages();
192 192
193 notification_registrar_.Remove(this, 193 notification_registrar_.Remove(this,
194 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, 194 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
195 content::Source<InfoBarTabHelper>( 195 content::Source<InfoBarTabHelper>(
196 contents_wrapper()->infobar_tab_helper())); 196 tab_contents()->infobar_tab_helper()));
197 197
198 TabContentsWrapperTestHarness::TearDown(); 198 TabContentsTestHarness::TearDown();
199 WebKit::shutdown(); 199 WebKit::shutdown();
200 } 200 }
201 201
202 void SimulateTranslateScriptURLFetch(bool success) { 202 void SimulateTranslateScriptURLFetch(bool success) {
203 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 203 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
204 ASSERT_TRUE(fetcher); 204 ASSERT_TRUE(fetcher);
205 net::URLRequestStatus status; 205 net::URLRequestStatus status;
206 status.set_status(success ? net::URLRequestStatus::SUCCESS : 206 status.set_status(success ? net::URLRequestStatus::SUCCESS :
207 net::URLRequestStatus::FAILED); 207 net::URLRequestStatus::FAILED);
208 fetcher->set_url(fetcher->GetOriginalURL()); 208 fetcher->set_url(fetcher->GetOriginalURL());
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 NULL); 1459 NULL);
1460 // Now simulate the URL fetch. 1460 // Now simulate the URL fetch.
1461 SimulateTranslateScriptURLFetch(true); 1461 SimulateTranslateScriptURLFetch(true);
1462 // Now the message should have been sent. 1462 // Now the message should have been sent.
1463 int page_id = 0; 1463 int page_id = 0;
1464 std::string original_lang, target_lang; 1464 std::string original_lang, target_lang;
1465 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); 1465 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang));
1466 EXPECT_EQ("es", original_lang); 1466 EXPECT_EQ("es", original_lang);
1467 EXPECT_EQ("en", target_lang); 1467 EXPECT_EQ("en", target_lang);
1468 } 1468 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698