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

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

Issue 10795090: Move ExecuteJavaScript functions from ui_test_utils.h to browser_test_utils.h so they can be reused… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 months 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) 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 "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/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_list.h" 15 #include "chrome/browser/ui/browser_list.h"
16 #include "chrome/browser/ui/browser_tabstrip.h" 16 #include "chrome/browser/ui/browser_tabstrip.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
20 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
21 #include "content/public/browser/devtools_agent_host_registry.h" 21 #include "content/public/browser/devtools_agent_host_registry.h"
22 #include "content/public/browser/devtools_client_host.h" 22 #include "content/public/browser/devtools_client_host.h"
23 #include "content/public/browser/devtools_manager.h" 23 #include "content/public/browser/devtools_manager.h"
24 #include "content/public/browser/render_view_host.h" 24 #include "content/public/browser/render_view_host.h"
25 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
26 #include "content/public/test/browser_test_utils.h"
26 #include "net/base/net_util.h" 27 #include "net/base/net_util.h"
27 28
28 using content::DevToolsAgentHost; 29 using content::DevToolsAgentHost;
29 using content::DevToolsAgentHostRegistry; 30 using content::DevToolsAgentHostRegistry;
30 using content::DevToolsClientHost; 31 using content::DevToolsClientHost;
31 using content::DevToolsManager; 32 using content::DevToolsManager;
32 using content::WebContents; 33 using content::WebContents;
33 34
34 // Looks for an background ExtensionHost whose URL has the given path component 35 // Looks for an background ExtensionHost whose URL has the given path component
35 // (including leading slash). Also verifies that the expected number of hosts 36 // (including leading slash). Also verifies that the expected number of hosts
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 72
72 // Grab the tab_id of whatever tab happens to be first. 73 // Grab the tab_id of whatever tab happens to be first.
73 WebContents* web_contents = chrome::GetWebContentsAt(browser(), 0); 74 WebContents* web_contents = chrome::GetWebContentsAt(browser(), 0);
74 ASSERT_TRUE(web_contents); 75 ASSERT_TRUE(web_contents);
75 int tab_id = ExtensionTabUtil::GetTabId(web_contents); 76 int tab_id = ExtensionTabUtil::GetTabId(web_contents);
76 77
77 // Test setup. 78 // Test setup.
78 bool result = false; 79 bool result = false;
79 std::wstring register_listeners_js = base::StringPrintf( 80 std::wstring register_listeners_js = base::StringPrintf(
80 L"setListenersOnTab(%d)", tab_id); 81 L"setListenersOnTab(%d)", tab_id);
81 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 82 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
82 host->render_view_host(), L"", register_listeners_js, &result)); 83 host->render_view_host(), L"", register_listeners_js, &result));
83 EXPECT_TRUE(result); 84 EXPECT_TRUE(result);
84 85
85 // Setting the events should have caused an ExtensionDevToolsBridge to be 86 // Setting the events should have caused an ExtensionDevToolsBridge to be
86 // registered for the tab's RenderViewHost. 87 // registered for the tab's RenderViewHost.
87 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( 88 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost(
88 web_contents->GetRenderViewHost()); 89 web_contents->GetRenderViewHost());
89 DevToolsClientHost* devtools_client_host = 90 DevToolsClientHost* devtools_client_host =
90 devtools_manager->GetDevToolsClientHostFor(agent); 91 devtools_manager->GetDevToolsClientHostFor(agent);
91 ASSERT_TRUE(devtools_client_host); 92 ASSERT_TRUE(devtools_client_host);
92 93
93 // Test onPageEvent event. 94 // Test onPageEvent event.
94 result = false; 95 result = false;
95 96
96 devtools_client_host->DispatchOnInspectorFrontend(""); 97 devtools_client_host->DispatchOnInspectorFrontend("");
97 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 98 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
98 host->render_view_host(), L"", L"testReceivePageEvent()", &result)); 99 host->render_view_host(), L"", L"testReceivePageEvent()", &result));
99 EXPECT_TRUE(result); 100 EXPECT_TRUE(result);
100 101
101 // Test onTabClose event. 102 // Test onTabClose event.
102 result = false; 103 result = false;
103 devtools_manager->UnregisterDevToolsClientHostFor( 104 devtools_manager->UnregisterDevToolsClientHostFor(
104 DevToolsAgentHostRegistry::GetDevToolsAgentHost( 105 DevToolsAgentHostRegistry::GetDevToolsAgentHost(
105 web_contents->GetRenderViewHost())); 106 web_contents->GetRenderViewHost()));
106 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 107 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
107 host->render_view_host(), L"", L"testReceiveTabCloseEvent()", &result)); 108 host->render_view_host(), L"", L"testReceiveTabCloseEvent()", &result));
108 EXPECT_TRUE(result); 109 EXPECT_TRUE(result);
109 } 110 }
110 111
111 112
112 // Tests that ref counting of listeners from multiple processes works. 113 // Tests that ref counting of listeners from multiple processes works.
113 IN_PROC_BROWSER_TEST_F(ExtensionDevToolsBrowserTest, ProcessRefCounting) { 114 IN_PROC_BROWSER_TEST_F(ExtensionDevToolsBrowserTest, ProcessRefCounting) {
114 ASSERT_TRUE(LoadExtension( 115 ASSERT_TRUE(LoadExtension(
115 test_data_dir_.AppendASCII("devtools").AppendASCII("timeline_api"))); 116 test_data_dir_.AppendASCII("devtools").AppendASCII("timeline_api")));
116 117
(...skipping 13 matching lines...) Expand all
130 131
131 // Grab the tab_id of whatever tab happens to be first. 132 // Grab the tab_id of whatever tab happens to be first.
132 WebContents* web_contents = chrome::GetWebContentsAt(browser(), 0); 133 WebContents* web_contents = chrome::GetWebContentsAt(browser(), 0);
133 ASSERT_TRUE(web_contents); 134 ASSERT_TRUE(web_contents);
134 int tab_id = ExtensionTabUtil::GetTabId(web_contents); 135 int tab_id = ExtensionTabUtil::GetTabId(web_contents);
135 136
136 // Test setup. 137 // Test setup.
137 bool result = false; 138 bool result = false;
138 std::wstring register_listeners_js = base::StringPrintf( 139 std::wstring register_listeners_js = base::StringPrintf(
139 L"setListenersOnTab(%d)", tab_id); 140 L"setListenersOnTab(%d)", tab_id);
140 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 141 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
141 host_one->render_view_host(), L"", register_listeners_js, &result)); 142 host_one->render_view_host(), L"", register_listeners_js, &result));
142 EXPECT_TRUE(result); 143 EXPECT_TRUE(result);
143 144
144 // Setting the event listeners should have caused an ExtensionDevToolsBridge 145 // Setting the event listeners should have caused an ExtensionDevToolsBridge
145 // to be registered for the tab's RenderViewHost. 146 // to be registered for the tab's RenderViewHost.
146 ASSERT_TRUE(devtools_manager->GetDevToolsClientHostFor( 147 ASSERT_TRUE(devtools_manager->GetDevToolsClientHostFor(
147 DevToolsAgentHostRegistry::GetDevToolsAgentHost( 148 DevToolsAgentHostRegistry::GetDevToolsAgentHost(
148 web_contents->GetRenderViewHost()))); 149 web_contents->GetRenderViewHost())));
149 150
150 // Register listeners from the second extension as well. 151 // Register listeners from the second extension as well.
151 std::wstring script = base::StringPrintf(L"registerListenersForTab(%d)", 152 std::wstring script = base::StringPrintf(L"registerListenersForTab(%d)",
152 tab_id); 153 tab_id);
153 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 154 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
154 host_two->render_view_host(), L"", script, &result)); 155 host_two->render_view_host(), L"", script, &result));
155 EXPECT_TRUE(result); 156 EXPECT_TRUE(result);
156 157
157 // Removing the listeners from the first extension should leave the bridge 158 // Removing the listeners from the first extension should leave the bridge
158 // alive. 159 // alive.
159 result = false; 160 result = false;
160 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 161 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
161 host_one->render_view_host(), L"", L"unregisterListeners()", &result)); 162 host_one->render_view_host(), L"", L"unregisterListeners()", &result));
162 EXPECT_TRUE(result); 163 EXPECT_TRUE(result);
163 ASSERT_TRUE(devtools_manager->GetDevToolsClientHostFor( 164 ASSERT_TRUE(devtools_manager->GetDevToolsClientHostFor(
164 DevToolsAgentHostRegistry::GetDevToolsAgentHost( 165 DevToolsAgentHostRegistry::GetDevToolsAgentHost(
165 web_contents->GetRenderViewHost()))); 166 web_contents->GetRenderViewHost())));
166 167
167 // Removing the listeners from the second extension should tear the bridge 168 // Removing the listeners from the second extension should tear the bridge
168 // down. 169 // down.
169 result = false; 170 result = false;
170 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 171 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
171 host_two->render_view_host(), L"", L"unregisterListeners()", &result)); 172 host_two->render_view_host(), L"", L"unregisterListeners()", &result));
172 EXPECT_TRUE(result); 173 EXPECT_TRUE(result);
173 ASSERT_FALSE(devtools_manager->GetDevToolsClientHostFor( 174 ASSERT_FALSE(devtools_manager->GetDevToolsClientHostFor(
174 DevToolsAgentHostRegistry::GetDevToolsAgentHost( 175 DevToolsAgentHostRegistry::GetDevToolsAgentHost(
175 web_contents->GetRenderViewHost()))); 176 web_contents->GetRenderViewHost())));
176 } 177 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_browsertest.cc ('k') | chrome/browser/extensions/extension_dom_clipboard_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698