| 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/base64.h" | 5 #include "base/base64.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 ExtensionBuilder() | 454 ExtensionBuilder() |
| 455 .SetID("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") | 455 .SetID("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") |
| 456 .SetManifest(DictionaryBuilder() | 456 .SetManifest(DictionaryBuilder() |
| 457 .Set("name", "Fake extension") | 457 .Set("name", "Fake extension") |
| 458 .Set("version", "1") | 458 .Set("version", "1") |
| 459 .Set("manifest_version", 2)) | 459 .Set("manifest_version", 2)) |
| 460 .Build(); | 460 .Build(); |
| 461 | 461 |
| 462 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 462 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
| 463 EXPECT_EQ(NAMESPACE_NOT_DEFINED, | 463 EXPECT_EQ(NAMESPACE_NOT_DEFINED, |
| 464 CanConnectAndSendMessagesToMainFrame(extension)); | 464 CanConnectAndSendMessagesToMainFrame(extension.get())); |
| 465 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 465 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
| 466 | 466 |
| 467 ui_test_utils::NavigateToURL(browser(), google_com_url()); | 467 ui_test_utils::NavigateToURL(browser(), google_com_url()); |
| 468 EXPECT_EQ(NAMESPACE_NOT_DEFINED, | 468 EXPECT_EQ(NAMESPACE_NOT_DEFINED, |
| 469 CanConnectAndSendMessagesToMainFrame(extension)); | 469 CanConnectAndSendMessagesToMainFrame(extension.get())); |
| 470 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 470 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
| 471 } | 471 } |
| 472 | 472 |
| 473 // Tests two extensions on the same sites: one web connectable, one not. | 473 // Tests two extensions on the same sites: one web connectable, one not. |
| 474 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 474 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 475 WebConnectableAndNotConnectable) { | 475 WebConnectableAndNotConnectable) { |
| 476 InitializeTestServer(); | 476 InitializeTestServer(); |
| 477 | 477 |
| 478 // Install the web connectable extension. chromium.org can connect to it, | 478 // Install the web connectable extension. chromium.org can connect to it, |
| 479 // google.com can't. | 479 // google.com can't. |
| 480 const Extension* chromium_connectable = LoadChromiumConnectableExtension(); | 480 scoped_refptr<const Extension> chromium_connectable = |
| 481 LoadChromiumConnectableExtension(); |
| 481 | 482 |
| 482 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 483 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
| 483 EXPECT_EQ(OK, CanConnectAndSendMessagesToMainFrame(chromium_connectable)); | 484 EXPECT_EQ(OK, |
| 485 CanConnectAndSendMessagesToMainFrame(chromium_connectable.get())); |
| 484 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 486 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
| 485 | 487 |
| 486 ui_test_utils::NavigateToURL(browser(), google_com_url()); | 488 ui_test_utils::NavigateToURL(browser(), google_com_url()); |
| 487 EXPECT_EQ(NAMESPACE_NOT_DEFINED, | 489 EXPECT_EQ(NAMESPACE_NOT_DEFINED, |
| 488 CanConnectAndSendMessagesToMainFrame(chromium_connectable)); | 490 CanConnectAndSendMessagesToMainFrame(chromium_connectable.get())); |
| 489 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 491 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
| 490 | 492 |
| 491 // Install the non-connectable extension. Nothing can connect to it. | 493 // Install the non-connectable extension. Nothing can connect to it. |
| 492 const Extension* not_connectable = LoadNotConnectableExtension(); | 494 scoped_refptr<const Extension> not_connectable = |
| 495 LoadNotConnectableExtension(); |
| 493 | 496 |
| 494 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 497 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
| 495 // Namespace will be defined here because |chromium_connectable| can connect | 498 // Namespace will be defined here because |chromium_connectable| can connect |
| 496 // to it - so this will be the "cannot establish connection" error. | 499 // to it - so this will be the "cannot establish connection" error. |
| 497 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, | 500 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
| 498 CanConnectAndSendMessagesToMainFrame(not_connectable)); | 501 CanConnectAndSendMessagesToMainFrame(not_connectable.get())); |
| 499 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 502 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
| 500 | 503 |
| 501 ui_test_utils::NavigateToURL(browser(), google_com_url()); | 504 ui_test_utils::NavigateToURL(browser(), google_com_url()); |
| 502 EXPECT_EQ(NAMESPACE_NOT_DEFINED, | 505 EXPECT_EQ(NAMESPACE_NOT_DEFINED, |
| 503 CanConnectAndSendMessagesToMainFrame(not_connectable)); | 506 CanConnectAndSendMessagesToMainFrame(not_connectable.get())); |
| 504 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 507 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
| 505 } | 508 } |
| 506 | 509 |
| 507 // See http://crbug.com/297866 | 510 // See http://crbug.com/297866 |
| 508 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 511 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 509 DISABLED_BackgroundPageClosesOnMessageReceipt) { | 512 DISABLED_BackgroundPageClosesOnMessageReceipt) { |
| 510 InitializeTestServer(); | 513 InitializeTestServer(); |
| 511 | 514 |
| 512 // Install the web connectable extension. | 515 // Install the web connectable extension. |
| 513 const Extension* chromium_connectable = LoadChromiumConnectableExtension(); | 516 scoped_refptr<const Extension> chromium_connectable = |
| 517 LoadChromiumConnectableExtension(); |
| 514 | 518 |
| 515 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 519 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
| 516 // If the background page closes after receipt of the message, it will still | 520 // If the background page closes after receipt of the message, it will still |
| 517 // reply to this message... | 521 // reply to this message... |
| 518 EXPECT_EQ(OK, | 522 EXPECT_EQ(OK, |
| 519 CanConnectAndSendMessagesToMainFrame(chromium_connectable, | 523 CanConnectAndSendMessagesToMainFrame(chromium_connectable.get(), |
| 520 close_background_message())); | 524 close_background_message())); |
| 521 // and be re-opened by receipt of a subsequent message. | 525 // and be re-opened by receipt of a subsequent message. |
| 522 EXPECT_EQ(OK, CanConnectAndSendMessagesToMainFrame(chromium_connectable)); | 526 EXPECT_EQ(OK, |
| 527 CanConnectAndSendMessagesToMainFrame(chromium_connectable.get())); |
| 523 } | 528 } |
| 524 | 529 |
| 525 // Tests a web connectable extension that doesn't receive TLS channel id. | 530 // Tests a web connectable extension that doesn't receive TLS channel id. |
| 526 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 531 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 527 WebConnectableWithoutTlsChannelId) { | 532 WebConnectableWithoutTlsChannelId) { |
| 528 InitializeTestServer(); | 533 InitializeTestServer(); |
| 529 | 534 |
| 530 // Install the web connectable extension. chromium.org can connect to it, | 535 // Install the web connectable extension. chromium.org can connect to it, |
| 531 // google.com can't. | 536 // google.com can't. |
| 532 const Extension* chromium_connectable = LoadChromiumConnectableExtension(); | 537 scoped_refptr<const Extension> chromium_connectable = |
| 533 ASSERT_TRUE(chromium_connectable); | 538 LoadChromiumConnectableExtension(); |
| 539 ASSERT_TRUE(chromium_connectable.get()); |
| 534 | 540 |
| 535 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 541 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
| 536 // The web connectable extension doesn't request the TLS channel ID, so it | 542 // The web connectable extension doesn't request the TLS channel ID, so it |
| 537 // doesn't get it, whether or not the page asks for it. | 543 // doesn't get it, whether or not the page asks for it. |
| 538 EXPECT_EQ(std::string(), | 544 EXPECT_EQ(std::string(), |
| 539 GetTlsChannelIdFromPortConnect(chromium_connectable, false)); | 545 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), false)); |
| 540 EXPECT_EQ(std::string(), | 546 EXPECT_EQ(std::string(), |
| 541 GetTlsChannelIdFromSendMessage(chromium_connectable, true)); | 547 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), true)); |
| 542 EXPECT_EQ(std::string(), | 548 EXPECT_EQ(std::string(), |
| 543 GetTlsChannelIdFromPortConnect(chromium_connectable, false)); | 549 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), false)); |
| 544 EXPECT_EQ(std::string(), | 550 EXPECT_EQ(std::string(), |
| 545 GetTlsChannelIdFromSendMessage(chromium_connectable, true)); | 551 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), true)); |
| 546 } | 552 } |
| 547 | 553 |
| 548 // Tests a web connectable extension that receives TLS channel id with a site | 554 // Tests a web connectable extension that receives TLS channel id with a site |
| 549 // that can't connect to it. | 555 // that can't connect to it. |
| 550 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 556 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 551 WebConnectableWithTlsChannelIdWithNonMatchingSite) { | 557 WebConnectableWithTlsChannelIdWithNonMatchingSite) { |
| 552 InitializeTestServer(); | 558 InitializeTestServer(); |
| 553 | 559 |
| 554 const Extension* chromium_connectable = | 560 scoped_refptr<const Extension> chromium_connectable = |
| 555 LoadChromiumConnectableExtensionWithTlsChannelId(); | 561 LoadChromiumConnectableExtensionWithTlsChannelId(); |
| 556 ASSERT_TRUE(chromium_connectable); | 562 ASSERT_TRUE(chromium_connectable.get()); |
| 557 | 563 |
| 558 ui_test_utils::NavigateToURL(browser(), google_com_url()); | 564 ui_test_utils::NavigateToURL(browser(), google_com_url()); |
| 559 // The extension requests the TLS channel ID, but it doesn't get it for a | 565 // The extension requests the TLS channel ID, but it doesn't get it for a |
| 560 // site that can't connect to it, regardless of whether the page asks for it. | 566 // site that can't connect to it, regardless of whether the page asks for it. |
| 561 EXPECT_EQ(base::StringPrintf("%d", NAMESPACE_NOT_DEFINED), | 567 EXPECT_EQ(base::StringPrintf("%d", NAMESPACE_NOT_DEFINED), |
| 562 GetTlsChannelIdFromPortConnect(chromium_connectable, false)); | 568 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), false)); |
| 563 EXPECT_EQ(base::StringPrintf("%d", NAMESPACE_NOT_DEFINED), | 569 EXPECT_EQ(base::StringPrintf("%d", NAMESPACE_NOT_DEFINED), |
| 564 GetTlsChannelIdFromSendMessage(chromium_connectable, true)); | 570 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), true)); |
| 565 EXPECT_EQ(base::StringPrintf("%d", NAMESPACE_NOT_DEFINED), | 571 EXPECT_EQ(base::StringPrintf("%d", NAMESPACE_NOT_DEFINED), |
| 566 GetTlsChannelIdFromPortConnect(chromium_connectable, false)); | 572 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), false)); |
| 567 EXPECT_EQ(base::StringPrintf("%d", NAMESPACE_NOT_DEFINED), | 573 EXPECT_EQ(base::StringPrintf("%d", NAMESPACE_NOT_DEFINED), |
| 568 GetTlsChannelIdFromSendMessage(chromium_connectable, true)); | 574 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), true)); |
| 569 } | 575 } |
| 570 | 576 |
| 571 // Tests a web connectable extension that receives TLS channel id on a site | 577 // Tests a web connectable extension that receives TLS channel id on a site |
| 572 // that can connect to it, but with no TLS channel ID having been generated. | 578 // that can connect to it, but with no TLS channel ID having been generated. |
| 573 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 579 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 574 WebConnectableWithTlsChannelIdWithEmptyTlsChannelId) { | 580 WebConnectableWithTlsChannelIdWithEmptyTlsChannelId) { |
| 575 InitializeTestServer(); | 581 InitializeTestServer(); |
| 576 | 582 |
| 577 const Extension* chromium_connectable = | 583 scoped_refptr<const Extension> chromium_connectable = |
| 578 LoadChromiumConnectableExtensionWithTlsChannelId(); | 584 LoadChromiumConnectableExtensionWithTlsChannelId(); |
| 579 ASSERT_TRUE(chromium_connectable); | 585 ASSERT_TRUE(chromium_connectable.get()); |
| 580 | 586 |
| 581 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 587 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
| 582 | 588 |
| 583 // Since the extension requests the TLS channel ID, it gets it for a site that | 589 // Since the extension requests the TLS channel ID, it gets it for a site that |
| 584 // can connect to it, but only if the page also asks to include it. | 590 // can connect to it, but only if the page also asks to include it. |
| 585 EXPECT_EQ(std::string(), | 591 EXPECT_EQ(std::string(), |
| 586 GetTlsChannelIdFromPortConnect(chromium_connectable, false)); | 592 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), false)); |
| 587 EXPECT_EQ(std::string(), | 593 EXPECT_EQ(std::string(), |
| 588 GetTlsChannelIdFromSendMessage(chromium_connectable, false)); | 594 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), false)); |
| 589 // If the page does ask for it, it isn't empty. | 595 // If the page does ask for it, it isn't empty. |
| 590 std::string tls_channel_id = | 596 std::string tls_channel_id = |
| 591 GetTlsChannelIdFromPortConnect(chromium_connectable, true); | 597 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), true); |
| 592 // Because the TLS channel ID has never been generated for this domain, | 598 // Because the TLS channel ID has never been generated for this domain, |
| 593 // no TLS channel ID is reported. | 599 // no TLS channel ID is reported. |
| 594 EXPECT_EQ(std::string(), tls_channel_id); | 600 EXPECT_EQ(std::string(), tls_channel_id); |
| 595 } | 601 } |
| 596 | 602 |
| 597 // Flaky on Linux and Windows. http://crbug.com/315264 | 603 // Flaky on Linux and Windows. http://crbug.com/315264 |
| 598 // Tests a web connectable extension that receives TLS channel id, but | 604 // Tests a web connectable extension that receives TLS channel id, but |
| 599 // immediately closes its background page upon receipt of a message. | 605 // immediately closes its background page upon receipt of a message. |
| 600 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 606 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 601 DISABLED_WebConnectableWithEmptyTlsChannelIdAndClosedBackgroundPage) { | 607 DISABLED_WebConnectableWithEmptyTlsChannelIdAndClosedBackgroundPage) { |
| 602 InitializeTestServer(); | 608 InitializeTestServer(); |
| 603 | 609 |
| 604 const Extension* chromium_connectable = | 610 scoped_refptr<const Extension> chromium_connectable = |
| 605 LoadChromiumConnectableExtensionWithTlsChannelId(); | 611 LoadChromiumConnectableExtensionWithTlsChannelId(); |
| 606 | 612 |
| 607 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 613 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
| 608 // If the page does ask for it, it isn't empty, even if the background page | 614 // If the page does ask for it, it isn't empty, even if the background page |
| 609 // closes upon receipt of the connect. | 615 // closes upon receipt of the connect. |
| 610 std::string tls_channel_id = GetTlsChannelIdFromPortConnect( | 616 std::string tls_channel_id = GetTlsChannelIdFromPortConnect( |
| 611 chromium_connectable, true, close_background_message()); | 617 chromium_connectable.get(), true, close_background_message()); |
| 612 // Because the TLS channel ID has never been generated for this domain, | 618 // Because the TLS channel ID has never been generated for this domain, |
| 613 // no TLS channel ID is reported. | 619 // no TLS channel ID is reported. |
| 614 EXPECT_EQ(std::string(), tls_channel_id); | 620 EXPECT_EQ(std::string(), tls_channel_id); |
| 615 // A subsequent connect will still succeed, even if the background page was | 621 // A subsequent connect will still succeed, even if the background page was |
| 616 // previously closed. | 622 // previously closed. |
| 617 tls_channel_id = GetTlsChannelIdFromPortConnect(chromium_connectable, true); | 623 tls_channel_id = |
| 624 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), true); |
| 618 // And the empty value is still retrieved. | 625 // And the empty value is still retrieved. |
| 619 EXPECT_EQ(std::string(), tls_channel_id); | 626 EXPECT_EQ(std::string(), tls_channel_id); |
| 620 } | 627 } |
| 621 | 628 |
| 622 // Tests that enabling and disabling an extension makes the runtime bindings | 629 // Tests that enabling and disabling an extension makes the runtime bindings |
| 623 // appear and disappear. | 630 // appear and disappear. |
| 624 // | 631 // |
| 625 // TODO(kalman): Test with multiple extensions that can be accessed by the same | 632 // TODO(kalman): Test with multiple extensions that can be accessed by the same |
| 626 // host. | 633 // host. |
| 627 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 634 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 628 EnablingAndDisabling) { | 635 EnablingAndDisabling) { |
| 629 InitializeTestServer(); | 636 InitializeTestServer(); |
| 630 | 637 |
| 631 const Extension* chromium_connectable = LoadChromiumConnectableExtension(); | 638 scoped_refptr<const Extension> chromium_connectable = |
| 632 const Extension* not_connectable = LoadNotConnectableExtension(); | 639 LoadChromiumConnectableExtension(); |
| 640 scoped_refptr<const Extension> not_connectable = |
| 641 LoadNotConnectableExtension(); |
| 633 | 642 |
| 634 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 643 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
| 635 EXPECT_EQ(OK, CanConnectAndSendMessagesToMainFrame(chromium_connectable)); | 644 EXPECT_EQ(OK, |
| 645 CanConnectAndSendMessagesToMainFrame(chromium_connectable.get())); |
| 636 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, | 646 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
| 637 CanConnectAndSendMessagesToMainFrame(not_connectable)); | 647 CanConnectAndSendMessagesToMainFrame(not_connectable.get())); |
| 638 | 648 |
| 639 DisableExtension(chromium_connectable->id()); | 649 DisableExtension(chromium_connectable->id()); |
| 640 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, | 650 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
| 641 CanConnectAndSendMessagesToMainFrame(chromium_connectable)); | 651 CanConnectAndSendMessagesToMainFrame(chromium_connectable.get())); |
| 642 | 652 |
| 643 EnableExtension(chromium_connectable->id()); | 653 EnableExtension(chromium_connectable->id()); |
| 644 EXPECT_EQ(OK, CanConnectAndSendMessagesToMainFrame(chromium_connectable)); | 654 EXPECT_EQ(OK, |
| 655 CanConnectAndSendMessagesToMainFrame(chromium_connectable.get())); |
| 645 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, | 656 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
| 646 CanConnectAndSendMessagesToMainFrame(not_connectable)); | 657 CanConnectAndSendMessagesToMainFrame(not_connectable.get())); |
| 647 } | 658 } |
| 648 | 659 |
| 649 // Tests connection from incognito tabs when the user denies the connection | 660 // Tests connection from incognito tabs when the user denies the connection |
| 650 // request. Spanning mode only. A separate test for apps and extensions. | 661 // request. Spanning mode only. A separate test for apps and extensions. |
| 651 // | 662 // |
| 652 // TODO(kalman): ensure that we exercise split vs spanning incognito logic | 663 // TODO(kalman): ensure that we exercise split vs spanning incognito logic |
| 653 // somewhere. This is a test that should be shared with the content script logic | 664 // somewhere. This is a test that should be shared with the content script logic |
| 654 // so it's not really our specific concern for web connectable. | 665 // so it's not really our specific concern for web connectable. |
| 655 // | 666 // |
| 656 // TODO(kalman): test messages from incognito extensions too. | 667 // TODO(kalman): test messages from incognito extensions too. |
| 657 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 668 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 658 FromIncognitoDenyApp) { | 669 FromIncognitoDenyApp) { |
| 659 InitializeTestServer(); | 670 InitializeTestServer(); |
| 660 | 671 |
| 661 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(); | 672 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(); |
| 662 ASSERT_TRUE(app->is_platform_app()); | 673 ASSERT_TRUE(app->is_platform_app()); |
| 663 | 674 |
| 664 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( | 675 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( |
| 665 profile()->GetOffTheRecordProfile(), | 676 profile()->GetOffTheRecordProfile(), |
| 666 chromium_org_url()); | 677 chromium_org_url()); |
| 667 content::RenderFrameHost* incognito_frame = incognito_browser-> | 678 content::RenderFrameHost* incognito_frame = incognito_browser-> |
| 668 tab_strip_model()->GetActiveWebContents()->GetMainFrame(); | 679 tab_strip_model()->GetActiveWebContents()->GetMainFrame(); |
| 669 | 680 |
| 670 { | 681 { |
| 671 IncognitoConnectability::ScopedAlertTracker alert_tracker( | 682 IncognitoConnectability::ScopedAlertTracker alert_tracker( |
| 672 IncognitoConnectability::ScopedAlertTracker::ALWAYS_DENY); | 683 IncognitoConnectability::ScopedAlertTracker::ALWAYS_DENY); |
| 673 | 684 |
| 674 // No connection because incognito-enabled hasn't been set for the app, and | 685 // No connection because incognito-enabled hasn't been set for the app, and |
| 675 // the user denied our interactive request. | 686 // the user denied our interactive request. |
| 676 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, | 687 EXPECT_EQ( |
| 677 CanConnectAndSendMessagesToFrame(incognito_frame, app, NULL)); | 688 COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
| 689 CanConnectAndSendMessagesToFrame(incognito_frame, app.get(), NULL)); |
| 678 EXPECT_EQ(1, alert_tracker.GetAndResetAlertCount()); | 690 EXPECT_EQ(1, alert_tracker.GetAndResetAlertCount()); |
| 679 | 691 |
| 680 // Try again. User has already denied so alert not shown. | 692 // Try again. User has already denied so alert not shown. |
| 681 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, | 693 EXPECT_EQ( |
| 682 CanConnectAndSendMessagesToFrame(incognito_frame, app, NULL)); | 694 COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
| 695 CanConnectAndSendMessagesToFrame(incognito_frame, app.get(), NULL)); |
| 683 EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); | 696 EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); |
| 684 } | 697 } |
| 685 | 698 |
| 686 // It's not possible to allow an app in incognito. | 699 // It's not possible to allow an app in incognito. |
| 687 ExtensionPrefs::Get(profile())->SetIsIncognitoEnabled(app->id(), true); | 700 ExtensionPrefs::Get(profile())->SetIsIncognitoEnabled(app->id(), true); |
| 688 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, | 701 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
| 689 CanConnectAndSendMessagesToFrame(incognito_frame, app, NULL)); | 702 CanConnectAndSendMessagesToFrame(incognito_frame, app.get(), NULL)); |
| 690 } | 703 } |
| 691 | 704 |
| 692 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 705 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 693 FromIncognitoDenyExtension) { | 706 FromIncognitoDenyExtension) { |
| 694 InitializeTestServer(); | 707 InitializeTestServer(); |
| 695 | 708 |
| 696 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); | 709 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); |
| 697 | 710 |
| 698 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( | 711 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( |
| 699 profile()->GetOffTheRecordProfile(), chromium_org_url()); | 712 profile()->GetOffTheRecordProfile(), chromium_org_url()); |
| 700 content::RenderFrameHost* incognito_frame = | 713 content::RenderFrameHost* incognito_frame = |
| 701 incognito_browser->tab_strip_model() | 714 incognito_browser->tab_strip_model() |
| 702 ->GetActiveWebContents() | 715 ->GetActiveWebContents() |
| 703 ->GetMainFrame(); | 716 ->GetMainFrame(); |
| 704 | 717 |
| 705 { | 718 { |
| 706 IncognitoConnectability::ScopedAlertTracker alert_tracker( | 719 IncognitoConnectability::ScopedAlertTracker alert_tracker( |
| 707 IncognitoConnectability::ScopedAlertTracker::ALWAYS_DENY); | 720 IncognitoConnectability::ScopedAlertTracker::ALWAYS_DENY); |
| 708 | 721 |
| 709 // The alert doesn't show for extensions. | 722 // The alert doesn't show for extensions. |
| 710 EXPECT_EQ( | 723 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
| 711 COULD_NOT_ESTABLISH_CONNECTION_ERROR, | 724 CanConnectAndSendMessagesToFrame( |
| 712 CanConnectAndSendMessagesToFrame(incognito_frame, extension, NULL)); | 725 incognito_frame, extension.get(), NULL)); |
| 713 EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); | 726 EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); |
| 714 } | 727 } |
| 715 | 728 |
| 716 // Allowing the extension in incognito mode will bypass the deny. | 729 // Allowing the extension in incognito mode will bypass the deny. |
| 717 ExtensionPrefs::Get(profile())->SetIsIncognitoEnabled(extension->id(), true); | 730 ExtensionPrefs::Get(profile())->SetIsIncognitoEnabled(extension->id(), true); |
| 718 EXPECT_EQ(OK, | 731 EXPECT_EQ( |
| 719 CanConnectAndSendMessagesToFrame(incognito_frame, extension, NULL)); | 732 OK, |
| 733 CanConnectAndSendMessagesToFrame(incognito_frame, extension.get(), NULL)); |
| 720 } | 734 } |
| 721 | 735 |
| 722 // Tests connection from incognito tabs when the user accepts the connection | 736 // Tests connection from incognito tabs when the user accepts the connection |
| 723 // request. Spanning mode only. Separate tests for apps and extensions. | 737 // request. Spanning mode only. Separate tests for apps and extensions. |
| 724 // | 738 // |
| 725 // TODO(kalman): see comment above about split mode. | 739 // TODO(kalman): see comment above about split mode. |
| 726 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 740 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 727 FromIncognitoAllowApp) { | 741 FromIncognitoAllowApp) { |
| 728 InitializeTestServer(); | 742 InitializeTestServer(); |
| 729 | 743 |
| 730 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(); | 744 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(); |
| 731 ASSERT_TRUE(app->is_platform_app()); | 745 ASSERT_TRUE(app->is_platform_app()); |
| 732 | 746 |
| 733 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( | 747 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( |
| 734 profile()->GetOffTheRecordProfile(), | 748 profile()->GetOffTheRecordProfile(), |
| 735 chromium_org_url()); | 749 chromium_org_url()); |
| 736 content::RenderFrameHost* incognito_frame = incognito_browser-> | 750 content::RenderFrameHost* incognito_frame = incognito_browser-> |
| 737 tab_strip_model()->GetActiveWebContents()->GetMainFrame(); | 751 tab_strip_model()->GetActiveWebContents()->GetMainFrame(); |
| 738 | 752 |
| 739 { | 753 { |
| 740 IncognitoConnectability::ScopedAlertTracker alert_tracker( | 754 IncognitoConnectability::ScopedAlertTracker alert_tracker( |
| 741 IncognitoConnectability::ScopedAlertTracker::ALWAYS_ALLOW); | 755 IncognitoConnectability::ScopedAlertTracker::ALWAYS_ALLOW); |
| 742 | 756 |
| 743 // Connection allowed even with incognito disabled, because the user | 757 // Connection allowed even with incognito disabled, because the user |
| 744 // accepted the interactive request. | 758 // accepted the interactive request. |
| 745 EXPECT_EQ(OK, CanConnectAndSendMessagesToFrame(incognito_frame, app, NULL)); | 759 EXPECT_EQ( |
| 760 OK, CanConnectAndSendMessagesToFrame(incognito_frame, app.get(), NULL)); |
| 746 EXPECT_EQ(1, alert_tracker.GetAndResetAlertCount()); | 761 EXPECT_EQ(1, alert_tracker.GetAndResetAlertCount()); |
| 747 | 762 |
| 748 // Try again. User has already allowed. | 763 // Try again. User has already allowed. |
| 749 EXPECT_EQ(OK, CanConnectAndSendMessagesToFrame(incognito_frame, app, NULL)); | 764 EXPECT_EQ( |
| 765 OK, CanConnectAndSendMessagesToFrame(incognito_frame, app.get(), NULL)); |
| 750 EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); | 766 EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); |
| 751 } | 767 } |
| 752 | 768 |
| 753 // Apps can't be allowed in incognito mode, but it's moot because it's | 769 // Apps can't be allowed in incognito mode, but it's moot because it's |
| 754 // already allowed. | 770 // already allowed. |
| 755 ExtensionPrefs::Get(profile())->SetIsIncognitoEnabled(app->id(), true); | 771 ExtensionPrefs::Get(profile())->SetIsIncognitoEnabled(app->id(), true); |
| 756 EXPECT_EQ(OK, CanConnectAndSendMessagesToFrame(incognito_frame, app, NULL)); | 772 EXPECT_EQ(OK, |
| 773 CanConnectAndSendMessagesToFrame(incognito_frame, app.get(), NULL)); |
| 757 } | 774 } |
| 758 | 775 |
| 759 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 776 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 760 FromIncognitoAllowExtension) { | 777 FromIncognitoAllowExtension) { |
| 761 InitializeTestServer(); | 778 InitializeTestServer(); |
| 762 | 779 |
| 763 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); | 780 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); |
| 764 | 781 |
| 765 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( | 782 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( |
| 766 profile()->GetOffTheRecordProfile(), chromium_org_url()); | 783 profile()->GetOffTheRecordProfile(), chromium_org_url()); |
| 767 content::RenderFrameHost* incognito_frame = | 784 content::RenderFrameHost* incognito_frame = |
| 768 incognito_browser->tab_strip_model() | 785 incognito_browser->tab_strip_model() |
| 769 ->GetActiveWebContents() | 786 ->GetActiveWebContents() |
| 770 ->GetMainFrame(); | 787 ->GetMainFrame(); |
| 771 | 788 |
| 772 { | 789 { |
| 773 IncognitoConnectability::ScopedAlertTracker alert_tracker( | 790 IncognitoConnectability::ScopedAlertTracker alert_tracker( |
| 774 IncognitoConnectability::ScopedAlertTracker::ALWAYS_ALLOW); | 791 IncognitoConnectability::ScopedAlertTracker::ALWAYS_ALLOW); |
| 775 | 792 |
| 776 // No alert is shown. | 793 // No alert is shown. |
| 777 EXPECT_EQ( | 794 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
| 778 COULD_NOT_ESTABLISH_CONNECTION_ERROR, | 795 CanConnectAndSendMessagesToFrame( |
| 779 CanConnectAndSendMessagesToFrame(incognito_frame, extension, NULL)); | 796 incognito_frame, extension.get(), NULL)); |
| 780 EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); | 797 EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); |
| 781 } | 798 } |
| 782 | 799 |
| 783 // Allowing the extension in incognito mode is what allows connections. | 800 // Allowing the extension in incognito mode is what allows connections. |
| 784 ExtensionPrefs::Get(profile())->SetIsIncognitoEnabled(extension->id(), true); | 801 ExtensionPrefs::Get(profile())->SetIsIncognitoEnabled(extension->id(), true); |
| 785 EXPECT_EQ(OK, | 802 EXPECT_EQ( |
| 786 CanConnectAndSendMessagesToFrame(incognito_frame, extension, NULL)); | 803 OK, |
| 804 CanConnectAndSendMessagesToFrame(incognito_frame, extension.get(), NULL)); |
| 787 } | 805 } |
| 788 | 806 |
| 789 // Tests a connection from an iframe within a tab which doesn't have | 807 // Tests a connection from an iframe within a tab which doesn't have |
| 790 // permission. Iframe should work. | 808 // permission. Iframe should work. |
| 791 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 809 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 792 FromIframeWithPermission) { | 810 FromIframeWithPermission) { |
| 793 InitializeTestServer(); | 811 InitializeTestServer(); |
| 794 | 812 |
| 795 const Extension* extension = LoadChromiumConnectableExtension(); | 813 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); |
| 796 | 814 |
| 797 ui_test_utils::NavigateToURL(browser(), google_com_url()); | 815 ui_test_utils::NavigateToURL(browser(), google_com_url()); |
| 798 EXPECT_EQ(NAMESPACE_NOT_DEFINED, | 816 EXPECT_EQ(NAMESPACE_NOT_DEFINED, |
| 799 CanConnectAndSendMessagesToMainFrame(extension)); | 817 CanConnectAndSendMessagesToMainFrame(extension.get())); |
| 800 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 818 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
| 801 | 819 |
| 802 ASSERT_TRUE(AppendIframe(chromium_org_url())); | 820 ASSERT_TRUE(AppendIframe(chromium_org_url())); |
| 803 | 821 |
| 804 EXPECT_EQ(OK, CanConnectAndSendMessagesToIFrame(extension)); | 822 EXPECT_EQ(OK, CanConnectAndSendMessagesToIFrame(extension.get())); |
| 805 EXPECT_FALSE(AreAnyNonWebApisDefinedForIFrame()); | 823 EXPECT_FALSE(AreAnyNonWebApisDefinedForIFrame()); |
| 806 } | 824 } |
| 807 | 825 |
| 808 // Tests connection from an iframe without permission within a tab that does. | 826 // Tests connection from an iframe without permission within a tab that does. |
| 809 // Iframe shouldn't work. | 827 // Iframe shouldn't work. |
| 810 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 828 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 811 FromIframeWithoutPermission) { | 829 FromIframeWithoutPermission) { |
| 812 InitializeTestServer(); | 830 InitializeTestServer(); |
| 813 | 831 |
| 814 const Extension* extension = LoadChromiumConnectableExtension(); | 832 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); |
| 815 | 833 |
| 816 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 834 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
| 817 EXPECT_EQ(OK, CanConnectAndSendMessagesToMainFrame(extension)); | 835 EXPECT_EQ(OK, CanConnectAndSendMessagesToMainFrame(extension.get())); |
| 818 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 836 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
| 819 | 837 |
| 820 ASSERT_TRUE(AppendIframe(google_com_url())); | 838 ASSERT_TRUE(AppendIframe(google_com_url())); |
| 821 | 839 |
| 822 EXPECT_EQ(NAMESPACE_NOT_DEFINED, | 840 EXPECT_EQ(NAMESPACE_NOT_DEFINED, |
| 823 CanConnectAndSendMessagesToIFrame(extension)); | 841 CanConnectAndSendMessagesToIFrame(extension.get())); |
| 824 EXPECT_FALSE(AreAnyNonWebApisDefinedForIFrame()); | 842 EXPECT_FALSE(AreAnyNonWebApisDefinedForIFrame()); |
| 825 } | 843 } |
| 826 | 844 |
| 827 // Tests externally_connectable between a web page and an extension with a | 845 // Tests externally_connectable between a web page and an extension with a |
| 828 // TLS channel ID created for the origin. | 846 // TLS channel ID created for the origin. |
| 829 class ExternallyConnectableMessagingWithTlsChannelIdTest : | 847 class ExternallyConnectableMessagingWithTlsChannelIdTest : |
| 830 public ExternallyConnectableMessagingTest { | 848 public ExternallyConnectableMessagingTest { |
| 831 public: | 849 public: |
| 832 ExternallyConnectableMessagingWithTlsChannelIdTest() | 850 ExternallyConnectableMessagingWithTlsChannelIdTest() |
| 833 : tls_channel_id_created_(false, false) { | 851 : tls_channel_id_created_(false, false) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 base::WaitableEvent tls_channel_id_created_; | 910 base::WaitableEvent tls_channel_id_created_; |
| 893 }; | 911 }; |
| 894 | 912 |
| 895 // Tests a web connectable extension that receives TLS channel id on a site | 913 // Tests a web connectable extension that receives TLS channel id on a site |
| 896 // that can connect to it, with a TLS channel ID having been generated. | 914 // that can connect to it, with a TLS channel ID having been generated. |
| 897 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingWithTlsChannelIdTest, | 915 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingWithTlsChannelIdTest, |
| 898 WebConnectableWithNonEmptyTlsChannelId) { | 916 WebConnectableWithNonEmptyTlsChannelId) { |
| 899 InitializeTestServer(); | 917 InitializeTestServer(); |
| 900 std::string expected_tls_channel_id_value = CreateTlsChannelId(); | 918 std::string expected_tls_channel_id_value = CreateTlsChannelId(); |
| 901 | 919 |
| 902 const Extension* chromium_connectable = | 920 scoped_refptr<const Extension> chromium_connectable = |
| 903 LoadChromiumConnectableExtensionWithTlsChannelId(); | 921 LoadChromiumConnectableExtensionWithTlsChannelId(); |
| 904 ASSERT_TRUE(chromium_connectable); | 922 ASSERT_TRUE(chromium_connectable.get()); |
| 905 | 923 |
| 906 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 924 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
| 907 | 925 |
| 908 // Since the extension requests the TLS channel ID, it gets it for a site that | 926 // Since the extension requests the TLS channel ID, it gets it for a site that |
| 909 // can connect to it, but only if the page also asks to send it. | 927 // can connect to it, but only if the page also asks to send it. |
| 910 EXPECT_EQ(std::string(), | 928 EXPECT_EQ(std::string(), |
| 911 GetTlsChannelIdFromPortConnect(chromium_connectable, false)); | 929 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), false)); |
| 912 EXPECT_EQ(std::string(), | 930 EXPECT_EQ(std::string(), |
| 913 GetTlsChannelIdFromSendMessage(chromium_connectable, false)); | 931 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), false)); |
| 914 | 932 |
| 915 // If the page does ask to send the TLS channel ID, it's sent and non-empty. | 933 // If the page does ask to send the TLS channel ID, it's sent and non-empty. |
| 916 std::string tls_channel_id_from_port_connect = | 934 std::string tls_channel_id_from_port_connect = |
| 917 GetTlsChannelIdFromPortConnect(chromium_connectable, true); | 935 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), true); |
| 918 EXPECT_NE(0u, tls_channel_id_from_port_connect.size()); | 936 EXPECT_NE(0u, tls_channel_id_from_port_connect.size()); |
| 919 | 937 |
| 920 // The same value is received by both connect and sendMessage. | 938 // The same value is received by both connect and sendMessage. |
| 921 std::string tls_channel_id_from_send_message = | 939 std::string tls_channel_id_from_send_message = |
| 922 GetTlsChannelIdFromSendMessage(chromium_connectable, true); | 940 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), true); |
| 923 EXPECT_EQ(tls_channel_id_from_port_connect, tls_channel_id_from_send_message); | 941 EXPECT_EQ(tls_channel_id_from_port_connect, tls_channel_id_from_send_message); |
| 924 | 942 |
| 925 // And since a TLS channel ID exists for the domain, the value received is | 943 // And since a TLS channel ID exists for the domain, the value received is |
| 926 // parseable as a JWK. (In particular, it has the same value we created by | 944 // parseable as a JWK. (In particular, it has the same value we created by |
| 927 // converting the public key to JWK with net::ConvertSpkiFromDerToJwk.) | 945 // converting the public key to JWK with net::ConvertSpkiFromDerToJwk.) |
| 928 std::string tls_channel_id(tls_channel_id_from_port_connect); | 946 std::string tls_channel_id(tls_channel_id_from_port_connect); |
| 929 EXPECT_EQ(expected_tls_channel_id_value, tls_channel_id); | 947 EXPECT_EQ(expected_tls_channel_id_value, tls_channel_id); |
| 930 | 948 |
| 931 // The TLS channel ID shouldn't change from one connection to the next... | 949 // The TLS channel ID shouldn't change from one connection to the next... |
| 932 std::string tls_channel_id2 = | 950 std::string tls_channel_id2 = |
| 933 GetTlsChannelIdFromPortConnect(chromium_connectable, true); | 951 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), true); |
| 934 EXPECT_EQ(tls_channel_id, tls_channel_id2); | 952 EXPECT_EQ(tls_channel_id, tls_channel_id2); |
| 935 tls_channel_id2 = GetTlsChannelIdFromSendMessage(chromium_connectable, true); | 953 tls_channel_id2 = |
| 954 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), true); |
| 936 EXPECT_EQ(tls_channel_id, tls_channel_id2); | 955 EXPECT_EQ(tls_channel_id, tls_channel_id2); |
| 937 | 956 |
| 938 // nor should it change when navigating away, revisiting the page and | 957 // nor should it change when navigating away, revisiting the page and |
| 939 // requesting it again. | 958 // requesting it again. |
| 940 ui_test_utils::NavigateToURL(browser(), google_com_url()); | 959 ui_test_utils::NavigateToURL(browser(), google_com_url()); |
| 941 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 960 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
| 942 tls_channel_id2 = GetTlsChannelIdFromPortConnect(chromium_connectable, true); | 961 tls_channel_id2 = |
| 962 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), true); |
| 943 EXPECT_EQ(tls_channel_id, tls_channel_id2); | 963 EXPECT_EQ(tls_channel_id, tls_channel_id2); |
| 944 tls_channel_id2 = GetTlsChannelIdFromSendMessage(chromium_connectable, true); | 964 tls_channel_id2 = |
| 965 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), true); |
| 945 EXPECT_EQ(tls_channel_id, tls_channel_id2); | 966 EXPECT_EQ(tls_channel_id, tls_channel_id2); |
| 946 } | 967 } |
| 947 | 968 |
| 948 // Tests a web connectable extension that receives TLS channel id, but | 969 // Tests a web connectable extension that receives TLS channel id, but |
| 949 // immediately closes its background page upon receipt of a message. | 970 // immediately closes its background page upon receipt of a message. |
| 950 // Same flakiness seen in http://crbug.com/297866 | 971 // Same flakiness seen in http://crbug.com/297866 |
| 951 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingWithTlsChannelIdTest, | 972 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingWithTlsChannelIdTest, |
| 952 DISABLED_WebConnectableWithNonEmptyTlsChannelIdAndClosedBackgroundPage) { | 973 DISABLED_WebConnectableWithNonEmptyTlsChannelIdAndClosedBackgroundPage) { |
| 953 InitializeTestServer(); | 974 InitializeTestServer(); |
| 954 std::string expected_tls_channel_id_value = CreateTlsChannelId(); | 975 std::string expected_tls_channel_id_value = CreateTlsChannelId(); |
| 955 | 976 |
| 956 const Extension* chromium_connectable = | 977 scoped_refptr<const Extension> chromium_connectable = |
| 957 LoadChromiumConnectableExtensionWithTlsChannelId(); | 978 LoadChromiumConnectableExtensionWithTlsChannelId(); |
| 958 | 979 |
| 959 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 980 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
| 960 // If the page does ask for it, it isn't empty, even if the background page | 981 // If the page does ask for it, it isn't empty, even if the background page |
| 961 // closes upon receipt of the connect. | 982 // closes upon receipt of the connect. |
| 962 std::string tls_channel_id = GetTlsChannelIdFromPortConnect( | 983 std::string tls_channel_id = GetTlsChannelIdFromPortConnect( |
| 963 chromium_connectable, true, close_background_message()); | 984 chromium_connectable.get(), true, close_background_message()); |
| 964 EXPECT_EQ(expected_tls_channel_id_value, tls_channel_id); | 985 EXPECT_EQ(expected_tls_channel_id_value, tls_channel_id); |
| 965 // A subsequent connect will still succeed, even if the background page was | 986 // A subsequent connect will still succeed, even if the background page was |
| 966 // previously closed. | 987 // previously closed. |
| 967 tls_channel_id = GetTlsChannelIdFromPortConnect(chromium_connectable, true); | 988 tls_channel_id = |
| 989 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), true); |
| 968 // And the expected value is still retrieved. | 990 // And the expected value is still retrieved. |
| 969 EXPECT_EQ(expected_tls_channel_id_value, tls_channel_id); | 991 EXPECT_EQ(expected_tls_channel_id_value, tls_channel_id); |
| 970 } | 992 } |
| 971 | 993 |
| 972 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MessagingUserGesture) { | 994 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MessagingUserGesture) { |
| 973 const char kManifest[] = "{" | 995 const char kManifest[] = "{" |
| 974 " \"name\": \"user_gesture\"," | 996 " \"name\": \"user_gesture\"," |
| 975 " \"version\": \"1.0\"," | 997 " \"version\": \"1.0\"," |
| 976 " \"background\": {" | 998 " \"background\": {" |
| 977 " \"scripts\": [\"background.js\"]" | 999 " \"scripts\": [\"background.js\"]" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 | 1038 |
| 1017 // Tests that a hosted app on a connectable site doesn't interfere with the | 1039 // Tests that a hosted app on a connectable site doesn't interfere with the |
| 1018 // connectability of that site. | 1040 // connectability of that site. |
| 1019 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, HostedAppOnWebsite) { | 1041 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, HostedAppOnWebsite) { |
| 1020 InitializeTestServer(); | 1042 InitializeTestServer(); |
| 1021 | 1043 |
| 1022 scoped_refptr<const Extension> app = LoadChromiumHostedApp(); | 1044 scoped_refptr<const Extension> app = LoadChromiumHostedApp(); |
| 1023 | 1045 |
| 1024 // The presence of the hosted app shouldn't give the ability to send messages. | 1046 // The presence of the hosted app shouldn't give the ability to send messages. |
| 1025 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 1047 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
| 1026 EXPECT_EQ(NAMESPACE_NOT_DEFINED, CanConnectAndSendMessagesToMainFrame(app)); | 1048 EXPECT_EQ(NAMESPACE_NOT_DEFINED, |
| 1049 CanConnectAndSendMessagesToMainFrame(app.get())); |
| 1027 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 1050 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
| 1028 | 1051 |
| 1029 // Once a connectable extension is installed, it should. | 1052 // Once a connectable extension is installed, it should. |
| 1030 const Extension* extension = LoadChromiumConnectableExtension(); | 1053 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); |
| 1031 EXPECT_EQ(OK, CanConnectAndSendMessagesToMainFrame(extension)); | 1054 EXPECT_EQ(OK, CanConnectAndSendMessagesToMainFrame(extension.get())); |
| 1032 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 1055 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
| 1033 } | 1056 } |
| 1034 | 1057 |
| 1035 // Tests that an invalid extension ID specified in a hosted app does not crash | 1058 // Tests that an invalid extension ID specified in a hosted app does not crash |
| 1036 // the hosted app's renderer. | 1059 // the hosted app's renderer. |
| 1037 // | 1060 // |
| 1038 // This is a regression test for http://crbug.com/326250#c12. | 1061 // This is a regression test for http://crbug.com/326250#c12. |
| 1039 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 1062 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 1040 InvalidExtensionIDFromHostedApp) { | 1063 InvalidExtensionIDFromHostedApp) { |
| 1041 InitializeTestServer(); | 1064 InitializeTestServer(); |
| 1042 | 1065 |
| 1043 // The presence of the chromium hosted app triggers this bug. The chromium | 1066 // The presence of the chromium hosted app triggers this bug. The chromium |
| 1044 // connectable extension needs to be installed to set up the runtime bindings. | 1067 // connectable extension needs to be installed to set up the runtime bindings. |
| 1045 LoadChromiumHostedApp(); | 1068 LoadChromiumHostedApp(); |
| 1046 LoadChromiumConnectableExtension(); | 1069 LoadChromiumConnectableExtension(); |
| 1047 | 1070 |
| 1048 scoped_refptr<const Extension> invalid = | 1071 scoped_refptr<const Extension> invalid = |
| 1049 ExtensionBuilder() | 1072 ExtensionBuilder() |
| 1050 // A bit scary that this works... | 1073 // A bit scary that this works... |
| 1051 .SetID("invalid") | 1074 .SetID("invalid") |
| 1052 .SetManifest(DictionaryBuilder() | 1075 .SetManifest(DictionaryBuilder() |
| 1053 .Set("name", "Fake extension") | 1076 .Set("name", "Fake extension") |
| 1054 .Set("version", "1") | 1077 .Set("version", "1") |
| 1055 .Set("manifest_version", 2)) | 1078 .Set("manifest_version", 2)) |
| 1056 .Build(); | 1079 .Build(); |
| 1057 | 1080 |
| 1058 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 1081 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
| 1059 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, | 1082 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
| 1060 CanConnectAndSendMessagesToMainFrame(invalid)); | 1083 CanConnectAndSendMessagesToMainFrame(invalid.get())); |
| 1061 } | 1084 } |
| 1062 | 1085 |
| 1063 #endif // !defined(OS_WIN) - http://crbug.com/350517. | 1086 #endif // !defined(OS_WIN) - http://crbug.com/350517. |
| 1064 | 1087 |
| 1065 } // namespace | 1088 } // namespace |
| 1066 | 1089 |
| 1067 }; // namespace extensions | 1090 }; // namespace extensions |
| OLD | NEW |