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

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

Issue 10539007: NetworkSmsHandler: Use the ModemManager1 dbus interfaces (Closed) Base URL: http://git.chromium.org/git/chromium/src@master
Patch Set: Only deliver messages after call to RequestUpdate Created 8 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
« 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>
8 #include <string>
9
7 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h" 11 #include "base/message_loop.h"
9 #include "chromeos/dbus/dbus_thread_manager.h" 12 #include "chromeos/dbus/dbus_thread_manager.h"
10 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
11 14
12 namespace chromeos { 15 namespace chromeos {
13 16
14 namespace { 17 namespace {
15 18
16 class TestObserver : public NetworkSmsHandler::Observer { 19 class TestObserver : public NetworkSmsHandler::Observer {
17 public: 20 public:
18 TestObserver() : message_count_(0) {} 21 TestObserver() {}
19 virtual ~TestObserver() {} 22 virtual ~TestObserver() {}
20 23
21 virtual void MessageReceived(const base::DictionaryValue& message) OVERRIDE { 24 virtual void MessageReceived(const base::DictionaryValue& message) OVERRIDE {
22 ++message_count_; 25 std::string text;
26 if (message.GetStringWithoutPathExpansion(
27 NetworkSmsHandler::kTextKey, &text)) {
28 messages_.insert(text);
29 }
23 } 30 }
24 31
25 int message_count() { return message_count_; } 32 void ClearMessages() {
33 messages_.clear();
34 }
35
36 int message_count() { return messages_.size(); }
37 const std::set<std::string>& messages() const {
38 return messages_;
39 }
26 40
27 private: 41 private:
28 int message_count_; 42 std::set<std::string> messages_;
29 }; 43 };
30 44
31 } // namespace 45 } // namespace
32 46
33 class NetworkSmsHandlerTest : public testing::Test { 47 class NetworkSmsHandlerTest : public testing::Test {
34 public: 48 public:
35 NetworkSmsHandlerTest() {} 49 NetworkSmsHandlerTest() {}
36 virtual ~NetworkSmsHandlerTest() {} 50 virtual ~NetworkSmsHandlerTest() {}
37 51
38 virtual void SetUp() OVERRIDE { 52 virtual void SetUp() OVERRIDE {
39 // Initialize DBusThreadManager with a stub implementation. 53 // Initialize DBusThreadManager with a stub implementation.
40 DBusThreadManager::InitializeWithStub(); 54 DBusThreadManager::InitializeWithStub();
41 } 55 }
42 56
43 virtual void TearDown() OVERRIDE { 57 virtual void TearDown() OVERRIDE {
44 DBusThreadManager::Shutdown(); 58 DBusThreadManager::Shutdown();
45 } 59 }
46 60
47 protected: 61 protected:
48 MessageLoopForUI message_loop_; 62 MessageLoopForUI message_loop_;
49 }; 63 };
50 64
51 TEST_F(NetworkSmsHandlerTest, SmsHandlerDbusStub) { 65 TEST_F(NetworkSmsHandlerTest, SmsHandlerDbusStub) {
52 // This relies on the stub dbus implementations for FlimflamManagerClient, 66 // This relies on the stub dbus implementations for FlimflamManagerClient,
53 // FlimflamDeviceClient, and GsmSMSClient. 67 // FlimflamDeviceClient, GsmSMSClient, ModemMessagingClient and SMSClient.
54 // Initialize a sms handler. The stub dbus clients will send the first test 68 // Initialize a sms handler. The stub dbus clients will not send the
55 // message when Gsm.SMS.List is called in NetworkSmsHandler::Init. 69 // first test message until RequestUpdate has been called.
56 scoped_ptr<NetworkSmsHandler> sms_handler(new NetworkSmsHandler()); 70 scoped_ptr<NetworkSmsHandler> sms_handler(new NetworkSmsHandler());
57 scoped_ptr<TestObserver> test_observer(new TestObserver()); 71 scoped_ptr<TestObserver> test_observer(new TestObserver());
58 sms_handler->AddObserver(test_observer.get()); 72 sms_handler->AddObserver(test_observer.get());
59 sms_handler->Init(); 73 sms_handler->Init();
60 message_loop_.RunAllPending(); 74 message_loop_.RunAllPending();
75 EXPECT_EQ(test_observer->message_count(), 0);
76
77 // Test that no messages have been received yet
78 const std::set<std::string>& messages(test_observer->messages());
79 // Note: The following string corresponds to values in
80 // ModemMessagingClientStubImpl and SmsClientStubImpl.
81 const char kMessage1[] = "SMSClientStubImpl: Test Message: /SMS/0";
82 EXPECT_EQ(messages.find(kMessage1), messages.end());
83
84 // Test for messages delivered by signals.
85 test_observer->ClearMessages();
61 sms_handler->RequestUpdate(); 86 sms_handler->RequestUpdate();
62 message_loop_.RunAllPending(); 87 message_loop_.RunAllPending();
63 EXPECT_GE(test_observer->message_count(), 1); 88 EXPECT_GE(test_observer->message_count(), 1);
89 EXPECT_NE(messages.find(kMessage1), messages.end());
64 } 90 }
65 91
66 } // namespace chromeos 92 } // 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