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

Side by Side Diff: chrome/test/ppapi/ppapi_test.cc

Issue 10787010: Switch to TimeDelta interfaces in chrome automation test infrastructure. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase onto master. 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
« no previous file with comments | « chrome/test/ppapi/ppapi_test.h ('k') | chrome/test/pyautolib/pyautolib.h » ('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) 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 "chrome/test/ppapi/ppapi_test.h" 5 #include "chrome/test/ppapi/ppapi_test.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 bool IsAudioOutputAvailable() { 54 bool IsAudioOutputAvailable() {
55 scoped_ptr<media::AudioManager> audio_manager(media::AudioManager::Create()); 55 scoped_ptr<media::AudioManager> audio_manager(media::AudioManager::Create());
56 return audio_manager->HasAudioOutputDevices(); 56 return audio_manager->HasAudioOutputDevices();
57 } 57 }
58 58
59 } // namespace 59 } // namespace
60 60
61 PPAPITestBase::TestFinishObserver::TestFinishObserver( 61 PPAPITestBase::TestFinishObserver::TestFinishObserver(
62 RenderViewHost* render_view_host, 62 RenderViewHost* render_view_host,
63 int timeout_s) 63 base::TimeDelta timeout)
64 : finished_(false), 64 : finished_(false),
65 waiting_(false), 65 waiting_(false),
66 timeout_s_(timeout_s) { 66 timeout_(timeout) {
67 registrar_.Add(this, content::NOTIFICATION_DOM_OPERATION_RESPONSE, 67 registrar_.Add(this, content::NOTIFICATION_DOM_OPERATION_RESPONSE,
68 content::Source<RenderViewHost>(render_view_host)); 68 content::Source<RenderViewHost>(render_view_host));
69 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(timeout_s), 69 timer_.Start(FROM_HERE, timeout, this, &TestFinishObserver::OnTimeout);
70 this, &TestFinishObserver::OnTimeout);
71 } 70 }
72 71
73 bool PPAPITestBase::TestFinishObserver::WaitForFinish() { 72 bool PPAPITestBase::TestFinishObserver::WaitForFinish() {
74 if (!finished_) { 73 if (!finished_) {
75 waiting_ = true; 74 waiting_ = true;
76 ui_test_utils::RunMessageLoop(); 75 ui_test_utils::RunMessageLoop();
77 waiting_ = false; 76 waiting_ = false;
78 } 77 }
79 return finished_; 78 return finished_;
80 } 79 }
81 80
82 void PPAPITestBase::TestFinishObserver::Observe( 81 void PPAPITestBase::TestFinishObserver::Observe(
83 int type, 82 int type,
84 const content::NotificationSource& source, 83 const content::NotificationSource& source,
85 const content::NotificationDetails& details) { 84 const content::NotificationDetails& details) {
86 DCHECK(type == content::NOTIFICATION_DOM_OPERATION_RESPONSE); 85 DCHECK(type == content::NOTIFICATION_DOM_OPERATION_RESPONSE);
87 content::Details<DomOperationNotificationDetails> dom_op_details(details); 86 content::Details<DomOperationNotificationDetails> dom_op_details(details);
88 // We might receive responses for other script execution, but we only 87 // We might receive responses for other script execution, but we only
89 // care about the test finished message. 88 // care about the test finished message.
90 std::string response; 89 std::string response;
91 TrimString(dom_op_details->json, "\"", &response); 90 TrimString(dom_op_details->json, "\"", &response);
92 if (response == "...") { 91 if (response == "...") {
93 timer_.Stop(); 92 timer_.Stop();
94 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(timeout_s_), 93 timer_.Start(FROM_HERE, timeout_, this, &TestFinishObserver::OnTimeout);
95 this, &TestFinishObserver::OnTimeout);
96 } else { 94 } else {
97 result_ = response; 95 result_ = response;
98 finished_ = true; 96 finished_ = true;
99 if (waiting_) 97 if (waiting_)
100 MessageLoopForUI::current()->Quit(); 98 MessageLoopForUI::current()->Quit();
101 } 99 }
102 } 100 }
103 101
104 void PPAPITestBase::TestFinishObserver::Reset() { 102 void PPAPITestBase::TestFinishObserver::Reset() {
105 finished_ = false; 103 finished_ = false;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 return test_name; 222 return test_name;
225 } 223 }
226 224
227 void PPAPITestBase::RunTestURL(const GURL& test_url) { 225 void PPAPITestBase::RunTestURL(const GURL& test_url) {
228 // See comment above TestingInstance in ppapi/test/testing_instance.h. 226 // See comment above TestingInstance in ppapi/test/testing_instance.h.
229 // Basically it sends messages using the DOM automation controller. The 227 // Basically it sends messages using the DOM automation controller. The
230 // value of "..." means it's still working and we should continue to wait, 228 // value of "..." means it's still working and we should continue to wait,
231 // any other value indicates completion (in this case it will start with 229 // any other value indicates completion (in this case it will start with
232 // "PASS" or "FAIL"). This keeps us from timing out on waits for long tests. 230 // "PASS" or "FAIL"). This keeps us from timing out on waits for long tests.
233 TestFinishObserver observer( 231 TestFinishObserver observer(
234 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), kTimeoutMs); 232 chrome::GetActiveWebContents(browser())->GetRenderViewHost(),
233 base::TimeDelta::FromMilliseconds(kTimeoutMs));
235 234
236 ui_test_utils::NavigateToURL(browser(), test_url); 235 ui_test_utils::NavigateToURL(browser(), test_url);
237 236
238 ASSERT_TRUE(observer.WaitForFinish()) << "Test timed out."; 237 ASSERT_TRUE(observer.WaitForFinish()) << "Test timed out.";
239 238
240 EXPECT_STREQ("PASS", observer.result().c_str()); 239 EXPECT_STREQ("PASS", observer.result().c_str());
241 } 240 }
242 241
243 void PPAPITestBase::RunHTTPTestServer( 242 void PPAPITestBase::RunHTTPTestServer(
244 const FilePath& document_root, 243 const FilePath& document_root,
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 } 369 }
371 370
372 // Append the correct mode and testcase string 371 // Append the correct mode and testcase string
373 std::string PPAPINaClTestDisallowedSockets::BuildQuery( 372 std::string PPAPINaClTestDisallowedSockets::BuildQuery(
374 const std::string& base, 373 const std::string& base,
375 const std::string& test_case) { 374 const std::string& test_case) {
376 return StringPrintf("%smode=nacl_newlib&testcase=%s", base.c_str(), 375 return StringPrintf("%smode=nacl_newlib&testcase=%s", base.c_str(),
377 test_case.c_str()); 376 test_case.c_str());
378 } 377 }
379 378
OLDNEW
« no previous file with comments | « chrome/test/ppapi/ppapi_test.h ('k') | chrome/test/pyautolib/pyautolib.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698