| OLD | NEW |
| 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 Loading... |
| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 return test_name; | 223 return test_name; |
| 226 } | 224 } |
| 227 | 225 |
| 228 void PPAPITestBase::RunTestURL(const GURL& test_url) { | 226 void PPAPITestBase::RunTestURL(const GURL& test_url) { |
| 229 // See comment above TestingInstance in ppapi/test/testing_instance.h. | 227 // See comment above TestingInstance in ppapi/test/testing_instance.h. |
| 230 // Basically it sends messages using the DOM automation controller. The | 228 // Basically it sends messages using the DOM automation controller. The |
| 231 // value of "..." means it's still working and we should continue to wait, | 229 // value of "..." means it's still working and we should continue to wait, |
| 232 // any other value indicates completion (in this case it will start with | 230 // any other value indicates completion (in this case it will start with |
| 233 // "PASS" or "FAIL"). This keeps us from timing out on waits for long tests. | 231 // "PASS" or "FAIL"). This keeps us from timing out on waits for long tests. |
| 234 TestFinishObserver observer( | 232 TestFinishObserver observer( |
| 235 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), kTimeoutMs); | 233 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), |
| 234 base::TimeDelta::FromMilliseconds(kTimeoutMs)); |
| 236 | 235 |
| 237 ui_test_utils::NavigateToURL(browser(), test_url); | 236 ui_test_utils::NavigateToURL(browser(), test_url); |
| 238 | 237 |
| 239 ASSERT_TRUE(observer.WaitForFinish()) << "Test timed out."; | 238 ASSERT_TRUE(observer.WaitForFinish()) << "Test timed out."; |
| 240 | 239 |
| 241 EXPECT_STREQ("PASS", observer.result().c_str()); | 240 EXPECT_STREQ("PASS", observer.result().c_str()); |
| 242 } | 241 } |
| 243 | 242 |
| 244 void PPAPITestBase::RunHTTPTestServer( | 243 void PPAPITestBase::RunHTTPTestServer( |
| 245 const FilePath& document_root, | 244 const FilePath& document_root, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 } | 370 } |
| 372 | 371 |
| 373 // Append the correct mode and testcase string | 372 // Append the correct mode and testcase string |
| 374 std::string PPAPINaClTestDisallowedSockets::BuildQuery( | 373 std::string PPAPINaClTestDisallowedSockets::BuildQuery( |
| 375 const std::string& base, | 374 const std::string& base, |
| 376 const std::string& test_case) { | 375 const std::string& test_case) { |
| 377 return StringPrintf("%smode=nacl_newlib&testcase=%s", base.c_str(), | 376 return StringPrintf("%smode=nacl_newlib&testcase=%s", base.c_str(), |
| 378 test_case.c_str()); | 377 test_case.c_str()); |
| 379 } | 378 } |
| 380 | 379 |
| OLD | NEW |