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/command_line.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "chromeos/chromeos_switches.h" | 13 #include "chromeos/chromeos_switches.h" |
14 #include "chromeos/dbus/dbus_thread_manager.h" | 14 #include "chromeos/dbus/dbus_thread_manager.h" |
15 #include "chromeos/dbus/shill_device_client.h" | 15 #include "chromeos/dbus/shill_device_client.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "third_party/cros_system_api/dbus/service_constants.h" | 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
18 | 18 |
19 namespace chromeos { | 19 namespace chromeos { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 class TestObserver : public NetworkSmsHandler::Observer { | 23 class TestObserver : public NetworkSmsHandler::Observer { |
24 public: | 24 public: |
25 TestObserver() {} | 25 TestObserver() {} |
26 virtual ~TestObserver() {} | 26 virtual ~TestObserver() {} |
27 | 27 |
28 virtual void MessageReceived(const base::DictionaryValue& message) OVERRIDE { | 28 virtual void MessageReceived(const base::DictionaryValue& message) override { |
29 std::string text; | 29 std::string text; |
30 if (message.GetStringWithoutPathExpansion( | 30 if (message.GetStringWithoutPathExpansion( |
31 NetworkSmsHandler::kTextKey, &text)) { | 31 NetworkSmsHandler::kTextKey, &text)) { |
32 messages_.insert(text); | 32 messages_.insert(text); |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 void ClearMessages() { | 36 void ClearMessages() { |
37 messages_.clear(); | 37 messages_.clear(); |
38 } | 38 } |
39 | 39 |
40 int message_count() { return messages_.size(); } | 40 int message_count() { return messages_.size(); } |
41 const std::set<std::string>& messages() const { | 41 const std::set<std::string>& messages() const { |
42 return messages_; | 42 return messages_; |
43 } | 43 } |
44 | 44 |
45 private: | 45 private: |
46 std::set<std::string> messages_; | 46 std::set<std::string> messages_; |
47 }; | 47 }; |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 class NetworkSmsHandlerTest : public testing::Test { | 51 class NetworkSmsHandlerTest : public testing::Test { |
52 public: | 52 public: |
53 NetworkSmsHandlerTest() {} | 53 NetworkSmsHandlerTest() {} |
54 virtual ~NetworkSmsHandlerTest() {} | 54 virtual ~NetworkSmsHandlerTest() {} |
55 | 55 |
56 virtual void SetUp() OVERRIDE { | 56 virtual void SetUp() override { |
57 // Append '--sms-test-messages' to the command line to tell | 57 // Append '--sms-test-messages' to the command line to tell |
58 // SMSClientStubImpl to generate a series of test SMS messages. | 58 // SMSClientStubImpl to generate a series of test SMS messages. |
59 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 59 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
60 command_line->AppendSwitch(chromeos::switches::kSmsTestMessages); | 60 command_line->AppendSwitch(chromeos::switches::kSmsTestMessages); |
61 | 61 |
62 // Initialize DBusThreadManager with a stub implementation. | 62 // Initialize DBusThreadManager with a stub implementation. |
63 DBusThreadManager::Initialize(); | 63 DBusThreadManager::Initialize(); |
64 ShillDeviceClient::TestInterface* device_test = | 64 ShillDeviceClient::TestInterface* device_test = |
65 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); | 65 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); |
66 ASSERT_TRUE(device_test); | 66 ASSERT_TRUE(device_test); |
67 device_test->AddDevice("/org/freedesktop/ModemManager1/stub/0", | 67 device_test->AddDevice("/org/freedesktop/ModemManager1/stub/0", |
68 shill::kTypeCellular, | 68 shill::kTypeCellular, |
69 "stub_cellular_device2"); | 69 "stub_cellular_device2"); |
70 | 70 |
71 // This relies on the stub dbus implementations for ShillManagerClient, | 71 // This relies on the stub dbus implementations for ShillManagerClient, |
72 // ShillDeviceClient, GsmSMSClient, ModemMessagingClient and SMSClient. | 72 // ShillDeviceClient, GsmSMSClient, ModemMessagingClient and SMSClient. |
73 // Initialize a sms handler. The stub dbus clients will not send the | 73 // Initialize a sms handler. The stub dbus clients will not send the |
74 // first test message until RequestUpdate has been called. | 74 // first test message until RequestUpdate has been called. |
75 network_sms_handler_.reset(new NetworkSmsHandler()); | 75 network_sms_handler_.reset(new NetworkSmsHandler()); |
76 network_sms_handler_->Init(); | 76 network_sms_handler_->Init(); |
77 test_observer_.reset(new TestObserver()); | 77 test_observer_.reset(new TestObserver()); |
78 network_sms_handler_->AddObserver(test_observer_.get()); | 78 network_sms_handler_->AddObserver(test_observer_.get()); |
79 network_sms_handler_->RequestUpdate(true); | 79 network_sms_handler_->RequestUpdate(true); |
80 message_loop_.RunUntilIdle(); | 80 message_loop_.RunUntilIdle(); |
81 } | 81 } |
82 | 82 |
83 virtual void TearDown() OVERRIDE { | 83 virtual void TearDown() override { |
84 network_sms_handler_.reset(); | 84 network_sms_handler_.reset(); |
85 DBusThreadManager::Shutdown(); | 85 DBusThreadManager::Shutdown(); |
86 } | 86 } |
87 | 87 |
88 protected: | 88 protected: |
89 base::MessageLoopForUI message_loop_; | 89 base::MessageLoopForUI message_loop_; |
90 scoped_ptr<NetworkSmsHandler> network_sms_handler_; | 90 scoped_ptr<NetworkSmsHandler> network_sms_handler_; |
91 scoped_ptr<TestObserver> test_observer_; | 91 scoped_ptr<TestObserver> test_observer_; |
92 }; | 92 }; |
93 | 93 |
(...skipping 10 matching lines...) Expand all Loading... |
104 | 104 |
105 // Test for messages delivered by signals. | 105 // Test for messages delivered by signals. |
106 test_observer_->ClearMessages(); | 106 test_observer_->ClearMessages(); |
107 network_sms_handler_->RequestUpdate(false); | 107 network_sms_handler_->RequestUpdate(false); |
108 message_loop_.RunUntilIdle(); | 108 message_loop_.RunUntilIdle(); |
109 EXPECT_GE(test_observer_->message_count(), 1); | 109 EXPECT_GE(test_observer_->message_count(), 1); |
110 EXPECT_NE(messages.find(kMessage1), messages.end()); | 110 EXPECT_NE(messages.find(kMessage1), messages.end()); |
111 } | 111 } |
112 | 112 |
113 } // namespace chromeos | 113 } // namespace chromeos |
OLD | NEW |