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

Unified Diff: chrome_frame/test/chrome_frame_test_utils.h

Issue 10007043: Attempt to fix ChromeFrameTestWithWebServer tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: take snapshots on timeout Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome_frame/test/chrome_frame_test_utils.h
diff --git a/chrome_frame/test/chrome_frame_test_utils.h b/chrome_frame/test/chrome_frame_test_utils.h
index 8affbd56431ce148784bc06078eb508b7923ff18..ba1a310ecc04d6247df3d7dc26e5d4861cad9e7e 100644
--- a/chrome_frame/test/chrome_frame_test_utils.h
+++ b/chrome_frame/test/chrome_frame_test_utils.h
@@ -13,13 +13,16 @@
#include <string>
#include "base/basictypes.h"
+#include "base/cancelable_callback.h"
#include "base/compiler_specific.h"
+#include "base/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/process_util.h"
#include "base/test/test_reg_util_win.h"
#include "base/win/registry.h"
#include "base/win/scoped_comptr.h"
+#include "chrome/test/base/ui_test_utils.h"
#include "chrome_frame/chrome_tab.h"
#include "chrome_frame/test/simulate_input.h"
#include "chrome_frame/test_utils.h"
@@ -36,6 +39,8 @@ interface IWebBrowser2;
namespace chrome_frame_test {
+FilePath GetSnapshotDirectory();
+
int CloseVisibleWindowsOnAllThreads(HANDLE process);
base::ProcessHandle LaunchIE(const std::wstring& url);
@@ -188,13 +193,23 @@ class HungCOMCallDetector
// We need a UI message loop in the main thread.
class TimedMsgLoop {
public:
- TimedMsgLoop() : quit_loop_invoked_(false) {
+ TimedMsgLoop() : snapshot_on_timeout_(false), quit_loop_invoked_(false) {
+ }
+
+ void set_snapshot_on_timeout(bool value) {
+ snapshot_on_timeout_ = value;
}
void RunFor(int seconds) {
- QuitAfter(seconds);
quit_loop_invoked_ = false;
+ if (snapshot_on_timeout_)
+ timeout_closure_.Reset(base::Bind(&TimedMsgLoop::SnapshotAndQuit));
+ else
+ timeout_closure_.Reset(MessageLoop::QuitClosure());
+ loop_.PostDelayedTask(
+ FROM_HERE, timeout_closure_.callback(), 1000 * seconds);
loop_.MessageLoop::Run();
+ timeout_closure_.Cancel();
}
void PostTask(const tracked_objects::Location& from_here,
@@ -212,6 +227,7 @@ class TimedMsgLoop {
}
void QuitAfter(int seconds) {
+ timeout_closure_.Cancel();
quit_loop_invoked_ = true;
loop_.PostDelayedTask(
FROM_HERE, MessageLoop::QuitClosure(), 1000 * seconds);
@@ -221,8 +237,34 @@ class TimedMsgLoop {
return !quit_loop_invoked_;
}
+ void RunAllPending() {
+ loop_.RunAllPending();
+ }
+
private:
+ static void SnapshotAndQuit() {
+ FilePath snapshot;
+ if (ui_test_utils::SaveScreenSnapshotToDirectory(GetSnapshotDirectory(),
+ &snapshot)) {
+ testing::UnitTest* unit_test = testing::UnitTest::GetInstance();
+ const testing::TestInfo* test_info = unit_test->current_test_info();
+ std::string name;
+ if (test_info != NULL) {
+ name.append(test_info->test_case_name())
+ .append(1, '.')
+ .append(test_info->name());
+ } else {
+ name = "unknown test";
+ }
+ LOG(ERROR) << name << " timed out. Screen snapshot saved to "
+ << snapshot.value();
+ }
+ MessageLoop::current()->Quit();
+ }
+
MessageLoopForUI loop_;
+ base::CancelableClosure timeout_closure_;
+ bool snapshot_on_timeout_;
bool quit_loop_invoked_;
};

Powered by Google App Engine
This is Rietveld 408576698