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 17 matching lines...) Expand all Loading... |
28 #include "chrome/common/render_messages.h" | 28 #include "chrome/common/render_messages.h" |
29 #include "chrome/test/base/testing_browser_process.h" | 29 #include "chrome/test/base/testing_browser_process.h" |
30 #include "chrome/test/base/testing_profile.h" | 30 #include "chrome/test/base/testing_profile.h" |
31 #include "content/browser/renderer_host/mock_render_process_host.h" | 31 #include "content/browser/renderer_host/mock_render_process_host.h" |
32 #include "content/browser/tab_contents/test_tab_contents.h" | 32 #include "content/browser/tab_contents/test_tab_contents.h" |
33 #include "content/public/browser/navigation_details.h" | 33 #include "content/public/browser/navigation_details.h" |
34 #include "content/public/browser/navigation_entry.h" | 34 #include "content/public/browser/navigation_entry.h" |
35 #include "content/public/browser/notification_details.h" | 35 #include "content/public/browser/notification_details.h" |
36 #include "content/public/browser/notification_registrar.h" | 36 #include "content/public/browser/notification_registrar.h" |
37 #include "content/test/notification_observer_mock.h" | 37 #include "content/test/notification_observer_mock.h" |
| 38 #include "content/test/render_view_test.h" |
38 #include "content/test/test_browser_thread.h" | 39 #include "content/test/test_browser_thread.h" |
39 #include "content/test/test_url_fetcher_factory.h" | 40 #include "content/test/test_url_fetcher_factory.h" |
40 #include "grit/generated_resources.h" | 41 #include "grit/generated_resources.h" |
41 #include "ipc/ipc_test_sink.h" | 42 #include "ipc/ipc_test_sink.h" |
42 #include "testing/gmock/include/gmock/gmock.h" | 43 #include "testing/gmock/include/gmock/gmock.h" |
43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" | 44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
| 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
44 #include "third_party/cld/languages/public/languages.h" | 46 #include "third_party/cld/languages/public/languages.h" |
45 | 47 |
46 #if defined(USE_WEBKIT_COMPOSITOR) | |
47 #include "content/test/render_view_test.h" | |
48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | |
49 #endif | |
50 | |
51 using content::BrowserThread; | 48 using content::BrowserThread; |
52 using content::NavigationController; | 49 using content::NavigationController; |
53 using content::WebContents; | 50 using content::WebContents; |
54 using testing::_; | 51 using testing::_; |
55 using testing::Pointee; | 52 using testing::Pointee; |
56 using testing::Property; | 53 using testing::Property; |
57 using WebKit::WebContextMenuData; | 54 using WebKit::WebContextMenuData; |
58 | 55 |
59 class TranslateManagerTest : public TabContentsWrapperTestHarness, | 56 class TranslateManagerTest : public TabContentsWrapperTestHarness, |
60 public content::NotificationObserver { | 57 public content::NotificationObserver { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 virtual void Observe(int type, | 154 virtual void Observe(int type, |
158 const content::NotificationSource& source, | 155 const content::NotificationSource& source, |
159 const content::NotificationDetails& details) { | 156 const content::NotificationDetails& details) { |
160 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); | 157 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); |
161 removed_infobars_.insert( | 158 removed_infobars_.insert( |
162 content::Details<InfoBarRemovedDetails>(details)->first); | 159 content::Details<InfoBarRemovedDetails>(details)->first); |
163 } | 160 } |
164 | 161 |
165 protected: | 162 protected: |
166 virtual void SetUp() { | 163 virtual void SetUp() { |
167 #if defined(USE_WEBKIT_COMPOSITOR) | |
168 WebKit::initialize(&webkit_platform_support_); | 164 WebKit::initialize(&webkit_platform_support_); |
169 #endif | |
170 // Access the TranslateManager singleton so it is created before we call | 165 // Access the TranslateManager singleton so it is created before we call |
171 // TabContentsWrapperTestHarness::SetUp() to match what's done in Chrome, | 166 // TabContentsWrapperTestHarness::SetUp() to match what's done in Chrome, |
172 // where the TranslateManager is created before the TabContents. This | 167 // where the TranslateManager is created before the TabContents. This |
173 // matters as they both register for similar events and we want the | 168 // matters as they both register for similar events and we want the |
174 // notifications to happen in the same sequence (TranslateManager first, | 169 // notifications to happen in the same sequence (TranslateManager first, |
175 // TabContents second). Also clears the translate script so it is fetched | 170 // TabContents second). Also clears the translate script so it is fetched |
176 // everytime and sets the expiration delay to a large value by default (in | 171 // everytime and sets the expiration delay to a large value by default (in |
177 // case it was zeroed in a previous test). | 172 // case it was zeroed in a previous test). |
178 TranslateManager::GetInstance()->ClearTranslateScript(); | 173 TranslateManager::GetInstance()->ClearTranslateScript(); |
179 TranslateManager::GetInstance()-> | 174 TranslateManager::GetInstance()-> |
180 set_translate_script_expiration_delay(60 * 60 * 1000); | 175 set_translate_script_expiration_delay(60 * 60 * 1000); |
181 | 176 |
182 TabContentsWrapperTestHarness::SetUp(); | 177 TabContentsWrapperTestHarness::SetUp(); |
183 | 178 |
184 notification_registrar_.Add(this, | 179 notification_registrar_.Add(this, |
185 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 180 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
186 content::Source<InfoBarTabHelper>( | 181 content::Source<InfoBarTabHelper>( |
187 contents_wrapper()->infobar_tab_helper())); | 182 contents_wrapper()->infobar_tab_helper())); |
188 } | 183 } |
189 | 184 |
190 virtual void TearDown() { | 185 virtual void TearDown() { |
191 process()->sink().ClearMessages(); | 186 process()->sink().ClearMessages(); |
192 | 187 |
193 notification_registrar_.Remove(this, | 188 notification_registrar_.Remove(this, |
194 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 189 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
195 content::Source<InfoBarTabHelper>( | 190 content::Source<InfoBarTabHelper>( |
196 contents_wrapper()->infobar_tab_helper())); | 191 contents_wrapper()->infobar_tab_helper())); |
197 | 192 |
198 TabContentsWrapperTestHarness::TearDown(); | 193 TabContentsWrapperTestHarness::TearDown(); |
199 #if defined(USE_WEBKIT_COMPOSITOR) | |
200 WebKit::shutdown(); | 194 WebKit::shutdown(); |
201 #endif | |
202 } | 195 } |
203 | 196 |
204 void SimulateTranslateScriptURLFetch(bool success) { | 197 void SimulateTranslateScriptURLFetch(bool success) { |
205 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 198 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
206 ASSERT_TRUE(fetcher); | 199 ASSERT_TRUE(fetcher); |
207 net::URLRequestStatus status; | 200 net::URLRequestStatus status; |
208 status.set_status(success ? net::URLRequestStatus::SUCCESS : | 201 status.set_status(success ? net::URLRequestStatus::SUCCESS : |
209 net::URLRequestStatus::FAILED); | 202 net::URLRequestStatus::FAILED); |
210 fetcher->set_url(fetcher->GetOriginalURL()); | 203 fetcher->set_url(fetcher->GetOriginalURL()); |
211 fetcher->set_status(status); | 204 fetcher->set_status(status); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 _, | 242 _, |
250 Property(&content::Details<std::string>::ptr, Pointee(path)))); | 243 Property(&content::Details<std::string>::ptr, Pointee(path)))); |
251 } | 244 } |
252 | 245 |
253 content::NotificationObserverMock pref_observer_; | 246 content::NotificationObserverMock pref_observer_; |
254 | 247 |
255 private: | 248 private: |
256 content::NotificationRegistrar notification_registrar_; | 249 content::NotificationRegistrar notification_registrar_; |
257 TestURLFetcherFactory url_fetcher_factory_; | 250 TestURLFetcherFactory url_fetcher_factory_; |
258 content::TestBrowserThread ui_thread_; | 251 content::TestBrowserThread ui_thread_; |
259 #if defined(USE_WEBKIT_COMPOSITOR) | |
260 content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox | 252 content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox |
261 webkit_platform_support_; | 253 webkit_platform_support_; |
262 #endif | |
263 | 254 |
264 // The infobars that have been removed. | 255 // The infobars that have been removed. |
265 // WARNING: the pointers point to deleted objects, use only for comparison. | 256 // WARNING: the pointers point to deleted objects, use only for comparison. |
266 std::set<InfoBarDelegate*> removed_infobars_; | 257 std::set<InfoBarDelegate*> removed_infobars_; |
267 | 258 |
268 DISALLOW_COPY_AND_ASSIGN(TranslateManagerTest); | 259 DISALLOW_COPY_AND_ASSIGN(TranslateManagerTest); |
269 }; | 260 }; |
270 | 261 |
271 // 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. |
272 class NavEntryCommittedObserver : public content::NotificationObserver { | 263 class NavEntryCommittedObserver : public content::NotificationObserver { |
(...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 NULL); | 1425 NULL); |
1435 // Now simulate the URL fetch. | 1426 // Now simulate the URL fetch. |
1436 SimulateTranslateScriptURLFetch(true); | 1427 SimulateTranslateScriptURLFetch(true); |
1437 // Now the message should have been sent. | 1428 // Now the message should have been sent. |
1438 int page_id = 0; | 1429 int page_id = 0; |
1439 std::string original_lang, target_lang; | 1430 std::string original_lang, target_lang; |
1440 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1431 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
1441 EXPECT_EQ("es", original_lang); | 1432 EXPECT_EQ("es", original_lang); |
1442 EXPECT_EQ("en", target_lang); | 1433 EXPECT_EQ("en", target_lang); |
1443 } | 1434 } |
OLD | NEW |