| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
| 6 #include "base/stringprintf.h" | 6 #include "base/stringprintf.h" |
| 7 #include "chrome/browser/extensions/extension_devtools_browsertest.h" | 7 #include "chrome/browser/extensions/extension_devtools_browsertest.h" |
| 8 #include "chrome/browser/extensions/extension_error_reporter.h" | 8 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 9 #include "chrome/browser/extensions/extension_host.h" | 9 #include "chrome/browser/extensions/extension_host.h" |
| 10 #include "chrome/browser/extensions/extension_process_manager.h" | 10 #include "chrome/browser/extensions/extension_process_manager.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/extension_tab_util.h" | 12 #include "chrome/browser/extensions/extension_tab_util.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/tabs/tab_strip_model.h" | 14 #include "chrome/browser/tabs/tab_strip_model.h" |
| 15 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
| 16 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 17 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
| 19 #include "content/browser/debugger/devtools_client_host.h" | 19 #include "content/browser/debugger/devtools_client_host.h" |
| 20 #include "content/browser/debugger/devtools_manager.h" | |
| 21 #include "content/browser/renderer_host/render_view_host.h" | 20 #include "content/browser/renderer_host/render_view_host.h" |
| 22 #include "content/browser/site_instance.h" | 21 #include "content/browser/site_instance.h" |
| 23 #include "content/browser/tab_contents/tab_contents.h" | 22 #include "content/browser/tab_contents/tab_contents.h" |
| 24 #include "content/common/devtools_messages.h" | 23 #include "content/common/devtools_messages.h" |
| 24 #include "content/public/browser/devtools/devtools_agent_host_registry.h" |
| 25 #include "content/public/browser/devtools/devtools_manager.h" |
| 25 #include "net/base/net_util.h" | 26 #include "net/base/net_util.h" |
| 26 | 27 |
| 28 using content::DevToolsAgentHostRegistry; |
| 29 using content::DevToolsManager; |
| 30 |
| 27 // Looks for an ExtensionHost whose URL has the given path component (including | 31 // Looks for an ExtensionHost whose URL has the given path component (including |
| 28 // leading slash). Also verifies that the expected number of hosts are loaded. | 32 // leading slash). Also verifies that the expected number of hosts are loaded. |
| 29 static ExtensionHost* FindHostWithPath(ExtensionProcessManager* manager, | 33 static ExtensionHost* FindHostWithPath(ExtensionProcessManager* manager, |
| 30 const std::string& path, | 34 const std::string& path, |
| 31 int expected_hosts) { | 35 int expected_hosts) { |
| 32 ExtensionHost* host = NULL; | 36 ExtensionHost* host = NULL; |
| 33 int num_hosts = 0; | 37 int num_hosts = 0; |
| 34 for (ExtensionProcessManager::const_iterator iter = manager->begin(); | 38 for (ExtensionProcessManager::const_iterator iter = manager->begin(); |
| 35 iter != manager->end(); ++iter) { | 39 iter != manager->end(); ++iter) { |
| 36 if ((*iter)->GetURL().path() == path) { | 40 if ((*iter)->GetURL().path() == path) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 66 // Test setup. | 70 // Test setup. |
| 67 bool result = false; | 71 bool result = false; |
| 68 std::wstring register_listeners_js = base::StringPrintf( | 72 std::wstring register_listeners_js = base::StringPrintf( |
| 69 L"setListenersOnTab(%d)", tab_id); | 73 L"setListenersOnTab(%d)", tab_id); |
| 70 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 74 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 71 host->render_view_host(), L"", register_listeners_js, &result)); | 75 host->render_view_host(), L"", register_listeners_js, &result)); |
| 72 EXPECT_TRUE(result); | 76 EXPECT_TRUE(result); |
| 73 | 77 |
| 74 // Setting the events should have caused an ExtensionDevToolsBridge to be | 78 // Setting the events should have caused an ExtensionDevToolsBridge to be |
| 75 // registered for the tab's RenderViewHost. | 79 // registered for the tab's RenderViewHost. |
| 80 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 81 tab_contents->render_view_host()); |
| 76 DevToolsClientHost* devtools_client_host = | 82 DevToolsClientHost* devtools_client_host = |
| 77 devtools_manager->GetDevToolsClientHostFor( | 83 devtools_manager->GetDevToolsClientHostFor(agent); |
| 78 tab_contents->render_view_host()); | |
| 79 ASSERT_TRUE(devtools_client_host); | 84 ASSERT_TRUE(devtools_client_host); |
| 80 | 85 |
| 81 // Test onPageEvent event. | 86 // Test onPageEvent event. |
| 82 result = false; | 87 result = false; |
| 83 | 88 |
| 84 DevToolsClientMsg_DispatchOnInspectorFrontend pageEventMessage( | 89 DevToolsClientMsg_DispatchOnInspectorFrontend pageEventMessage( |
| 85 MSG_ROUTING_NONE, | 90 MSG_ROUTING_NONE, |
| 86 ""); | 91 ""); |
| 87 devtools_client_host->SendMessageToClient(pageEventMessage); | 92 devtools_client_host->SendMessageToClient(pageEventMessage); |
| 88 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 93 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 89 host->render_view_host(), L"", L"testReceivePageEvent()", &result)); | 94 host->render_view_host(), L"", L"testReceivePageEvent()", &result)); |
| 90 EXPECT_TRUE(result); | 95 EXPECT_TRUE(result); |
| 91 | 96 |
| 92 // Test onTabClose event. | 97 // Test onTabClose event. |
| 93 result = false; | 98 result = false; |
| 94 devtools_manager->UnregisterDevToolsClientHostFor( | 99 devtools_manager->UnregisterDevToolsClientHostFor( |
| 95 tab_contents->render_view_host()); | 100 DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 101 tab_contents->render_view_host())); |
| 96 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 102 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 97 host->render_view_host(), L"", L"testReceiveTabCloseEvent()", &result)); | 103 host->render_view_host(), L"", L"testReceiveTabCloseEvent()", &result)); |
| 98 EXPECT_TRUE(result); | 104 EXPECT_TRUE(result); |
| 99 } | 105 } |
| 100 | 106 |
| 101 | 107 |
| 102 // Tests that ref counting of listeners from multiple processes works. | 108 // Tests that ref counting of listeners from multiple processes works. |
| 103 IN_PROC_BROWSER_TEST_F(ExtensionDevToolsBrowserTest, ProcessRefCounting) { | 109 IN_PROC_BROWSER_TEST_F(ExtensionDevToolsBrowserTest, ProcessRefCounting) { |
| 104 ASSERT_TRUE(LoadExtension( | 110 ASSERT_TRUE(LoadExtension( |
| 105 test_data_dir_.AppendASCII("devtools").AppendASCII("timeline_api"))); | 111 test_data_dir_.AppendASCII("devtools").AppendASCII("timeline_api"))); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 125 bool result = false; | 131 bool result = false; |
| 126 std::wstring register_listeners_js = base::StringPrintf( | 132 std::wstring register_listeners_js = base::StringPrintf( |
| 127 L"setListenersOnTab(%d)", tab_id); | 133 L"setListenersOnTab(%d)", tab_id); |
| 128 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 134 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 129 host_one->render_view_host(), L"", register_listeners_js, &result)); | 135 host_one->render_view_host(), L"", register_listeners_js, &result)); |
| 130 EXPECT_TRUE(result); | 136 EXPECT_TRUE(result); |
| 131 | 137 |
| 132 // Setting the event listeners should have caused an ExtensionDevToolsBridge | 138 // Setting the event listeners should have caused an ExtensionDevToolsBridge |
| 133 // to be registered for the tab's RenderViewHost. | 139 // to be registered for the tab's RenderViewHost. |
| 134 ASSERT_TRUE(devtools_manager->GetDevToolsClientHostFor( | 140 ASSERT_TRUE(devtools_manager->GetDevToolsClientHostFor( |
| 135 tab_contents->render_view_host())); | 141 DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 142 tab_contents->render_view_host()))); |
| 136 | 143 |
| 137 // Register listeners from the second extension as well. | 144 // Register listeners from the second extension as well. |
| 138 std::wstring script = base::StringPrintf(L"registerListenersForTab(%d)", | 145 std::wstring script = base::StringPrintf(L"registerListenersForTab(%d)", |
| 139 tab_id); | 146 tab_id); |
| 140 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 147 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 141 host_two->render_view_host(), L"", script, &result)); | 148 host_two->render_view_host(), L"", script, &result)); |
| 142 EXPECT_TRUE(result); | 149 EXPECT_TRUE(result); |
| 143 | 150 |
| 144 // Removing the listeners from the first extension should leave the bridge | 151 // Removing the listeners from the first extension should leave the bridge |
| 145 // alive. | 152 // alive. |
| 146 result = false; | 153 result = false; |
| 147 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 154 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 148 host_one->render_view_host(), L"", L"unregisterListeners()", &result)); | 155 host_one->render_view_host(), L"", L"unregisterListeners()", &result)); |
| 149 EXPECT_TRUE(result); | 156 EXPECT_TRUE(result); |
| 150 ASSERT_TRUE(devtools_manager->GetDevToolsClientHostFor( | 157 ASSERT_TRUE(devtools_manager->GetDevToolsClientHostFor( |
| 151 tab_contents->render_view_host())); | 158 DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 159 tab_contents->render_view_host()))); |
| 152 | 160 |
| 153 // Removing the listeners from the second extension should tear the bridge | 161 // Removing the listeners from the second extension should tear the bridge |
| 154 // down. | 162 // down. |
| 155 result = false; | 163 result = false; |
| 156 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 164 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 157 host_two->render_view_host(), L"", L"unregisterListeners()", &result)); | 165 host_two->render_view_host(), L"", L"unregisterListeners()", &result)); |
| 158 EXPECT_TRUE(result); | 166 EXPECT_TRUE(result); |
| 159 ASSERT_FALSE(devtools_manager->GetDevToolsClientHostFor( | 167 ASSERT_FALSE(devtools_manager->GetDevToolsClientHostFor( |
| 160 tab_contents->render_view_host())); | 168 DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 169 tab_contents->render_view_host()))); |
| 161 } | 170 } |
| OLD | NEW |