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" |
(...skipping 21 matching lines...) Expand all Loading... |
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" |
37 #include "content/public/test/mock_notification_observer.h" | 37 #include "content/public/test/mock_notification_observer.h" |
38 #include "content/public/test/mock_render_process_host.h" | 38 #include "content/public/test/mock_render_process_host.h" |
39 #include "content/public/test/render_view_test.h" | 39 #include "content/public/test/render_view_test.h" |
40 #include "content/public/test/test_browser_thread.h" | 40 #include "content/public/test/test_browser_thread.h" |
41 #include "content/public/test/test_renderer_host.h" | 41 #include "content/public/test/test_renderer_host.h" |
42 #include "content/public/test/test_url_fetcher_factory.h" | |
43 #include "grit/generated_resources.h" | 42 #include "grit/generated_resources.h" |
44 #include "ipc/ipc_test_sink.h" | 43 #include "ipc/ipc_test_sink.h" |
| 44 #include "net/url_request/test_url_fetcher_factory.h" |
45 #include "testing/gmock/include/gmock/gmock.h" | 45 #include "testing/gmock/include/gmock/gmock.h" |
| 46 #include "third_party/cld/languages/public/languages.h" |
46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" | 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
48 #include "third_party/cld/languages/public/languages.h" | |
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 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 tab_contents()->infobar_tab_helper())); | 196 tab_contents()->infobar_tab_helper())); |
197 | 197 |
198 TabContentsTestHarness::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 net::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()); |
209 fetcher->set_status(status); | 209 fetcher->set_status(status); |
210 fetcher->set_response_code(success ? 200 : 500); | 210 fetcher->set_response_code(success ? 200 : 500); |
211 fetcher->delegate()->OnURLFetchComplete(fetcher); | 211 fetcher->delegate()->OnURLFetchComplete(fetcher); |
212 } | 212 } |
213 | 213 |
214 void SimulateSupportedLanguagesURLFetch( | 214 void SimulateSupportedLanguagesURLFetch( |
215 bool success, const std::vector<std::string>& languages) { | 215 bool success, const std::vector<std::string>& languages) { |
216 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(1); | 216 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(1); |
217 ASSERT_TRUE(fetcher); | 217 ASSERT_TRUE(fetcher); |
218 net::URLRequestStatus status; | 218 net::URLRequestStatus status; |
219 status.set_status(success ? net::URLRequestStatus::SUCCESS : | 219 status.set_status(success ? net::URLRequestStatus::SUCCESS : |
220 net::URLRequestStatus::FAILED); | 220 net::URLRequestStatus::FAILED); |
221 | 221 |
222 std::string data; | 222 std::string data; |
223 if (success) { | 223 if (success) { |
224 data = base::StringPrintf("%s{'sl': {'bla': 'bla'}, '%s': {", | 224 data = base::StringPrintf("%s{'sl': {'bla': 'bla'}, '%s': {", |
225 TranslateManager::kLanguageListCallbackName, | 225 TranslateManager::kLanguageListCallbackName, |
226 TranslateManager::kTargetLanguagesKey); | 226 TranslateManager::kTargetLanguagesKey); |
(...skipping 18 matching lines...) Expand all Loading... |
245 pref_observer_, | 245 pref_observer_, |
246 Observe(int(chrome::NOTIFICATION_PREF_CHANGED), | 246 Observe(int(chrome::NOTIFICATION_PREF_CHANGED), |
247 _, | 247 _, |
248 Property(&content::Details<std::string>::ptr, Pointee(path)))); | 248 Property(&content::Details<std::string>::ptr, Pointee(path)))); |
249 } | 249 } |
250 | 250 |
251 content::MockNotificationObserver pref_observer_; | 251 content::MockNotificationObserver pref_observer_; |
252 | 252 |
253 private: | 253 private: |
254 content::NotificationRegistrar notification_registrar_; | 254 content::NotificationRegistrar notification_registrar_; |
255 TestURLFetcherFactory url_fetcher_factory_; | 255 net::TestURLFetcherFactory url_fetcher_factory_; |
256 content::TestBrowserThread ui_thread_; | 256 content::TestBrowserThread ui_thread_; |
257 content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox | 257 content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox |
258 webkit_platform_support_; | 258 webkit_platform_support_; |
259 | 259 |
260 // The infobars that have been removed. | 260 // The infobars that have been removed. |
261 // WARNING: the pointers point to deleted objects, use only for comparison. | 261 // WARNING: the pointers point to deleted objects, use only for comparison. |
262 std::set<InfoBarDelegate*> removed_infobars_; | 262 std::set<InfoBarDelegate*> removed_infobars_; |
263 | 263 |
264 DISALLOW_COPY_AND_ASSIGN(TranslateManagerTest); | 264 DISALLOW_COPY_AND_ASSIGN(TranslateManagerTest); |
265 }; | 265 }; |
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
OLD | NEW |