1 // Copyright 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/ui/webui/identity_internals_ui_browsertest.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "base/time/time.h"
9 #include "chrome/browser/extensions/api/identity/extension_token_key.h"
10 #include "chrome/browser/extensions/api/identity/identity_api.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser.h"
16 const char kChromeWebStoreId
[] = "ahfgeienlihckogmohjhadlkjgocpleb";
17 const int kOneHour
= 3600;
20 IdentityInternalsUIBrowserTest::IdentityInternalsUIBrowserTest() {}
22 IdentityInternalsUIBrowserTest::~IdentityInternalsUIBrowserTest() {}
24 void IdentityInternalsUIBrowserTest::SetupTokenCache(int number_of_tokens
) {
25 for (int number
= 0; number
< number_of_tokens
; ++number
) {
26 const std::string token_number
= base::IntToString(number
);
27 std::string
token_id("token");
28 token_id
+= token_number
;
29 std::string
extension_id("extension");
30 extension_id
+= token_number
;
31 std::vector
<std::string
> scopes
;
32 scopes
.push_back(std::string("scope_1_") + token_number
);
33 scopes
.push_back(std::string("scope_2_") + token_number
);
34 AddTokenToCache(token_id
, extension_id
, scopes
, kOneHour
);
38 void IdentityInternalsUIBrowserTest::SetupTokenCacheWithStoreApp() {
39 std::vector
<std::string
> scopes
;
40 scopes
.push_back(std::string("store_scope1"));
41 scopes
.push_back(std::string("store_scope2"));
42 AddTokenToCache("store_token", kChromeWebStoreId
, scopes
, kOneHour
);
45 void IdentityInternalsUIBrowserTest::AddTokenToCache(
46 const std::string token_id
,
47 const std::string extension_id
,
48 const std::vector
<std::string
>& scopes
,
50 extensions::IdentityTokenCacheValue token_cache_value
=
51 extensions::IdentityTokenCacheValue(token_id
,
52 base::TimeDelta::FromSeconds(time_to_live
));
53 extensions::ExtensionTokenKey
key(
56 std::set
<std::string
>(scopes
.begin(), scopes
.end()));
57 extensions::IdentityAPI::GetFactoryInstance()->
58 GetForProfile(browser()->profile())->
59 SetCachedToken(key
, token_cache_value
);