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

Side by Side Diff: chrome/browser/sync/net/network_change_notifier_io_thread_unittest.cc

Issue 2802015: Massively simplify the NetworkChangeNotifier infrastructure:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/net/network_change_notifier_io_thread.h"
6
7 #include "base/basictypes.h"
8 #include "base/message_loop.h"
9 #include "base/scoped_ptr.h"
10 #include "base/task.h"
11 #include "chrome/browser/io_thread.h"
12 #include "chrome/common/net/thread_blocker.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace {
16
17 class NetworkChangeNotifierIOThreadTest : public testing::Test {
18 protected:
19 NetworkChangeNotifierIOThreadTest() {}
20
21 virtual ~NetworkChangeNotifierIOThreadTest() {}
22
23 virtual void SetUp() {
24 // We need to set the message loop type explicitly because
25 // IOThread doesn't do it for us and the Linux
26 // NetworkChangeNotifier expects it.
27 base::Thread::Options options;
28 options.message_loop_type = MessageLoop::TYPE_IO;
29 EXPECT_TRUE(io_thread_.StartWithOptions(options));
30 thread_blocker_.reset(new chrome_common_net::ThreadBlocker(&io_thread_));
31 thread_blocker_->Block();
32 network_change_notifier_io_thread_.reset(
33 new NetworkChangeNotifierIOThread(&io_thread_));
34 }
35
36 virtual void TearDown() {
37 network_change_notifier_io_thread_.reset();
38 // Nothing should be posted on |io_thread_| at this point;
39 // otherwise, it may try to access
40 // network_change_notifier_io_thread_, which now NULL
41 thread_blocker_->Unblock();
42 thread_blocker_.reset();
43 io_thread_.Stop();
44 }
45
46 IOThread io_thread_;
47 scoped_ptr<chrome_common_net::ThreadBlocker> thread_blocker_;
48 scoped_ptr<NetworkChangeNotifierIOThread>
49 network_change_notifier_io_thread_;
50
51 private:
52 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierIOThreadTest);
53 };
54
55 void CompareNetworkChangeNotifiers(
56 IOThread* io_thread,
57 NetworkChangeNotifierIOThread* network_change_notifier_io_thread) {
58 EXPECT_EQ(network_change_notifier_io_thread->GetMessageLoop(),
59 MessageLoop::current());
60 EXPECT_EQ(io_thread->globals()->network_change_notifier.get(),
61 network_change_notifier_io_thread->GetNetworkChangeNotifier());
62 }
63
64 TEST_F(NetworkChangeNotifierIOThreadTest, Basic) {
65 EXPECT_EQ(io_thread_.message_loop(),
66 network_change_notifier_io_thread_->GetMessageLoop());
67 ASSERT_TRUE(
68 io_thread_.PostTask(ChromeThread::IO,
69 FROM_HERE,
70 NewRunnableFunction(
71 &CompareNetworkChangeNotifiers,
72 &io_thread_,
73 network_change_notifier_io_thread_.get())));
74 // Pump the thread to make sure the task we just posted is run
75 // before this test ends.
76 thread_blocker_->Unblock();
77 thread_blocker_->Block();
78 }
79
80 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698