| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 GURL GetNonSecureURL(const std::string& path) const { | 68 GURL GetNonSecureURL(const std::string& path) const { |
| 69 std::string prefix(kNonSecurePrefix); | 69 std::string prefix(kNonSecurePrefix); |
| 70 return embedded_test_server()->GetURL(prefix + path); | 70 return embedded_test_server()->GetURL(prefix + path); |
| 71 } | 71 } |
| 72 | 72 |
| 73 GURL GetSecureURL(const std::string& path) const { | 73 GURL GetSecureURL(const std::string& path) const { |
| 74 std::string prefix(kSecurePrefix); | 74 std::string prefix(kSecurePrefix); |
| 75 return https_server_.GetURL(prefix + path); | 75 return https_server_.GetURL(prefix + path); |
| 76 } | 76 } |
| 77 | 77 |
| 78 TranslateInfoBarDelegate* GetExistingTranslateInfoBarDelegate() { | 78 translate::TranslateInfoBarDelegate* GetExistingTranslateInfoBarDelegate() { |
| 79 if (!infobar_service_) { | 79 if (!infobar_service_) { |
| 80 content::WebContents* web_contents = | 80 content::WebContents* web_contents = |
| 81 browser()->tab_strip_model()->GetActiveWebContents(); | 81 browser()->tab_strip_model()->GetActiveWebContents(); |
| 82 if (web_contents) | 82 if (web_contents) |
| 83 infobar_service_ = InfoBarService::FromWebContents(web_contents); | 83 infobar_service_ = InfoBarService::FromWebContents(web_contents); |
| 84 } | 84 } |
| 85 if (!infobar_service_) { | 85 if (!infobar_service_) { |
| 86 ADD_FAILURE() << "infobar service is not available"; | 86 ADD_FAILURE() << "infobar service is not available"; |
| 87 return NULL; | 87 return NULL; |
| 88 } | 88 } |
| 89 | 89 |
| 90 TranslateInfoBarDelegate* delegate = NULL; | 90 translate::TranslateInfoBarDelegate* delegate = NULL; |
| 91 for (size_t i = 0; i < infobar_service_->infobar_count(); ++i) { | 91 for (size_t i = 0; i < infobar_service_->infobar_count(); ++i) { |
| 92 // Check if the shown infobar is a confirm infobar coming from the | 92 // Check if the shown infobar is a confirm infobar coming from the |
| 93 // |kTranslateSecurityOrigin| flag specified in SetUpCommandLine(). | 93 // |kTranslateSecurityOrigin| flag specified in SetUpCommandLine(). |
| 94 // This infobar appears in all tests of TranslateBrowserTest and can be | 94 // This infobar appears in all tests of TranslateBrowserTest and can be |
| 95 // ignored here. | 95 // ignored here. |
| 96 if (infobar_service_->infobar_at(i)->delegate()-> | 96 if (infobar_service_->infobar_at(i)->delegate()-> |
| 97 AsConfirmInfoBarDelegate()) { | 97 AsConfirmInfoBarDelegate()) { |
| 98 continue; | 98 continue; |
| 99 } | 99 } |
| 100 | 100 |
| 101 TranslateInfoBarDelegate* translate = | 101 translate::TranslateInfoBarDelegate* translate = |
| 102 infobar_service_->infobar_at(i)->delegate()-> | 102 infobar_service_->infobar_at(i) |
| 103 AsTranslateInfoBarDelegate(); | 103 ->delegate() |
| 104 ->AsTranslateInfoBarDelegate(); |
| 104 if (translate) { | 105 if (translate) { |
| 105 EXPECT_FALSE(delegate) << "multiple infobars are shown unexpectedly"; | 106 EXPECT_FALSE(delegate) << "multiple infobars are shown unexpectedly"; |
| 106 delegate = translate; | 107 delegate = translate; |
| 107 continue; | 108 continue; |
| 108 } | 109 } |
| 109 | 110 |
| 110 // Other infobar should not be shown. | 111 // Other infobar should not be shown. |
| 111 EXPECT_TRUE(delegate); | 112 EXPECT_TRUE(delegate); |
| 112 } | 113 } |
| 113 return delegate; | 114 return delegate; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 124 | 125 |
| 125 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, TranslateInIsolatedWorld) { | 126 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, TranslateInIsolatedWorld) { |
| 126 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 | 127 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 |
| 127 if (TranslateService::IsTranslateBubbleEnabled()) | 128 if (TranslateService::IsTranslateBubbleEnabled()) |
| 128 return; | 129 return; |
| 129 | 130 |
| 130 net::TestURLFetcherFactory factory; | 131 net::TestURLFetcherFactory factory; |
| 131 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 132 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 132 | 133 |
| 133 // Check if there is no Translate infobar. | 134 // Check if there is no Translate infobar. |
| 134 TranslateInfoBarDelegate* translate = GetExistingTranslateInfoBarDelegate(); | 135 translate::TranslateInfoBarDelegate* translate = |
| 136 GetExistingTranslateInfoBarDelegate(); |
| 135 EXPECT_FALSE(translate); | 137 EXPECT_FALSE(translate); |
| 136 | 138 |
| 137 // Setup infobar observer. | 139 // Setup infobar observer. |
| 138 content::WindowedNotificationObserver infobar( | 140 content::WindowedNotificationObserver infobar( |
| 139 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 141 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
| 140 content::NotificationService::AllSources()); | 142 content::NotificationService::AllSources()); |
| 141 | 143 |
| 142 // Setup page title observer. | 144 // Setup page title observer. |
| 143 content::WebContents* web_contents = | 145 content::WebContents* web_contents = |
| 144 browser()->tab_strip_model()->GetActiveWebContents(); | 146 browser()->tab_strip_model()->GetActiveWebContents(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 167 " isAvailable: function() {\n" | 169 " isAvailable: function() {\n" |
| 168 " cr.googleTranslate.onLoadJavascript(main_script_url);\n" | 170 " cr.googleTranslate.onLoadJavascript(main_script_url);\n" |
| 169 " return true;\n" | 171 " return true;\n" |
| 170 " },\n" | 172 " },\n" |
| 171 " translatePage: function(sl, tl, cb) {\n" | 173 " translatePage: function(sl, tl, cb) {\n" |
| 172 " cb(1, true);\n" | 174 " cb(1, true);\n" |
| 173 " }\n" | 175 " }\n" |
| 174 "} } } };\n" | 176 "} } } };\n" |
| 175 "cr.googleTranslate.onTranslateElementLoad();\n"; | 177 "cr.googleTranslate.onTranslateElementLoad();\n"; |
| 176 net::TestURLFetcher* fetcher = | 178 net::TestURLFetcher* fetcher = |
| 177 factory.GetFetcherByID(TranslateScript::kFetcherId); | 179 factory.GetFetcherByID(translate::TranslateScript::kFetcherId); |
| 178 ASSERT_TRUE(fetcher); | 180 ASSERT_TRUE(fetcher); |
| 179 net::URLRequestStatus status; | 181 net::URLRequestStatus status; |
| 180 status.set_status(net::URLRequestStatus::SUCCESS); | 182 status.set_status(net::URLRequestStatus::SUCCESS); |
| 181 fetcher->set_status(status); | 183 fetcher->set_status(status); |
| 182 fetcher->set_url(fetcher->GetOriginalURL()); | 184 fetcher->set_url(fetcher->GetOriginalURL()); |
| 183 fetcher->set_response_code(net::HTTP_OK); | 185 fetcher->set_response_code(net::HTTP_OK); |
| 184 fetcher->SetResponseString(element_js); | 186 fetcher->SetResponseString(element_js); |
| 185 fetcher->delegate()->OnURLFetchComplete(fetcher); | 187 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 186 | 188 |
| 187 // Wait for the page title is changed after the test finished. | 189 // Wait for the page title is changed after the test finished. |
| 188 const base::string16 result = watcher.WaitAndGetTitle(); | 190 const base::string16 result = watcher.WaitAndGetTitle(); |
| 189 EXPECT_EQ("PASS", base::UTF16ToASCII(result)); | 191 EXPECT_EQ("PASS", base::UTF16ToASCII(result)); |
| 190 } | 192 } |
| 191 | 193 |
| 192 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, IgnoreRefreshMetaTag) { | 194 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, IgnoreRefreshMetaTag) { |
| 193 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 | 195 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 |
| 194 if (TranslateService::IsTranslateBubbleEnabled()) | 196 if (TranslateService::IsTranslateBubbleEnabled()) |
| 195 return; | 197 return; |
| 196 | 198 |
| 197 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 199 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 198 | 200 |
| 199 // Check if there is no Translate infobar. | 201 // Check if there is no Translate infobar. |
| 200 TranslateInfoBarDelegate* translate = GetExistingTranslateInfoBarDelegate(); | 202 translate::TranslateInfoBarDelegate* translate = |
| 203 GetExistingTranslateInfoBarDelegate(); |
| 201 EXPECT_FALSE(translate); | 204 EXPECT_FALSE(translate); |
| 202 | 205 |
| 203 // Setup page title observer. | 206 // Setup page title observer. |
| 204 content::WebContents* web_contents = | 207 content::WebContents* web_contents = |
| 205 browser()->tab_strip_model()->GetActiveWebContents(); | 208 browser()->tab_strip_model()->GetActiveWebContents(); |
| 206 ASSERT_TRUE(web_contents); | 209 ASSERT_TRUE(web_contents); |
| 207 content::TitleWatcher watcher(web_contents, base::ASCIIToUTF16("PASS")); | 210 content::TitleWatcher watcher(web_contents, base::ASCIIToUTF16("PASS")); |
| 208 watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); | 211 watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); |
| 209 | 212 |
| 210 // Visit a test page. | 213 // Visit a test page. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 223 | 226 |
| 224 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, | 227 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, |
| 225 IgnoreRefreshMetaTagInCaseInsensitive) { | 228 IgnoreRefreshMetaTagInCaseInsensitive) { |
| 226 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 | 229 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 |
| 227 if (TranslateService::IsTranslateBubbleEnabled()) | 230 if (TranslateService::IsTranslateBubbleEnabled()) |
| 228 return; | 231 return; |
| 229 | 232 |
| 230 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 233 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 231 | 234 |
| 232 // Check if there is no Translate infobar. | 235 // Check if there is no Translate infobar. |
| 233 TranslateInfoBarDelegate* translate = GetExistingTranslateInfoBarDelegate(); | 236 translate::TranslateInfoBarDelegate* translate = |
| 237 GetExistingTranslateInfoBarDelegate(); |
| 234 EXPECT_FALSE(translate); | 238 EXPECT_FALSE(translate); |
| 235 | 239 |
| 236 // Setup page title observer. | 240 // Setup page title observer. |
| 237 content::WebContents* web_contents = | 241 content::WebContents* web_contents = |
| 238 browser()->tab_strip_model()->GetActiveWebContents(); | 242 browser()->tab_strip_model()->GetActiveWebContents(); |
| 239 ASSERT_TRUE(web_contents); | 243 ASSERT_TRUE(web_contents); |
| 240 content::TitleWatcher watcher(web_contents, base::ASCIIToUTF16("PASS")); | 244 content::TitleWatcher watcher(web_contents, base::ASCIIToUTF16("PASS")); |
| 241 watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); | 245 watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); |
| 242 | 246 |
| 243 // Visit a test page. | 247 // Visit a test page. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 255 } | 259 } |
| 256 | 260 |
| 257 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, IgnoreRefreshMetaTagAtOnload) { | 261 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, IgnoreRefreshMetaTagAtOnload) { |
| 258 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 | 262 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 |
| 259 if (TranslateService::IsTranslateBubbleEnabled()) | 263 if (TranslateService::IsTranslateBubbleEnabled()) |
| 260 return; | 264 return; |
| 261 | 265 |
| 262 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 266 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 263 | 267 |
| 264 // Check if there is no Translate infobar. | 268 // Check if there is no Translate infobar. |
| 265 TranslateInfoBarDelegate* translate = GetExistingTranslateInfoBarDelegate(); | 269 translate::TranslateInfoBarDelegate* translate = |
| 270 GetExistingTranslateInfoBarDelegate(); |
| 266 EXPECT_FALSE(translate); | 271 EXPECT_FALSE(translate); |
| 267 | 272 |
| 268 // Setup page title observer. | 273 // Setup page title observer. |
| 269 content::WebContents* web_contents = | 274 content::WebContents* web_contents = |
| 270 browser()->tab_strip_model()->GetActiveWebContents(); | 275 browser()->tab_strip_model()->GetActiveWebContents(); |
| 271 ASSERT_TRUE(web_contents); | 276 ASSERT_TRUE(web_contents); |
| 272 content::TitleWatcher watcher(web_contents, base::ASCIIToUTF16("PASS")); | 277 content::TitleWatcher watcher(web_contents, base::ASCIIToUTF16("PASS")); |
| 273 watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); | 278 watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); |
| 274 | 279 |
| 275 // Visit a test page. | 280 // Visit a test page. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 287 } | 292 } |
| 288 | 293 |
| 289 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocation) { | 294 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocation) { |
| 290 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 | 295 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 |
| 291 if (TranslateService::IsTranslateBubbleEnabled()) | 296 if (TranslateService::IsTranslateBubbleEnabled()) |
| 292 return; | 297 return; |
| 293 | 298 |
| 294 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 299 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 295 | 300 |
| 296 // Check if there is no Translate infobar. | 301 // Check if there is no Translate infobar. |
| 297 TranslateInfoBarDelegate* translate = GetExistingTranslateInfoBarDelegate(); | 302 translate::TranslateInfoBarDelegate* translate = |
| 303 GetExistingTranslateInfoBarDelegate(); |
| 298 EXPECT_FALSE(translate); | 304 EXPECT_FALSE(translate); |
| 299 | 305 |
| 300 // Setup page title observer. | 306 // Setup page title observer. |
| 301 content::WebContents* web_contents = | 307 content::WebContents* web_contents = |
| 302 browser()->tab_strip_model()->GetActiveWebContents(); | 308 browser()->tab_strip_model()->GetActiveWebContents(); |
| 303 ASSERT_TRUE(web_contents); | 309 ASSERT_TRUE(web_contents); |
| 304 content::TitleWatcher watcher(web_contents, base::ASCIIToUTF16("PASS")); | 310 content::TitleWatcher watcher(web_contents, base::ASCIIToUTF16("PASS")); |
| 305 watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); | 311 watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); |
| 306 | 312 |
| 307 // Visit a test page. | 313 // Visit a test page. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 319 } | 325 } |
| 320 | 326 |
| 321 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocationAtOnload) { | 327 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocationAtOnload) { |
| 322 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 | 328 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 |
| 323 if (TranslateService::IsTranslateBubbleEnabled()) | 329 if (TranslateService::IsTranslateBubbleEnabled()) |
| 324 return; | 330 return; |
| 325 | 331 |
| 326 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 332 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 327 | 333 |
| 328 // Check if there is no Translate infobar. | 334 // Check if there is no Translate infobar. |
| 329 TranslateInfoBarDelegate* translate = GetExistingTranslateInfoBarDelegate(); | 335 translate::TranslateInfoBarDelegate* translate = |
| 336 GetExistingTranslateInfoBarDelegate(); |
| 330 EXPECT_FALSE(translate); | 337 EXPECT_FALSE(translate); |
| 331 | 338 |
| 332 // Setup page title observer. | 339 // Setup page title observer. |
| 333 content::WebContents* web_contents = | 340 content::WebContents* web_contents = |
| 334 browser()->tab_strip_model()->GetActiveWebContents(); | 341 browser()->tab_strip_model()->GetActiveWebContents(); |
| 335 ASSERT_TRUE(web_contents); | 342 ASSERT_TRUE(web_contents); |
| 336 content::TitleWatcher watcher(web_contents, base::ASCIIToUTF16("PASS")); | 343 content::TitleWatcher watcher(web_contents, base::ASCIIToUTF16("PASS")); |
| 337 watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); | 344 watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); |
| 338 | 345 |
| 339 // Visit a test page. | 346 // Visit a test page. |
| 340 ui_test_utils::NavigateToURL( | 347 ui_test_utils::NavigateToURL( |
| 341 browser(), | 348 browser(), |
| 342 GetNonSecureURL(kUpdateLocationAtOnloadTestPath)); | 349 GetNonSecureURL(kUpdateLocationAtOnloadTestPath)); |
| 343 | 350 |
| 344 // Wait for the page title is changed after the test finished. | 351 // Wait for the page title is changed after the test finished. |
| 345 const base::string16 result = watcher.WaitAndGetTitle(); | 352 const base::string16 result = watcher.WaitAndGetTitle(); |
| 346 EXPECT_EQ("PASS", base::UTF16ToASCII(result)); | 353 EXPECT_EQ("PASS", base::UTF16ToASCII(result)); |
| 347 | 354 |
| 348 // Check if there is no Translate infobar. | 355 // Check if there is no Translate infobar. |
| 349 translate = GetExistingTranslateInfoBarDelegate(); | 356 translate = GetExistingTranslateInfoBarDelegate(); |
| 350 EXPECT_FALSE(translate); | 357 EXPECT_FALSE(translate); |
| 351 } | 358 } |
| OLD | NEW |