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

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: Created 7 years, 9 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
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 NetworkSmsHandler::Initialize();
80 test_observer_.reset(new TestObserver());
81 NetworkSmsHandler::Get()->AddObserver(test_observer_.get());
82 NetworkSmsHandler::Get()->RequestUpdate(true);
83 message_loop_.RunUntilIdle();
69 } 84 }
70 85
71 virtual void TearDown() OVERRIDE { 86 virtual void TearDown() OVERRIDE {
72 DBusThreadManager::Shutdown(); 87 DBusThreadManager::Shutdown();
73 } 88 }
74 89
75 protected: 90 protected:
76 MessageLoopForUI message_loop_; 91 MessageLoopForUI message_loop_;
92 scoped_ptr<TestObserver> test_observer_;
77 }; 93 };
78 94
79 TEST_F(NetworkSmsHandlerTest, SmsHandlerDbusStub) { 95 TEST_F(NetworkSmsHandlerTest, SmsHandlerDbusStub) {
80 // Append '--sms-test-messages' to the command line to tell SMSClientStubImpl 96 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 97
96 // Test that no messages have been received yet 98 // Test that no messages have been received yet
97 const std::set<std::string>& messages(test_observer->messages()); 99 const std::set<std::string>& messages(test_observer_->messages());
98 // Note: The following string corresponds to values in 100 // Note: The following string corresponds to values in
99 // ModemMessagingClientStubImpl and SmsClientStubImpl. 101 // ModemMessagingClientStubImpl and SmsClientStubImpl.
100 // TODO(stevenjb): Use a TestInterface to set this up to remove dependency. 102 // TODO(stevenjb): Use a TestInterface to set this up to remove dependency.
101 const char kMessage1[] = "SMSClientStubImpl: Test Message: /SMS/0"; 103 const char kMessage1[] = "SMSClientStubImpl: Test Message: /SMS/0";
102 EXPECT_EQ(messages.find(kMessage1), messages.end()); 104 EXPECT_EQ(messages.find(kMessage1), messages.end());
103 105
104 // Test for messages delivered by signals. 106 // Test for messages delivered by signals.
105 test_observer->ClearMessages(); 107 test_observer_->ClearMessages();
106 sms_handler->RequestUpdate(); 108 NetworkSmsHandler::Get()->RequestUpdate(false);
107 message_loop_.RunUntilIdle(); 109 message_loop_.RunUntilIdle();
108 EXPECT_GE(test_observer->message_count(), 1); 110 EXPECT_GE(test_observer_->message_count(), 1);
109 EXPECT_NE(messages.find(kMessage1), messages.end()); 111 EXPECT_NE(messages.find(kMessage1), messages.end());
110 } 112 }
111 113
112 } // namespace chromeos 114 } // namespace chromeos
OLDNEW
« chromeos/network/network_sms_handler.cc ('K') | « chromeos/network/network_sms_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698