diff options
author | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-26 07:28:34 +0000 |
---|---|---|
committer | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-26 07:28:34 +0000 |
commit | dd3eac25b4b1600058cfb88a45fdc3be5dbf52a6 (patch) | |
tree | cc7b3346263a97fc3edc901b8a4cfd552a5e7fb2 | |
parent | 036284dcd16ca460fac90dd9d26b80c32e879b05 (diff) | |
download | chromium_src-dd3eac25b4b1600058cfb88a45fdc3be5dbf52a6.zip chromium_src-dd3eac25b4b1600058cfb88a45fdc3be5dbf52a6.tar.gz chromium_src-dd3eac25b4b1600058cfb88a45fdc3be5dbf52a6.tar.bz2 |
fix unit tests
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1371 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/download_manager_unittest.cc | 1 | ||||
-rw-r--r-- | chrome/browser/printing/page_overlays_unittest.cc | 8 | ||||
-rw-r--r-- | chrome/common/ipc_sync_channel_unittest.cc | 79 | ||||
-rw-r--r-- | chrome/renderer/spellcheck_unittest.cc | 7 |
4 files changed, 79 insertions, 16 deletions
diff --git a/chrome/browser/download_manager_unittest.cc b/chrome/browser/download_manager_unittest.cc index 5699b1b..db509e0 100644 --- a/chrome/browser/download_manager_unittest.cc +++ b/chrome/browser/download_manager_unittest.cc @@ -29,6 +29,7 @@ class DownloadManagerTest : public testing::Test { protected: scoped_refptr<DownloadManager> download_manager_; + MessageLoopForUI message_loop_; DISALLOW_EVIL_CONSTRUCTORS(DownloadManagerTest); }; diff --git a/chrome/browser/printing/page_overlays_unittest.cc b/chrome/browser/printing/page_overlays_unittest.cc index 398b625..beca2ae 100644 --- a/chrome/browser/printing/page_overlays_unittest.cc +++ b/chrome/browser/printing/page_overlays_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/message_loop.h" #include "base/string_util.h" #include "chrome/browser/printing/page_overlays.h" #include "chrome/browser/printing/print_settings.h" @@ -12,6 +13,11 @@ namespace { +class PageOverlaysTest : public testing::Test { + private: + MessageLoop message_loop_; +}; + struct Keys { const wchar_t* key; const wchar_t* expected; @@ -46,7 +52,7 @@ class PagesSource : public printing::PrintedPagesSource { } // namespace -TEST(PageOverlaysTest, StringConversion) { +TEST_F(PageOverlaysTest, StringConversion) { printing::PageOverlays overlays; overlays.GetOverlay(printing::PageOverlays::LEFT, printing::PageOverlays::BOTTOM); diff --git a/chrome/common/ipc_sync_channel_unittest.cc b/chrome/common/ipc_sync_channel_unittest.cc index 3899204..11ba159 100644 --- a/chrome/common/ipc_sync_channel_unittest.cc +++ b/chrome/common/ipc_sync_channel_unittest.cc @@ -28,6 +28,13 @@ using namespace IPC; +namespace { + +class IPCSyncChannelTest : public testing::Test { + private: + MessageLoop message_loop_; +}; + // SyncChannel should only be used in child processes as we don't want to hang // the browser. So in the unit test we need to have a ChildProcess object. class TestProcess : public ChildProcess { @@ -202,8 +209,13 @@ void RunTest(std::vector<Worker*> workers) { TestProcess::GlobalCleanup(); } +} // namespace + //----------------------------------------------------------------------------- + +namespace { + class SimpleServer : public Worker { public: SimpleServer() : Worker(Channel::MODE_SERVER, "simpler_server") { } @@ -226,8 +238,10 @@ class SimpleClient : public Worker { } }; +} // namespace + // Tests basic synchronous call -TEST(IPCSyncChannelTest, Simple) { +TEST_F(IPCSyncChannelTest, Simple) { std::vector<Worker*> workers; workers.push_back(new SimpleServer()); workers.push_back(new SimpleClient()); @@ -236,6 +250,9 @@ TEST(IPCSyncChannelTest, Simple) { //----------------------------------------------------------------------------- + +namespace { + class DelayClient : public Worker { public: DelayClient() : Worker(Channel::MODE_CLIENT, "delay_client") { } @@ -247,8 +264,10 @@ class DelayClient : public Worker { } }; +} // namespace + // Tests that asynchronous replies work -TEST(IPCSyncChannelTest, DelayReply) { +TEST_F(IPCSyncChannelTest, DelayReply) { std::vector<Worker*> workers; workers.push_back(new SimpleServer()); workers.push_back(new DelayClient()); @@ -257,6 +276,9 @@ TEST(IPCSyncChannelTest, DelayReply) { //----------------------------------------------------------------------------- + +namespace { + class NoHangServer : public Worker { public: explicit NoHangServer(Event* got_first_reply) @@ -296,8 +318,10 @@ class NoHangClient : public Worker { Event* got_first_reply_; }; +} // namespace + // Tests that caller doesn't hang if receiver dies -TEST(IPCSyncChannelTest, NoHang) { +TEST_F(IPCSyncChannelTest, NoHang) { Event got_first_reply; std::vector<Worker*> workers; @@ -308,6 +332,9 @@ TEST(IPCSyncChannelTest, NoHang) { //----------------------------------------------------------------------------- + +namespace { + class RecursiveServer : public Worker { public: RecursiveServer() : Worker(Channel::MODE_SERVER, "recursive_server") { } @@ -335,8 +362,10 @@ class RecursiveClient : public Worker { } }; +} // namespace + // Tests that the caller unblocks to answer a sync message from the receiver. -TEST(IPCSyncChannelTest, Recursive) { +TEST_F(IPCSyncChannelTest, Recursive) { std::vector<Worker*> workers; workers.push_back(new RecursiveServer()); workers.push_back(new RecursiveClient()); @@ -345,6 +374,9 @@ TEST(IPCSyncChannelTest, Recursive) { //----------------------------------------------------------------------------- + +namespace { + class MultipleServer1 : public Worker { public: MultipleServer1() : Worker(L"test_channel1", Channel::MODE_SERVER) { } @@ -406,9 +438,11 @@ class MultipleClient2 : public Worker { Event *client1_msg_received_, *client1_can_reply_; }; +} // namespace + // Tests that multiple SyncObjects on the same listener thread can unblock each // other. -TEST(IPCSyncChannelTest, Multiple) { +TEST_F(IPCSyncChannelTest, Multiple) { std::vector<Worker*> workers; // A shared worker thread so that server1 and server2 run on one thread. @@ -443,6 +477,9 @@ TEST(IPCSyncChannelTest, Multiple) { //----------------------------------------------------------------------------- + +namespace { + class QueuedReplyServer1 : public Worker { public: QueuedReplyServer1() : Worker(L"test_channel1", Channel::MODE_SERVER) { } @@ -511,11 +548,13 @@ class QueuedReplyClient2 : public Worker { Event *client1_msg_received_; }; +} // namespace + // While a blocking send is in progress, the listener thread might answer other // synchronous messages. This tests that if during the response to another // message the reply to the original messages comes, it is queued up correctly // and the original Send is unblocked later. -TEST(IPCSyncChannelTest, QueuedReply) { +TEST_F(IPCSyncChannelTest, QueuedReply) { std::vector<Worker*> workers; // A shared worker thread so that server1 and server2 run on one thread. @@ -546,6 +585,9 @@ TEST(IPCSyncChannelTest, QueuedReply) { //----------------------------------------------------------------------------- + +namespace { + class BadServer : public Worker { public: BadServer() : Worker(Channel::MODE_SERVER, "simpler_server") { } @@ -573,8 +615,10 @@ class BadServer : public Worker { } }; +} // namespace + // Tests that if a message is not serialized correctly, the Send() will fail. -TEST(IPCSyncChannelTest, BadMessage) { +TEST_F(IPCSyncChannelTest, BadMessage) { std::vector<Worker*> workers; workers.push_back(new BadServer()); workers.push_back(new SimpleClient()); @@ -583,6 +627,9 @@ TEST(IPCSyncChannelTest, BadMessage) { //----------------------------------------------------------------------------- + +namespace { + class ChattyRecursiveClient : public Worker { public: ChattyRecursiveClient() : @@ -602,10 +649,12 @@ class ChattyRecursiveClient : public Worker { } }; +} // namespace + // Tests http://b/issue?id=1093251 - that sending lots of sync messages while // the receiver is waiting for a sync reply does not overflow the PostMessage // queue. -TEST(IPCSyncChannelTest, ChattyServer) { +TEST_F(IPCSyncChannelTest, ChattyServer) { std::vector<Worker*> workers; workers.push_back(new RecursiveServer()); workers.push_back(new ChattyRecursiveClient()); @@ -614,6 +663,9 @@ TEST(IPCSyncChannelTest, ChattyServer) { //------------------------------------------------------------------------------ + +namespace { + class TimeoutServer : public Worker { public: TimeoutServer(int timeout_ms, @@ -673,9 +725,11 @@ class UnresponsiveClient : public Worker { std::vector<bool> timeout_seq_; }; +} // namespace + // Tests that SendWithTimeout does not time-out if the response comes back fast // enough. -TEST(IPCSyncChannelTest, SendWithTimeoutOK) { +TEST_F(IPCSyncChannelTest, SendWithTimeoutOK) { std::vector<Worker*> workers; std::vector<bool> timeout_seq; timeout_seq.push_back(false); @@ -687,7 +741,7 @@ TEST(IPCSyncChannelTest, SendWithTimeoutOK) { } // Tests that SendWithTimeout does time-out. -TEST(IPCSyncChannelTest, SendWithTimeoutTimeout) { +TEST_F(IPCSyncChannelTest, SendWithTimeoutTimeout) { std::vector<Worker*> workers; std::vector<bool> timeout_seq; timeout_seq.push_back(true); @@ -699,7 +753,7 @@ TEST(IPCSyncChannelTest, SendWithTimeoutTimeout) { } // Sends some message that time-out and some that succeed. -TEST(IPCSyncChannelTest, SendWithTimeoutMixedOKAndTimeout) { +TEST_F(IPCSyncChannelTest, SendWithTimeoutMixedOKAndTimeout) { std::vector<Worker*> workers; std::vector<bool> timeout_seq; timeout_seq.push_back(true); @@ -710,5 +764,4 @@ TEST(IPCSyncChannelTest, SendWithTimeoutMixedOKAndTimeout) { workers.push_back(new TimeoutServer(100, timeout_seq)); workers.push_back(new UnresponsiveClient(timeout_seq)); RunTest(workers); -} - +}
\ No newline at end of file diff --git a/chrome/renderer/spellcheck_unittest.cc b/chrome/renderer/spellcheck_unittest.cc index b4c5dbc..61940cb 100644 --- a/chrome/renderer/spellcheck_unittest.cc +++ b/chrome/renderer/spellcheck_unittest.cc @@ -5,6 +5,7 @@ #include "webkit/glue/webkit_glue.h" #include "base/file_util.h" +#include "base/message_loop.h" #include "base/path_service.h" #include "chrome/browser/spellchecker.h" #include "chrome/common/chrome_paths.h" @@ -12,6 +13,8 @@ namespace { class SpellCheckTest : public testing::Test { + private: + MessageLoop message_loop_; }; } // namespace @@ -50,7 +53,7 @@ extern void InitHunspellWithFiles(FILE* file_aff_hunspell, // A test with a "[ROBUSTNESS]" mark shows it is a robustness test and it uses // grammartically incorrect string. // TODO(hbono): Please feel free to add more tests. -TEST(SpellCheckTest, SpellCheckStrings_EN_US) { +TEST_F(SpellCheckTest, SpellCheckStrings_EN_US) { static const struct { // A string to be tested. const wchar_t* input; @@ -269,7 +272,7 @@ TEST(SpellCheckTest, SpellCheckStrings_EN_US) { } -TEST(SpellCheckTest, SpellCheckSuggestions_EN_US) { +TEST_F(SpellCheckTest, SpellCheckSuggestions_EN_US) { static const struct { // A string to be tested. const wchar_t* input; |