OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 namespace extensions { | 40 namespace extensions { |
41 | 41 |
42 namespace { | 42 namespace { |
43 | 43 |
44 // The TestingFactoryFunction uses a BrowserContext as its context pointer. | 44 // The TestingFactoryFunction uses a BrowserContext as its context pointer. |
45 // But each BrowserContext is still associated with a unit test. | 45 // But each BrowserContext is still associated with a unit test. |
46 // So we store the StubModem created in each test. | 46 // So we store the StubModem created in each test. |
47 std::map<BrowserContext*, StubModem*> g_modems; | 47 std::map<BrowserContext*, StubModem*> g_modems; |
48 | 48 |
49 // Create a test AudioModemAPI and store the modem it uses. | 49 // Create a test AudioModemAPI and store the modem it uses. |
50 KeyedService* ApiFactoryFunction(BrowserContext* context) { | 50 scoped_ptr<KeyedService> ApiFactoryFunction(BrowserContext* context) { |
51 StubModem* modem = new StubModem; | 51 StubModem* modem = new StubModem; |
52 g_modems[context] = modem; | 52 g_modems[context] = modem; |
53 return new AudioModemAPI( | 53 return make_scoped_ptr(new AudioModemAPI( |
54 context, | 54 context, |
55 make_scoped_ptr<audio_modem::WhispernetClient>(new StubWhispernetClient), | 55 make_scoped_ptr<audio_modem::WhispernetClient>(new StubWhispernetClient), |
56 make_scoped_ptr<audio_modem::Modem>(modem)); | 56 make_scoped_ptr<audio_modem::Modem>(modem))); |
57 } | 57 } |
58 | 58 |
59 DictionaryValue* CreateParams(const std::string& audio_band) { | 59 DictionaryValue* CreateParams(const std::string& audio_band) { |
60 DictionaryValue* params = new DictionaryValue; | 60 DictionaryValue* params = new DictionaryValue; |
61 params->SetInteger("timeoutMillis", 60000); | 61 params->SetInteger("timeoutMillis", 60000); |
62 params->SetString("band", audio_band); | 62 params->SetString("band", audio_band); |
63 params->SetInteger("encoding.tokenLength", 4); | 63 params->SetInteger("encoding.tokenLength", 4); |
64 return params; | 64 return params; |
65 } | 65 } |
66 | 66 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 124 |
125 void ClearEventCallback() { | 125 void ClearEventCallback() { |
126 event_callback_.Reset(); | 126 event_callback_.Reset(); |
127 } | 127 } |
128 | 128 |
129 private: | 129 private: |
130 EventCallback event_callback_; | 130 EventCallback event_callback_; |
131 }; | 131 }; |
132 | 132 |
133 // StubEventRouter factory function | 133 // StubEventRouter factory function |
134 KeyedService* StubEventRouterFactoryFunction(content::BrowserContext* context) { | 134 scoped_ptr<KeyedService> StubEventRouterFactoryFunction( |
135 return new StubEventRouter(context); | 135 content::BrowserContext* context) { |
| 136 return make_scoped_ptr(new StubEventRouter(context)); |
136 } | 137 } |
137 | 138 |
138 } // namespace | 139 } // namespace |
139 | 140 |
140 class AudioModemApiUnittest : public ExtensionApiUnittest { | 141 class AudioModemApiUnittest : public ExtensionApiUnittest { |
141 public: | 142 public: |
142 AudioModemApiUnittest() {} | 143 AudioModemApiUnittest() {} |
143 ~AudioModemApiUnittest() override { | 144 ~AudioModemApiUnittest() override { |
144 for (const auto& events : events_by_extension_id_) { | 145 for (const auto& events : events_by_extension_id_) { |
145 for (const Event* event : events.second) | 146 for (const Event* event : events.second) |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 expected_token.reset(CreateReceivedToken("1234", "inaudible")); | 378 expected_token.reset(CreateReceivedToken("1234", "inaudible")); |
378 EXPECT_TRUE(ReceivedSingleToken( | 379 EXPECT_TRUE(ReceivedSingleToken( |
379 GetEventsForExtension("ext2")[1], expected_token.get())); | 380 GetEventsForExtension("ext2")[1], expected_token.get())); |
380 | 381 |
381 EXPECT_EQ("success", RunFunction<AudioModemStopReceiveFunction>( | 382 EXPECT_EQ("success", RunFunction<AudioModemStopReceiveFunction>( |
382 CreateList(new StringValue("inaudible")), GetExtension("ext2"))); | 383 CreateList(new StringValue("inaudible")), GetExtension("ext2"))); |
383 EXPECT_FALSE(GetModem()->IsRecording(INAUDIBLE)); | 384 EXPECT_FALSE(GetModem()->IsRecording(INAUDIBLE)); |
384 } | 385 } |
385 | 386 |
386 } // namespace extensions | 387 } // namespace extensions |
OLD | NEW |