| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/singleton.h" | 6 #include "base/memory/singleton.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 using blink::WebInputEvent; | 47 using blink::WebInputEvent; |
| 48 using blink::WebMouseEvent; | 48 using blink::WebMouseEvent; |
| 49 using content::BrowserPluginEmbedder; | 49 using content::BrowserPluginEmbedder; |
| 50 using content::BrowserPluginGuest; | 50 using content::BrowserPluginGuest; |
| 51 using content::BrowserPluginHostFactory; | 51 using content::BrowserPluginHostFactory; |
| 52 using content::WebContentsImpl; | 52 using content::WebContentsImpl; |
| 53 | 53 |
| 54 const char kHTMLForGuest[] = | 54 const char kHTMLForGuest[] = |
| 55 "data:text/html,<html><body>hello world</body></html>"; | 55 "data:text/html,<html><body>hello world</body></html>"; |
| 56 | 56 |
| 57 const char kHTMLForGuestTouchHandler[] = | |
| 58 "data:text/html,<html><body><div id=\"touch\">With touch</div></body>" | |
| 59 "<script type=\"text/javascript\">" | |
| 60 "function handler() {}" | |
| 61 "function InstallTouchHandler() { " | |
| 62 " document.getElementById(\"touch\").addEventListener(\"touchstart\", " | |
| 63 " handler);" | |
| 64 "}" | |
| 65 "function UninstallTouchHandler() { " | |
| 66 " document.getElementById(\"touch\").removeEventListener(\"touchstart\", " | |
| 67 " handler);" | |
| 68 "}" | |
| 69 "</script></html>"; | |
| 70 | |
| 71 const char kHTMLForGuestAcceptDrag[] = | 57 const char kHTMLForGuestAcceptDrag[] = |
| 72 "data:text/html,<html><body>" | 58 "data:text/html,<html><body>" |
| 73 "<script>" | 59 "<script>" |
| 74 "function dropped() {" | 60 "function dropped() {" |
| 75 " document.title = \"DROPPED\";" | 61 " document.title = \"DROPPED\";" |
| 76 "}" | 62 "}" |
| 77 "</script>" | 63 "</script>" |
| 78 "<textarea id=\"text\" style=\"width:100%; height: 100%\"" | 64 "<textarea id=\"text\" style=\"width:100%; height: 100%\"" |
| 79 " ondrop=\"dropped();\">" | 65 " ondrop=\"dropped();\">" |
| 80 "</textarea>" | 66 "</textarea>" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 TestShortHangTimeoutGuestFactory() {} | 140 TestShortHangTimeoutGuestFactory() {} |
| 155 virtual ~TestShortHangTimeoutGuestFactory() {} | 141 virtual ~TestShortHangTimeoutGuestFactory() {} |
| 156 | 142 |
| 157 private: | 143 private: |
| 158 // For Singleton. | 144 // For Singleton. |
| 159 friend struct DefaultSingletonTraits<TestShortHangTimeoutGuestFactory>; | 145 friend struct DefaultSingletonTraits<TestShortHangTimeoutGuestFactory>; |
| 160 | 146 |
| 161 DISALLOW_COPY_AND_ASSIGN(TestShortHangTimeoutGuestFactory); | 147 DISALLOW_COPY_AND_ASSIGN(TestShortHangTimeoutGuestFactory); |
| 162 }; | 148 }; |
| 163 | 149 |
| 164 // A transparent observer that can be used to verify that a RenderViewHost | |
| 165 // received a specific message. | |
| 166 class MessageObserver : public WebContentsObserver { | |
| 167 public: | |
| 168 MessageObserver(WebContents* web_contents, uint32 message_id) | |
| 169 : WebContentsObserver(web_contents), | |
| 170 message_id_(message_id), | |
| 171 message_received_(false) { | |
| 172 } | |
| 173 | |
| 174 virtual ~MessageObserver() {} | |
| 175 | |
| 176 void WaitUntilMessageReceived() { | |
| 177 if (message_received_) | |
| 178 return; | |
| 179 message_loop_runner_ = new MessageLoopRunner(); | |
| 180 message_loop_runner_->Run(); | |
| 181 } | |
| 182 | |
| 183 void ResetState() { | |
| 184 message_received_ = false; | |
| 185 } | |
| 186 | |
| 187 // IPC::Listener implementation. | |
| 188 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | |
| 189 if (message.type() == message_id_) { | |
| 190 message_received_ = true; | |
| 191 if (message_loop_runner_) | |
| 192 message_loop_runner_->Quit(); | |
| 193 } | |
| 194 return false; | |
| 195 } | |
| 196 | |
| 197 private: | |
| 198 scoped_refptr<MessageLoopRunner> message_loop_runner_; | |
| 199 uint32 message_id_; | |
| 200 bool message_received_; | |
| 201 | |
| 202 DISALLOW_COPY_AND_ASSIGN(MessageObserver); | |
| 203 }; | |
| 204 | |
| 205 class BrowserPluginHostTest : public ContentBrowserTest { | 150 class BrowserPluginHostTest : public ContentBrowserTest { |
| 206 public: | 151 public: |
| 207 BrowserPluginHostTest() | 152 BrowserPluginHostTest() |
| 208 : test_embedder_(NULL), | 153 : test_embedder_(NULL), |
| 209 test_guest_(NULL), | 154 test_guest_(NULL), |
| 210 test_guest_manager_(NULL) {} | 155 test_guest_manager_(NULL) {} |
| 211 | 156 |
| 212 virtual void SetUp() OVERRIDE { | 157 virtual void SetUp() OVERRIDE { |
| 213 // Override factory to create tests instances of BrowserPlugin*. | 158 // Override factory to create tests instances of BrowserPlugin*. |
| 214 BrowserPluginEmbedder::set_factory_for_testing( | 159 BrowserPluginEmbedder::set_factory_for_testing( |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 EXPECT_EQ(expected_title, actual_title); | 362 EXPECT_EQ(expected_title, actual_title); |
| 418 VLOG(0) << "Done navigating to second page"; | 363 VLOG(0) << "Done navigating to second page"; |
| 419 | 364 |
| 420 TestBrowserPluginEmbedder* test_embedder_after_nav = | 365 TestBrowserPluginEmbedder* test_embedder_after_nav = |
| 421 static_cast<TestBrowserPluginEmbedder*>( | 366 static_cast<TestBrowserPluginEmbedder*>( |
| 422 embedder_web_contents->GetBrowserPluginEmbedder()); | 367 embedder_web_contents->GetBrowserPluginEmbedder()); |
| 423 // Embedder must not change in web_contents. | 368 // Embedder must not change in web_contents. |
| 424 ASSERT_EQ(test_embedder_after_nav, test_embedder()); | 369 ASSERT_EQ(test_embedder_after_nav, test_embedder()); |
| 425 } | 370 } |
| 426 | 371 |
| 427 // Verifies that installing/uninstalling touch-event handlers in the guest | |
| 428 // plugin correctly updates the touch-event handling state in the embedder. | |
| 429 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AcceptTouchEvents) { | |
| 430 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; | |
| 431 StartBrowserPluginTest( | |
| 432 kEmbedderURL, kHTMLForGuestTouchHandler, true, std::string()); | |
| 433 | |
| 434 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
| 435 test_embedder()->web_contents()->GetRenderViewHost()); | |
| 436 // The embedder should not have any touch event handlers at this point. | |
| 437 EXPECT_FALSE(rvh->has_touch_handler()); | |
| 438 | |
| 439 // Install the touch handler in the guest. This should cause the embedder to | |
| 440 // start listening for touch events too. | |
| 441 MessageObserver observer(test_embedder()->web_contents(), | |
| 442 ViewHostMsg_HasTouchEventHandlers::ID); | |
| 443 ExecuteSyncJSFunction(test_guest()->web_contents()->GetMainFrame(), | |
| 444 "InstallTouchHandler();"); | |
| 445 observer.WaitUntilMessageReceived(); | |
| 446 EXPECT_TRUE(rvh->has_touch_handler()); | |
| 447 | |
| 448 // Uninstalling the touch-handler in guest should cause the embedder to stop | |
| 449 // listening for touch events. | |
| 450 observer.ResetState(); | |
| 451 ExecuteSyncJSFunction(test_guest()->web_contents()->GetMainFrame(), | |
| 452 "UninstallTouchHandler();"); | |
| 453 observer.WaitUntilMessageReceived(); | |
| 454 EXPECT_FALSE(rvh->has_touch_handler()); | |
| 455 } | |
| 456 | |
| 457 // This tests verifies that reloading the embedder does not crash the browser | 372 // This tests verifies that reloading the embedder does not crash the browser |
| 458 // and that the guest is reset. | 373 // and that the guest is reset. |
| 459 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_ReloadEmbedder) { | 374 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_ReloadEmbedder) { |
| 460 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; | 375 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
| 461 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 376 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
| 462 RenderFrameHost* rfh = test_embedder()->web_contents()->GetMainFrame(); | 377 RenderFrameHost* rfh = test_embedder()->web_contents()->GetMainFrame(); |
| 463 | 378 |
| 464 // Change the title of the page to 'modified' so that we know that | 379 // Change the title of the page to 'modified' so that we know that |
| 465 // the page has successfully reloaded when it goes back to 'embedder' | 380 // the page has successfully reloaded when it goes back to 'embedder' |
| 466 // in the next step. | 381 // in the next step. |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 scoped_ptr<base::Value> value = | 912 scoped_ptr<base::Value> value = |
| 998 content::ExecuteScriptAndGetValue( | 913 content::ExecuteScriptAndGetValue( |
| 999 guest_rfh, "document.getElementById('input1').value"); | 914 guest_rfh, "document.getElementById('input1').value"); |
| 1000 std::string actual_value; | 915 std::string actual_value; |
| 1001 ASSERT_TRUE(value->GetAsString(&actual_value)); | 916 ASSERT_TRUE(value->GetAsString(&actual_value)); |
| 1002 EXPECT_EQ(base::UTF16ToUTF8(expected_value), actual_value); | 917 EXPECT_EQ(base::UTF16ToUTF8(expected_value), actual_value); |
| 1003 } | 918 } |
| 1004 } | 919 } |
| 1005 | 920 |
| 1006 } // namespace content | 921 } // namespace content |
| OLD | NEW |