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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 GURL("http://b.com/"))); | 117 GURL("http://b.com/"))); |
118 event_router->BroadcastEvent(BuildEvent( | 118 event_router->BroadcastEvent(BuildEvent( |
119 BuildEventArguments(true, "last message"), | 119 BuildEventArguments(true, "last message"), |
120 content::Source<Profile>(source).ptr(), | 120 content::Source<Profile>(source).ptr(), |
121 GURL())); | 121 GURL())); |
122 } | 122 } |
123 | 123 |
124 content::NotificationRegistrar registrar_; | 124 content::NotificationRegistrar registrar_; |
125 }; | 125 }; |
126 | 126 |
| 127 class MessagingApiTest : public ExtensionApiTest { |
| 128 public: |
| 129 void SetUpOnMainThread() override { |
| 130 ExtensionApiTest::SetUpOnMainThread(); |
| 131 host_resolver()->AddRule("*", "127.0.0.1"); |
| 132 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 133 } |
| 134 }; |
| 135 |
127 // Tests that message passing between extensions and content scripts works. | 136 // Tests that message passing between extensions and content scripts works. |
128 #if defined(MEMORY_SANITIZER) || defined(OS_MACOSX) | 137 #if defined(MEMORY_SANITIZER) || defined(OS_MACOSX) |
129 // https://crbug.com/582185 - flakily times out on Linux/CrOS MSAN | 138 // https://crbug.com/582185 - flakily times out on Linux/CrOS MSAN |
130 // https://crbug.com/681705 - flakily times out on mac_chromium_rel_ng | 139 // https://crbug.com/681705 - flakily times out on mac_chromium_rel_ng |
131 #define MAYBE_Messaging DISABLED_Messaging | 140 #define MAYBE_Messaging DISABLED_Messaging |
132 #else | 141 #else |
133 #define MAYBE_Messaging Messaging | 142 #define MAYBE_Messaging Messaging |
134 #endif | 143 #endif |
135 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_Messaging) { | 144 IN_PROC_BROWSER_TEST_F(MessagingApiTest, MAYBE_Messaging) { |
136 ASSERT_TRUE(StartEmbeddedTestServer()); | |
137 ASSERT_TRUE(RunExtensionTest("messaging/connect")) << message_; | 145 ASSERT_TRUE(RunExtensionTest("messaging/connect")) << message_; |
138 } | 146 } |
139 | 147 |
140 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MessagingCrash) { | 148 IN_PROC_BROWSER_TEST_F(MessagingApiTest, MessagingCrash) { |
141 ASSERT_TRUE(StartEmbeddedTestServer()); | |
142 ExtensionTestMessageListener ready_to_crash("ready_to_crash", false); | 149 ExtensionTestMessageListener ready_to_crash("ready_to_crash", false); |
143 ASSERT_TRUE(LoadExtension( | 150 ASSERT_TRUE(LoadExtension( |
144 test_data_dir_.AppendASCII("messaging/connect_crash"))); | 151 test_data_dir_.AppendASCII("messaging/connect_crash"))); |
145 ui_test_utils::NavigateToURL( | 152 ui_test_utils::NavigateToURL( |
146 browser(), embedded_test_server()->GetURL("/extensions/test_file.html")); | 153 browser(), embedded_test_server()->GetURL("/extensions/test_file.html")); |
147 content::WebContents* tab = | 154 content::WebContents* tab = |
148 browser()->tab_strip_model()->GetActiveWebContents(); | 155 browser()->tab_strip_model()->GetActiveWebContents(); |
149 EXPECT_TRUE(ready_to_crash.WaitUntilSatisfied()); | 156 EXPECT_TRUE(ready_to_crash.WaitUntilSatisfied()); |
150 | 157 |
151 ResultCatcher catcher; | 158 ResultCatcher catcher; |
152 CrashTab(tab); | 159 CrashTab(tab); |
153 EXPECT_TRUE(catcher.GetNextResult()); | 160 EXPECT_TRUE(catcher.GetNextResult()); |
154 } | 161 } |
155 | 162 |
156 // Tests that message passing from one extension to another works. | 163 // Tests that message passing from one extension to another works. |
157 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MessagingExternal) { | 164 IN_PROC_BROWSER_TEST_F(MessagingApiTest, MessagingExternal) { |
158 ASSERT_TRUE(LoadExtension( | 165 ASSERT_TRUE(LoadExtension( |
159 test_data_dir_.AppendASCII("..").AppendASCII("good") | 166 test_data_dir_.AppendASCII("..").AppendASCII("good") |
160 .AppendASCII("Extensions") | 167 .AppendASCII("Extensions") |
161 .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa") | 168 .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa") |
162 .AppendASCII("1.0"))); | 169 .AppendASCII("1.0"))); |
163 | 170 |
164 ASSERT_TRUE(RunExtensionTest("messaging/connect_external")) << message_; | 171 ASSERT_TRUE(RunExtensionTest("messaging/connect_external")) << message_; |
165 } | 172 } |
166 | 173 |
167 // Tests that a content script can exchange messages with a tab even if there is | 174 // Tests that a content script can exchange messages with a tab even if there is |
168 // no background page. | 175 // no background page. |
169 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MessagingNoBackground) { | 176 IN_PROC_BROWSER_TEST_F(MessagingApiTest, MessagingNoBackground) { |
170 ASSERT_TRUE(StartEmbeddedTestServer()); | |
171 ASSERT_TRUE(RunExtensionSubtest("messaging/connect_nobackground", | 177 ASSERT_TRUE(RunExtensionSubtest("messaging/connect_nobackground", |
172 "page_in_main_frame.html")) << message_; | 178 "page_in_main_frame.html")) << message_; |
173 } | 179 } |
174 | 180 |
175 // Tests that messages with event_urls are only passed to extensions with | 181 // Tests that messages with event_urls are only passed to extensions with |
176 // appropriate permissions. | 182 // appropriate permissions. |
177 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MessagingEventURL) { | 183 IN_PROC_BROWSER_TEST_F(MessagingApiTest, MessagingEventURL) { |
178 MessageSender sender; | 184 MessageSender sender; |
179 ASSERT_TRUE(RunExtensionTest("messaging/event_url")) << message_; | 185 ASSERT_TRUE(RunExtensionTest("messaging/event_url")) << message_; |
180 } | 186 } |
181 | 187 |
182 // Tests that messages cannot be received from the same frame. | 188 // Tests that messages cannot be received from the same frame. |
183 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MessagingBackgroundOnly) { | 189 IN_PROC_BROWSER_TEST_F(MessagingApiTest, MessagingBackgroundOnly) { |
184 ASSERT_TRUE(RunExtensionTest("messaging/background_only")) << message_; | 190 ASSERT_TRUE(RunExtensionTest("messaging/background_only")) << message_; |
185 } | 191 } |
186 | 192 |
187 // Tests whether an extension in an interstitial page can send messages to the | 193 // Tests whether an extension in an interstitial page can send messages to the |
188 // background page. | 194 // background page. |
189 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MessagingInterstitial) { | 195 IN_PROC_BROWSER_TEST_F(MessagingApiTest, MessagingInterstitial) { |
190 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); | 196 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
191 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); | 197 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
192 ASSERT_TRUE(https_server.Start()); | 198 ASSERT_TRUE(https_server.Start()); |
193 | 199 |
194 ASSERT_TRUE(RunExtensionSubtest("messaging/interstitial_component", | 200 ASSERT_TRUE(RunExtensionSubtest("messaging/interstitial_component", |
195 https_server.base_url().spec(), | 201 https_server.base_url().spec(), |
196 kFlagLoadAsComponent)) << message_; | 202 kFlagLoadAsComponent)) << message_; |
197 } | 203 } |
198 | 204 |
199 // XXX(kalman): All web messaging tests disabled on windows due to extreme | 205 // XXX(kalman): All web messaging tests disabled on windows due to extreme |
200 // flakiness. See http://crbug.com/350517. | 206 // flakiness. See http://crbug.com/350517. |
201 #if !defined(OS_WIN) | 207 #if !defined(OS_WIN) |
202 | 208 |
203 // Tests externally_connectable between a web page and an extension. | 209 // Tests externally_connectable between a web page and an extension. |
204 // | 210 // |
205 // TODO(kalman): Test between extensions. This is already tested in this file, | 211 // TODO(kalman): Test between extensions. This is already tested in this file, |
206 // but not with externally_connectable set in the manifest. | 212 // but not with externally_connectable set in the manifest. |
207 // | 213 // |
208 // TODO(kalman): Test with host permissions. | 214 // TODO(kalman): Test with host permissions. |
209 class ExternallyConnectableMessagingTest : public ExtensionApiTest { | 215 class ExternallyConnectableMessagingTest : public MessagingApiTest { |
210 protected: | 216 protected: |
211 // Result codes from the test. These must match up with |results| in | 217 // Result codes from the test. These must match up with |results| in |
212 // c/t/d/extensions/api_test/externally_connectable/assertions.json. | 218 // c/t/d/extensions/api_test/externally_connectable/assertions.json. |
213 enum Result { | 219 enum Result { |
214 OK = 0, | 220 OK = 0, |
215 NAMESPACE_NOT_DEFINED = 1, | 221 NAMESPACE_NOT_DEFINED = 1, |
216 FUNCTION_NOT_DEFINED = 2, | 222 FUNCTION_NOT_DEFINED = 2, |
217 COULD_NOT_ESTABLISH_CONNECTION_ERROR = 3, | 223 COULD_NOT_ESTABLISH_CONNECTION_ERROR = 3, |
218 OTHER_ERROR = 4, | 224 OTHER_ERROR = 4, |
219 INCORRECT_RESPONSE_SENDER = 5, | 225 INCORRECT_RESPONSE_SENDER = 5, |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 " \"web_url\": \"%s\"" | 427 " \"web_url\": \"%s\"" |
422 " }\n" | 428 " }\n" |
423 " }\n" | 429 " }\n" |
424 "}", | 430 "}", |
425 chromium_org_url().spec().c_str(), | 431 chromium_org_url().spec().c_str(), |
426 chromium_org_url().spec().c_str())); | 432 chromium_org_url().spec().c_str())); |
427 CHECK(hosted_app.get()); | 433 CHECK(hosted_app.get()); |
428 return hosted_app; | 434 return hosted_app; |
429 } | 435 } |
430 | 436 |
431 void InitializeTestServer() { | 437 void SetUpOnMainThread() override { |
432 base::FilePath test_data; | 438 base::FilePath test_data; |
433 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data)); | 439 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data)); |
434 embedded_test_server()->ServeFilesFromDirectory(test_data.AppendASCII( | 440 embedded_test_server()->ServeFilesFromDirectory(test_data.AppendASCII( |
435 "extensions/api_test/messaging/externally_connectable/sites")); | 441 "extensions/api_test/messaging/externally_connectable/sites")); |
436 ASSERT_TRUE(embedded_test_server()->Start()); | 442 MessagingApiTest::SetUpOnMainThread(); |
437 host_resolver()->AddRule("*", embedded_test_server()->base_url().host()); | |
438 } | 443 } |
439 | 444 |
440 const char* close_background_message() { | 445 const char* close_background_message() { |
441 return "closeBackgroundPage"; | 446 return "closeBackgroundPage"; |
442 } | 447 } |
443 | 448 |
444 private: | 449 private: |
445 scoped_refptr<const Extension> LoadExtensionIntoDir( | 450 scoped_refptr<const Extension> LoadExtensionIntoDir( |
446 TestExtensionDir* dir, | 451 TestExtensionDir* dir, |
447 const std::string& manifest, | 452 const std::string& manifest, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 } | 518 } |
514 | 519 |
515 TestExtensionDir web_connectable_dir_extension_; | 520 TestExtensionDir web_connectable_dir_extension_; |
516 TestExtensionDir web_connectable_dir_app_; | 521 TestExtensionDir web_connectable_dir_app_; |
517 TestExtensionDir not_connectable_dir_; | 522 TestExtensionDir not_connectable_dir_; |
518 TestExtensionDir tls_channel_id_connectable_dir_; | 523 TestExtensionDir tls_channel_id_connectable_dir_; |
519 TestExtensionDir hosted_app_dir_; | 524 TestExtensionDir hosted_app_dir_; |
520 }; | 525 }; |
521 | 526 |
522 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, NotInstalled) { | 527 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, NotInstalled) { |
523 InitializeTestServer(); | |
524 | |
525 scoped_refptr<const Extension> extension = | 528 scoped_refptr<const Extension> extension = |
526 ExtensionBuilder() | 529 ExtensionBuilder() |
527 .SetID("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") | 530 .SetID("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") |
528 .SetManifest(DictionaryBuilder() | 531 .SetManifest(DictionaryBuilder() |
529 .Set("name", "Fake extension") | 532 .Set("name", "Fake extension") |
530 .Set("version", "1") | 533 .Set("version", "1") |
531 .Set("manifest_version", 2) | 534 .Set("manifest_version", 2) |
532 .Build()) | 535 .Build()) |
533 .Build(); | 536 .Build(); |
534 | 537 |
535 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 538 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
536 EXPECT_EQ(NAMESPACE_NOT_DEFINED, | 539 EXPECT_EQ(NAMESPACE_NOT_DEFINED, |
537 CanConnectAndSendMessagesToMainFrame(extension.get())); | 540 CanConnectAndSendMessagesToMainFrame(extension.get())); |
538 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 541 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
539 | 542 |
540 ui_test_utils::NavigateToURL(browser(), google_com_url()); | 543 ui_test_utils::NavigateToURL(browser(), google_com_url()); |
541 EXPECT_EQ(NAMESPACE_NOT_DEFINED, | 544 EXPECT_EQ(NAMESPACE_NOT_DEFINED, |
542 CanConnectAndSendMessagesToMainFrame(extension.get())); | 545 CanConnectAndSendMessagesToMainFrame(extension.get())); |
543 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 546 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
544 } | 547 } |
545 | 548 |
546 // Tests two extensions on the same sites: one web connectable, one not. | 549 // Tests two extensions on the same sites: one web connectable, one not. |
547 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 550 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
548 WebConnectableAndNotConnectable) { | 551 WebConnectableAndNotConnectable) { |
549 InitializeTestServer(); | |
550 | |
551 // Install the web connectable extension. chromium.org can connect to it, | 552 // Install the web connectable extension. chromium.org can connect to it, |
552 // google.com can't. | 553 // google.com can't. |
553 scoped_refptr<const Extension> chromium_connectable = | 554 scoped_refptr<const Extension> chromium_connectable = |
554 LoadChromiumConnectableExtension(); | 555 LoadChromiumConnectableExtension(); |
555 | 556 |
556 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 557 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
557 EXPECT_EQ(OK, | 558 EXPECT_EQ(OK, |
558 CanConnectAndSendMessagesToMainFrame(chromium_connectable.get())); | 559 CanConnectAndSendMessagesToMainFrame(chromium_connectable.get())); |
559 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 560 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
560 | 561 |
(...skipping 15 matching lines...) Expand all Loading... |
576 | 577 |
577 ui_test_utils::NavigateToURL(browser(), google_com_url()); | 578 ui_test_utils::NavigateToURL(browser(), google_com_url()); |
578 EXPECT_EQ(NAMESPACE_NOT_DEFINED, | 579 EXPECT_EQ(NAMESPACE_NOT_DEFINED, |
579 CanConnectAndSendMessagesToMainFrame(not_connectable.get())); | 580 CanConnectAndSendMessagesToMainFrame(not_connectable.get())); |
580 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 581 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
581 } | 582 } |
582 | 583 |
583 // See http://crbug.com/297866 | 584 // See http://crbug.com/297866 |
584 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 585 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
585 DISABLED_BackgroundPageClosesOnMessageReceipt) { | 586 DISABLED_BackgroundPageClosesOnMessageReceipt) { |
586 InitializeTestServer(); | |
587 | |
588 // Install the web connectable extension. | 587 // Install the web connectable extension. |
589 scoped_refptr<const Extension> chromium_connectable = | 588 scoped_refptr<const Extension> chromium_connectable = |
590 LoadChromiumConnectableExtension(); | 589 LoadChromiumConnectableExtension(); |
591 | 590 |
592 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 591 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
593 // If the background page closes after receipt of the message, it will still | 592 // If the background page closes after receipt of the message, it will still |
594 // reply to this message... | 593 // reply to this message... |
595 EXPECT_EQ(OK, | 594 EXPECT_EQ(OK, |
596 CanConnectAndSendMessagesToMainFrame(chromium_connectable.get(), | 595 CanConnectAndSendMessagesToMainFrame(chromium_connectable.get(), |
597 close_background_message())); | 596 close_background_message())); |
598 // and be re-opened by receipt of a subsequent message. | 597 // and be re-opened by receipt of a subsequent message. |
599 EXPECT_EQ(OK, | 598 EXPECT_EQ(OK, |
600 CanConnectAndSendMessagesToMainFrame(chromium_connectable.get())); | 599 CanConnectAndSendMessagesToMainFrame(chromium_connectable.get())); |
601 } | 600 } |
602 | 601 |
603 // Tests a web connectable extension that doesn't receive TLS channel id. | 602 // Tests a web connectable extension that doesn't receive TLS channel id. |
604 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 603 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
605 WebConnectableWithoutTlsChannelId) { | 604 WebConnectableWithoutTlsChannelId) { |
606 InitializeTestServer(); | |
607 | |
608 // Install the web connectable extension. chromium.org can connect to it, | 605 // Install the web connectable extension. chromium.org can connect to it, |
609 // google.com can't. | 606 // google.com can't. |
610 scoped_refptr<const Extension> chromium_connectable = | 607 scoped_refptr<const Extension> chromium_connectable = |
611 LoadChromiumConnectableExtension(); | 608 LoadChromiumConnectableExtension(); |
612 ASSERT_TRUE(chromium_connectable.get()); | 609 ASSERT_TRUE(chromium_connectable.get()); |
613 | 610 |
614 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 611 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
615 // The web connectable extension doesn't request the TLS channel ID, so it | 612 // The web connectable extension doesn't request the TLS channel ID, so it |
616 // doesn't get it, whether or not the page asks for it. | 613 // doesn't get it, whether or not the page asks for it. |
617 EXPECT_EQ(std::string(), | 614 EXPECT_EQ(std::string(), |
618 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), false)); | 615 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), false)); |
619 EXPECT_EQ(std::string(), | 616 EXPECT_EQ(std::string(), |
620 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), true)); | 617 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), true)); |
621 EXPECT_EQ(std::string(), | 618 EXPECT_EQ(std::string(), |
622 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), false)); | 619 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), false)); |
623 EXPECT_EQ(std::string(), | 620 EXPECT_EQ(std::string(), |
624 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), true)); | 621 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), true)); |
625 } | 622 } |
626 | 623 |
627 // Tests a web connectable extension that receives TLS channel id with a site | 624 // Tests a web connectable extension that receives TLS channel id with a site |
628 // that can't connect to it. | 625 // that can't connect to it. |
629 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 626 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
630 WebConnectableWithTlsChannelIdWithNonMatchingSite) { | 627 WebConnectableWithTlsChannelIdWithNonMatchingSite) { |
631 InitializeTestServer(); | |
632 | |
633 scoped_refptr<const Extension> chromium_connectable = | 628 scoped_refptr<const Extension> chromium_connectable = |
634 LoadChromiumConnectableExtensionWithTlsChannelId(); | 629 LoadChromiumConnectableExtensionWithTlsChannelId(); |
635 ASSERT_TRUE(chromium_connectable.get()); | 630 ASSERT_TRUE(chromium_connectable.get()); |
636 | 631 |
637 ui_test_utils::NavigateToURL(browser(), google_com_url()); | 632 ui_test_utils::NavigateToURL(browser(), google_com_url()); |
638 // The extension requests the TLS channel ID, but it doesn't get it for a | 633 // The extension requests the TLS channel ID, but it doesn't get it for a |
639 // site that can't connect to it, regardless of whether the page asks for it. | 634 // site that can't connect to it, regardless of whether the page asks for it. |
640 EXPECT_EQ(base::IntToString(NAMESPACE_NOT_DEFINED), | 635 EXPECT_EQ(base::IntToString(NAMESPACE_NOT_DEFINED), |
641 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), false)); | 636 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), false)); |
642 EXPECT_EQ(base::IntToString(NAMESPACE_NOT_DEFINED), | 637 EXPECT_EQ(base::IntToString(NAMESPACE_NOT_DEFINED), |
643 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), true)); | 638 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), true)); |
644 EXPECT_EQ(base::IntToString(NAMESPACE_NOT_DEFINED), | 639 EXPECT_EQ(base::IntToString(NAMESPACE_NOT_DEFINED), |
645 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), false)); | 640 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), false)); |
646 EXPECT_EQ(base::IntToString(NAMESPACE_NOT_DEFINED), | 641 EXPECT_EQ(base::IntToString(NAMESPACE_NOT_DEFINED), |
647 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), true)); | 642 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), true)); |
648 } | 643 } |
649 | 644 |
650 // Tests a web connectable extension that receives TLS channel id on a site | 645 // Tests a web connectable extension that receives TLS channel id on a site |
651 // that can connect to it, but with no TLS channel ID having been generated. | 646 // that can connect to it, but with no TLS channel ID having been generated. |
652 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 647 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
653 WebConnectableWithTlsChannelIdWithEmptyTlsChannelId) { | 648 WebConnectableWithTlsChannelIdWithEmptyTlsChannelId) { |
654 InitializeTestServer(); | |
655 | |
656 scoped_refptr<const Extension> chromium_connectable = | 649 scoped_refptr<const Extension> chromium_connectable = |
657 LoadChromiumConnectableExtensionWithTlsChannelId(); | 650 LoadChromiumConnectableExtensionWithTlsChannelId(); |
658 ASSERT_TRUE(chromium_connectable.get()); | 651 ASSERT_TRUE(chromium_connectable.get()); |
659 | 652 |
660 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 653 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
661 | 654 |
662 // Since the extension requests the TLS channel ID, it gets it for a site that | 655 // Since the extension requests the TLS channel ID, it gets it for a site that |
663 // can connect to it, but only if the page also asks to include it. | 656 // can connect to it, but only if the page also asks to include it. |
664 EXPECT_EQ(std::string(), | 657 EXPECT_EQ(std::string(), |
665 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), false)); | 658 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), false)); |
666 EXPECT_EQ(std::string(), | 659 EXPECT_EQ(std::string(), |
667 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), false)); | 660 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), false)); |
668 // If the page does ask for it, it isn't empty. | 661 // If the page does ask for it, it isn't empty. |
669 std::string tls_channel_id = | 662 std::string tls_channel_id = |
670 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), true); | 663 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), true); |
671 // Because the TLS channel ID has never been generated for this domain, | 664 // Because the TLS channel ID has never been generated for this domain, |
672 // no TLS channel ID is reported. | 665 // no TLS channel ID is reported. |
673 EXPECT_EQ(std::string(), tls_channel_id); | 666 EXPECT_EQ(std::string(), tls_channel_id); |
674 } | 667 } |
675 | 668 |
676 // Flaky on Linux and Windows. http://crbug.com/315264 | 669 // Flaky on Linux and Windows. http://crbug.com/315264 |
677 // Tests a web connectable extension that receives TLS channel id, but | 670 // Tests a web connectable extension that receives TLS channel id, but |
678 // immediately closes its background page upon receipt of a message. | 671 // immediately closes its background page upon receipt of a message. |
679 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 672 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
680 DISABLED_WebConnectableWithEmptyTlsChannelIdAndClosedBackgroundPage) { | 673 DISABLED_WebConnectableWithEmptyTlsChannelIdAndClosedBackgroundPage) { |
681 InitializeTestServer(); | |
682 | |
683 scoped_refptr<const Extension> chromium_connectable = | 674 scoped_refptr<const Extension> chromium_connectable = |
684 LoadChromiumConnectableExtensionWithTlsChannelId(); | 675 LoadChromiumConnectableExtensionWithTlsChannelId(); |
685 | 676 |
686 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 677 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
687 // If the page does ask for it, it isn't empty, even if the background page | 678 // If the page does ask for it, it isn't empty, even if the background page |
688 // closes upon receipt of the connect. | 679 // closes upon receipt of the connect. |
689 std::string tls_channel_id = GetTlsChannelIdFromPortConnect( | 680 std::string tls_channel_id = GetTlsChannelIdFromPortConnect( |
690 chromium_connectable.get(), true, close_background_message()); | 681 chromium_connectable.get(), true, close_background_message()); |
691 // Because the TLS channel ID has never been generated for this domain, | 682 // Because the TLS channel ID has never been generated for this domain, |
692 // no TLS channel ID is reported. | 683 // no TLS channel ID is reported. |
693 EXPECT_EQ(std::string(), tls_channel_id); | 684 EXPECT_EQ(std::string(), tls_channel_id); |
694 // A subsequent connect will still succeed, even if the background page was | 685 // A subsequent connect will still succeed, even if the background page was |
695 // previously closed. | 686 // previously closed. |
696 tls_channel_id = | 687 tls_channel_id = |
697 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), true); | 688 GetTlsChannelIdFromPortConnect(chromium_connectable.get(), true); |
698 // And the empty value is still retrieved. | 689 // And the empty value is still retrieved. |
699 EXPECT_EQ(std::string(), tls_channel_id); | 690 EXPECT_EQ(std::string(), tls_channel_id); |
700 } | 691 } |
701 | 692 |
702 // Tests that enabling and disabling an extension makes the runtime bindings | 693 // Tests that enabling and disabling an extension makes the runtime bindings |
703 // appear and disappear. | 694 // appear and disappear. |
704 // | 695 // |
705 // TODO(kalman): Test with multiple extensions that can be accessed by the same | 696 // TODO(kalman): Test with multiple extensions that can be accessed by the same |
706 // host. | 697 // host. |
707 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 698 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
708 EnablingAndDisabling) { | 699 EnablingAndDisabling) { |
709 InitializeTestServer(); | |
710 | |
711 scoped_refptr<const Extension> chromium_connectable = | 700 scoped_refptr<const Extension> chromium_connectable = |
712 LoadChromiumConnectableExtension(); | 701 LoadChromiumConnectableExtension(); |
713 scoped_refptr<const Extension> not_connectable = | 702 scoped_refptr<const Extension> not_connectable = |
714 LoadNotConnectableExtension(); | 703 LoadNotConnectableExtension(); |
715 | 704 |
716 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 705 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
717 EXPECT_EQ(OK, | 706 EXPECT_EQ(OK, |
718 CanConnectAndSendMessagesToMainFrame(chromium_connectable.get())); | 707 CanConnectAndSendMessagesToMainFrame(chromium_connectable.get())); |
719 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, | 708 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
720 CanConnectAndSendMessagesToMainFrame(not_connectable.get())); | 709 CanConnectAndSendMessagesToMainFrame(not_connectable.get())); |
(...skipping 12 matching lines...) Expand all Loading... |
733 // Tests connection from incognito tabs when the user denies the connection | 722 // Tests connection from incognito tabs when the user denies the connection |
734 // request. Spanning mode only. A separate test for apps and extensions. | 723 // request. Spanning mode only. A separate test for apps and extensions. |
735 // | 724 // |
736 // TODO(kalman): ensure that we exercise split vs spanning incognito logic | 725 // TODO(kalman): ensure that we exercise split vs spanning incognito logic |
737 // somewhere. This is a test that should be shared with the content script logic | 726 // somewhere. This is a test that should be shared with the content script logic |
738 // so it's not really our specific concern for web connectable. | 727 // so it's not really our specific concern for web connectable. |
739 // | 728 // |
740 // TODO(kalman): test messages from incognito extensions too. | 729 // TODO(kalman): test messages from incognito extensions too. |
741 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 730 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
742 FromIncognitoDenyApp) { | 731 FromIncognitoDenyApp) { |
743 InitializeTestServer(); | |
744 | |
745 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(); | 732 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(); |
746 ASSERT_TRUE(app->is_platform_app()); | 733 ASSERT_TRUE(app->is_platform_app()); |
747 | 734 |
748 Browser* incognito_browser = OpenURLOffTheRecord( | 735 Browser* incognito_browser = OpenURLOffTheRecord( |
749 profile()->GetOffTheRecordProfile(), chromium_org_url()); | 736 profile()->GetOffTheRecordProfile(), chromium_org_url()); |
750 content::RenderFrameHost* incognito_frame = incognito_browser-> | 737 content::RenderFrameHost* incognito_frame = incognito_browser-> |
751 tab_strip_model()->GetActiveWebContents()->GetMainFrame(); | 738 tab_strip_model()->GetActiveWebContents()->GetMainFrame(); |
752 | 739 |
753 { | 740 { |
754 IncognitoConnectability::ScopedAlertTracker alert_tracker( | 741 IncognitoConnectability::ScopedAlertTracker alert_tracker( |
(...skipping 14 matching lines...) Expand all Loading... |
769 } | 756 } |
770 | 757 |
771 // It's not possible to allow an app in incognito. | 758 // It's not possible to allow an app in incognito. |
772 ExtensionPrefs::Get(profile())->SetIsIncognitoEnabled(app->id(), true); | 759 ExtensionPrefs::Get(profile())->SetIsIncognitoEnabled(app->id(), true); |
773 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, | 760 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
774 CanConnectAndSendMessagesToFrame(incognito_frame, app.get(), NULL)); | 761 CanConnectAndSendMessagesToFrame(incognito_frame, app.get(), NULL)); |
775 } | 762 } |
776 | 763 |
777 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 764 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
778 FromIncognitoDenyExtensionAndApp) { | 765 FromIncognitoDenyExtensionAndApp) { |
779 InitializeTestServer(); | |
780 | |
781 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); | 766 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); |
782 EXPECT_FALSE(util::IsIncognitoEnabled(extension->id(), profile())); | 767 EXPECT_FALSE(util::IsIncognitoEnabled(extension->id(), profile())); |
783 | 768 |
784 Browser* incognito_browser = OpenURLOffTheRecord( | 769 Browser* incognito_browser = OpenURLOffTheRecord( |
785 profile()->GetOffTheRecordProfile(), chromium_org_url()); | 770 profile()->GetOffTheRecordProfile(), chromium_org_url()); |
786 content::RenderFrameHost* incognito_frame = | 771 content::RenderFrameHost* incognito_frame = |
787 incognito_browser->tab_strip_model() | 772 incognito_browser->tab_strip_model() |
788 ->GetActiveWebContents() | 773 ->GetActiveWebContents() |
789 ->GetMainFrame(); | 774 ->GetMainFrame(); |
790 | 775 |
(...skipping 29 matching lines...) Expand all Loading... |
820 | 805 |
821 // No alert is shown for extensions since they support being enabled in | 806 // No alert is shown for extensions since they support being enabled in |
822 // incognito mode. | 807 // incognito mode. |
823 EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); | 808 EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); |
824 } | 809 } |
825 | 810 |
826 // Tests connection from incognito tabs when the extension doesn't have an event | 811 // Tests connection from incognito tabs when the extension doesn't have an event |
827 // handler for the connection event. | 812 // handler for the connection event. |
828 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 813 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
829 FromIncognitoNoEventHandlerInApp) { | 814 FromIncognitoNoEventHandlerInApp) { |
830 InitializeTestServer(); | |
831 | |
832 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(false); | 815 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(false); |
833 ASSERT_TRUE(app->is_platform_app()); | 816 ASSERT_TRUE(app->is_platform_app()); |
834 | 817 |
835 Browser* incognito_browser = OpenURLOffTheRecord( | 818 Browser* incognito_browser = OpenURLOffTheRecord( |
836 profile()->GetOffTheRecordProfile(), chromium_org_url()); | 819 profile()->GetOffTheRecordProfile(), chromium_org_url()); |
837 content::RenderFrameHost* incognito_frame = | 820 content::RenderFrameHost* incognito_frame = |
838 incognito_browser->tab_strip_model() | 821 incognito_browser->tab_strip_model() |
839 ->GetActiveWebContents() | 822 ->GetActiveWebContents() |
840 ->GetMainFrame(); | 823 ->GetMainFrame(); |
841 | 824 |
(...skipping 10 matching lines...) Expand all Loading... |
852 EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); | 835 EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); |
853 } | 836 } |
854 } | 837 } |
855 | 838 |
856 // Tests connection from incognito tabs when the user accepts the connection | 839 // Tests connection from incognito tabs when the user accepts the connection |
857 // request. Spanning mode only. Separate tests for apps and extensions. | 840 // request. Spanning mode only. Separate tests for apps and extensions. |
858 // | 841 // |
859 // TODO(kalman): see comment above about split mode. | 842 // TODO(kalman): see comment above about split mode. |
860 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 843 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
861 FromIncognitoAllowApp) { | 844 FromIncognitoAllowApp) { |
862 InitializeTestServer(); | |
863 | |
864 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(); | 845 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(); |
865 ASSERT_TRUE(app->is_platform_app()); | 846 ASSERT_TRUE(app->is_platform_app()); |
866 | 847 |
867 Browser* incognito_browser = OpenURLOffTheRecord( | 848 Browser* incognito_browser = OpenURLOffTheRecord( |
868 profile()->GetOffTheRecordProfile(), chromium_org_url()); | 849 profile()->GetOffTheRecordProfile(), chromium_org_url()); |
869 content::RenderFrameHost* incognito_frame = incognito_browser-> | 850 content::RenderFrameHost* incognito_frame = incognito_browser-> |
870 tab_strip_model()->GetActiveWebContents()->GetMainFrame(); | 851 tab_strip_model()->GetActiveWebContents()->GetMainFrame(); |
871 | 852 |
872 { | 853 { |
873 IncognitoConnectability::ScopedAlertTracker alert_tracker( | 854 IncognitoConnectability::ScopedAlertTracker alert_tracker( |
(...skipping 15 matching lines...) Expand all Loading... |
889 // already allowed. | 870 // already allowed. |
890 ExtensionPrefs::Get(profile())->SetIsIncognitoEnabled(app->id(), true); | 871 ExtensionPrefs::Get(profile())->SetIsIncognitoEnabled(app->id(), true); |
891 EXPECT_EQ(OK, | 872 EXPECT_EQ(OK, |
892 CanConnectAndSendMessagesToFrame(incognito_frame, app.get(), NULL)); | 873 CanConnectAndSendMessagesToFrame(incognito_frame, app.get(), NULL)); |
893 } | 874 } |
894 | 875 |
895 // Tests connection from incognito tabs when there are multiple tabs open to the | 876 // Tests connection from incognito tabs when there are multiple tabs open to the |
896 // same origin. The user should only need to accept the connection request once. | 877 // same origin. The user should only need to accept the connection request once. |
897 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 878 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
898 FromIncognitoPromptApp) { | 879 FromIncognitoPromptApp) { |
899 InitializeTestServer(); | |
900 | |
901 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(); | 880 scoped_refptr<const Extension> app = LoadChromiumConnectableApp(); |
902 ASSERT_TRUE(app->is_platform_app()); | 881 ASSERT_TRUE(app->is_platform_app()); |
903 | 882 |
904 // Open an incognito browser with two tabs displaying "chromium.org". | 883 // Open an incognito browser with two tabs displaying "chromium.org". |
905 Browser* incognito_browser = OpenURLOffTheRecord( | 884 Browser* incognito_browser = OpenURLOffTheRecord( |
906 profile()->GetOffTheRecordProfile(), chromium_org_url()); | 885 profile()->GetOffTheRecordProfile(), chromium_org_url()); |
907 content::RenderFrameHost* incognito_frame1 = | 886 content::RenderFrameHost* incognito_frame1 = |
908 incognito_browser->tab_strip_model() | 887 incognito_browser->tab_strip_model() |
909 ->GetActiveWebContents() | 888 ->GetActiveWebContents() |
910 ->GetMainFrame(); | 889 ->GetMainFrame(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 EXPECT_EQ(OK, CanConnectAndSendMessagesToFrame(incognito_frame2, app.get(), | 929 EXPECT_EQ(OK, CanConnectAndSendMessagesToFrame(incognito_frame2, app.get(), |
951 NULL)); | 930 NULL)); |
952 EXPECT_EQ(1, alert_tracker.GetAndResetAlertCount()); | 931 EXPECT_EQ(1, alert_tracker.GetAndResetAlertCount()); |
953 EXPECT_EQ(0U, infobar_service1->infobar_count()); | 932 EXPECT_EQ(0U, infobar_service1->infobar_count()); |
954 } | 933 } |
955 } | 934 } |
956 | 935 |
957 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, IllegalArguments) { | 936 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, IllegalArguments) { |
958 // Tests that malformed arguments to connect() don't crash. | 937 // Tests that malformed arguments to connect() don't crash. |
959 // Regression test for crbug.com/472700. | 938 // Regression test for crbug.com/472700. |
960 InitializeTestServer(); | |
961 LoadChromiumConnectableExtension(); | 939 LoadChromiumConnectableExtension(); |
962 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 940 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
963 bool result; | 941 bool result; |
964 CHECK(content::ExecuteScriptAndExtractBool( | 942 CHECK(content::ExecuteScriptAndExtractBool( |
965 browser()->tab_strip_model()->GetActiveWebContents(), | 943 browser()->tab_strip_model()->GetActiveWebContents(), |
966 "assertions.tryIllegalArguments()", &result)); | 944 "assertions.tryIllegalArguments()", &result)); |
967 EXPECT_TRUE(result); | 945 EXPECT_TRUE(result); |
968 } | 946 } |
969 | 947 |
970 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 948 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
971 FromIncognitoAllowExtension) { | 949 FromIncognitoAllowExtension) { |
972 InitializeTestServer(); | |
973 | |
974 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); | 950 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); |
975 EXPECT_FALSE(util::IsIncognitoEnabled(extension->id(), profile())); | 951 EXPECT_FALSE(util::IsIncognitoEnabled(extension->id(), profile())); |
976 | 952 |
977 Browser* incognito_browser = OpenURLOffTheRecord( | 953 Browser* incognito_browser = OpenURLOffTheRecord( |
978 profile()->GetOffTheRecordProfile(), chromium_org_url()); | 954 profile()->GetOffTheRecordProfile(), chromium_org_url()); |
979 content::RenderFrameHost* incognito_frame = | 955 content::RenderFrameHost* incognito_frame = |
980 incognito_browser->tab_strip_model() | 956 incognito_browser->tab_strip_model() |
981 ->GetActiveWebContents() | 957 ->GetActiveWebContents() |
982 ->GetMainFrame(); | 958 ->GetMainFrame(); |
983 | 959 |
(...skipping 22 matching lines...) Expand all Loading... |
1006 | 982 |
1007 // No alert is shown for extensions which support being enabled in incognito | 983 // No alert is shown for extensions which support being enabled in incognito |
1008 // mode. | 984 // mode. |
1009 EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); | 985 EXPECT_EQ(0, alert_tracker.GetAndResetAlertCount()); |
1010 } | 986 } |
1011 | 987 |
1012 // Tests a connection from an iframe within a tab which doesn't have | 988 // Tests a connection from an iframe within a tab which doesn't have |
1013 // permission. Iframe should work. | 989 // permission. Iframe should work. |
1014 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 990 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
1015 FromIframeWithPermission) { | 991 FromIframeWithPermission) { |
1016 InitializeTestServer(); | |
1017 | |
1018 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); | 992 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); |
1019 | 993 |
1020 ui_test_utils::NavigateToURL(browser(), google_com_url()); | 994 ui_test_utils::NavigateToURL(browser(), google_com_url()); |
1021 EXPECT_EQ(NAMESPACE_NOT_DEFINED, | 995 EXPECT_EQ(NAMESPACE_NOT_DEFINED, |
1022 CanConnectAndSendMessagesToMainFrame(extension.get())); | 996 CanConnectAndSendMessagesToMainFrame(extension.get())); |
1023 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 997 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
1024 | 998 |
1025 ASSERT_TRUE(AppendIframe(chromium_org_url())); | 999 ASSERT_TRUE(AppendIframe(chromium_org_url())); |
1026 | 1000 |
1027 EXPECT_EQ(OK, CanConnectAndSendMessagesToIFrame(extension.get())); | 1001 EXPECT_EQ(OK, CanConnectAndSendMessagesToIFrame(extension.get())); |
1028 EXPECT_FALSE(AreAnyNonWebApisDefinedForIFrame()); | 1002 EXPECT_FALSE(AreAnyNonWebApisDefinedForIFrame()); |
1029 } | 1003 } |
1030 | 1004 |
1031 // Tests connection from an iframe without permission within a tab that does. | 1005 // Tests connection from an iframe without permission within a tab that does. |
1032 // Iframe shouldn't work. | 1006 // Iframe shouldn't work. |
1033 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 1007 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
1034 FromIframeWithoutPermission) { | 1008 FromIframeWithoutPermission) { |
1035 InitializeTestServer(); | |
1036 | |
1037 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); | 1009 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); |
1038 | 1010 |
1039 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 1011 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
1040 EXPECT_EQ(OK, CanConnectAndSendMessagesToMainFrame(extension.get())); | 1012 EXPECT_EQ(OK, CanConnectAndSendMessagesToMainFrame(extension.get())); |
1041 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 1013 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
1042 | 1014 |
1043 ASSERT_TRUE(AppendIframe(google_com_url())); | 1015 ASSERT_TRUE(AppendIframe(google_com_url())); |
1044 | 1016 |
1045 EXPECT_EQ(NAMESPACE_NOT_DEFINED, | 1017 EXPECT_EQ(NAMESPACE_NOT_DEFINED, |
1046 CanConnectAndSendMessagesToIFrame(extension.get())); | 1018 CanConnectAndSendMessagesToIFrame(extension.get())); |
1047 EXPECT_FALSE(AreAnyNonWebApisDefinedForIFrame()); | 1019 EXPECT_FALSE(AreAnyNonWebApisDefinedForIFrame()); |
1048 } | 1020 } |
1049 | 1021 |
1050 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, FromPopup) { | 1022 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, FromPopup) { |
1051 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1023 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
1052 switches::kDisablePopupBlocking); | 1024 switches::kDisablePopupBlocking); |
1053 | 1025 |
1054 InitializeTestServer(); | |
1055 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); | 1026 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); |
1056 | 1027 |
1057 // This will let us wait for the chromium.org.html page to load in a popup. | 1028 // This will let us wait for the chromium.org.html page to load in a popup. |
1058 ui_test_utils::UrlLoadObserver url_observer( | 1029 ui_test_utils::UrlLoadObserver url_observer( |
1059 chromium_org_url(), content::NotificationService::AllSources()); | 1030 chromium_org_url(), content::NotificationService::AllSources()); |
1060 | 1031 |
1061 // The page at popup_opener_url() should open chromium_org_url() as a popup. | 1032 // The page at popup_opener_url() should open chromium_org_url() as a popup. |
1062 ui_test_utils::NavigateToURL(browser(), popup_opener_url()); | 1033 ui_test_utils::NavigateToURL(browser(), popup_opener_url()); |
1063 url_observer.Wait(); | 1034 url_observer.Wait(); |
1064 | 1035 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 tls_channel_id_created_.Signal(); | 1116 tls_channel_id_created_.Signal(); |
1146 } | 1117 } |
1147 | 1118 |
1148 base::WaitableEvent tls_channel_id_created_; | 1119 base::WaitableEvent tls_channel_id_created_; |
1149 }; | 1120 }; |
1150 | 1121 |
1151 // Tests a web connectable extension that receives TLS channel id on a site | 1122 // Tests a web connectable extension that receives TLS channel id on a site |
1152 // that can connect to it, with a TLS channel ID having been generated. | 1123 // that can connect to it, with a TLS channel ID having been generated. |
1153 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingWithTlsChannelIdTest, | 1124 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingWithTlsChannelIdTest, |
1154 WebConnectableWithNonEmptyTlsChannelId) { | 1125 WebConnectableWithNonEmptyTlsChannelId) { |
1155 InitializeTestServer(); | |
1156 std::string expected_tls_channel_id_value = CreateTlsChannelId(); | 1126 std::string expected_tls_channel_id_value = CreateTlsChannelId(); |
1157 | 1127 |
1158 scoped_refptr<const Extension> chromium_connectable = | 1128 scoped_refptr<const Extension> chromium_connectable = |
1159 LoadChromiumConnectableExtensionWithTlsChannelId(); | 1129 LoadChromiumConnectableExtensionWithTlsChannelId(); |
1160 ASSERT_TRUE(chromium_connectable.get()); | 1130 ASSERT_TRUE(chromium_connectable.get()); |
1161 | 1131 |
1162 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 1132 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
1163 | 1133 |
1164 // Since the extension requests the TLS channel ID, it gets it for a site that | 1134 // Since the extension requests the TLS channel ID, it gets it for a site that |
1165 // can connect to it, but only if the page also asks to send it. | 1135 // can connect to it, but only if the page also asks to send it. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 tls_channel_id2 = | 1172 tls_channel_id2 = |
1203 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), true); | 1173 GetTlsChannelIdFromSendMessage(chromium_connectable.get(), true); |
1204 EXPECT_EQ(tls_channel_id, tls_channel_id2); | 1174 EXPECT_EQ(tls_channel_id, tls_channel_id2); |
1205 } | 1175 } |
1206 | 1176 |
1207 // Tests a web connectable extension that receives TLS channel id, but | 1177 // Tests a web connectable extension that receives TLS channel id, but |
1208 // immediately closes its background page upon receipt of a message. | 1178 // immediately closes its background page upon receipt of a message. |
1209 // Same flakiness seen in http://crbug.com/297866 | 1179 // Same flakiness seen in http://crbug.com/297866 |
1210 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingWithTlsChannelIdTest, | 1180 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingWithTlsChannelIdTest, |
1211 DISABLED_WebConnectableWithNonEmptyTlsChannelIdAndClosedBackgroundPage) { | 1181 DISABLED_WebConnectableWithNonEmptyTlsChannelIdAndClosedBackgroundPage) { |
1212 InitializeTestServer(); | |
1213 std::string expected_tls_channel_id_value = CreateTlsChannelId(); | 1182 std::string expected_tls_channel_id_value = CreateTlsChannelId(); |
1214 | 1183 |
1215 scoped_refptr<const Extension> chromium_connectable = | 1184 scoped_refptr<const Extension> chromium_connectable = |
1216 LoadChromiumConnectableExtensionWithTlsChannelId(); | 1185 LoadChromiumConnectableExtensionWithTlsChannelId(); |
1217 | 1186 |
1218 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 1187 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
1219 // If the page does ask for it, it isn't empty, even if the background page | 1188 // If the page does ask for it, it isn't empty, even if the background page |
1220 // closes upon receipt of the connect. | 1189 // closes upon receipt of the connect. |
1221 std::string tls_channel_id = GetTlsChannelIdFromPortConnect( | 1190 std::string tls_channel_id = GetTlsChannelIdFromPortConnect( |
1222 chromium_connectable.get(), true, close_background_message()); | 1191 chromium_connectable.get(), true, close_background_message()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1270 "chrome.test.runWithUserGesture(function() {\n" | 1239 "chrome.test.runWithUserGesture(function() {\n" |
1271 " chrome.runtime.sendMessage('%s', {}, function(response) {\n" | 1240 " chrome.runtime.sendMessage('%s', {}, function(response) {\n" |
1272 " window.domAutomationController.send('' + response.result);\n" | 1241 " window.domAutomationController.send('' + response.result);\n" |
1273 " });\n" | 1242 " });\n" |
1274 "});", receiver->id().c_str()))); | 1243 "});", receiver->id().c_str()))); |
1275 } | 1244 } |
1276 | 1245 |
1277 // Tests that a hosted app on a connectable site doesn't interfere with the | 1246 // Tests that a hosted app on a connectable site doesn't interfere with the |
1278 // connectability of that site. | 1247 // connectability of that site. |
1279 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, HostedAppOnWebsite) { | 1248 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, HostedAppOnWebsite) { |
1280 InitializeTestServer(); | |
1281 | |
1282 scoped_refptr<const Extension> app = LoadChromiumHostedApp(); | 1249 scoped_refptr<const Extension> app = LoadChromiumHostedApp(); |
1283 | 1250 |
1284 // The presence of the hosted app shouldn't give the ability to send messages. | 1251 // The presence of the hosted app shouldn't give the ability to send messages. |
1285 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 1252 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
1286 EXPECT_EQ(NAMESPACE_NOT_DEFINED, | 1253 EXPECT_EQ(NAMESPACE_NOT_DEFINED, |
1287 CanConnectAndSendMessagesToMainFrame(app.get())); | 1254 CanConnectAndSendMessagesToMainFrame(app.get())); |
1288 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 1255 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
1289 | 1256 |
1290 // Once a connectable extension is installed, it should. | 1257 // Once a connectable extension is installed, it should. |
1291 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); | 1258 scoped_refptr<const Extension> extension = LoadChromiumConnectableExtension(); |
1292 EXPECT_EQ(OK, CanConnectAndSendMessagesToMainFrame(extension.get())); | 1259 EXPECT_EQ(OK, CanConnectAndSendMessagesToMainFrame(extension.get())); |
1293 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); | 1260 EXPECT_FALSE(AreAnyNonWebApisDefinedForMainFrame()); |
1294 } | 1261 } |
1295 | 1262 |
1296 // Tests that an invalid extension ID specified in a hosted app does not crash | 1263 // Tests that an invalid extension ID specified in a hosted app does not crash |
1297 // the hosted app's renderer. | 1264 // the hosted app's renderer. |
1298 // | 1265 // |
1299 // This is a regression test for http://crbug.com/326250#c12. | 1266 // This is a regression test for http://crbug.com/326250#c12. |
1300 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, | 1267 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, |
1301 InvalidExtensionIDFromHostedApp) { | 1268 InvalidExtensionIDFromHostedApp) { |
1302 InitializeTestServer(); | |
1303 | |
1304 // The presence of the chromium hosted app triggers this bug. The chromium | 1269 // The presence of the chromium hosted app triggers this bug. The chromium |
1305 // connectable extension needs to be installed to set up the runtime bindings. | 1270 // connectable extension needs to be installed to set up the runtime bindings. |
1306 LoadChromiumHostedApp(); | 1271 LoadChromiumHostedApp(); |
1307 LoadChromiumConnectableExtension(); | 1272 LoadChromiumConnectableExtension(); |
1308 | 1273 |
1309 scoped_refptr<const Extension> invalid = | 1274 scoped_refptr<const Extension> invalid = |
1310 ExtensionBuilder() | 1275 ExtensionBuilder() |
1311 // A bit scary that this works... | 1276 // A bit scary that this works... |
1312 .SetID("invalid") | 1277 .SetID("invalid") |
1313 .SetManifest(DictionaryBuilder() | 1278 .SetManifest(DictionaryBuilder() |
1314 .Set("name", "Fake extension") | 1279 .Set("name", "Fake extension") |
1315 .Set("version", "1") | 1280 .Set("version", "1") |
1316 .Set("manifest_version", 2) | 1281 .Set("manifest_version", 2) |
1317 .Build()) | 1282 .Build()) |
1318 .Build(); | 1283 .Build(); |
1319 | 1284 |
1320 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); | 1285 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); |
1321 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, | 1286 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, |
1322 CanConnectAndSendMessagesToMainFrame(invalid.get())); | 1287 CanConnectAndSendMessagesToMainFrame(invalid.get())); |
1323 } | 1288 } |
1324 | 1289 |
1325 #endif // !defined(OS_WIN) - http://crbug.com/350517. | 1290 #endif // !defined(OS_WIN) - http://crbug.com/350517. |
1326 | 1291 |
1327 // Tests that messages sent in the unload handler of a window arrive. | 1292 // Tests that messages sent in the unload handler of a window arrive. |
1328 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MessagingOnUnload) { | 1293 IN_PROC_BROWSER_TEST_F(MessagingApiTest, MessagingOnUnload) { |
1329 host_resolver()->AddRule("*", "127.0.0.1"); | |
1330 ASSERT_TRUE(StartEmbeddedTestServer()); | |
1331 const Extension* extension = | 1294 const Extension* extension = |
1332 LoadExtension(test_data_dir_.AppendASCII("messaging/on_unload")); | 1295 LoadExtension(test_data_dir_.AppendASCII("messaging/on_unload")); |
1333 ExtensionTestMessageListener listener("listening", false); | 1296 ExtensionTestMessageListener listener("listening", false); |
1334 ASSERT_TRUE(extension); | 1297 ASSERT_TRUE(extension); |
1335 ui_test_utils::NavigateToURL( | 1298 ui_test_utils::NavigateToURL( |
1336 browser(), embedded_test_server()->GetURL("example.com", "/empty.html")); | 1299 browser(), embedded_test_server()->GetURL("example.com", "/empty.html")); |
1337 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 1300 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
1338 ExtensionHost* background_host = | 1301 ExtensionHost* background_host = |
1339 ProcessManager::Get(profile())->GetBackgroundHostForExtension( | 1302 ProcessManager::Get(profile())->GetBackgroundHostForExtension( |
1340 extension->id()); | 1303 extension->id()); |
(...skipping 17 matching lines...) Expand all Loading... |
1358 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 1321 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
1359 background_contents, | 1322 background_contents, |
1360 "window.domAutomationController.send(window.messageCount);", | 1323 "window.domAutomationController.send(window.messageCount);", |
1361 &message_count)); | 1324 &message_count)); |
1362 EXPECT_EQ(1, message_count); | 1325 EXPECT_EQ(1, message_count); |
1363 } | 1326 } |
1364 | 1327 |
1365 } // namespace | 1328 } // namespace |
1366 | 1329 |
1367 }; // namespace extensions | 1330 }; // namespace extensions |
OLD | NEW |