| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 GURL::Replacements replacements; | 340 GURL::Replacements replacements; |
| 341 replacements.SetHostStr(host); | 341 replacements.SetHostStr(host); |
| 342 replacements.SetPortStr(port); | 342 replacements.SetPortStr(port); |
| 343 return embedded_test_server()->GetURL(path).ReplaceComponents(replacements); | 343 return embedded_test_server()->GetURL(path).ReplaceComponents(replacements); |
| 344 } | 344 } |
| 345 | 345 |
| 346 GURL chromium_org_url() { | 346 GURL chromium_org_url() { |
| 347 return GetURLForPath("www.chromium.org", "/chromium.org.html"); | 347 return GetURLForPath("www.chromium.org", "/chromium.org.html"); |
| 348 } | 348 } |
| 349 | 349 |
| 350 GURL popup_opener_url() { |
| 351 return GetURLForPath("www.chromium.org", "/popup_opener.html"); |
| 352 } |
| 353 |
| 350 GURL google_com_url() { | 354 GURL google_com_url() { |
| 351 return GetURLForPath("www.google.com", "/google.com.html"); | 355 return GetURLForPath("www.google.com", "/google.com.html"); |
| 352 } | 356 } |
| 353 | 357 |
| 354 scoped_refptr<const Extension> LoadChromiumConnectableExtension() { | 358 scoped_refptr<const Extension> LoadChromiumConnectableExtension() { |
| 355 scoped_refptr<const Extension> extension = | 359 scoped_refptr<const Extension> extension = |
| 356 LoadExtensionIntoDir(&web_connectable_dir_, | 360 LoadExtensionIntoDir(&web_connectable_dir_, |
| 357 base::StringPrintf( | 361 base::StringPrintf( |
| 358 "{" | 362 "{" |
| 359 " \"name\": \"chromium_connectable\"," | 363 " \"name\": \"chromium_connectable\"," |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 EXPECT_EQ(OK, CanConnectAndSendMessagesToMainFrame(extension.get())); | 1015 EXPECT_EQ(OK, CanConnectAndSendMessagesToMainFrame(extension.get())); |
| 1012 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 1016 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
| 1013 | 1017 |
| 1014 ASSERT_TRUE(AppendIframe(google_com_url())); | 1018 ASSERT_TRUE(AppendIframe(google_com_url())); |
| 1015 | 1019 |
| 1016 EXPECT_EQ(NAMESPACE_NOT_DEFINED, | 1020 EXPECT_EQ(NAMESPACE_NOT_DEFINED, |
| 1017 CanConnectAndSendMessagesToIFrame(extension.get())); | 1021 CanConnectAndSendMessagesToIFrame(extension.get())); |
| 1018 EXPECT_FALSE(AreAnyNonWebApisDefinedForIFrame()); | 1022 EXPECT_FALSE(AreAnyNonWebApisDefinedForIFrame()); |
| 1019 } | 1023 } |
| 1020 | 1024 |
| 1025 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, FromPopup) { |
| 1026 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1027 switches::kDisablePopupBlocking); |
| 1028 |
| 1029 InitializeTestServer(); |
| 1030 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); |
| 1031 |
| 1032 // This will let us wait for the chromium.org.html page to load in a popup. |
| 1033 ui_test_utils::UrlLoadObserver url_observer( |
| 1034 chromium_org_url(), content::NotificationService::AllSources()); |
| 1035 |
| 1036 // The page at popup_opener_url() should open chromium_org_url() as a popup. |
| 1037 ui_test_utils::NavigateToURL(browser(), popup_opener_url()); |
| 1038 url_observer.Wait(); |
| 1039 |
| 1040 // Find the WebContents that committed the chromium_org_url(). |
| 1041 // TODO(devlin) - it would be nice if UrlLoadObserver handled this for |
| 1042 // us, which it could pretty easily do. |
| 1043 content::WebContents* popup_contents = nullptr; |
| 1044 for (int i = 0; i < browser()->tab_strip_model()->count(); i++) { |
| 1045 content::WebContents* contents = |
| 1046 browser()->tab_strip_model()->GetWebContentsAt(i); |
| 1047 if (contents->GetLastCommittedURL() == chromium_org_url()) { |
| 1048 popup_contents = contents; |
| 1049 break; |
| 1050 } |
| 1051 } |
| 1052 ASSERT_NE(nullptr, popup_contents) << "Could not find WebContents for popup"; |
| 1053 |
| 1054 // Make sure the popup can connect and send messages to the extension. |
| 1055 content::RenderFrameHost* popup_frame = popup_contents->GetMainFrame(); |
| 1056 |
| 1057 EXPECT_EQ(OK, CanConnectAndSendMessagesToFrame(popup_frame, extension.get(), |
| 1058 nullptr)); |
| 1059 EXPECT_FALSE(AreAnyNonWebApisDefinedForFrame(popup_frame)); |
| 1060 } |
| 1061 |
| 1021 // Tests externally_connectable between a web page and an extension with a | 1062 // Tests externally_connectable between a web page and an extension with a |
| 1022 // TLS channel ID created for the origin. | 1063 // TLS channel ID created for the origin. |
| 1023 class ExternallyConnectableMessagingWithTlsChannelIdTest : | 1064 class ExternallyConnectableMessagingWithTlsChannelIdTest : |
| 1024 public ExternallyConnectableMessagingTest { | 1065 public ExternallyConnectableMessagingTest { |
| 1025 public: | 1066 public: |
| 1026 ExternallyConnectableMessagingWithTlsChannelIdTest() | 1067 ExternallyConnectableMessagingWithTlsChannelIdTest() |
| 1027 : tls_channel_id_created_( | 1068 : tls_channel_id_created_( |
| 1028 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 1069 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 1029 base::WaitableEvent::InitialState::NOT_SIGNALED) {} | 1070 base::WaitableEvent::InitialState::NOT_SIGNALED) {} |
| 1030 | 1071 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1253 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 1294 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
| 1254 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, | 1295 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
| 1255 CanConnectAndSendMessagesToMainFrame(invalid.get())); | 1296 CanConnectAndSendMessagesToMainFrame(invalid.get())); |
| 1256 } | 1297 } |
| 1257 | 1298 |
| 1258 #endif // !defined(OS_WIN) - http://crbug.com/350517. | 1299 #endif // !defined(OS_WIN) - http://crbug.com/350517. |
| 1259 | 1300 |
| 1260 } // namespace | 1301 } // namespace |
| 1261 | 1302 |
| 1262 }; // namespace extensions | 1303 }; // namespace extensions |
| OLD | NEW |