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/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
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/renderer_host/mock_render_process_host.h" | 28 #include "content/browser/renderer_host/mock_render_process_host.h" |
29 #include "content/browser/tab_contents/navigation_details.h" | 29 #include "content/browser/tab_contents/navigation_details.h" |
30 #include "content/browser/tab_contents/test_tab_contents.h" | 30 #include "content/browser/tab_contents/test_tab_contents.h" |
31 #include "content/public/browser/notification_details.h" | 31 #include "content/public/browser/notification_details.h" |
32 #include "content/public/browser/notification_registrar.h" | 32 #include "content/public/browser/notification_registrar.h" |
33 #include "content/test/notification_observer_mock.h" | 33 #include "content/test/notification_observer_mock.h" |
34 #include "content/test/render_view_test.h" | |
34 #include "content/test/test_browser_thread.h" | 35 #include "content/test/test_browser_thread.h" |
35 #include "content/test/test_url_fetcher_factory.h" | 36 #include "content/test/test_url_fetcher_factory.h" |
36 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
37 #include "ipc/ipc_test_sink.h" | 38 #include "ipc/ipc_test_sink.h" |
38 #include "testing/gmock/include/gmock/gmock.h" | 39 #include "testing/gmock/include/gmock/gmock.h" |
39 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" | 40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | |
oshima
2011/12/06 18:40:51
move new includes into "if defined(USE_WEBKIT_COMP
piman
2011/12/06 19:30:49
Done.
| |
40 #include "third_party/cld/languages/public/languages.h" | 42 #include "third_party/cld/languages/public/languages.h" |
41 | 43 |
42 using content::BrowserThread; | 44 using content::BrowserThread; |
43 using testing::_; | 45 using testing::_; |
44 using testing::Pointee; | 46 using testing::Pointee; |
45 using testing::Property; | 47 using testing::Property; |
46 using WebKit::WebContextMenuData; | 48 using WebKit::WebContextMenuData; |
47 | 49 |
48 class TranslateManagerTest : public TabContentsWrapperTestHarness, | 50 class TranslateManagerTest : public TabContentsWrapperTestHarness, |
49 public content::NotificationObserver { | 51 public content::NotificationObserver { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 virtual void Observe(int type, | 148 virtual void Observe(int type, |
147 const content::NotificationSource& source, | 149 const content::NotificationSource& source, |
148 const content::NotificationDetails& details) { | 150 const content::NotificationDetails& details) { |
149 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); | 151 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); |
150 removed_infobars_.insert( | 152 removed_infobars_.insert( |
151 content::Details<InfoBarRemovedDetails>(details)->first); | 153 content::Details<InfoBarRemovedDetails>(details)->first); |
152 } | 154 } |
153 | 155 |
154 protected: | 156 protected: |
155 virtual void SetUp() { | 157 virtual void SetUp() { |
158 #if defined(USE_WEBKIT_COMPOSITOR) | |
159 WebKit::initialize(&webkit_platform_support_); | |
160 #endif | |
156 // Access the TranslateManager singleton so it is created before we call | 161 // Access the TranslateManager singleton so it is created before we call |
157 // TabContentsWrapperTestHarness::SetUp() to match what's done in Chrome, | 162 // TabContentsWrapperTestHarness::SetUp() to match what's done in Chrome, |
158 // where the TranslateManager is created before the TabContents. This | 163 // where the TranslateManager is created before the TabContents. This |
159 // matters as they both register for similar events and we want the | 164 // matters as they both register for similar events and we want the |
160 // notifications to happen in the same sequence (TranslateManager first, | 165 // notifications to happen in the same sequence (TranslateManager first, |
161 // TabContents second). Also clears the translate script so it is fetched | 166 // TabContents second). Also clears the translate script so it is fetched |
162 // everytime and sets the expiration delay to a large value by default (in | 167 // everytime and sets the expiration delay to a large value by default (in |
163 // case it was zeroed in a previous test). | 168 // case it was zeroed in a previous test). |
164 TranslateManager::GetInstance()->ClearTranslateScript(); | 169 TranslateManager::GetInstance()->ClearTranslateScript(); |
165 TranslateManager::GetInstance()-> | 170 TranslateManager::GetInstance()-> |
166 set_translate_script_expiration_delay(60 * 60 * 1000); | 171 set_translate_script_expiration_delay(60 * 60 * 1000); |
167 | 172 |
168 TabContentsWrapperTestHarness::SetUp(); | 173 TabContentsWrapperTestHarness::SetUp(); |
169 | 174 |
170 notification_registrar_.Add(this, | 175 notification_registrar_.Add(this, |
171 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 176 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
172 content::Source<InfoBarTabHelper>( | 177 content::Source<InfoBarTabHelper>( |
173 contents_wrapper()->infobar_tab_helper())); | 178 contents_wrapper()->infobar_tab_helper())); |
174 } | 179 } |
175 | 180 |
176 virtual void TearDown() { | 181 virtual void TearDown() { |
177 process()->sink().ClearMessages(); | 182 process()->sink().ClearMessages(); |
178 | 183 |
179 notification_registrar_.Remove(this, | 184 notification_registrar_.Remove(this, |
180 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 185 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
181 content::Source<InfoBarTabHelper>( | 186 content::Source<InfoBarTabHelper>( |
182 contents_wrapper()->infobar_tab_helper())); | 187 contents_wrapper()->infobar_tab_helper())); |
183 | 188 |
184 TabContentsWrapperTestHarness::TearDown(); | 189 TabContentsWrapperTestHarness::TearDown(); |
190 #if defined(USE_WEBKIT_COMPOSITOR) | |
191 WebKit::shutdown(); | |
192 #endif | |
185 } | 193 } |
186 | 194 |
187 void SimulateTranslateScriptURLFetch(bool success) { | 195 void SimulateTranslateScriptURLFetch(bool success) { |
188 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 196 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
189 ASSERT_TRUE(fetcher); | 197 ASSERT_TRUE(fetcher); |
190 net::URLRequestStatus status; | 198 net::URLRequestStatus status; |
191 status.set_status(success ? net::URLRequestStatus::SUCCESS : | 199 status.set_status(success ? net::URLRequestStatus::SUCCESS : |
192 net::URLRequestStatus::FAILED); | 200 net::URLRequestStatus::FAILED); |
193 fetcher->set_url(fetcher->GetOriginalURL()); | 201 fetcher->set_url(fetcher->GetOriginalURL()); |
194 fetcher->set_status(status); | 202 fetcher->set_status(status); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 _, | 240 _, |
233 Property(&content::Details<std::string>::ptr, Pointee(path)))); | 241 Property(&content::Details<std::string>::ptr, Pointee(path)))); |
234 } | 242 } |
235 | 243 |
236 content::NotificationObserverMock pref_observer_; | 244 content::NotificationObserverMock pref_observer_; |
237 | 245 |
238 private: | 246 private: |
239 content::NotificationRegistrar notification_registrar_; | 247 content::NotificationRegistrar notification_registrar_; |
240 TestURLFetcherFactory url_fetcher_factory_; | 248 TestURLFetcherFactory url_fetcher_factory_; |
241 content::TestBrowserThread ui_thread_; | 249 content::TestBrowserThread ui_thread_; |
250 #if defined(USE_WEBKIT_COMPOSITOR) | |
251 content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox | |
252 webkit_platform_support_; | |
253 #endif | |
242 | 254 |
243 // The infobars that have been removed. | 255 // The infobars that have been removed. |
244 // WARNING: the pointers point to deleted objects, use only for comparison. | 256 // WARNING: the pointers point to deleted objects, use only for comparison. |
245 std::set<InfoBarDelegate*> removed_infobars_; | 257 std::set<InfoBarDelegate*> removed_infobars_; |
246 | 258 |
247 DISALLOW_COPY_AND_ASSIGN(TranslateManagerTest); | 259 DISALLOW_COPY_AND_ASSIGN(TranslateManagerTest); |
248 }; | 260 }; |
249 | 261 |
250 // An observer that keeps track of whether a navigation entry was committed. | 262 // An observer that keeps track of whether a navigation entry was committed. |
251 class NavEntryCommittedObserver : public content::NotificationObserver { | 263 class NavEntryCommittedObserver : public content::NotificationObserver { |
(...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1340 NULL); | 1352 NULL); |
1341 // Now simulate the URL fetch. | 1353 // Now simulate the URL fetch. |
1342 SimulateTranslateScriptURLFetch(true); | 1354 SimulateTranslateScriptURLFetch(true); |
1343 // Now the message should have been sent. | 1355 // Now the message should have been sent. |
1344 int page_id = 0; | 1356 int page_id = 0; |
1345 std::string original_lang, target_lang; | 1357 std::string original_lang, target_lang; |
1346 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1358 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
1347 EXPECT_EQ("es", original_lang); | 1359 EXPECT_EQ("es", original_lang); |
1348 EXPECT_EQ("en", target_lang); | 1360 EXPECT_EQ("en", target_lang); |
1349 } | 1361 } |
OLD | NEW |