Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: chrome/browser/extensions/extension_devtools_browsertests.cc

Issue 8549022: Define DevTools content API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DevToolsManager -> DevToolsManagerImpl, moved client to public Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/common/devtools_messages.h"
23 #include "content/public/browser/devtools/devtools_agent_host_registry.h"
24 #include "content/public/browser/devtools/devtools_client_host.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::DevToolsAgentHost;
29 using content::DevToolsAgentHostRegistry;
30 using content::DevToolsClientHost;
31 using content::DevToolsManager;
32
27 // Looks for an ExtensionHost whose URL has the given path component (including 33 // 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. 34 // leading slash). Also verifies that the expected number of hosts are loaded.
29 static ExtensionHost* FindHostWithPath(ExtensionProcessManager* manager, 35 static ExtensionHost* FindHostWithPath(ExtensionProcessManager* manager,
30 const std::string& path, 36 const std::string& path,
31 int expected_hosts) { 37 int expected_hosts) {
32 ExtensionHost* host = NULL; 38 ExtensionHost* host = NULL;
33 int num_hosts = 0; 39 int num_hosts = 0;
34 for (ExtensionProcessManager::const_iterator iter = manager->begin(); 40 for (ExtensionProcessManager::const_iterator iter = manager->begin();
35 iter != manager->end(); ++iter) { 41 iter != manager->end(); ++iter) {
36 if ((*iter)->GetURL().path() == path) { 42 if ((*iter)->GetURL().path() == path) {
(...skipping 29 matching lines...) Expand all
66 // Test setup. 72 // Test setup.
67 bool result = false; 73 bool result = false;
68 std::wstring register_listeners_js = base::StringPrintf( 74 std::wstring register_listeners_js = base::StringPrintf(
69 L"setListenersOnTab(%d)", tab_id); 75 L"setListenersOnTab(%d)", tab_id);
70 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 76 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
71 host->render_view_host(), L"", register_listeners_js, &result)); 77 host->render_view_host(), L"", register_listeners_js, &result));
72 EXPECT_TRUE(result); 78 EXPECT_TRUE(result);
73 79
74 // Setting the events should have caused an ExtensionDevToolsBridge to be 80 // Setting the events should have caused an ExtensionDevToolsBridge to be
75 // registered for the tab's RenderViewHost. 81 // registered for the tab's RenderViewHost.
82 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost(
83 tab_contents->render_view_host());
76 DevToolsClientHost* devtools_client_host = 84 DevToolsClientHost* devtools_client_host =
77 devtools_manager->GetDevToolsClientHostFor( 85 devtools_manager->GetDevToolsClientHostFor(agent);
78 tab_contents->render_view_host());
79 ASSERT_TRUE(devtools_client_host); 86 ASSERT_TRUE(devtools_client_host);
80 87
81 // Test onPageEvent event. 88 // Test onPageEvent event.
82 result = false; 89 result = false;
83 90
84 DevToolsClientMsg_DispatchOnInspectorFrontend pageEventMessage( 91 DevToolsClientMsg_DispatchOnInspectorFrontend pageEventMessage(
85 MSG_ROUTING_NONE, 92 MSG_ROUTING_NONE,
86 ""); 93 "");
87 devtools_client_host->SendMessageToClient(pageEventMessage); 94 devtools_client_host->SendMessageToClient(pageEventMessage);
88 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 95 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
89 host->render_view_host(), L"", L"testReceivePageEvent()", &result)); 96 host->render_view_host(), L"", L"testReceivePageEvent()", &result));
90 EXPECT_TRUE(result); 97 EXPECT_TRUE(result);
91 98
92 // Test onTabClose event. 99 // Test onTabClose event.
93 result = false; 100 result = false;
94 devtools_manager->UnregisterDevToolsClientHostFor( 101 devtools_manager->UnregisterDevToolsClientHostFor(
95 tab_contents->render_view_host()); 102 DevToolsAgentHostRegistry::GetDevToolsAgentHost(
103 tab_contents->render_view_host()));
96 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 104 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
97 host->render_view_host(), L"", L"testReceiveTabCloseEvent()", &result)); 105 host->render_view_host(), L"", L"testReceiveTabCloseEvent()", &result));
98 EXPECT_TRUE(result); 106 EXPECT_TRUE(result);
99 } 107 }
100 108
101 109
102 // Tests that ref counting of listeners from multiple processes works. 110 // Tests that ref counting of listeners from multiple processes works.
103 IN_PROC_BROWSER_TEST_F(ExtensionDevToolsBrowserTest, ProcessRefCounting) { 111 IN_PROC_BROWSER_TEST_F(ExtensionDevToolsBrowserTest, ProcessRefCounting) {
104 ASSERT_TRUE(LoadExtension( 112 ASSERT_TRUE(LoadExtension(
105 test_data_dir_.AppendASCII("devtools").AppendASCII("timeline_api"))); 113 test_data_dir_.AppendASCII("devtools").AppendASCII("timeline_api")));
(...skipping 19 matching lines...) Expand all
125 bool result = false; 133 bool result = false;
126 std::wstring register_listeners_js = base::StringPrintf( 134 std::wstring register_listeners_js = base::StringPrintf(
127 L"setListenersOnTab(%d)", tab_id); 135 L"setListenersOnTab(%d)", tab_id);
128 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 136 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
129 host_one->render_view_host(), L"", register_listeners_js, &result)); 137 host_one->render_view_host(), L"", register_listeners_js, &result));
130 EXPECT_TRUE(result); 138 EXPECT_TRUE(result);
131 139
132 // Setting the event listeners should have caused an ExtensionDevToolsBridge 140 // Setting the event listeners should have caused an ExtensionDevToolsBridge
133 // to be registered for the tab's RenderViewHost. 141 // to be registered for the tab's RenderViewHost.
134 ASSERT_TRUE(devtools_manager->GetDevToolsClientHostFor( 142 ASSERT_TRUE(devtools_manager->GetDevToolsClientHostFor(
135 tab_contents->render_view_host())); 143 DevToolsAgentHostRegistry::GetDevToolsAgentHost(
144 tab_contents->render_view_host())));
136 145
137 // Register listeners from the second extension as well. 146 // Register listeners from the second extension as well.
138 std::wstring script = base::StringPrintf(L"registerListenersForTab(%d)", 147 std::wstring script = base::StringPrintf(L"registerListenersForTab(%d)",
139 tab_id); 148 tab_id);
140 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 149 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
141 host_two->render_view_host(), L"", script, &result)); 150 host_two->render_view_host(), L"", script, &result));
142 EXPECT_TRUE(result); 151 EXPECT_TRUE(result);
143 152
144 // Removing the listeners from the first extension should leave the bridge 153 // Removing the listeners from the first extension should leave the bridge
145 // alive. 154 // alive.
146 result = false; 155 result = false;
147 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 156 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
148 host_one->render_view_host(), L"", L"unregisterListeners()", &result)); 157 host_one->render_view_host(), L"", L"unregisterListeners()", &result));
149 EXPECT_TRUE(result); 158 EXPECT_TRUE(result);
150 ASSERT_TRUE(devtools_manager->GetDevToolsClientHostFor( 159 ASSERT_TRUE(devtools_manager->GetDevToolsClientHostFor(
151 tab_contents->render_view_host())); 160 DevToolsAgentHostRegistry::GetDevToolsAgentHost(
161 tab_contents->render_view_host())));
152 162
153 // Removing the listeners from the second extension should tear the bridge 163 // Removing the listeners from the second extension should tear the bridge
154 // down. 164 // down.
155 result = false; 165 result = false;
156 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 166 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
157 host_two->render_view_host(), L"", L"unregisterListeners()", &result)); 167 host_two->render_view_host(), L"", L"unregisterListeners()", &result));
158 EXPECT_TRUE(result); 168 EXPECT_TRUE(result);
159 ASSERT_FALSE(devtools_manager->GetDevToolsClientHostFor( 169 ASSERT_FALSE(devtools_manager->GetDevToolsClientHostFor(
160 tab_contents->render_view_host())); 170 DevToolsAgentHostRegistry::GetDevToolsAgentHost(
171 tab_contents->render_view_host())));
161 } 172 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698