| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/json/json_file_value_serializer.h" | 7 #include "base/json/json_file_value_serializer.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), | 317 registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), |
| 318 ASCIIToUTF16("*"), | 318 ASCIIToUTF16("*"), |
| 319 base::Bind(&TestConsumer::OnIntentsQueryDone, | 319 base::Bind(&TestConsumer::OnIntentsQueryDone, |
| 320 base::Unretained(&consumer))); | 320 base::Unretained(&consumer))); |
| 321 consumer.WaitForData(); | 321 consumer.WaitForData(); |
| 322 ASSERT_EQ(1U, consumer.services_.size()); | 322 ASSERT_EQ(1U, consumer.services_.size()); |
| 323 } | 323 } |
| 324 | 324 |
| 325 TEST_F(WebIntentsRegistryTest, GetIntentsWithMimeAndLiteralMatching) { | 325 TEST_F(WebIntentsRegistryTest, GetIntentsWithMimeAndLiteralMatching) { |
| 326 WebIntentServiceData services[] = { | 326 WebIntentServiceData services[] = { |
| 327 WebIntentServiceData(GURL("http://elsewhere.com/intent/share.html"), | 327 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 328 ASCIIToUTF16("http://webintents.org/share"), | |
| 329 ASCIIToUTF16("image/*"), | 328 ASCIIToUTF16("image/*"), |
| 329 string16(), |
| 330 GURL("http://elsewhere.com/intent/share.html"), |
| 330 ASCIIToUTF16("Image Sharing Service")), | 331 ASCIIToUTF16("Image Sharing Service")), |
| 331 WebIntentServiceData(GURL("http://somewhere.com/intent/share.html"), | 332 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 332 ASCIIToUTF16("http://webintents.org/share"), | |
| 333 ASCIIToUTF16("image/jpeg"), | 333 ASCIIToUTF16("image/jpeg"), |
| 334 string16(), |
| 335 GURL("http://somewhere.com/intent/share.html"), |
| 334 ASCIIToUTF16("Specific Image Editing Service")), | 336 ASCIIToUTF16("Specific Image Editing Service")), |
| 335 WebIntentServiceData(GURL("http://somewhere.com/intent/share.html"), | 337 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 336 ASCIIToUTF16("http://webintents.org/share"), | |
| 337 ASCIIToUTF16("text/uri-list"), | 338 ASCIIToUTF16("text/uri-list"), |
| 339 string16(), |
| 340 GURL("http://somewhere.com/intent/share.html"), |
| 338 ASCIIToUTF16("Text Link Sharing Service")), | 341 ASCIIToUTF16("Text Link Sharing Service")), |
| 339 WebIntentServiceData(GURL("http://somewhere2.com/intent/share.html"), | 342 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 340 ASCIIToUTF16("http://webintents.org/share"), | |
| 341 ASCIIToUTF16("text/plain"), | 343 ASCIIToUTF16("text/plain"), |
| 344 string16(), |
| 345 GURL("http://somewhere2.com/intent/share.html"), |
| 342 ASCIIToUTF16("Text Sharing Service")), | 346 ASCIIToUTF16("Text Sharing Service")), |
| 343 WebIntentServiceData(GURL("http://elsewhere.com/intent/share.html"), | 347 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 344 ASCIIToUTF16("http://webintents.org/share"), | |
| 345 ASCIIToUTF16("elsewhere"), | 348 ASCIIToUTF16("elsewhere"), |
| 349 string16(), |
| 350 GURL("http://elsewhere.com/intent/share.html"), |
| 346 ASCIIToUTF16("Text Sharing Service")), | 351 ASCIIToUTF16("Text Sharing Service")), |
| 347 WebIntentServiceData(GURL("http://somewhere.com/intent/share.html"), | 352 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 348 ASCIIToUTF16("http://webintents.org/share"), | |
| 349 ASCIIToUTF16("somewhere"), | 353 ASCIIToUTF16("somewhere"), |
| 354 string16(), |
| 355 GURL("http://somewhere.com/intent/share.html"), |
| 350 ASCIIToUTF16("Text Sharing Service")), | 356 ASCIIToUTF16("Text Sharing Service")), |
| 351 WebIntentServiceData(GURL("http://somewhere.com/intent/share.html"), | 357 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 352 ASCIIToUTF16("http://webintents.org/share"), | |
| 353 ASCIIToUTF16("nota/*"), | 358 ASCIIToUTF16("nota/*"), |
| 359 string16(), |
| 360 GURL("http://somewhere.com/intent/share.html"), |
| 354 ASCIIToUTF16("Text Sharing Service")), | 361 ASCIIToUTF16("Text Sharing Service")), |
| 355 WebIntentServiceData(GURL("http://somewhere.com/intent/share.html"), | 362 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 356 ASCIIToUTF16("http://webintents.org/share"), | |
| 357 ASCIIToUTF16("*nomime"), | 363 ASCIIToUTF16("*nomime"), |
| 364 string16(), |
| 365 GURL("http://somewhere.com/intent/share.html"), |
| 358 ASCIIToUTF16("Text Sharing Service")), | 366 ASCIIToUTF16("Text Sharing Service")), |
| 359 WebIntentServiceData(GURL("http://somewhere.com/intent/share.html"), | 367 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 360 ASCIIToUTF16("http://webintents.org/share"), | |
| 361 ASCIIToUTF16("*/nomime"), | 368 ASCIIToUTF16("*/nomime"), |
| 369 string16(), |
| 370 GURL("http://somewhere.com/intent/share.html"), |
| 362 ASCIIToUTF16("Text Sharing Service")), | 371 ASCIIToUTF16("Text Sharing Service")), |
| 363 WebIntentServiceData(GURL("http://somewhere.com/intent/share.html"), | 372 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 364 ASCIIToUTF16("http://webintents.org/share"), | |
| 365 ASCIIToUTF16("*/*nomime"), | 373 ASCIIToUTF16("*/*nomime"), |
| 374 string16(), |
| 375 GURL("http://somewhere.com/intent/share.html"), |
| 366 ASCIIToUTF16("Text Sharing Service")), | 376 ASCIIToUTF16("Text Sharing Service")), |
| 367 WebIntentServiceData(GURL("http://somewhere.com/intent/share.html"), | 377 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 368 ASCIIToUTF16("http://webintents.org/share"), | |
| 369 ASCIIToUTF16("*/*/nomime"), | 378 ASCIIToUTF16("*/*/nomime"), |
| 379 string16(), |
| 380 GURL("http://somewhere.com/intent/share.html"), |
| 370 ASCIIToUTF16("Text Sharing Service")), | 381 ASCIIToUTF16("Text Sharing Service")), |
| 371 WebIntentServiceData(GURL("http://somewhere.com/intent/share.html"), | 382 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 372 ASCIIToUTF16("http://webintents.org/share"), | |
| 373 ASCIIToUTF16("nomime/*"), | 383 ASCIIToUTF16("nomime/*"), |
| 384 string16(), |
| 385 GURL("http://somewhere.com/intent/share.html"), |
| 374 ASCIIToUTF16("Text Sharing Service")), | 386 ASCIIToUTF16("Text Sharing Service")), |
| 375 WebIntentServiceData(GURL("http://somewhere.com/intent/share.html"), | 387 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 376 ASCIIToUTF16("http://webintents.org/share"), | |
| 377 ASCIIToUTF16("x-type/*"), | 388 ASCIIToUTF16("x-type/*"), |
| 389 string16(), |
| 390 GURL("http://somewhere.com/intent/share.html"), |
| 378 ASCIIToUTF16("Text Sharing Service")), | 391 ASCIIToUTF16("Text Sharing Service")), |
| 379 WebIntentServiceData(GURL("http://somewhere.com/intent/share.html"), | 392 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 380 ASCIIToUTF16("http://webintents.org/share"), | |
| 381 ASCIIToUTF16("x-/*"), // actually a string literal | 393 ASCIIToUTF16("x-/*"), // actually a string literal |
| 394 string16(), |
| 395 GURL("http://somewhere.com/intent/share.html"), |
| 382 ASCIIToUTF16("Text Sharing Service")) | 396 ASCIIToUTF16("Text Sharing Service")) |
| 383 }; | 397 }; |
| 384 registry_.RegisterIntentService(services[0]); | 398 registry_.RegisterIntentService(services[0]); |
| 385 registry_.RegisterIntentService(services[1]); | 399 registry_.RegisterIntentService(services[1]); |
| 386 registry_.RegisterIntentService(services[2]); | 400 registry_.RegisterIntentService(services[2]); |
| 387 registry_.RegisterIntentService(services[3]); | 401 registry_.RegisterIntentService(services[3]); |
| 388 registry_.RegisterIntentService(services[4]); | 402 registry_.RegisterIntentService(services[4]); |
| 389 registry_.RegisterIntentService(services[5]); | 403 registry_.RegisterIntentService(services[5]); |
| 390 registry_.RegisterIntentService(services[6]); | 404 registry_.RegisterIntentService(services[6]); |
| 391 registry_.RegisterIntentService(services[7]); | 405 registry_.RegisterIntentService(services[7]); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 | 568 |
| 555 EXPECT_EQ("", consumer.default_.service_url); | 569 EXPECT_EQ("", consumer.default_.service_url); |
| 556 } | 570 } |
| 557 | 571 |
| 558 // Verify that collapsing equivalent intents works properly. | 572 // Verify that collapsing equivalent intents works properly. |
| 559 TEST_F(WebIntentsRegistryTest, CollapseIntents) { | 573 TEST_F(WebIntentsRegistryTest, CollapseIntents) { |
| 560 WebIntentsRegistry::IntentServiceList services; | 574 WebIntentsRegistry::IntentServiceList services; |
| 561 | 575 |
| 562 // Add two intents with identical |service_url|, |title|, and |action|. | 576 // Add two intents with identical |service_url|, |title|, and |action|. |
| 563 services.push_back( | 577 services.push_back( |
| 564 WebIntentServiceData(GURL("http://somewhere.com/intent/share.html"), | 578 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 565 ASCIIToUTF16("http://webintents.org/share"), | |
| 566 ASCIIToUTF16("image/png"), | 579 ASCIIToUTF16("image/png"), |
| 580 string16(), |
| 581 GURL("http://somewhere.com/intent/share.html"), |
| 567 ASCIIToUTF16("Image Sharing Service"))); | 582 ASCIIToUTF16("Image Sharing Service"))); |
| 568 services.push_back( | 583 services.push_back( |
| 569 WebIntentServiceData(GURL("http://somewhere.com/intent/share.html"), | 584 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 570 ASCIIToUTF16("http://webintents.org/share"), | |
| 571 ASCIIToUTF16("image/jpg"), | 585 ASCIIToUTF16("image/jpg"), |
| 586 string16(), |
| 587 GURL("http://somewhere.com/intent/share.html"), |
| 572 ASCIIToUTF16("Image Sharing Service"))); | 588 ASCIIToUTF16("Image Sharing Service"))); |
| 573 // Service that differs in disposition. | 589 // Service that differs in disposition. |
| 574 services.push_back( | 590 services.push_back( |
| 575 WebIntentServiceData(GURL("http://somewhere.com/intent/share.html"), | 591 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 576 ASCIIToUTF16("http://webintents.org/share"), | |
| 577 ASCIIToUTF16("image/png"), | 592 ASCIIToUTF16("image/png"), |
| 593 string16(), |
| 594 GURL("http://somewhere.com/intent/share.html"), |
| 578 ASCIIToUTF16("Image Sharing Service"))); | 595 ASCIIToUTF16("Image Sharing Service"))); |
| 579 ASSERT_EQ(WebIntentServiceData::DISPOSITION_WINDOW, | 596 ASSERT_EQ(WebIntentServiceData::DISPOSITION_WINDOW, |
| 580 services.back().disposition); | 597 services.back().disposition); |
| 581 services.back().disposition = WebIntentServiceData::DISPOSITION_INLINE; | 598 services.back().disposition = WebIntentServiceData::DISPOSITION_INLINE; |
| 582 // Service that differs in title. | 599 // Service that differs in title. |
| 583 services.push_back( | 600 services.push_back( |
| 584 WebIntentServiceData(GURL("http://somewhere.com/intent/share.html"), | 601 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 585 ASCIIToUTF16("http://webintents.org/share"), | |
| 586 ASCIIToUTF16("image/png"), | 602 ASCIIToUTF16("image/png"), |
| 603 string16(), |
| 604 GURL("http://somewhere.com/intent/share.html"), |
| 587 ASCIIToUTF16("Sharing Service"))); | 605 ASCIIToUTF16("Sharing Service"))); |
| 588 // Service that differs in |action|. | 606 // Service that differs in |action|. |
| 589 services.push_back( | 607 services.push_back( |
| 590 WebIntentServiceData(GURL("http://somewhere.com/intent/share.html"), | 608 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share-old"), |
| 591 ASCIIToUTF16("http://webintents.org/share-old"), | |
| 592 ASCIIToUTF16("image/png"), | 609 ASCIIToUTF16("image/png"), |
| 610 string16(), |
| 611 GURL("http://somewhere.com/intent/share.html"), |
| 593 ASCIIToUTF16("Image Sharing Service"))); | 612 ASCIIToUTF16("Image Sharing Service"))); |
| 594 // Service that differs in |service_url|. | 613 // Service that differs in |service_url|. |
| 595 services.push_back( | 614 services.push_back( |
| 596 WebIntentServiceData(GURL("http://zoo.com/share.html"), | 615 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 597 ASCIIToUTF16("http://webintents.org/share"), | |
| 598 ASCIIToUTF16("image/png"), | 616 ASCIIToUTF16("image/png"), |
| 617 string16(), |
| 618 GURL("http://zoo.com/share.html"), |
| 599 ASCIIToUTF16("Image Sharing Service"))); | 619 ASCIIToUTF16("Image Sharing Service"))); |
| 600 | 620 |
| 601 // Only the first two services should be collapsed. | 621 // Only the first two services should be collapsed. |
| 602 registry_.CollapseIntents(&services); | 622 registry_.CollapseIntents(&services); |
| 603 ASSERT_EQ(5UL, services.size()); | 623 ASSERT_EQ(5UL, services.size()); |
| 604 | 624 |
| 605 // Joined services have their mime types combined | 625 // Joined services have their mime types combined |
| 606 EXPECT_EQ(ASCIIToUTF16("image/png,image/jpg"), services[0].type); | 626 EXPECT_EQ(ASCIIToUTF16("image/png,image/jpg"), services[0].type); |
| 607 | 627 |
| 608 // Verify the remaining services via distinguishing characteristics. | 628 // Verify the remaining services via distinguishing characteristics. |
| 609 EXPECT_EQ(WebIntentServiceData::DISPOSITION_INLINE, services[1].disposition); | 629 EXPECT_EQ(WebIntentServiceData::DISPOSITION_INLINE, services[1].disposition); |
| 610 EXPECT_EQ(ASCIIToUTF16("Sharing Service"), services[2].title); | 630 EXPECT_EQ(ASCIIToUTF16("Sharing Service"), services[2].title); |
| 611 EXPECT_EQ(ASCIIToUTF16("http://webintents.org/share-old"), | 631 EXPECT_EQ(ASCIIToUTF16("http://webintents.org/share-old"), |
| 612 services[3].action); | 632 services[3].action); |
| 613 EXPECT_EQ(GURL("http://zoo.com/share.html").spec(), | 633 EXPECT_EQ(GURL("http://zoo.com/share.html").spec(), |
| 614 services[4].service_url.spec()); | 634 services[4].service_url.spec()); |
| 615 } | 635 } |
| 616 | 636 |
| 617 // Verify that GetIntentServices collapses equivalent intents. | 637 // Verify that GetIntentServices collapses equivalent intents. |
| 618 TEST_F(WebIntentsRegistryTest, GetIntentsCollapsesEquivalentIntents) { | 638 TEST_F(WebIntentsRegistryTest, GetIntentsCollapsesEquivalentIntents) { |
| 619 WebIntentServiceData services[] = { | 639 WebIntentServiceData services[] = { |
| 620 WebIntentServiceData(GURL("http://somewhere.com/intent/share.html"), | 640 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 621 ASCIIToUTF16("http://webintents.org/share"), | |
| 622 ASCIIToUTF16("image/png"), | 641 ASCIIToUTF16("image/png"), |
| 642 string16(), |
| 643 GURL("http://somewhere.com/intent/share.html"), |
| 623 ASCIIToUTF16("Image Sharing Service")), | 644 ASCIIToUTF16("Image Sharing Service")), |
| 624 WebIntentServiceData(GURL("http://somewhere.com/intent/share.html"), | 645 WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), |
| 625 ASCIIToUTF16("http://webintents.org/share"), | 646 ASCIIToUTF16("image/jpg"), |
| 626 ASCIIToUTF16("image/jpg"), | 647 string16(), |
| 627 ASCIIToUTF16("Image Sharing Service")) | 648 GURL("http://somewhere.com/intent/share.html"), |
| 649 ASCIIToUTF16("Image Sharing Service")) |
| 628 }; | 650 }; |
| 629 registry_.RegisterIntentService(services[0]); | 651 registry_.RegisterIntentService(services[0]); |
| 630 registry_.RegisterIntentService(services[1]); | 652 registry_.RegisterIntentService(services[1]); |
| 631 | 653 |
| 632 TestConsumer consumer; | 654 TestConsumer consumer; |
| 633 registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), | 655 registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), |
| 634 ASCIIToUTF16("image/*"), | 656 ASCIIToUTF16("image/*"), |
| 635 base::Bind(&TestConsumer::OnIntentsQueryDone, | 657 base::Bind(&TestConsumer::OnIntentsQueryDone, |
| 636 base::Unretained(&consumer))); | 658 base::Unretained(&consumer))); |
| 637 | 659 |
| 638 consumer.WaitForData(); | 660 consumer.WaitForData(); |
| 639 ASSERT_EQ(1U, consumer.services_.size()); | 661 ASSERT_EQ(1U, consumer.services_.size()); |
| 640 EXPECT_EQ(ASCIIToUTF16("image/png,image/jpg"), consumer.services_[0].type); | 662 EXPECT_EQ(ASCIIToUTF16("image/png,image/jpg"), consumer.services_[0].type); |
| 641 } | 663 } |
| OLD | NEW |