Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / copresence / handlers / audio / audio_directive_list_unittest.cc
blobac7bd41752aa976f4c5e2a26c6c4fd222444da55
1 // Copyright 2014 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.
5 #include "components/copresence/handlers/audio/audio_directive_list.h"
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/message_loop/message_loop.h"
10 #include "testing/gmock/include/gmock/gmock.h"
12 using testing::IsNull;
14 namespace copresence {
16 static const int64 kTtl = 10;
18 const Directive CreateDirective(int64 ttl) {
19 Directive directive;
20 directive.set_ttl_millis(ttl);
21 return directive;
24 class AudioDirectiveListTest : public testing::Test {
25 public:
26 AudioDirectiveListTest() : directive_list_(new AudioDirectiveList) {}
28 protected:
29 base::MessageLoop message_loop_;
30 scoped_ptr<AudioDirectiveList> directive_list_;
33 TEST_F(AudioDirectiveListTest, Basic) {
34 EXPECT_THAT(directive_list_->GetActiveDirective(), IsNull());
36 directive_list_->AddDirective("op_id1", CreateDirective(kTtl));
37 directive_list_->AddDirective("op_id2", CreateDirective(kTtl * 3));
38 directive_list_->AddDirective("op_id3", CreateDirective(kTtl * 2));
39 EXPECT_EQ("op_id2", directive_list_->GetActiveDirective()->op_id);
41 directive_list_->RemoveDirective("op_id2");
42 EXPECT_EQ("op_id3", directive_list_->GetActiveDirective()->op_id);
45 TEST_F(AudioDirectiveListTest, AddDirectiveMultiple) {
46 directive_list_->AddDirective("op_id1", CreateDirective(kTtl));
47 directive_list_->AddDirective("op_id2", CreateDirective(kTtl * 2));
48 directive_list_->AddDirective("op_id3", CreateDirective(kTtl * 3 * 2));
49 directive_list_->AddDirective("op_id3", CreateDirective(kTtl * 3 * 3));
50 directive_list_->AddDirective("op_id4", CreateDirective(kTtl * 4));
52 EXPECT_EQ("op_id3", directive_list_->GetActiveDirective()->op_id);
53 directive_list_->RemoveDirective("op_id3");
54 EXPECT_EQ("op_id4", directive_list_->GetActiveDirective()->op_id);
55 directive_list_->RemoveDirective("op_id4");
56 EXPECT_EQ("op_id2", directive_list_->GetActiveDirective()->op_id);
57 directive_list_->RemoveDirective("op_id2");
58 EXPECT_EQ("op_id1", directive_list_->GetActiveDirective()->op_id);
59 directive_list_->RemoveDirective("op_id1");
60 EXPECT_THAT(directive_list_->GetActiveDirective(), IsNull());
63 TEST_F(AudioDirectiveListTest, RemoveDirectiveMultiple) {
64 directive_list_->AddDirective("op_id1", CreateDirective(kTtl));
65 directive_list_->AddDirective("op_id2", CreateDirective(kTtl * 2));
66 directive_list_->AddDirective("op_id3", CreateDirective(kTtl * 3));
67 directive_list_->AddDirective("op_id4", CreateDirective(kTtl * 4));
69 EXPECT_EQ("op_id4", directive_list_->GetActiveDirective()->op_id);
70 directive_list_->RemoveDirective("op_id4");
71 EXPECT_EQ("op_id3", directive_list_->GetActiveDirective()->op_id);
72 directive_list_->RemoveDirective("op_id3");
73 directive_list_->RemoveDirective("op_id3");
74 directive_list_->RemoveDirective("op_id3");
75 EXPECT_EQ("op_id2", directive_list_->GetActiveDirective()->op_id);
76 directive_list_->RemoveDirective("op_id2");
77 EXPECT_EQ("op_id1", directive_list_->GetActiveDirective()->op_id);
78 directive_list_->RemoveDirective("op_id1");
79 EXPECT_THAT(directive_list_->GetActiveDirective(), IsNull());
82 } // namespace copresence