summaryrefslogtreecommitdiffstats
path: root/ios/web/test
diff options
context:
space:
mode:
authorsdefresne <sdefresne@chromium.org>2014-12-16 05:29:05 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-16 13:29:26 +0000
commitf0f8a40b5c6e6bf1c94b65e0688a0cf42f894c75 (patch)
treec381e26b0dccd1c69d69f13e61d5ed9c8f95c6f7 /ios/web/test
parent7cc973648e29e9dbd286d76790dd16d8259abcd9 (diff)
downloadchromium_src-f0f8a40b5c6e6bf1c94b65e0688a0cf42f894c75.zip
chromium_src-f0f8a40b5c6e6bf1c94b65e0688a0cf42f894c75.tar.gz
chromium_src-f0f8a40b5c6e6bf1c94b65e0688a0cf42f894c75.tar.bz2
Introduce web::TestWebThread class
Introduce web::TestWebThread that delegate to content::BrowserThread so that ios/web has content free public API to write tests that uses web::WebThread. BUG=442292 Review URL: https://codereview.chromium.org/803163002 Cr-Commit-Position: refs/heads/master@{#308575}
Diffstat (limited to 'ios/web/test')
-rw-r--r--ios/web/test/test_web_thread.cc65
1 files changed, 65 insertions, 0 deletions
diff --git a/ios/web/test/test_web_thread.cc b/ios/web/test/test_web_thread.cc
new file mode 100644
index 0000000..6318e71
--- /dev/null
+++ b/ios/web/test/test_web_thread.cc
@@ -0,0 +1,65 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/web/public/test/test_web_thread.h"
+
+#include "content/public/test/test_browser_thread.h"
+#include "ios/web/web_thread_impl.h"
+
+namespace web {
+
+// TestWebThreadImpl delegates to content::TestBrowserThread until WebThread
+// implementation is indenpendent of content::BrowserThread.
+class TestWebThreadImpl {
+ public:
+ TestWebThreadImpl(WebThread::ID identifier)
+ : test_browser_thread_(BrowserThreadIDFromWebThreadID(identifier)) {}
+
+ TestWebThreadImpl(WebThread::ID identifier, base::MessageLoop* message_loop)
+ : test_browser_thread_(BrowserThreadIDFromWebThreadID(identifier),
+ message_loop) {}
+
+ ~TestWebThreadImpl() { Stop(); }
+
+ bool Start() { return test_browser_thread_.Start(); }
+
+ bool StartIOThread() { return test_browser_thread_.StartIOThread(); }
+
+ void Stop() { test_browser_thread_.Stop(); }
+
+ bool IsRunning() { return test_browser_thread_.IsRunning(); }
+
+ private:
+ content::TestBrowserThread test_browser_thread_;
+};
+
+TestWebThread::TestWebThread(WebThread::ID identifier)
+ : impl_(new TestWebThreadImpl(identifier)) {
+}
+
+TestWebThread::TestWebThread(WebThread::ID identifier,
+ base::MessageLoop* message_loop)
+ : impl_(new TestWebThreadImpl(identifier, message_loop)) {
+}
+
+TestWebThread::~TestWebThread() {
+}
+
+bool TestWebThread::Start() {
+ return impl_->Start();
+}
+
+bool TestWebThread::StartIOThread() {
+ return impl_->StartIOThread();
+}
+
+void TestWebThread::Stop() {
+ impl_->Stop();
+}
+
+bool TestWebThread::IsRunning() {
+ return impl_->IsRunning();
+}
+
+} // namespace web