OLD | NEW |
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/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "chromeos/chromeos_switches.h" |
12 #include "chromeos/dbus/dbus_thread_manager.h" | 14 #include "chromeos/dbus/dbus_thread_manager.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
14 | 16 |
15 namespace chromeos { | 17 namespace chromeos { |
16 | 18 |
17 namespace { | 19 namespace { |
18 | 20 |
19 class TestObserver : public NetworkSmsHandler::Observer { | 21 class TestObserver : public NetworkSmsHandler::Observer { |
20 public: | 22 public: |
21 TestObserver() {} | 23 TestObserver() {} |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 58 |
57 virtual void TearDown() OVERRIDE { | 59 virtual void TearDown() OVERRIDE { |
58 DBusThreadManager::Shutdown(); | 60 DBusThreadManager::Shutdown(); |
59 } | 61 } |
60 | 62 |
61 protected: | 63 protected: |
62 MessageLoopForUI message_loop_; | 64 MessageLoopForUI message_loop_; |
63 }; | 65 }; |
64 | 66 |
65 TEST_F(NetworkSmsHandlerTest, SmsHandlerDbusStub) { | 67 TEST_F(NetworkSmsHandlerTest, SmsHandlerDbusStub) { |
| 68 // Append '--sms-test-messages' to the command line to tell SMSClientStubImpl |
| 69 // to generate a series of test SMS messages. |
| 70 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 71 command_line->AppendSwitch(chromeos::switches::kSmsTestMessages); |
| 72 |
66 // This relies on the stub dbus implementations for FlimflamManagerClient, | 73 // This relies on the stub dbus implementations for FlimflamManagerClient, |
67 // FlimflamDeviceClient, GsmSMSClient, ModemMessagingClient and SMSClient. | 74 // FlimflamDeviceClient, GsmSMSClient, ModemMessagingClient and SMSClient. |
68 // Initialize a sms handler. The stub dbus clients will not send the | 75 // Initialize a sms handler. The stub dbus clients will not send the |
69 // first test message until RequestUpdate has been called. | 76 // first test message until RequestUpdate has been called. |
70 scoped_ptr<NetworkSmsHandler> sms_handler(new NetworkSmsHandler()); | 77 scoped_ptr<NetworkSmsHandler> sms_handler(new NetworkSmsHandler()); |
71 scoped_ptr<TestObserver> test_observer(new TestObserver()); | 78 scoped_ptr<TestObserver> test_observer(new TestObserver()); |
72 sms_handler->AddObserver(test_observer.get()); | 79 sms_handler->AddObserver(test_observer.get()); |
73 sms_handler->Init(); | 80 sms_handler->Init(); |
74 message_loop_.RunAllPending(); | 81 message_loop_.RunAllPending(); |
75 EXPECT_EQ(test_observer->message_count(), 0); | 82 EXPECT_EQ(test_observer->message_count(), 0); |
76 | 83 |
77 // Test that no messages have been received yet | 84 // Test that no messages have been received yet |
78 const std::set<std::string>& messages(test_observer->messages()); | 85 const std::set<std::string>& messages(test_observer->messages()); |
79 // Note: The following string corresponds to values in | 86 // Note: The following string corresponds to values in |
80 // ModemMessagingClientStubImpl and SmsClientStubImpl. | 87 // ModemMessagingClientStubImpl and SmsClientStubImpl. |
81 const char kMessage1[] = "SMSClientStubImpl: Test Message: /SMS/0"; | 88 const char kMessage1[] = "SMSClientStubImpl: Test Message: /SMS/0"; |
82 EXPECT_EQ(messages.find(kMessage1), messages.end()); | 89 EXPECT_EQ(messages.find(kMessage1), messages.end()); |
83 | 90 |
84 // Test for messages delivered by signals. | 91 // Test for messages delivered by signals. |
85 test_observer->ClearMessages(); | 92 test_observer->ClearMessages(); |
86 sms_handler->RequestUpdate(); | 93 sms_handler->RequestUpdate(); |
87 message_loop_.RunAllPending(); | 94 message_loop_.RunAllPending(); |
88 EXPECT_GE(test_observer->message_count(), 1); | 95 EXPECT_GE(test_observer->message_count(), 1); |
89 EXPECT_NE(messages.find(kMessage1), messages.end()); | 96 EXPECT_NE(messages.find(kMessage1), messages.end()); |
90 } | 97 } |
91 | 98 |
92 } // namespace chromeos | 99 } // namespace chromeos |
OLD | NEW |