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 #include "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/extensions/autoupdate_interceptor.h" | 8 #include "chrome/browser/extensions/autoupdate_interceptor.h" |
9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
10 #include "chrome/browser/extensions/extension_browsertest.h" | 10 #include "chrome/browser/extensions/extension_browsertest.h" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionRefreshCrash) { | 205 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionRefreshCrash) { |
206 base::TimeTicks start_time = base::TimeTicks::Now(); | 206 base::TimeTicks start_time = base::TimeTicks::Now(); |
207 | 207 |
208 ExtensionService* service = browser()->profile()->GetExtensionService(); | 208 ExtensionService* service = browser()->profile()->GetExtensionService(); |
209 | 209 |
210 size_t size_before = service->extensions()->size(); | 210 size_t size_before = service->extensions()->size(); |
211 | 211 |
212 FilePath base_path = test_data_dir_.AppendASCII("browsertest") | 212 FilePath base_path = test_data_dir_.AppendASCII("browsertest") |
213 .AppendASCII("crash_44415"); | 213 .AppendASCII("crash_44415"); |
214 // Load extension A. | 214 // Load extension A. |
215 const Extension* extensionA = LoadExtension(base_path.AppendASCII("ExtA")); | 215 ASSERT_TRUE(LoadExtension(base_path.AppendASCII("ExtA"))); |
216 ASSERT_TRUE(extensionA); | |
217 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 216 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
218 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 217 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 218 const Extension* extensionA = service->extensions()->at(size_before); |
219 | 219 |
220 LOG(INFO) << "Load extension A done : " | 220 LOG(INFO) << "Load extension A done : " |
221 << (base::TimeTicks::Now() - start_time).InMilliseconds() | 221 << (base::TimeTicks::Now() - start_time).InMilliseconds() |
222 << " ms" << std::flush; | 222 << " ms" << std::flush; |
223 | 223 |
224 // Load extension B. | 224 // Load extension B. |
225 const Extension* extensionB = LoadExtension(base_path.AppendASCII("ExtB")); | 225 ASSERT_TRUE(LoadExtension(base_path.AppendASCII("ExtB"))); |
226 ASSERT_TRUE(extensionB); | |
227 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(2)); | 226 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(2)); |
228 ASSERT_EQ(size_before + 2, service->extensions()->size()); | 227 ASSERT_EQ(size_before + 2, service->extensions()->size()); |
| 228 const Extension* extensionB = service->extensions()->at(size_before + 1); |
229 | 229 |
230 LOG(INFO) << "Load extension B done : " | 230 LOG(INFO) << "Load extension B done : " |
231 << (base::TimeTicks::Now() - start_time).InMilliseconds() | 231 << (base::TimeTicks::Now() - start_time).InMilliseconds() |
232 << " ms" << std::flush; | 232 << " ms" << std::flush; |
233 | 233 |
234 std::string idA = extensionA->id(); | |
235 ReloadExtension(extensionA->id()); | 234 ReloadExtension(extensionA->id()); |
236 // ExtensionA has changed, so refetch it. | 235 // ExtensionA has changed, so refetch it. |
237 ASSERT_EQ(size_before + 2, service->extensions()->size()); | 236 ASSERT_EQ(size_before + 2, service->extensions()->size()); |
238 extensionA = service->extensions()->GetByID(idA); | 237 extensionA = service->extensions()->at(size_before + 1); |
239 | 238 |
240 LOG(INFO) << "Reload extension A done: " | 239 LOG(INFO) << "Reload extension A done: " |
241 << (base::TimeTicks::Now() - start_time).InMilliseconds() | 240 << (base::TimeTicks::Now() - start_time).InMilliseconds() |
242 << " ms" << std::flush; | 241 << " ms" << std::flush; |
243 | 242 |
244 ReloadExtension(extensionB->id()); | 243 ReloadExtension(extensionB->id()); |
245 | 244 |
246 LOG(INFO) << "Reload extension B done: " | 245 LOG(INFO) << "Reload extension B done: " |
247 << (base::TimeTicks::Now() - start_time).InMilliseconds() | 246 << (base::TimeTicks::Now() - start_time).InMilliseconds() |
248 << " ms" << std::flush; | 247 << " ms" << std::flush; |
(...skipping 23 matching lines...) Expand all Loading... |
272 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 271 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
273 } | 272 } |
274 | 273 |
275 // Tests that tooltips of a browser action icon can be specified using UTF8. | 274 // Tests that tooltips of a browser action icon can be specified using UTF8. |
276 // See http://crbug.com/25349. | 275 // See http://crbug.com/25349. |
277 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationBrowserAction) { | 276 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationBrowserAction) { |
278 ExtensionService* service = browser()->profile()->GetExtensionService(); | 277 ExtensionService* service = browser()->profile()->GetExtensionService(); |
279 const size_t size_before = service->extensions()->size(); | 278 const size_t size_before = service->extensions()->size(); |
280 FilePath extension_path(test_data_dir_.AppendASCII("browsertest") | 279 FilePath extension_path(test_data_dir_.AppendASCII("browsertest") |
281 .AppendASCII("title_localized")); | 280 .AppendASCII("title_localized")); |
282 const Extension* extension = LoadExtension(extension_path); | 281 ASSERT_TRUE(LoadExtension(extension_path)); |
283 ASSERT_TRUE(extension); | |
284 | 282 |
285 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 283 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 284 const Extension* extension = service->extensions()->at(size_before); |
286 | 285 |
287 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur: l10n browser action").c_str(), | 286 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur: l10n browser action").c_str(), |
288 extension->description().c_str()); | 287 extension->description().c_str()); |
289 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur is my name").c_str(), | 288 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur is my name").c_str(), |
290 extension->name().c_str()); | 289 extension->name().c_str()); |
291 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents()); | 290 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents()); |
292 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur").c_str(), | 291 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur").c_str(), |
293 extension->browser_action()->GetTitle(tab_id).c_str()); | 292 extension->browser_action()->GetTitle(tab_id).c_str()); |
294 } | 293 } |
295 | 294 |
296 // Tests that tooltips of a page action icon can be specified using UTF8. | 295 // Tests that tooltips of a page action icon can be specified using UTF8. |
297 // See http://crbug.com/25349. | 296 // See http://crbug.com/25349. |
298 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) { | 297 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) { |
299 ASSERT_TRUE(test_server()->Start()); | 298 ASSERT_TRUE(test_server()->Start()); |
300 | 299 |
301 ExtensionService* service = browser()->profile()->GetExtensionService(); | 300 ExtensionService* service = browser()->profile()->GetExtensionService(); |
302 const size_t size_before = service->extensions()->size(); | 301 const size_t size_before = service->extensions()->size(); |
303 | 302 |
304 FilePath extension_path(test_data_dir_.AppendASCII("browsertest") | 303 FilePath extension_path(test_data_dir_.AppendASCII("browsertest") |
305 .AppendASCII("title_localized_pa")); | 304 .AppendASCII("title_localized_pa")); |
306 const Extension* extension = LoadExtension(extension_path); | 305 ASSERT_TRUE(LoadExtension(extension_path)); |
307 ASSERT_TRUE(extension); | |
308 | 306 |
309 // Any navigation prompts the location bar to load the page action. | 307 // Any navigation prompts the location bar to load the page action. |
310 GURL url = test_server()->GetURL(kLocalization); | 308 GURL url = test_server()->GetURL(kLocalization); |
311 ui_test_utils::NavigateToURL(browser(), url); | 309 ui_test_utils::NavigateToURL(browser(), url); |
312 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 310 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
313 | 311 |
314 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 312 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
| 313 const Extension* extension = service->extensions()->at(size_before); |
315 | 314 |
316 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur: l10n page action").c_str(), | 315 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur: l10n page action").c_str(), |
317 extension->description().c_str()); | 316 extension->description().c_str()); |
318 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur is my name").c_str(), | 317 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur is my name").c_str(), |
319 extension->name().c_str()); | 318 extension->name().c_str()); |
320 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents()); | 319 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents()); |
321 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur").c_str(), | 320 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur").c_str(), |
322 extension->page_action()->GetTitle(tab_id).c_str()); | 321 extension->page_action()->GetTitle(tab_id).c_str()); |
323 } | 322 } |
324 | 323 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 return expected_value == returned_value; | 380 return expected_value == returned_value; |
382 } | 381 } |
383 | 382 |
384 // Navigates to a feed page and, if |sniff_xml_type| is set, wait for the | 383 // Navigates to a feed page and, if |sniff_xml_type| is set, wait for the |
385 // extension to kick in, detect the feed and redirect to a feed preview page. | 384 // extension to kick in, detect the feed and redirect to a feed preview page. |
386 // |sniff_xml_type| is generally set to true if the feed is sniffable and false | 385 // |sniff_xml_type| is generally set to true if the feed is sniffable and false |
387 // for invalid feeds. | 386 // for invalid feeds. |
388 void NavigateToFeedAndValidate(net::TestServer* server, | 387 void NavigateToFeedAndValidate(net::TestServer* server, |
389 const std::string& url, | 388 const std::string& url, |
390 Browser* browser, | 389 Browser* browser, |
391 std::string extension_id, | |
392 bool sniff_xml_type, | 390 bool sniff_xml_type, |
393 const std::string& expected_feed_title, | 391 const std::string& expected_feed_title, |
394 const std::string& expected_item_title, | 392 const std::string& expected_item_title, |
395 const std::string& expected_item_desc, | 393 const std::string& expected_item_desc, |
396 const std::string& expected_error) { | 394 const std::string& expected_error) { |
397 if (sniff_xml_type) { | 395 if (sniff_xml_type) { |
398 // TODO(finnur): Implement this is a non-flaky way. | 396 // TODO(finnur): Implement this is a non-flaky way. |
399 } | 397 } |
400 | 398 |
| 399 ExtensionService* service = browser->profile()->GetExtensionService(); |
| 400 const Extension* extension = service->extensions()->back(); |
| 401 std::string id = extension->id(); |
| 402 |
401 // Navigate to the subscribe page directly. | 403 // Navigate to the subscribe page directly. |
402 ui_test_utils::NavigateToURL(browser, | 404 ui_test_utils::NavigateToURL(browser, GetFeedUrl(server, url, true, id)); |
403 GetFeedUrl(server, url, true, extension_id)); | |
404 | 405 |
405 TabContents* tab = browser->GetSelectedTabContents(); | 406 TabContents* tab = browser->GetSelectedTabContents(); |
406 ASSERT_TRUE(ValidatePageElement(tab, | 407 ASSERT_TRUE(ValidatePageElement(tab, |
407 L"", | 408 L"", |
408 jscript_feed_title, | 409 jscript_feed_title, |
409 expected_feed_title)); | 410 expected_feed_title)); |
410 ASSERT_TRUE(ValidatePageElement(tab, | 411 ASSERT_TRUE(ValidatePageElement(tab, |
411 L"//html/body/div/iframe[1]", | 412 L"//html/body/div/iframe[1]", |
412 jscript_anchor, | 413 jscript_anchor, |
413 expected_item_title)); | 414 expected_item_title)); |
414 ASSERT_TRUE(ValidatePageElement(tab, | 415 ASSERT_TRUE(ValidatePageElement(tab, |
415 L"//html/body/div/iframe[1]", | 416 L"//html/body/div/iframe[1]", |
416 jscript_desc, | 417 jscript_desc, |
417 expected_item_desc)); | 418 expected_item_desc)); |
418 ASSERT_TRUE(ValidatePageElement(tab, | 419 ASSERT_TRUE(ValidatePageElement(tab, |
419 L"//html/body/div/iframe[1]", | 420 L"//html/body/div/iframe[1]", |
420 jscript_error, | 421 jscript_error, |
421 expected_error)); | 422 expected_error)); |
422 } | 423 } |
423 | 424 |
424 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed1) { | 425 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed1) { |
425 ASSERT_TRUE(test_server()->Start()); | 426 ASSERT_TRUE(test_server()->Start()); |
426 | 427 |
427 const Extension* extension = LoadExtension( | 428 ASSERT_TRUE(LoadExtension( |
428 test_data_dir_.AppendASCII("subscribe_page_action")); | 429 test_data_dir_.AppendASCII("subscribe_page_action"))); |
429 ASSERT_TRUE(extension); | |
430 std::string id = extension->id(); | |
431 | 430 |
432 NavigateToFeedAndValidate(test_server(), kValidFeed1, browser(), id, true, | 431 NavigateToFeedAndValidate(test_server(), kValidFeed1, browser(), true, |
433 "Feed for MyFeedTitle", | 432 "Feed for MyFeedTitle", |
434 "Title 1", | 433 "Title 1", |
435 "Desc", | 434 "Desc", |
436 "No error"); | 435 "No error"); |
437 } | 436 } |
438 | 437 |
439 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed2) { | 438 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed2) { |
440 ASSERT_TRUE(test_server()->Start()); | 439 ASSERT_TRUE(test_server()->Start()); |
441 | 440 |
442 const Extension* extension = LoadExtension( | 441 ASSERT_TRUE(LoadExtension( |
443 test_data_dir_.AppendASCII("subscribe_page_action")); | 442 test_data_dir_.AppendASCII("subscribe_page_action"))); |
444 ASSERT_TRUE(extension); | |
445 std::string id = extension->id(); | |
446 | 443 |
447 NavigateToFeedAndValidate(test_server(), kValidFeed2, browser(), id, true, | 444 NavigateToFeedAndValidate(test_server(), kValidFeed2, browser(), true, |
448 "Feed for MyFeed2", | 445 "Feed for MyFeed2", |
449 "My item title1", | 446 "My item title1", |
450 "This is a summary.", | 447 "This is a summary.", |
451 "No error"); | 448 "No error"); |
452 } | 449 } |
453 | 450 |
454 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed3) { | 451 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed3) { |
455 ASSERT_TRUE(test_server()->Start()); | 452 ASSERT_TRUE(test_server()->Start()); |
456 | 453 |
457 const Extension* extension = LoadExtension( | 454 ASSERT_TRUE(LoadExtension( |
458 test_data_dir_.AppendASCII("subscribe_page_action")); | 455 test_data_dir_.AppendASCII("subscribe_page_action"))); |
459 ASSERT_TRUE(extension); | |
460 std::string id = extension->id(); | |
461 | 456 |
462 NavigateToFeedAndValidate(test_server(), kValidFeed3, browser(), id, true, | 457 NavigateToFeedAndValidate(test_server(), kValidFeed3, browser(), true, |
463 "Feed for Google Code buglist rss feed", | 458 "Feed for Google Code buglist rss feed", |
464 "My dear title", | 459 "My dear title", |
465 "My dear content", | 460 "My dear content", |
466 "No error"); | 461 "No error"); |
467 } | 462 } |
468 | 463 |
469 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed4) { | 464 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed4) { |
470 ASSERT_TRUE(test_server()->Start()); | 465 ASSERT_TRUE(test_server()->Start()); |
471 | 466 |
472 const Extension* extension = LoadExtension( | 467 ASSERT_TRUE(LoadExtension( |
473 test_data_dir_.AppendASCII("subscribe_page_action")); | 468 test_data_dir_.AppendASCII("subscribe_page_action"))); |
474 ASSERT_TRUE(extension); | |
475 std::string id = extension->id(); | |
476 | 469 |
477 NavigateToFeedAndValidate(test_server(), kValidFeed4, browser(), id, true, | 470 NavigateToFeedAndValidate(test_server(), kValidFeed4, browser(), true, |
478 "Feed for Title chars <script> %23 stop", | 471 "Feed for Title chars <script> %23 stop", |
479 "Title chars %23 stop", | 472 "Title chars %23 stop", |
480 "My dear content %23 stop", | 473 "My dear content %23 stop", |
481 "No error"); | 474 "No error"); |
482 } | 475 } |
483 | 476 |
484 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed0) { | 477 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed0) { |
485 ASSERT_TRUE(test_server()->Start()); | 478 ASSERT_TRUE(test_server()->Start()); |
486 | 479 |
487 const Extension* extension = LoadExtension( | 480 ASSERT_TRUE(LoadExtension( |
488 test_data_dir_.AppendASCII("subscribe_page_action")); | 481 test_data_dir_.AppendASCII("subscribe_page_action"))); |
489 ASSERT_TRUE(extension); | |
490 std::string id = extension->id(); | |
491 | 482 |
492 // Try a feed with a link with an onclick handler (before r27440 this would | 483 // Try a feed with a link with an onclick handler (before r27440 this would |
493 // trigger a NOTREACHED). | 484 // trigger a NOTREACHED). |
494 NavigateToFeedAndValidate(test_server(), kValidFeed0, browser(), id, true, | 485 NavigateToFeedAndValidate(test_server(), kValidFeed0, browser(), true, |
495 "Feed for MyFeedTitle", | 486 "Feed for MyFeedTitle", |
496 "Title 1", | 487 "Title 1", |
497 "Desc VIDEO", | 488 "Desc VIDEO", |
498 "No error"); | 489 "No error"); |
499 } | 490 } |
500 | 491 |
501 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed5) { | 492 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed5) { |
502 ASSERT_TRUE(test_server()->Start()); | 493 ASSERT_TRUE(test_server()->Start()); |
503 | 494 |
504 const Extension* extension = LoadExtension( | 495 ASSERT_TRUE(LoadExtension( |
505 test_data_dir_.AppendASCII("subscribe_page_action")); | 496 test_data_dir_.AppendASCII("subscribe_page_action"))); |
506 ASSERT_TRUE(extension); | |
507 std::string id = extension->id(); | |
508 | 497 |
509 // Feed with valid but mostly empty xml. | 498 // Feed with valid but mostly empty xml. |
510 NavigateToFeedAndValidate(test_server(), kValidFeed5, browser(), id, true, | 499 NavigateToFeedAndValidate(test_server(), kValidFeed5, browser(), true, |
511 "Feed for Unknown feed name", | 500 "Feed for Unknown feed name", |
512 "element 'anchor_0' not found", | 501 "element 'anchor_0' not found", |
513 "element 'desc_0' not found", | 502 "element 'desc_0' not found", |
514 "This feed contains no entries."); | 503 "This feed contains no entries."); |
515 } | 504 } |
516 | 505 |
517 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed6) { | 506 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed6) { |
518 ASSERT_TRUE(test_server()->Start()); | 507 ASSERT_TRUE(test_server()->Start()); |
519 | 508 |
520 const Extension* extension = LoadExtension( | 509 ASSERT_TRUE(LoadExtension( |
521 test_data_dir_.AppendASCII("subscribe_page_action")); | 510 test_data_dir_.AppendASCII("subscribe_page_action"))); |
522 ASSERT_TRUE(extension); | |
523 std::string id = extension->id(); | |
524 | 511 |
525 // Feed that is technically invalid but still parseable. | 512 // Feed that is technically invalid but still parseable. |
526 NavigateToFeedAndValidate(test_server(), kValidFeed6, browser(), id, true, | 513 NavigateToFeedAndValidate(test_server(), kValidFeed6, browser(), true, |
527 "Feed for MyFeedTitle", | 514 "Feed for MyFeedTitle", |
528 "Title 1", | 515 "Title 1", |
529 "Desc", | 516 "Desc", |
530 "No error"); | 517 "No error"); |
531 } | 518 } |
532 | 519 |
533 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed1) { | 520 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed1) { |
534 ASSERT_TRUE(test_server()->Start()); | 521 ASSERT_TRUE(test_server()->Start()); |
535 | 522 |
536 const Extension* extension = LoadExtension( | 523 ASSERT_TRUE(LoadExtension( |
537 test_data_dir_.AppendASCII("subscribe_page_action")); | 524 test_data_dir_.AppendASCII("subscribe_page_action"))); |
538 ASSERT_TRUE(extension); | |
539 std::string id = extension->id(); | |
540 | 525 |
541 // Try an empty feed. | 526 // Try an empty feed. |
542 NavigateToFeedAndValidate(test_server(), kInvalidFeed1, browser(), id, false, | 527 NavigateToFeedAndValidate(test_server(), kInvalidFeed1, browser(), false, |
543 "Feed for Unknown feed name", | 528 "Feed for Unknown feed name", |
544 "element 'anchor_0' not found", | 529 "element 'anchor_0' not found", |
545 "element 'desc_0' not found", | 530 "element 'desc_0' not found", |
546 "This feed contains no entries."); | 531 "This feed contains no entries."); |
547 } | 532 } |
548 | 533 |
549 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed2) { | 534 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed2) { |
550 ASSERT_TRUE(test_server()->Start()); | 535 ASSERT_TRUE(test_server()->Start()); |
551 | 536 |
552 const Extension* extension = LoadExtension( | 537 ASSERT_TRUE(LoadExtension( |
553 test_data_dir_.AppendASCII("subscribe_page_action")); | 538 test_data_dir_.AppendASCII("subscribe_page_action"))); |
554 ASSERT_TRUE(extension); | |
555 std::string id = extension->id(); | |
556 | 539 |
557 // Try a garbage feed. | 540 // Try a garbage feed. |
558 NavigateToFeedAndValidate(test_server(), kInvalidFeed2, browser(), id, false, | 541 NavigateToFeedAndValidate(test_server(), kInvalidFeed2, browser(), false, |
559 "Feed for Unknown feed name", | 542 "Feed for Unknown feed name", |
560 "element 'anchor_0' not found", | 543 "element 'anchor_0' not found", |
561 "element 'desc_0' not found", | 544 "element 'desc_0' not found", |
562 "This feed contains no entries."); | 545 "This feed contains no entries."); |
563 } | 546 } |
564 | 547 |
565 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed3) { | 548 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed3) { |
566 ASSERT_TRUE(test_server()->Start()); | 549 ASSERT_TRUE(test_server()->Start()); |
567 | 550 |
568 const Extension* extension = LoadExtension( | 551 ASSERT_TRUE(LoadExtension( |
569 test_data_dir_.AppendASCII("subscribe_page_action")); | 552 test_data_dir_.AppendASCII("subscribe_page_action"))); |
570 ASSERT_TRUE(extension); | |
571 std::string id = extension->id(); | |
572 | 553 |
573 // Try a feed that doesn't exist. | 554 // Try a feed that doesn't exist. |
574 NavigateToFeedAndValidate(test_server(), "foo.xml", browser(), id, false, | 555 NavigateToFeedAndValidate(test_server(), "foo.xml", browser(), false, |
575 "Feed for Unknown feed name", | 556 "Feed for Unknown feed name", |
576 "element 'anchor_0' not found", | 557 "element 'anchor_0' not found", |
577 "element 'desc_0' not found", | 558 "element 'desc_0' not found", |
578 "This feed contains no entries."); | 559 "This feed contains no entries."); |
579 } | 560 } |
580 | 561 |
581 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed4) { | 562 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed4) { |
582 ASSERT_TRUE(test_server()->Start()); | 563 ASSERT_TRUE(test_server()->Start()); |
583 | 564 |
584 const Extension* extension = LoadExtension( | 565 ASSERT_TRUE(LoadExtension( |
585 test_data_dir_.AppendASCII("subscribe_page_action")); | 566 test_data_dir_.AppendASCII("subscribe_page_action"))); |
586 ASSERT_TRUE(extension); | |
587 std::string id = extension->id(); | |
588 | 567 |
589 // subscribe.js shouldn't double-decode the URL passed in. Otherwise feed | 568 // subscribe.js shouldn't double-decode the URL passed in. Otherwise feed |
590 // links such as http://search.twitter.com/search.atom?lang=en&q=%23chrome | 569 // links such as http://search.twitter.com/search.atom?lang=en&q=%23chrome |
591 // will result in no feed being downloaded because %23 gets decoded to # and | 570 // will result in no feed being downloaded because %23 gets decoded to # and |
592 // therefore #chrome is not treated as part of the Twitter query. This test | 571 // therefore #chrome is not treated as part of the Twitter query. This test |
593 // uses an underscore instead of a hash, but the principle is the same. If | 572 // uses an underscore instead of a hash, but the principle is the same. If |
594 // we start erroneously double decoding again, the path (and the feed) will | 573 // we start erroneously double decoding again, the path (and the feed) will |
595 // become valid resulting in a failure for this test. | 574 // become valid resulting in a failure for this test. |
596 NavigateToFeedAndValidate( | 575 NavigateToFeedAndValidate(test_server(), kFeedTripleEncoded, browser(), true, |
597 test_server(), kFeedTripleEncoded, browser(), id, true, | 576 "Feed for Unknown feed name", |
598 "Feed for Unknown feed name", | 577 "element 'anchor_0' not found", |
599 "element 'anchor_0' not found", | 578 "element 'desc_0' not found", |
600 "element 'desc_0' not found", | 579 "This feed contains no entries."); |
601 "This feed contains no entries."); | |
602 } | 580 } |
603 | 581 |
604 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeedNoLinks) { | 582 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeedNoLinks) { |
605 ASSERT_TRUE(test_server()->Start()); | 583 ASSERT_TRUE(test_server()->Start()); |
606 | 584 |
607 const Extension* extension = LoadExtension( | 585 ASSERT_TRUE(LoadExtension( |
608 test_data_dir_.AppendASCII("subscribe_page_action")); | 586 test_data_dir_.AppendASCII("subscribe_page_action"))); |
609 ASSERT_TRUE(extension); | |
610 std::string id = extension->id(); | |
611 | 587 |
612 // Valid feed but containing no links. | 588 // Valid feed but containing no links. |
613 NavigateToFeedAndValidate( | 589 NavigateToFeedAndValidate(test_server(), kValidFeedNoLinks, browser(), true, |
614 test_server(), kValidFeedNoLinks, browser(), id, true, | 590 "Feed for MyFeedTitle", |
615 "Feed for MyFeedTitle", | 591 "Title with no link", |
616 "Title with no link", | 592 "Desc", |
617 "Desc", | 593 "No error"); |
618 "No error"); | |
619 } | 594 } |
620 | 595 |
621 // Tests that an error raised during an async function still fires | 596 // Tests that an error raised during an async function still fires |
622 // the callback, but sets chrome.extension.lastError. | 597 // the callback, but sets chrome.extension.lastError. |
623 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, LastError) { | 598 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, LastError) { |
624 ASSERT_TRUE(LoadExtension( | 599 ASSERT_TRUE(LoadExtension( |
625 test_data_dir_.AppendASCII("browsertest").AppendASCII("last_error"))); | 600 test_data_dir_.AppendASCII("browsertest").AppendASCII("last_error"))); |
626 | 601 |
627 // Get the ExtensionHost that is hosting our background page. | 602 // Get the ExtensionHost that is hosting our background page. |
628 ExtensionProcessManager* manager = | 603 ExtensionProcessManager* manager = |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 | 715 |
741 // With no extensions, the plugin should not be loaded. | 716 // With no extensions, the plugin should not be loaded. |
742 bool result = false; | 717 bool result = false; |
743 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 718 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
744 tab->render_view_host(), L"", L"testPluginWorks()", &result)); | 719 tab->render_view_host(), L"", L"testPluginWorks()", &result)); |
745 EXPECT_FALSE(result); | 720 EXPECT_FALSE(result); |
746 | 721 |
747 ExtensionService* service = browser()->profile()->GetExtensionService(); | 722 ExtensionService* service = browser()->profile()->GetExtensionService(); |
748 service->set_show_extensions_prompts(false); | 723 service->set_show_extensions_prompts(false); |
749 const size_t size_before = service->extensions()->size(); | 724 const size_t size_before = service->extensions()->size(); |
750 const Extension* extension = LoadExtension(extension_dir); | 725 ASSERT_TRUE(LoadExtension(extension_dir)); |
751 ASSERT_TRUE(extension); | |
752 EXPECT_EQ(size_before + 1, service->extensions()->size()); | 726 EXPECT_EQ(size_before + 1, service->extensions()->size()); |
753 // Now the plugin should be in the cache, but we have to reload the page for | 727 // Now the plugin should be in the cache, but we have to reload the page for |
754 // it to work. | 728 // it to work. |
755 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 729 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
756 tab->render_view_host(), L"", L"testPluginWorks()", &result)); | 730 tab->render_view_host(), L"", L"testPluginWorks()", &result)); |
757 EXPECT_FALSE(result); | 731 EXPECT_FALSE(result); |
758 { | 732 { |
759 ui_test_utils::WindowedNotificationObserver observer( | 733 ui_test_utils::WindowedNotificationObserver observer( |
760 content::NOTIFICATION_LOAD_STOP, | 734 content::NOTIFICATION_LOAD_STOP, |
761 content::Source<NavigationController>( | 735 content::Source<NavigationController>( |
762 &browser()->GetSelectedTabContentsWrapper()->controller())); | 736 &browser()->GetSelectedTabContentsWrapper()->controller())); |
763 browser()->Reload(CURRENT_TAB); | 737 browser()->Reload(CURRENT_TAB); |
764 observer.Wait(); | 738 observer.Wait(); |
765 } | 739 } |
766 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 740 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
767 tab->render_view_host(), L"", L"testPluginWorks()", &result)); | 741 tab->render_view_host(), L"", L"testPluginWorks()", &result)); |
768 EXPECT_TRUE(result); | 742 EXPECT_TRUE(result); |
769 | 743 |
770 EXPECT_EQ(size_before + 1, service->extensions()->size()); | 744 EXPECT_EQ(size_before + 1, service->extensions()->size()); |
771 UnloadExtension(extension->id()); | 745 UnloadExtension(service->extensions()->at(size_before)->id()); |
772 EXPECT_EQ(size_before, service->extensions()->size()); | 746 EXPECT_EQ(size_before, service->extensions()->size()); |
773 | 747 |
774 // Now the plugin should be unloaded, and the page should be broken. | 748 // Now the plugin should be unloaded, and the page should be broken. |
775 | 749 |
776 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 750 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
777 tab->render_view_host(), L"", L"testPluginWorks()", &result)); | 751 tab->render_view_host(), L"", L"testPluginWorks()", &result)); |
778 EXPECT_FALSE(result); | 752 EXPECT_FALSE(result); |
779 | 753 |
780 // If we reload the extension and page, it should work again. | 754 // If we reload the extension and page, it should work again. |
781 | 755 |
(...skipping 21 matching lines...) Expand all Loading... |
803 #endif | 777 #endif |
804 | 778 |
805 // Tests that private extension plugins are only visible to the extension. | 779 // Tests that private extension plugins are only visible to the extension. |
806 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, MAYBE_PluginPrivate) { | 780 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, MAYBE_PluginPrivate) { |
807 FilePath extension_dir = | 781 FilePath extension_dir = |
808 test_data_dir_.AppendASCII("uitest").AppendASCII("plugins_private"); | 782 test_data_dir_.AppendASCII("uitest").AppendASCII("plugins_private"); |
809 | 783 |
810 ExtensionService* service = browser()->profile()->GetExtensionService(); | 784 ExtensionService* service = browser()->profile()->GetExtensionService(); |
811 service->set_show_extensions_prompts(false); | 785 service->set_show_extensions_prompts(false); |
812 const size_t size_before = service->extensions()->size(); | 786 const size_t size_before = service->extensions()->size(); |
813 const Extension* extension = LoadExtension(extension_dir); | 787 ASSERT_TRUE(LoadExtension(extension_dir)); |
814 ASSERT_TRUE(extension); | |
815 EXPECT_EQ(size_before + 1, service->extensions()->size()); | 788 EXPECT_EQ(size_before + 1, service->extensions()->size()); |
816 | 789 |
817 // Load the test page through the extension URL, and the plugin should work. | 790 // Load the test page through the extension URL, and the plugin should work. |
| 791 const Extension* extension = service->extensions()->back(); |
818 ui_test_utils::NavigateToURL(browser(), | 792 ui_test_utils::NavigateToURL(browser(), |
819 extension->GetResourceURL("test.html")); | 793 extension->GetResourceURL("test.html")); |
820 TabContents* tab = browser()->GetSelectedTabContents(); | 794 TabContents* tab = browser()->GetSelectedTabContents(); |
821 bool result = false; | 795 bool result = false; |
822 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 796 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
823 tab->render_view_host(), L"", L"testPluginWorks()", &result)); | 797 tab->render_view_host(), L"", L"testPluginWorks()", &result)); |
824 // We don't allow extension plugins to run on ChromeOS. | 798 // We don't allow extension plugins to run on ChromeOS. |
825 #if defined(OS_CHROMEOS) | 799 #if defined(OS_CHROMEOS) |
826 EXPECT_FALSE(result); | 800 EXPECT_FALSE(result); |
827 #else | 801 #else |
(...skipping 16 matching lines...) Expand all Loading... |
844 L" null).snapshotItem(0);" | 818 L" null).snapshotItem(0);" |
845 L" button.click();" | 819 L" button.click();" |
846 L"})();"; | 820 L"})();"; |
847 | 821 |
848 // Test that an extension with an options page makes an 'Options' button appear | 822 // Test that an extension with an options page makes an 'Options' button appear |
849 // on chrome://extensions, and that clicking the button opens a new tab with the | 823 // on chrome://extensions, and that clicking the button opens a new tab with the |
850 // extension's options page. | 824 // extension's options page. |
851 // Disabled. See http://crbug.com/26948 for details. | 825 // Disabled. See http://crbug.com/26948 for details. |
852 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_OptionsPage) { | 826 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_OptionsPage) { |
853 // Install an extension with an options page. | 827 // Install an extension with an options page. |
854 const Extension* extension = | 828 ASSERT_TRUE(InstallExtension(test_data_dir_.AppendASCII("options.crx"), 1)); |
855 InstallExtension(test_data_dir_.AppendASCII("options.crx"), 1); | |
856 ASSERT_TRUE(extension); | |
857 ExtensionService* service = browser()->profile()->GetExtensionService(); | 829 ExtensionService* service = browser()->profile()->GetExtensionService(); |
858 ASSERT_EQ(1u, service->extensions()->size()); | 830 const ExtensionList* extensions = service->extensions(); |
| 831 ASSERT_EQ(1u, extensions->size()); |
| 832 const Extension* extension = extensions->at(0); |
859 | 833 |
860 // Go to the Extension Settings page and click the Options button. | 834 // Go to the Extension Settings page and click the Options button. |
861 ui_test_utils::NavigateToURL( | 835 ui_test_utils::NavigateToURL( |
862 browser(), GURL(std::string(chrome::kChromeUISettingsURL) + | 836 browser(), GURL(std::string(chrome::kChromeUISettingsURL) + |
863 chrome::kExtensionsSubPage)); | 837 chrome::kExtensionsSubPage)); |
864 TabStripModel* tab_strip = browser()->tabstrip_model(); | 838 TabStripModel* tab_strip = browser()->tabstrip_model(); |
865 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 839 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
866 browser()->GetSelectedTabContents()->render_view_host(), L"", | 840 browser()->GetSelectedTabContents()->render_view_host(), L"", |
867 jscript_click_option_button)); | 841 jscript_click_option_button)); |
868 | 842 |
869 // If the options page hasn't already come up, wait for it. | 843 // If the options page hasn't already come up, wait for it. |
870 if (tab_strip->count() == 1) { | 844 if (tab_strip->count() == 1) { |
871 ui_test_utils::WaitForNewTab(browser()); | 845 ui_test_utils::WaitForNewTab(browser()); |
872 } | 846 } |
873 ASSERT_EQ(2, tab_strip->count()); | 847 ASSERT_EQ(2, tab_strip->count()); |
874 | 848 |
875 EXPECT_EQ(extension->GetResourceURL("options.html"), | 849 EXPECT_EQ(extension->GetResourceURL("options.html"), |
876 tab_strip->GetTabContentsAt(1)->tab_contents()->GetURL()); | 850 tab_strip->GetTabContentsAt(1)->tab_contents()->GetURL()); |
877 } | 851 } |
878 | 852 |
879 //============================================================================== | 853 //============================================================================== |
880 // STOP! Please do not add any more random-ass tests here. Create new files for | 854 // STOP! Please do not add any more random-ass tests here. Create new files for |
881 // your tests grouped by functionality. Also, you should strongly consider using | 855 // your tests grouped by functionality. Also, you should strongly consider using |
882 // ExtensionAPITest if possible. | 856 // ExtensionAPITest if possible. |
883 //============================================================================== | 857 //============================================================================== |
OLD | NEW |