OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/bind.h" | |
6 #include "base/memory/scoped_ptr.h" | |
7 #include "base/message_loop.h" | |
8 #include "base/run_loop.h" | |
9 #include "base/synchronization/waitable_event.h" | |
10 #include "base/threading/sequenced_worker_pool.h" | |
11 #include "content/browser/media/webrtc_identity_store.h" | |
12 #include "content/browser/renderer_host/media/webrtc_identity_service_host.h" | |
13 #include "content/common/media/webrtc_identity_messages.h" | |
14 #include "content/public/test/test_browser_thread_bundle.h" | |
15 #include "content/public/test/test_utils.h" | |
16 #include "googleurl/src/gurl.h" | |
17 #include "net/base/net_errors.h" | |
18 #include "testing/gtest/include/gtest/gtest.h" | |
19 | |
20 namespace content { | |
21 | |
22 class WebRTCIdentityStoreTest : public testing::Test { | |
23 public: | |
24 WebRTCIdentityStoreTest() | |
25 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | |
26 sequenced_worker_pool_( | |
27 new base::SequencedWorkerPool(3, "WebRTCIdentityStoreTest")), | |
28 webrtc_identity_store_(new WebRTCIdentityStore()) { | |
29 webrtc_identity_store_->SetTaskRunnerForTesting(sequenced_worker_pool_); | |
30 } | |
31 | |
32 virtual ~WebRTCIdentityStoreTest() { sequenced_worker_pool_->Shutdown(); } | |
33 | |
34 protected: | |
35 TestBrowserThreadBundle browser_thread_bundle_; | |
36 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; | |
37 scoped_ptr<WebRTCIdentityStore> webrtc_identity_store_; | |
38 }; | |
39 | |
40 static void OnRequestCompleted(bool* completed, | |
41 int error, | |
42 const std::string& certificate, | |
43 const std::string& private_key) { | |
44 ASSERT_EQ(net::OK, error); | |
45 ASSERT_NE("", certificate); | |
46 ASSERT_NE("", private_key); | |
47 *completed = true; | |
48 } | |
49 | |
50 TEST_F(WebRTCIdentityStoreTest, RequestIdentity) { | |
51 bool completed = false; | |
52 base::Closure cancel_callback = | |
53 webrtc_identity_store_->RequestIdentity( | |
54 GURL("http://google.com"), | |
55 "a", | |
56 "b", | |
57 base::Bind(&OnRequestCompleted, base::Unretained(&completed))); | |
Ami GONE FROM CHROMIUM
2013/06/27 21:30:32
Is Unretained really necessary here??
jiayl
2013/06/27 21:48:28
I thought it won't compile without it because it w
Ami GONE FROM CHROMIUM
2013/06/27 22:13:08
That concern only applies to the |this| argument b
| |
58 ASSERT_FALSE(cancel_callback.is_null()); | |
59 sequenced_worker_pool_->FlushForTesting(); | |
60 base::RunLoop().RunUntilIdle(); | |
61 EXPECT_EQ(true, completed); | |
62 } | |
63 | |
64 TEST_F(WebRTCIdentityStoreTest, CancelRequest) { | |
65 bool completed = false; | |
66 base::Closure cancel_callback = | |
67 webrtc_identity_store_->RequestIdentity( | |
68 GURL("http://google.com"), | |
69 "a", | |
70 "b", | |
71 base::Bind(&OnRequestCompleted, base::Unretained(&completed))); | |
72 ASSERT_FALSE(cancel_callback.is_null()); | |
73 cancel_callback.Run(); | |
74 sequenced_worker_pool_->FlushForTesting(); | |
75 base::RunLoop().RunUntilIdle(); | |
76 EXPECT_EQ(false, completed); | |
77 } | |
78 | |
79 TEST_F(WebRTCIdentityStoreTest, MultipleRequests) { | |
80 bool completed_1 = false; | |
81 bool completed_2 = false; | |
82 base::Closure cancel_callback_1 = | |
83 webrtc_identity_store_->RequestIdentity( | |
84 GURL("http://foo.com"), | |
85 "a", | |
86 "b", | |
87 base::Bind(&OnRequestCompleted, base::Unretained(&completed_1))); | |
88 ASSERT_FALSE(cancel_callback_1.is_null()); | |
89 | |
90 base::Closure cancel_callback_2 = | |
91 webrtc_identity_store_->RequestIdentity( | |
92 GURL("http://bar.com"), | |
93 "a", | |
94 "b", | |
95 base::Bind(&OnRequestCompleted, base::Unretained(&completed_2))); | |
96 ASSERT_FALSE(cancel_callback_2.is_null()); | |
97 | |
98 sequenced_worker_pool_->FlushForTesting(); | |
99 base::RunLoop().RunUntilIdle(); | |
100 EXPECT_EQ(true, completed_1); | |
101 EXPECT_EQ(true, completed_2); | |
102 } | |
103 | |
104 } // namespace content | |
OLD | NEW |