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

Side by Side Diff: components/dom_distiller/content/browser/test/dom_distiller_js_browsertest.cc

Issue 1123783002: Add ExecuteJavaScriptForTest and make all tests use it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/callback.h" 5 #include "base/callback.h"
6 #include "base/location.h" 6 #include "base/location.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 std::string()); 114 std::string());
115 url_loaded_runner.Run(); 115 url_loaded_runner.Run();
116 116
117 // Execute the JS to run the tests, and wait until it has finished. 117 // Execute the JS to run the tests, and wait until it has finished.
118 base::RunLoop run_loop; 118 base::RunLoop run_loop;
119 js_test_execution_done_callback_ = run_loop.QuitClosure(); 119 js_test_execution_done_callback_ = run_loop.QuitClosure();
120 // Add timeout in case JS Test execution fails. It is safe to call the 120 // Add timeout in case JS Test execution fails. It is safe to call the
121 // QuitClosure multiple times. 121 // QuitClosure multiple times.
122 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 122 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
123 FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(15)); 123 FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(15));
124 web_contents->GetMainFrame()->ExecuteJavaScript( 124 web_contents->GetMainFrame()->ExecuteJavaScriptForTests(
125 base::UTF8ToUTF16(kRunJsTestsJs), 125 base::UTF8ToUTF16(kRunJsTestsJs),
126 base::Bind(&DomDistillerJsTest::OnJsTestExecutionDone, 126 base::Bind(&DomDistillerJsTest::OnJsTestExecutionDone,
127 base::Unretained(this))); 127 base::Unretained(this)));
128 run_loop.Run(); 128 run_loop.Run();
129 129
130 // By now either the timeout has triggered, or there should be a result. 130 // By now either the timeout has triggered, or there should be a result.
131 ASSERT_TRUE(result_ != NULL) << "No result found. Timeout?"; 131 ASSERT_TRUE(result_ != NULL) << "No result found. Timeout?";
132 132
133 // Convert to dictionary and parse the results. 133 // Convert to dictionary and parse the results.
134 const base::DictionaryValue* dict; 134 const base::DictionaryValue* dict;
(...skipping 24 matching lines...) Expand all
159 // Only print the log if there was an error. 159 // Only print the log if there was an error.
160 if (!success) { 160 if (!success) {
161 ASSERT_TRUE(dict->HasKey("log")); 161 ASSERT_TRUE(dict->HasKey("log"));
162 std::string console_log; 162 std::string console_log;
163 ASSERT_TRUE(dict->GetString("log", &console_log)); 163 ASSERT_TRUE(dict->GetString("log", &console_log));
164 VLOG(0) << "Console log:\n" << console_log; 164 VLOG(0) << "Console log:\n" << console_log;
165 } 165 }
166 } 166 }
167 167
168 } // namespace dom_distiller 168 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698