| 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 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 // so it's not really our specific concern for web connectable. | 679 // so it's not really our specific concern for web connectable. |
| 680 // | 680 // |
| 681 // TODO(kalman): test messages from incognito extensions too. | 681 // TODO(kalman): test messages from incognito extensions too. |
| 682 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 682 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 683 FromIncognitoDenyApp) { | 683 FromIncognitoDenyApp) { |
| 684 InitializeTestServer(); | 684 InitializeTestServer(); |
| 685 | 685 |
| 686 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(); | 686 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(); |
| 687 ASSERT_TRUE(app->is_platform_app()); | 687 ASSERT_TRUE(app->is_platform_app()); |
| 688 | 688 |
| 689 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( | 689 Browser* incognito_browser = OpenURLOffTheRecord( |
| 690 profile()->GetOffTheRecordProfile(), | 690 profile()->GetOffTheRecordProfile(), chromium_org_url()); |
| 691 chromium_org_url()); | |
| 692 content::RenderFrameHost* incognito_frame = incognito_browser-> | 691 content::RenderFrameHost* incognito_frame = incognito_browser-> |
| 693 tab_strip_model()->GetActiveWebContents()->GetMainFrame(); | 692 tab_strip_model()->GetActiveWebContents()->GetMainFrame(); |
| 694 | 693 |
| 695 { | 694 { |
| 696 IncognitoConnectability::ScopedAlertTracker alert_tracker( | 695 IncognitoConnectability::ScopedAlertTracker alert_tracker( |
| 697 IncognitoConnectability::ScopedAlertTracker::ALWAYS_DENY); | 696 IncognitoConnectability::ScopedAlertTracker::ALWAYS_DENY); |
| 698 | 697 |
| 699 // No connection because incognito-enabled hasn't been set for the app, and | 698 // No connection because incognito-enabled hasn't been set for the app, and |
| 700 // the user denied our interactive request. | 699 // the user denied our interactive request. |
| 701 EXPECT_EQ( | 700 EXPECT_EQ( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 715 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, | 714 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
| 716 CanConnectAndSendMessagesToFrame(incognito_frame, app.get(), NULL)); | 715 CanConnectAndSendMessagesToFrame(incognito_frame, app.get(), NULL)); |
| 717 } | 716 } |
| 718 | 717 |
| 719 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 718 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 720 FromIncognitoDenyExtension) { | 719 FromIncognitoDenyExtension) { |
| 721 InitializeTestServer(); | 720 InitializeTestServer(); |
| 722 | 721 |
| 723 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); | 722 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); |
| 724 | 723 |
| 725 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( | 724 Browser* incognito_browser = OpenURLOffTheRecord( |
| 726 profile()->GetOffTheRecordProfile(), chromium_org_url()); | 725 profile()->GetOffTheRecordProfile(), chromium_org_url()); |
| 727 content::RenderFrameHost* incognito_frame = | 726 content::RenderFrameHost* incognito_frame = |
| 728 incognito_browser->tab_strip_model() | 727 incognito_browser->tab_strip_model() |
| 729 ->GetActiveWebContents() | 728 ->GetActiveWebContents() |
| 730 ->GetMainFrame(); | 729 ->GetMainFrame(); |
| 731 | 730 |
| 732 { | 731 { |
| 733 IncognitoConnectability::ScopedAlertTracker alert_tracker( | 732 IncognitoConnectability::ScopedAlertTracker alert_tracker( |
| 734 IncognitoConnectability::ScopedAlertTracker::ALWAYS_DENY); | 733 IncognitoConnectability::ScopedAlertTracker::ALWAYS_DENY); |
| 735 | 734 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 749 | 748 |
| 750 // Tests connection from incognito tabs when the extension doesn't have an event | 749 // Tests connection from incognito tabs when the extension doesn't have an event |
| 751 // handler for the connection event. | 750 // handler for the connection event. |
| 752 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 751 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 753 FromIncognitoNoEventHandlerInApp) { | 752 FromIncognitoNoEventHandlerInApp) { |
| 754 InitializeTestServer(); | 753 InitializeTestServer(); |
| 755 | 754 |
| 756 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(false); | 755 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(false); |
| 757 ASSERT_TRUE(app->is_platform_app()); | 756 ASSERT_TRUE(app->is_platform_app()); |
| 758 | 757 |
| 759 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( | 758 Browser* incognito_browser = OpenURLOffTheRecord( |
| 760 profile()->GetOffTheRecordProfile(), chromium_org_url()); | 759 profile()->GetOffTheRecordProfile(), chromium_org_url()); |
| 761 content::RenderFrameHost* incognito_frame = | 760 content::RenderFrameHost* incognito_frame = |
| 762 incognito_browser->tab_strip_model() | 761 incognito_browser->tab_strip_model() |
| 763 ->GetActiveWebContents() | 762 ->GetActiveWebContents() |
| 764 ->GetMainFrame(); | 763 ->GetMainFrame(); |
| 765 | 764 |
| 766 { | 765 { |
| 767 IncognitoConnectability::ScopedAlertTracker alert_tracker( | 766 IncognitoConnectability::ScopedAlertTracker alert_tracker( |
| 768 IncognitoConnectability::ScopedAlertTracker::ALWAYS_ALLOW); | 767 IncognitoConnectability::ScopedAlertTracker::ALWAYS_ALLOW); |
| 769 | 768 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 781 // request. Spanning mode only. Separate tests for apps and extensions. | 780 // request. Spanning mode only. Separate tests for apps and extensions. |
| 782 // | 781 // |
| 783 // TODO(kalman): see comment above about split mode. | 782 // TODO(kalman): see comment above about split mode. |
| 784 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 783 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 785 FromIncognitoAllowApp) { | 784 FromIncognitoAllowApp) { |
| 786 InitializeTestServer(); | 785 InitializeTestServer(); |
| 787 | 786 |
| 788 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(); | 787 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(); |
| 789 ASSERT_TRUE(app->is_platform_app()); | 788 ASSERT_TRUE(app->is_platform_app()); |
| 790 | 789 |
| 791 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( | 790 Browser* incognito_browser = OpenURLOffTheRecord( |
| 792 profile()->GetOffTheRecordProfile(), | 791 profile()->GetOffTheRecordProfile(), chromium_org_url()); |
| 793 chromium_org_url()); | |
| 794 content::RenderFrameHost* incognito_frame = incognito_browser-> | 792 content::RenderFrameHost* incognito_frame = incognito_browser-> |
| 795 tab_strip_model()->GetActiveWebContents()->GetMainFrame(); | 793 tab_strip_model()->GetActiveWebContents()->GetMainFrame(); |
| 796 | 794 |
| 797 { | 795 { |
| 798 IncognitoConnectability::ScopedAlertTracker alert_tracker( | 796 IncognitoConnectability::ScopedAlertTracker alert_tracker( |
| 799 IncognitoConnectability::ScopedAlertTracker::ALWAYS_ALLOW); | 797 IncognitoConnectability::ScopedAlertTracker::ALWAYS_ALLOW); |
| 800 | 798 |
| 801 // Connection allowed even with incognito disabled, because the user | 799 // Connection allowed even with incognito disabled, because the user |
| 802 // accepted the interactive request. | 800 // accepted the interactive request. |
| 803 EXPECT_EQ( | 801 EXPECT_EQ( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 820 // Tests connection from incognito tabs when there are multiple tabs open to the | 818 // Tests connection from incognito tabs when there are multiple tabs open to the |
| 821 // same origin. The user should only need to accept the connection request once. | 819 // same origin. The user should only need to accept the connection request once. |
| 822 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 820 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 823 FromIncognitoPromptApp) { | 821 FromIncognitoPromptApp) { |
| 824 InitializeTestServer(); | 822 InitializeTestServer(); |
| 825 | 823 |
| 826 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(); | 824 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(); |
| 827 ASSERT_TRUE(app->is_platform_app()); | 825 ASSERT_TRUE(app->is_platform_app()); |
| 828 | 826 |
| 829 // Open an incognito browser with two tabs displaying "chromium.org". | 827 // Open an incognito browser with two tabs displaying "chromium.org". |
| 830 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( | 828 Browser* incognito_browser = OpenURLOffTheRecord( |
| 831 profile()->GetOffTheRecordProfile(), chromium_org_url()); | 829 profile()->GetOffTheRecordProfile(), chromium_org_url()); |
| 832 content::RenderFrameHost* incognito_frame1 = | 830 content::RenderFrameHost* incognito_frame1 = |
| 833 incognito_browser->tab_strip_model() | 831 incognito_browser->tab_strip_model() |
| 834 ->GetActiveWebContents() | 832 ->GetActiveWebContents() |
| 835 ->GetMainFrame(); | 833 ->GetMainFrame(); |
| 836 InfoBarService* infobar_service1 = InfoBarService::FromWebContents( | 834 InfoBarService* infobar_service1 = InfoBarService::FromWebContents( |
| 837 incognito_browser->tab_strip_model()->GetActiveWebContents()); | 835 incognito_browser->tab_strip_model()->GetActiveWebContents()); |
| 838 | 836 |
| 839 CHECK(ui_test_utils::OpenURLOffTheRecord(profile()->GetOffTheRecordProfile(), | 837 CHECK(OpenURLOffTheRecord(profile()->GetOffTheRecordProfile(), |
| 840 chromium_org_url()) == | 838 chromium_org_url()) == incognito_browser); |
| 841 incognito_browser); | |
| 842 content::RenderFrameHost* incognito_frame2 = | 839 content::RenderFrameHost* incognito_frame2 = |
| 843 incognito_browser->tab_strip_model() | 840 incognito_browser->tab_strip_model() |
| 844 ->GetActiveWebContents() | 841 ->GetActiveWebContents() |
| 845 ->GetMainFrame(); | 842 ->GetMainFrame(); |
| 846 InfoBarService* infobar_service2 = InfoBarService::FromWebContents( | 843 InfoBarService* infobar_service2 = InfoBarService::FromWebContents( |
| 847 incognito_browser->tab_strip_model()->GetActiveWebContents()); | 844 incognito_browser->tab_strip_model()->GetActiveWebContents()); |
| 848 EXPECT_EQ(2, incognito_browser->tab_strip_model()->count()); | 845 EXPECT_EQ(2, incognito_browser->tab_strip_model()->count()); |
| 849 EXPECT_NE(incognito_frame1, incognito_frame2); | 846 EXPECT_NE(incognito_frame1, incognito_frame2); |
| 850 | 847 |
| 851 // Trigger a infobars in both tabs by trying to send messages. | 848 // Trigger a infobars in both tabs by trying to send messages. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 "assertions.tryIllegalArguments()", &result)); | 889 "assertions.tryIllegalArguments()", &result)); |
| 893 EXPECT_TRUE(result); | 890 EXPECT_TRUE(result); |
| 894 } | 891 } |
| 895 | 892 |
| 896 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 893 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
| 897 FromIncognitoAllowExtension) { | 894 FromIncognitoAllowExtension) { |
| 898 InitializeTestServer(); | 895 InitializeTestServer(); |
| 899 | 896 |
| 900 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); | 897 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); |
| 901 | 898 |
| 902 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( | 899 Browser* incognito_browser = OpenURLOffTheRecord( |
| 903 profile()->GetOffTheRecordProfile(), chromium_org_url()); | 900 profile()->GetOffTheRecordProfile(), chromium_org_url()); |
| 904 content::RenderFrameHost* incognito_frame = | 901 content::RenderFrameHost* incognito_frame = |
| 905 incognito_browser->tab_strip_model() | 902 incognito_browser->tab_strip_model() |
| 906 ->GetActiveWebContents() | 903 ->GetActiveWebContents() |
| 907 ->GetMainFrame(); | 904 ->GetMainFrame(); |
| 908 | 905 |
| 909 { | 906 { |
| 910 IncognitoConnectability::ScopedAlertTracker alert_tracker( | 907 IncognitoConnectability::ScopedAlertTracker alert_tracker( |
| 911 IncognitoConnectability::ScopedAlertTracker::ALWAYS_ALLOW); | 908 IncognitoConnectability::ScopedAlertTracker::ALWAYS_ALLOW); |
| 912 | 909 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 1192 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
| 1196 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, | 1193 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
| 1197 CanConnectAndSendMessagesToMainFrame(invalid.get())); | 1194 CanConnectAndSendMessagesToMainFrame(invalid.get())); |
| 1198 } | 1195 } |
| 1199 | 1196 |
| 1200 #endif // !defined(OS_WIN) - http://crbug.com/350517. | 1197 #endif // !defined(OS_WIN) - http://crbug.com/350517. |
| 1201 | 1198 |
| 1202 } // namespace | 1199 } // namespace |
| 1203 | 1200 |
| 1204 }; // namespace extensions | 1201 }; // namespace extensions |
| OLD | NEW |