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/debugger/devtools_sanity_unittest.cc

Issue 328029: DevTools: fix and enable DevToolsExtensionDebugTest.TestContentScriptIsPresen... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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
« no previous file with comments | « no previous file | chrome/test/data/devtools/page_with_content_script.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/browser/browser.h" 6 #include "chrome/browser/browser.h"
7 #include "chrome/browser/debugger/devtools_client_host.h" 7 #include "chrome/browser/debugger/devtools_client_host.h"
8 #include "chrome/browser/debugger/devtools_manager.h" 8 #include "chrome/browser/debugger/devtools_manager.h"
9 #include "chrome/browser/debugger/devtools_window.h" 9 #include "chrome/browser/debugger/devtools_window.h"
10 #include "chrome/browser/extensions/extensions_service.h" 10 #include "chrome/browser/extensions/extensions_service.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 devtools_manager->UnregisterDevToolsClientHostFor(inspected_rvh_); 129 devtools_manager->UnregisterDevToolsClientHostFor(inspected_rvh_);
130 BrowserClosedObserver close_observer(browser); 130 BrowserClosedObserver close_observer(browser);
131 } 131 }
132 132
133 TabContents* client_contents_; 133 TabContents* client_contents_;
134 DevToolsWindow* window_; 134 DevToolsWindow* window_;
135 RenderViewHost* inspected_rvh_; 135 RenderViewHost* inspected_rvh_;
136 }; 136 };
137 137
138 138
139 class CancelableQuitTask : public Task {
140 public:
141 CancelableQuitTask(const std::string& timeout_message)
142 : timeout_message_(timeout_message),
143 cancelled_(false) {
144 }
145
146 void cancel() {
147 cancelled_ = true;
148 }
149
150 virtual void Run() {
151 if (cancelled_) {
152 return;
153 }
154 FAIL() << timeout_message_;
155 MessageLoop::current()->Quit();
156 }
157
158 private:
159 std::string timeout_message_;
160 bool cancelled_;
161 };
162
163
139 // Base class for DevTools tests that test devtools functionality for 164 // Base class for DevTools tests that test devtools functionality for
140 // extensions and content scripts. 165 // extensions and content scripts.
141 class DevToolsExtensionDebugTest : public DevToolsSanityTest, 166 class DevToolsExtensionDebugTest : public DevToolsSanityTest,
142 public NotificationObserver { 167 public NotificationObserver {
143 public: 168 public:
144 DevToolsExtensionDebugTest() : DevToolsSanityTest() { 169 DevToolsExtensionDebugTest() : DevToolsSanityTest() {
145 PathService::Get(chrome::DIR_TEST_DATA, &test_extensions_dir_); 170 PathService::Get(chrome::DIR_TEST_DATA, &test_extensions_dir_);
146 test_extensions_dir_ = test_extensions_dir_.AppendASCII("devtools"); 171 test_extensions_dir_ = test_extensions_dir_.AppendASCII("devtools");
147 test_extensions_dir_ = test_extensions_dir_.AppendASCII("extensions"); 172 test_extensions_dir_ = test_extensions_dir_.AppendASCII("extensions");
148 } 173 }
149 174
150 protected: 175 protected:
151 // Load an extention from test\data\devtools\extensions\<extension_name> 176 // Load an extention from test\data\devtools\extensions\<extension_name>
152 void LoadExtension(const char* extension_name) { 177 void LoadExtension(const char* extension_name) {
153 FilePath path = test_extensions_dir_.AppendASCII(extension_name); 178 FilePath path = test_extensions_dir_.AppendASCII(extension_name);
154 ASSERT_TRUE(LoadExtensionFromPath(path)) << "Failed to load extension."; 179 ASSERT_TRUE(LoadExtensionFromPath(path)) << "Failed to load extension.";
155 } 180 }
156 181
157 private: 182 private:
158 bool LoadExtensionFromPath(const FilePath& path) { 183 bool LoadExtensionFromPath(const FilePath& path) {
159 ExtensionsService* service = browser()->profile()->GetExtensionsService(); 184 ExtensionsService* service = browser()->profile()->GetExtensionsService();
160 size_t num_before = service->extensions()->size(); 185 size_t num_before = service->extensions()->size();
161 { 186 {
162 NotificationRegistrar registrar; 187 NotificationRegistrar registrar;
163 registrar.Add(this, NotificationType::EXTENSION_LOADED, 188 registrar.Add(this, NotificationType::EXTENSION_LOADED,
164 NotificationService::AllSources()); 189 NotificationService::AllSources());
165 MessageLoop::current()->PostDelayedTask( 190 CancelableQuitTask* delayed_quit =
166 FROM_HERE, new MessageLoop::QuitTask, 5*1000); 191 new CancelableQuitTask("Extension load timed out.");
192 MessageLoop::current()->PostDelayedTask(FROM_HERE, delayed_quit,
193 4*1000);
167 service->LoadExtension(path); 194 service->LoadExtension(path);
168 ui_test_utils::RunMessageLoop(); 195 ui_test_utils::RunMessageLoop();
196 delayed_quit->cancel();
169 } 197 }
170 size_t num_after = service->extensions()->size(); 198 size_t num_after = service->extensions()->size();
171 return (num_after == (num_before + 1)); 199 if (num_after != (num_before + 1))
200 return false;
201
202 return WaitForExtensionHostsToLoad();
203 }
204
205 bool WaitForExtensionHostsToLoad() {
206 // Wait for all the extension hosts that exist to finish loading.
207 // NOTE: This assumes that the extension host list is not changing while
208 // this method is running.
209
210 NotificationRegistrar registrar;
211 registrar.Add(this, NotificationType::EXTENSION_HOST_DID_STOP_LOADING,
212 NotificationService::AllSources());
213 CancelableQuitTask* delayed_quit =
214 new CancelableQuitTask("Extension host load timed out.");
215 MessageLoop::current()->PostDelayedTask(FROM_HERE, delayed_quit,
216 4*1000);
217
218 ExtensionProcessManager* manager =
219 browser()->profile()->GetExtensionProcessManager();
220 for (ExtensionProcessManager::const_iterator iter = manager->begin();
221 iter != manager->end();) {
222 if ((*iter)->did_stop_loading())
223 ++iter;
224 else
225 ui_test_utils::RunMessageLoop();
226 }
227
228 delayed_quit->cancel();
229 return true;
172 } 230 }
173 231
174 void Observe(NotificationType type, 232 void Observe(NotificationType type,
175 const NotificationSource& source, 233 const NotificationSource& source,
176 const NotificationDetails& details) { 234 const NotificationDetails& details) {
177 switch (type.value) { 235 switch (type.value) {
178 case NotificationType::EXTENSION_LOADED: 236 case NotificationType::EXTENSION_LOADED:
179 std::cout << "Got EXTENSION_LOADED notification.\n"; 237 case NotificationType::EXTENSION_HOST_DID_STOP_LOADING:
180 MessageLoopForUI::current()->Quit(); 238 MessageLoopForUI::current()->Quit();
181 break; 239 break;
182
183 default: 240 default:
184 NOTREACHED(); 241 NOTREACHED();
185 break; 242 break;
186 } 243 }
187 } 244 }
188 245
189 FilePath test_extensions_dir_; 246 FilePath test_extensions_dir_;
190 }; 247 };
191 248
192 249
(...skipping 27 matching lines...) Expand all
220 RunTest("testProfilerTab", kJsPage); 277 RunTest("testProfilerTab", kJsPage);
221 } 278 }
222 279
223 // Tests scripts panel showing. 280 // Tests scripts panel showing.
224 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestShowScriptsTab) { 281 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestShowScriptsTab) {
225 RunTest("testShowScriptsTab", kDebuggerTestPage); 282 RunTest("testShowScriptsTab", kDebuggerTestPage);
226 } 283 }
227 284
228 // Tests that a content script is in the scripts list. 285 // Tests that a content script is in the scripts list.
229 IN_PROC_BROWSER_TEST_F(DevToolsExtensionDebugTest, 286 IN_PROC_BROWSER_TEST_F(DevToolsExtensionDebugTest,
230 DISABLED_TestContentScriptIsPresent) { 287 TestContentScriptIsPresent) {
231 LoadExtension("simple_content_script"); 288 LoadExtension("simple_content_script");
232 RunTest("testContentScriptIsPresent", kPageWithContentScript); 289 RunTest("testContentScriptIsPresent", kPageWithContentScript);
233 } 290 }
234 291
235 // Tests that scripts are not duplicated after Scripts Panel switch. 292 // Tests that scripts are not duplicated after Scripts Panel switch.
236 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, 293 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest,
237 TestNoScriptDuplicatesOnPanelSwitch) { 294 TestNoScriptDuplicatesOnPanelSwitch) {
238 RunTest("testNoScriptDuplicatesOnPanelSwitch", kDebuggerTestPage); 295 RunTest("testNoScriptDuplicatesOnPanelSwitch", kDebuggerTestPage);
239 } 296 }
240 297
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestConsoleLog) { 355 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestConsoleLog) {
299 RunTest("testConsoleLog", kConsoleTestPage); 356 RunTest("testConsoleLog", kConsoleTestPage);
300 } 357 }
301 358
302 // Tests eval global values. 359 // Tests eval global values.
303 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestEvalGlobal) { 360 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestEvalGlobal) {
304 RunTest("testEvalGlobal", kEvalTestPage); 361 RunTest("testEvalGlobal", kEvalTestPage);
305 } 362 }
306 363
307 } // namespace 364 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/devtools/page_with_content_script.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698