Chromium Code Reviews| 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 content::WebContents* popup_contents = nullptr; | |
| 1041 for (int i = 0; i < browser()->tab_strip_model()->count(); i++) { | |
|
Devlin
2016/08/03 16:16:49
This is a shame, because UrlLoadObserver could alr
asargent_no_longer_on_chrome
2016/08/04 05:47:18
Left a TODO, to try and get this CL in faster.
| |
| 1042 content::WebContents* contents = | |
| 1043 browser()->tab_strip_model()->GetWebContentsAt(i); | |
| 1044 if (contents->GetLastCommittedURL() == chromium_org_url()) { | |
| 1045 popup_contents = contents; | |
| 1046 break; | |
| 1047 } | |
| 1048 } | |
| 1049 ASSERT_NE(nullptr, popup_contents) << "Could not find WebContents for popup"; | |
| 1050 | |
| 1051 // Make sure the popup can connect and send messages to the extension. | |
| 1052 content::RenderFrameHost* popup_frame = popup_contents->GetMainFrame(); | |
| 1053 | |
| 1054 EXPECT_EQ(OK, CanConnectAndSendMessagesToFrame(popup_frame, extension.get(), | |
| 1055 nullptr)); | |
| 1056 EXPECT_FALSE(AreAnyNonWebApisDefinedForFrame(popup_frame)); | |
| 1057 } | |
| 1058 | |
| 1021 // Tests externally_connectable between a web page and an extension with a | 1059 // Tests externally_connectable between a web page and an extension with a |
| 1022 // TLS channel ID created for the origin. | 1060 // TLS channel ID created for the origin. |
| 1023 class ExternallyConnectableMessagingWithTlsChannelIdTest : | 1061 class ExternallyConnectableMessagingWithTlsChannelIdTest : |
| 1024 public ExternallyConnectableMessagingTest { | 1062 public ExternallyConnectableMessagingTest { |
| 1025 public: | 1063 public: |
| 1026 ExternallyConnectableMessagingWithTlsChannelIdTest() | 1064 ExternallyConnectableMessagingWithTlsChannelIdTest() |
| 1027 : tls_channel_id_created_( | 1065 : tls_channel_id_created_( |
| 1028 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 1066 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 1029 base::WaitableEvent::InitialState::NOT_SIGNALED) {} | 1067 base::WaitableEvent::InitialState::NOT_SIGNALED) {} |
| 1030 | 1068 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1253 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 1291 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
| 1254 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, | 1292 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
| 1255 CanConnectAndSendMessagesToMainFrame(invalid.get())); | 1293 CanConnectAndSendMessagesToMainFrame(invalid.get())); |
| 1256 } | 1294 } |
| 1257 | 1295 |
| 1258 #endif // !defined(OS_WIN) - http://crbug.com/350517. | 1296 #endif // !defined(OS_WIN) - http://crbug.com/350517. |
| 1259 | 1297 |
| 1260 } // namespace | 1298 } // namespace |
| 1261 | 1299 |
| 1262 }; // namespace extensions | 1300 }; // namespace extensions |
| OLD | NEW |