Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / api / identity / identity_mint_queue_unittest.cc
blob8626ef9de3abc4fad1d80513b0659415722e17cd
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.
5 #include "chrome/browser/extensions/api/identity/identity_mint_queue.h"
7 #include <vector>
9 #include "base/memory/scoped_ptr.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 using extensions::ExtensionTokenKey;
14 using extensions::IdentityMintRequestQueue;
16 namespace {
18 class MockRequest : public extensions::IdentityMintRequestQueue::Request {
19 public:
20 MOCK_METHOD1(StartMintToken, void(IdentityMintRequestQueue::MintType));
23 scoped_ptr<ExtensionTokenKey> ExtensionIdToKey(
24 const std::string& extension_id) {
25 return scoped_ptr<ExtensionTokenKey>(new ExtensionTokenKey(
26 extension_id, "user_id", std::set<std::string>()));
29 } // namespace
31 TEST(IdentityMintQueueTest, SerialRequests) {
32 IdentityMintRequestQueue::MintType type =
33 IdentityMintRequestQueue::MINT_TYPE_NONINTERACTIVE;
34 IdentityMintRequestQueue queue;
35 scoped_ptr<ExtensionTokenKey> key(ExtensionIdToKey("ext_id"));
36 MockRequest request1;
37 MockRequest request2;
39 EXPECT_CALL(request1, StartMintToken(type)).Times(1);
40 queue.RequestStart(type, *key, &request1);
41 queue.RequestComplete(type, *key, &request1);
43 EXPECT_CALL(request2, StartMintToken(type)).Times(1);
44 queue.RequestStart(type, *key, &request2);
45 queue.RequestComplete(type, *key, &request2);
48 TEST(IdentityMintQueueTest, InteractiveType) {
49 IdentityMintRequestQueue::MintType type =
50 IdentityMintRequestQueue::MINT_TYPE_INTERACTIVE;
51 IdentityMintRequestQueue queue;
52 scoped_ptr<ExtensionTokenKey> key(ExtensionIdToKey("ext_id"));
53 MockRequest request1;
55 EXPECT_CALL(request1, StartMintToken(type)).Times(1);
56 queue.RequestStart(type, *key, &request1);
57 queue.RequestComplete(type, *key, &request1);
60 TEST(IdentityMintQueueTest, ParallelRequests) {
61 IdentityMintRequestQueue::MintType type =
62 IdentityMintRequestQueue::MINT_TYPE_NONINTERACTIVE;
63 IdentityMintRequestQueue queue;
64 scoped_ptr<ExtensionTokenKey> key(ExtensionIdToKey("ext_id"));
65 MockRequest request1;
66 MockRequest request2;
67 MockRequest request3;
69 EXPECT_CALL(request1, StartMintToken(type)).Times(1);
70 queue.RequestStart(type, *key, &request1);
71 queue.RequestStart(type, *key, &request2);
72 queue.RequestStart(type, *key, &request3);
74 EXPECT_CALL(request2, StartMintToken(type)).Times(1);
75 queue.RequestComplete(type, *key, &request1);
77 EXPECT_CALL(request3, StartMintToken(type)).Times(1);
78 queue.RequestComplete(type, *key, &request2);
80 queue.RequestComplete(type, *key, &request3);
83 TEST(IdentityMintQueueTest, ParallelRequestsFromTwoKeys) {
84 IdentityMintRequestQueue::MintType type =
85 IdentityMintRequestQueue::MINT_TYPE_NONINTERACTIVE;
86 IdentityMintRequestQueue queue;
87 scoped_ptr<ExtensionTokenKey> key1(ExtensionIdToKey("ext_id_1"));
88 scoped_ptr<ExtensionTokenKey> key2(ExtensionIdToKey("ext_id_2"));
89 MockRequest request1;
90 MockRequest request2;
92 EXPECT_CALL(request1, StartMintToken(type)).Times(1);
93 EXPECT_CALL(request2, StartMintToken(type)).Times(1);
94 queue.RequestStart(type, *key1, &request1);
95 queue.RequestStart(type, *key2, &request2);
97 queue.RequestComplete(type, *key1, &request1);
98 queue.RequestComplete(type, *key2, &request2);
101 TEST(IdentityMintQueueTest, Empty) {
102 IdentityMintRequestQueue::MintType type =
103 IdentityMintRequestQueue::MINT_TYPE_INTERACTIVE;
104 IdentityMintRequestQueue queue;
105 scoped_ptr<ExtensionTokenKey> key(ExtensionIdToKey("ext_id"));
106 MockRequest request1;
108 EXPECT_TRUE(queue.empty(type, *key));
109 EXPECT_CALL(request1, StartMintToken(type)).Times(1);
110 queue.RequestStart(type, *key, &request1);
111 EXPECT_FALSE(queue.empty(type, *key));
112 queue.RequestComplete(type, *key, &request1);
113 EXPECT_TRUE(queue.empty(type, *key));
116 TEST(IdentityMintQueueTest, Cancel) {
117 IdentityMintRequestQueue::MintType type =
118 IdentityMintRequestQueue::MINT_TYPE_NONINTERACTIVE;
119 IdentityMintRequestQueue queue;
120 scoped_ptr<ExtensionTokenKey> key(ExtensionIdToKey("ext_id"));
121 MockRequest request1;
122 MockRequest request2;
123 MockRequest request3;
124 MockRequest request4;
126 EXPECT_CALL(request1, StartMintToken(type)).Times(1);
127 queue.RequestStart(type, *key, &request1);
128 queue.RequestStart(type, *key, &request2);
129 queue.RequestStart(type, *key, &request3);
131 // request1: cancel the running head
132 // request3: cancel a request that is not the head
133 // request2: cancel the last request
134 // request4: cancel a request that is not in the queue at all
135 queue.RequestCancel(*key, &request1);
136 queue.RequestCancel(*key, &request3);
137 queue.RequestCancel(*key, &request2);
138 queue.RequestCancel(*key, &request4);