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

Side by Side Diff: content/browser/media/webrtc_identity_store_unittest.cc

Issue 15969025: Generates the DTLS identity in browser process and returns it to render process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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
OLDNEW
(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/threading/sequenced_worker_pool.h"
8 #include "content/browser/media/webrtc_identity_store.h"
9 #include "content/public/test/test_browser_thread_bundle.h"
10 #include "content/public/test/test_utils.h"
11 #include "googleurl/src/gurl.h"
12 #include "net/base/net_errors.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace content {
16
17 // TODO(jiayl): the tests fail on Android since the openssl version of
18 // CreateSelfSignedCert is not implemented. We should mock out this dependency
19 // and remove the if-defined.
20
21 #if !defined(OS_ANDROID)
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, &completed));
58 ASSERT_FALSE(cancel_callback.is_null());
59 sequenced_worker_pool_->FlushForTesting();
60 base::RunLoop().RunUntilIdle();
61 EXPECT_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, &completed));
72 ASSERT_FALSE(cancel_callback.is_null());
73 cancel_callback.Run();
74 sequenced_worker_pool_->FlushForTesting();
75 base::RunLoop().RunUntilIdle();
76 EXPECT_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, &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, &completed_2));
96 ASSERT_FALSE(cancel_callback_2.is_null());
97
98 sequenced_worker_pool_->FlushForTesting();
99 base::RunLoop().RunUntilIdle();
100 EXPECT_TRUE(completed_1);
101 EXPECT_TRUE(completed_2);
102 }
103 #endif
104 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/webrtc_identity_store.cc ('k') | content/browser/renderer_host/media/webrtc_identity_service_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698