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

Side by Side Diff: chromeos/network/network_sms_handler_unittest.cc

Issue 12669004: Fix NetworkSmsHandler to observe Manager and improve API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 4 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
« no previous file with comments | « chromeos/network/network_sms_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chromeos/network/network_sms_handler.h" 5 #include "chromeos/network/network_sms_handler.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 }; 48 };
49 49
50 } // namespace 50 } // namespace
51 51
52 class NetworkSmsHandlerTest : public testing::Test { 52 class NetworkSmsHandlerTest : public testing::Test {
53 public: 53 public:
54 NetworkSmsHandlerTest() {} 54 NetworkSmsHandlerTest() {}
55 virtual ~NetworkSmsHandlerTest() {} 55 virtual ~NetworkSmsHandlerTest() {}
56 56
57 virtual void SetUp() OVERRIDE { 57 virtual void SetUp() OVERRIDE {
58 // Append '--sms-test-messages' to the command line to tell
59 // SMSClientStubImpl to generate a series of test SMS messages.
60 CommandLine* command_line = CommandLine::ForCurrentProcess();
61 command_line->AppendSwitch(chromeos::switches::kSmsTestMessages);
62
58 // Initialize DBusThreadManager with a stub implementation. 63 // Initialize DBusThreadManager with a stub implementation.
59 DBusThreadManager::InitializeWithStub(); 64 DBusThreadManager::InitializeWithStub();
60 ShillManagerClient::TestInterface* manager_test = 65 ShillManagerClient::TestInterface* manager_test =
61 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); 66 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface();
62 ASSERT_TRUE(manager_test); 67 ASSERT_TRUE(manager_test);
63 manager_test->AddDevice("stub_cellular_device2"); 68 manager_test->AddDevice("stub_cellular_device2");
64 ShillDeviceClient::TestInterface* device_test = 69 ShillDeviceClient::TestInterface* device_test =
65 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); 70 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface();
66 ASSERT_TRUE(device_test); 71 ASSERT_TRUE(device_test);
67 device_test->AddDevice("stub_cellular_device2", flimflam::kTypeCellular, 72 device_test->AddDevice("stub_cellular_device2", flimflam::kTypeCellular,
68 "/org/freedesktop/ModemManager1/stub/0"); 73 "/org/freedesktop/ModemManager1/stub/0");
74
75 // This relies on the stub dbus implementations for ShillManagerClient,
76 // ShillDeviceClient, GsmSMSClient, ModemMessagingClient and SMSClient.
77 // Initialize a sms handler. The stub dbus clients will not send the
78 // first test message until RequestUpdate has been called.
79 network_sms_handler_.reset(new NetworkSmsHandler());
80 network_sms_handler_->Init();
81 test_observer_.reset(new TestObserver());
82 network_sms_handler_->AddObserver(test_observer_.get());
83 network_sms_handler_->RequestUpdate(true);
84 message_loop_.RunUntilIdle();
69 } 85 }
70 86
71 virtual void TearDown() OVERRIDE { 87 virtual void TearDown() OVERRIDE {
88 network_sms_handler_.reset();
72 DBusThreadManager::Shutdown(); 89 DBusThreadManager::Shutdown();
73 } 90 }
74 91
75 protected: 92 protected:
76 base::MessageLoopForUI message_loop_; 93 base::MessageLoopForUI message_loop_;
94 scoped_ptr<NetworkSmsHandler> network_sms_handler_;
95 scoped_ptr<TestObserver> test_observer_;
77 }; 96 };
78 97
79 TEST_F(NetworkSmsHandlerTest, SmsHandlerDbusStub) { 98 TEST_F(NetworkSmsHandlerTest, SmsHandlerDbusStub) {
80 // Append '--sms-test-messages' to the command line to tell SMSClientStubImpl 99 EXPECT_EQ(test_observer_->message_count(), 0);
81 // to generate a series of test SMS messages.
82 CommandLine* command_line = CommandLine::ForCurrentProcess();
83 command_line->AppendSwitch(chromeos::switches::kSmsTestMessages);
84
85 // This relies on the stub dbus implementations for ShillManagerClient,
86 // ShillDeviceClient, GsmSMSClient, ModemMessagingClient and SMSClient.
87 // Initialize a sms handler. The stub dbus clients will not send the
88 // first test message until RequestUpdate has been called.
89 scoped_ptr<NetworkSmsHandler> sms_handler(new NetworkSmsHandler());
90 scoped_ptr<TestObserver> test_observer(new TestObserver());
91 sms_handler->AddObserver(test_observer.get());
92 sms_handler->Init();
93 message_loop_.RunUntilIdle();
94 EXPECT_EQ(test_observer->message_count(), 0);
95 100
96 // Test that no messages have been received yet 101 // Test that no messages have been received yet
97 const std::set<std::string>& messages(test_observer->messages()); 102 const std::set<std::string>& messages(test_observer_->messages());
98 // Note: The following string corresponds to values in 103 // Note: The following string corresponds to values in
99 // ModemMessagingClientStubImpl and SmsClientStubImpl. 104 // ModemMessagingClientStubImpl and SmsClientStubImpl.
100 // TODO(stevenjb): Use a TestInterface to set this up to remove dependency. 105 // TODO(stevenjb): Use a TestInterface to set this up to remove dependency.
101 const char kMessage1[] = "SMSClientStubImpl: Test Message: /SMS/0"; 106 const char kMessage1[] = "SMSClientStubImpl: Test Message: /SMS/0";
102 EXPECT_EQ(messages.find(kMessage1), messages.end()); 107 EXPECT_EQ(messages.find(kMessage1), messages.end());
103 108
104 // Test for messages delivered by signals. 109 // Test for messages delivered by signals.
105 test_observer->ClearMessages(); 110 test_observer_->ClearMessages();
106 sms_handler->RequestUpdate(); 111 network_sms_handler_->RequestUpdate(false);
107 message_loop_.RunUntilIdle(); 112 message_loop_.RunUntilIdle();
108 EXPECT_GE(test_observer->message_count(), 1); 113 EXPECT_GE(test_observer_->message_count(), 1);
109 EXPECT_NE(messages.find(kMessage1), messages.end()); 114 EXPECT_NE(messages.find(kMessage1), messages.end());
110 } 115 }
111 116
112 } // namespace chromeos 117 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_sms_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698