| 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/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/test/testing_browser_process.h" | 25 #include "chrome/test/testing_browser_process.h" |
| 26 #include "chrome/test/testing_profile.h" | 26 #include "chrome/test/testing_profile.h" |
| 27 #include "content/browser/browser_thread.h" | 27 #include "content/browser/browser_thread.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/renderer_host/test_render_view_host.h" | 29 #include "content/browser/renderer_host/test_render_view_host.h" |
| 30 #include "content/browser/tab_contents/navigation_details.h" | 30 #include "content/browser/tab_contents/navigation_details.h" |
| 31 #include "content/browser/tab_contents/test_tab_contents.h" | 31 #include "content/browser/tab_contents/test_tab_contents.h" |
| 32 #include "content/common/notification_details.h" | 32 #include "content/common/notification_details.h" |
| 33 #include "content/common/notification_observer_mock.h" | 33 #include "content/common/notification_observer_mock.h" |
| 34 #include "content/common/notification_registrar.h" | 34 #include "content/common/notification_registrar.h" |
| 35 #include "content/common/test_url_fetcher_factory.h" | |
| 36 #include "content/common/view_messages.h" | 35 #include "content/common/view_messages.h" |
| 36 #include "content/test/test_url_fetcher_factory.h" |
| 37 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
| 38 #include "ipc/ipc_test_sink.h" | 38 #include "ipc/ipc_test_sink.h" |
| 39 #include "testing/gmock/include/gmock/gmock.h" | 39 #include "testing/gmock/include/gmock/gmock.h" |
| 40 #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/cld/languages/public/languages.h" | 41 #include "third_party/cld/languages/public/languages.h" |
| 42 | 42 |
| 43 using testing::_; | 43 using testing::_; |
| 44 using testing::Pointee; | 44 using testing::Pointee; |
| 45 using testing::Property; | 45 using testing::Property; |
| 46 using WebKit::WebContextMenuData; | 46 using WebKit::WebContextMenuData; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 140 |
| 141 virtual void Observe(int type, | 141 virtual void Observe(int type, |
| 142 const NotificationSource& source, | 142 const NotificationSource& source, |
| 143 const NotificationDetails& details) { | 143 const NotificationDetails& details) { |
| 144 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); | 144 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); |
| 145 removed_infobars_.insert(Details<InfoBarRemovedDetails>(details)->first); | 145 removed_infobars_.insert(Details<InfoBarRemovedDetails>(details)->first); |
| 146 } | 146 } |
| 147 | 147 |
| 148 protected: | 148 protected: |
| 149 virtual void SetUp() { | 149 virtual void SetUp() { |
| 150 URLFetcher::set_factory(&url_fetcher_factory_); | |
| 151 | |
| 152 // Access the TranslateManager singleton so it is created before we call | 150 // Access the TranslateManager singleton so it is created before we call |
| 153 // RenderViewHostTestHarness::SetUp() to match what's done in Chrome, where | 151 // RenderViewHostTestHarness::SetUp() to match what's done in Chrome, where |
| 154 // the TranslateManager is created before the TabContents. This matters as | 152 // the TranslateManager is created before the TabContents. This matters as |
| 155 // they both register for similar events and we want the notifications to | 153 // they both register for similar events and we want the notifications to |
| 156 // happen in the same sequence (TranslateManager first, TabContents second). | 154 // happen in the same sequence (TranslateManager first, TabContents second). |
| 157 // Also clears the translate script so it is fetched everytime and sets the | 155 // Also clears the translate script so it is fetched everytime and sets the |
| 158 // expiration delay to a large value by default (in case it was zeroed in | 156 // expiration delay to a large value by default (in case it was zeroed in |
| 159 // a previous test). | 157 // a previous test). |
| 160 TranslateManager::GetInstance()->ClearTranslateScript(); | 158 TranslateManager::GetInstance()->ClearTranslateScript(); |
| 161 TranslateManager::GetInstance()-> | 159 TranslateManager::GetInstance()-> |
| 162 set_translate_script_expiration_delay(60 * 60 * 1000); | 160 set_translate_script_expiration_delay(60 * 60 * 1000); |
| 163 | 161 |
| 164 TabContentsWrapperTestHarness::SetUp(); | 162 TabContentsWrapperTestHarness::SetUp(); |
| 165 | 163 |
| 166 notification_registrar_.Add(this, | 164 notification_registrar_.Add(this, |
| 167 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 165 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 168 Source<TabContentsWrapper>(contents_wrapper())); | 166 Source<TabContentsWrapper>(contents_wrapper())); |
| 169 } | 167 } |
| 170 | 168 |
| 171 virtual void TearDown() { | 169 virtual void TearDown() { |
| 172 process()->sink().ClearMessages(); | 170 process()->sink().ClearMessages(); |
| 173 | 171 |
| 174 notification_registrar_.Remove(this, | 172 notification_registrar_.Remove(this, |
| 175 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 173 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 176 Source<TabContentsWrapper>(contents_wrapper())); | 174 Source<TabContentsWrapper>(contents_wrapper())); |
| 177 | 175 |
| 178 TabContentsWrapperTestHarness::TearDown(); | 176 TabContentsWrapperTestHarness::TearDown(); |
| 179 | |
| 180 URLFetcher::set_factory(NULL); | |
| 181 } | 177 } |
| 182 | 178 |
| 183 void SimulateTranslateScriptURLFetch(bool success) { | 179 void SimulateTranslateScriptURLFetch(bool success) { |
| 184 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 180 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
| 185 ASSERT_TRUE(fetcher); | 181 ASSERT_TRUE(fetcher); |
| 186 net::URLRequestStatus status; | 182 net::URLRequestStatus status; |
| 187 status.set_status(success ? net::URLRequestStatus::SUCCESS : | 183 status.set_status(success ? net::URLRequestStatus::SUCCESS : |
| 188 net::URLRequestStatus::FAILED); | 184 net::URLRequestStatus::FAILED); |
| 189 fetcher->delegate()->OnURLFetchComplete(fetcher, fetcher->original_url(), | 185 fetcher->delegate()->OnURLFetchComplete(fetcher, fetcher->original_url(), |
| 190 status, success ? 200 : 500, | 186 status, success ? 200 : 500, |
| (...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 NULL); | 1310 NULL); |
| 1315 // Now simulate the URL fetch. | 1311 // Now simulate the URL fetch. |
| 1316 SimulateTranslateScriptURLFetch(true); | 1312 SimulateTranslateScriptURLFetch(true); |
| 1317 // Now the message should have been sent. | 1313 // Now the message should have been sent. |
| 1318 int page_id = 0; | 1314 int page_id = 0; |
| 1319 std::string original_lang, target_lang; | 1315 std::string original_lang, target_lang; |
| 1320 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1316 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 1321 EXPECT_EQ("es", original_lang); | 1317 EXPECT_EQ("es", original_lang); |
| 1322 EXPECT_EQ("en", target_lang); | 1318 EXPECT_EQ("en", target_lang); |
| 1323 } | 1319 } |
| OLD | NEW |