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