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